mailr7876 - /1.3/test_suite/system_tests/scripts/latex_mf_table.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 21, 2008 - 11:50:
Author: bugman
Date: Tue Oct 21 11:50:12 2008
New Revision: 7876

URL: http://svn.gna.org/viewcvs/relax?rev=7876&view=rev
Log:
Fixes for the model-free LaTeX table generation sample script.

These fixes do not affect the system test result yet - as LaTeX compilation 
will not be part of the
test suite - but fix the LaTeX compilation.  These will be ported back to the 
sample script.

The docstring has been modified as the booktabs package is needed for this 
table.  The '&'
characters in the spin_id string have been escaped to avoid this being 
interpreted as a column
separator.  The 'Residue' column has been renamed to 'Spin'.  And finally 
missing model-free
parameter errors can be handled.


Modified:
    1.3/test_suite/system_tests/scripts/latex_mf_table.py

Modified: 1.3/test_suite/system_tests/scripts/latex_mf_table.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/system_tests/scripts/latex_mf_table.py?rev=7876&r1=7875&r2=7876&view=diff
==============================================================================
--- 1.3/test_suite/system_tests/scripts/latex_mf_table.py (original)
+++ 1.3/test_suite/system_tests/scripts/latex_mf_table.py Tue Oct 21 11:50:12 
2008
@@ -22,10 +22,12 @@
 
 """Script for converting the model-free results into a LaTeX table.
 
-The longtable LaTeX package is necessary to allow the table to span multiple 
pages.  The package
-can be included using the LaTeX command:
+The longtable LaTeX package is necessary to allow the table to span multiple 
pages.  This table also
+uses the more elegant booktable format.  The packages can be included using 
the LaTeX preamble
+commands:
 
 \usepackage{longtable}
+\usepackage{booktabs}
 
 Assuming the file name 'results.tex', the resultant table can be placed into 
a LaTeX manuscript
 with the command:
@@ -34,6 +36,7 @@
 """
 
 # Python module imports.
+from string import replace
 import sys
 
 # relax module imports.
@@ -101,7 +104,7 @@
 
         # Headings.
         self.file.write("% Headings.\n")
-        self.file.write("Residue &%\n")
+        self.file.write("Spin &%\n")
         self.file.write("Model &%\n")
         self.file.write("\multicolumn{2}{c}{$S^2$} &%\n")
         self.file.write("\multicolumn{2}{c}{$S^2_f$} &%\n")
@@ -137,12 +140,25 @@
         # End the font size.
         self.file.write("\\end{small}\n")
 
+        # Terminate the document.
+        self.file.write("\\end{document}\n")
+
 
     def latex_header(self):
         """Create the LaTeX header.
 
         This function will need to be heavily modified to suit your needs.
         """
+
+        # Document class - to allow for compilation tests.
+        self.file.write("\documentclass[a4paper, 12pt, twoside]{book}\n\n")
+
+        # Package inclusion.
+        self.file.write("\usepackage{longtable}\n")
+        self.file.write("\usepackage{booktabs}\n\n")
+
+        # Start the document.
+        self.file.write("\\begin{document}\n\n")
 
         # Font size.
         self.file.write("% Small font.\n")
@@ -173,6 +189,7 @@
         # Loop over the spin systems.
         for spin, spin_id in spin_loop(return_id=True):
             # The spin ID string.
+            spin_id = replace(spin_id, '&', '\&')
             self.file.write("%-20s & " % (spin_id))
 
             # The spin is not selected.
@@ -184,37 +201,55 @@
 
             # S2.
             if spin.s2 == None:
-                self.file.write("%21s & " % "\\multicolumn{2}{c}{}")
-            else:
-                self.file.write("%9.3f & %9.3f & " % (spin.s2, spin.s2_err))
+                self.file.write("%25s & " % "\\multicolumn{2}{c}{}")
+            elif not hasattr(spin, 's2_err'):
+                self.file.write("%24s & " % "\\multicolumn{2}{c}{%.3f}" % 
spin.s2)
+            else:
+                self.file.write("%11.3f & %11.3f & " % (spin.s2, 
spin.s2_err))
 
             # S2f.
             if spin.s2f == None:
-                self.file.write("%21s & " % "\\multicolumn{2}{c}{}")
-            else:
-                self.file.write("%9.3f & %9.3f & " % (spin.s2f, 
spin.s2f_err))
+                self.file.write("%25s & " % "\\multicolumn{2}{c}{}")
+            elif not hasattr(spin, 's2f_err'):
+                self.file.write("%24s & " % "\\multicolumn{2}{c}{%.3f}" % 
spin.s2f)
+            else:
+                self.file.write("%11.3f & %11.3f & " % (spin.s2f, 
spin.s2f_err))
 
             # Fast motion (te < 100 ps or tf).
             if spin.te != None and spin.te <= 100 * 1e-12:
-                self.file.write("%9.2f & %9.2f & " % (spin.te * 1e12, 
spin.te_err * 1e12))
+                if not hasattr(spin, 'te_err'):
+                    self.file.write("%27s & " % ("\\multicolumn{2}{c}{%.2f}" 
% (spin.te * 1e12)))
+                else:
+                    self.file.write("%12.2f & %12.2f & " % (spin.te * 1e12, 
spin.te_err * 1e12))
             elif spin.tf != None:
-                self.file.write("%9.2f & %9.2f & " % (spin.tf * 1e12, 
spin.tf_err * 1e12))
-            else:
-                self.file.write("%21s & " % "\\multicolumn{2}{c}{}")
+                if not hasattr(spin, 'tf_err'):
+                    self.file.write("%27s & " % ("\\multicolumn{2}{c}{%.2f}" 
% (spin.tf * 1e12)))
+                else:
+                    self.file.write("%12.2f & %12.2f & " % (spin.tf * 1e12, 
spin.tf_err * 1e12))
+            else:
+                self.file.write("%27s & " % "\\multicolumn{2}{c}{}")
 
             # Slow motion (te > 100 ps or ts).
             if spin.te != None and spin.te > 100 * 1e-12:
-                self.file.write("%9.2f & %9.2f & " % (spin.te * 1e12, 
spin.te_err * 1e12))
+                if not hasattr(spin, 'te_err'):
+                    self.file.write("%27s & " % ("\\multicolumn{2}{c}{%.2f}" 
% (spin.te * 1e12)))
+                else:
+                    self.file.write("%12.2f & %12.2f & " % (spin.te * 1e12, 
spin.te_err * 1e12))
             elif spin.ts != None:
-                self.file.write("%9.2f & %9.2f & " % (spin.ts * 1e12, 
spin.ts_err * 1e12))
-            else:
-                self.file.write("%21s & " % "\\multicolumn{2}{c}{}")
+                if not hasattr(spin, 'ts_err'):
+                    self.file.write("%27s & " % ("\\multicolumn{2}{c}{%.2f}" 
% (spin.ts * 1e12)))
+                else:
+                    self.file.write("%12.2f & %12.2f & " % (spin.ts * 1e12, 
spin.ts_err * 1e12))
+            else:
+                self.file.write("%27s & " % "\\multicolumn{2}{c}{}")
 
             # Rex.
             if spin.rex == None:
-                self.file.write("%21s \\\\\n" % "\\multicolumn{2}{c}{}")
-            else:
-                self.file.write("%9.3f & %9.3f \\\\\n" % (spin.rex * (2.0 * 
pi * spin.frq[0])**2, spin.rex_err * (2.0 * pi * spin.frq[0])**2))
+                self.file.write("%27s \\\\\n" % "\\multicolumn{2}{c}{}")
+            elif not hasattr(spin, 'rex_err'):
+                self.file.write("%27s \\\\\n" % ("\\multicolumn{2}{c}{%.3f}" 
% (spin.rex * (2.0 * pi * spin.frq[0])**2)))
+            else:
+                self.file.write("%12.3f & %12.3f \\\\\n" % (spin.rex * (2.0 
* pi * spin.frq[0])**2, spin.rex_err * (2.0 * pi * spin.frq[0])**2))
 
         # Start a new line.
         self.file.write("\n")




Related Messages


Powered by MHonArc, Updated Tue Oct 21 12:00:04 2008