Package generic_fns :: Module grace
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.grace

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  from os import system 
 24  from re import match 
 25   
 26   
27 -class Grace:
28 - def __init__(self, relax):
29 """Operations, functions, etc common to the different model-free analysis methods.""" 30 31 self.relax = relax
32 33
34 - def data(self):
35 """Write the data into the grace file.""" 36 37 # Determine the graph type. 38 errors = 0 39 for i in xrange(len(self.relax.data.res[self.run])): 40 # Remap the data structure 'self.relax.data.res[self.run][i]'. 41 data = self.relax.data.res[self.run][i] 42 43 # Get the value and error. 44 value, error = self.return_value(self.run, i, self.data_type) 45 46 # Skip the data if there is no value. 47 if value == None: 48 continue 49 50 # Test if there is an error. 51 if error != None: 52 errors = 1 53 break 54 55 if errors: 56 graph_type = 'xydy' 57 else: 58 graph_type = 'xy' 59 60 61 # Graph 0, set 0. 62 self.file.write("@target G0.S0\n") 63 self.file.write("@type " + graph_type + "\n") 64 65 # Loop over the sequence. 66 for i in xrange(len(self.relax.data.res[self.run])): 67 # Remap the data structure 'self.relax.data.res[self.run][i]'. 68 data = self.relax.data.res[self.run][i] 69 70 # Get the value and error. 71 value, error = self.return_value(self.run, i, self.data_type) 72 73 # Skip the data if there is no value. 74 if value == None: 75 continue 76 77 # Graph type xy. 78 if graph_type == 'xy': 79 # Write the data. 80 self.file.write("%-5i%-30s\n" % (data.num, `value`)) 81 82 # Graph type xydy. 83 elif graph_type == 'xydy': 84 # Missing error. 85 if error == None: 86 error = 0.0 87 88 # Write the data. 89 self.file.write("%-5i%-30s%-30s\n" % (data.num, `value`, `error`)) 90 91 # End of graph 0, set 0. 92 self.file.write("&\n")
93 94
95 - def header(self):
96 """Write the grace header.""" 97 98 # Grace version number (presumably for grace to interpret the header info). 99 self.file.write("@version 50114\n") 100 101 # Graph G0. 102 self.file.write("@with g0\n") 103 104 # X axis start and end. 105 self.file.write("@ world xmin " + `self.relax.data.res[self.run][0].num - 1` + "\n") 106 self.file.write("@ world xmax " + `self.relax.data.res[self.run][-1].num + 1` + "\n") 107 108 # Y axis start and end. 109 min_value = 0.0 110 max_value = -1e99 111 for i in xrange(len(self.relax.data.res[self.run])): 112 # Remap the data structure 'self.relax.data.res[self.run][i]'. 113 data = self.relax.data.res[self.run][i] 114 115 # Get the value and error. 116 value, error = self.return_value(self.run, i, self.data_type) 117 118 # Skip the data if there is no value. 119 if value == None: 120 continue 121 122 # Max check. 123 if value > max_value: 124 max_value = value 125 126 # Min check. 127 if value < min_value: 128 min_value = value 129 130 self.file.write("@ world ymin " + `min_value - min_value * 0.05` + "\n") 131 self.file.write("@ world ymax " + `max_value + max_value * 0.05` + "\n") 132 133 # Residue specific ticks. 134 self.file.write("@ xaxis tick major 10\n") 135 self.file.write("@ xaxis tick major size 0.48\n") 136 self.file.write("@ xaxis tick major linewidth 0.5\n") 137 self.file.write("@ xaxis tick minor linewidth 0.5\n") 138 self.file.write("@ xaxis tick minor size 0.24\n") 139 self.file.write("@ xaxis ticklabel char size 0.79\n") 140 141 # Data specific ticks. 142 self.file.write("@ yaxis tick major size 0.48\n") 143 self.file.write("@ yaxis tick major linewidth 0.5\n") 144 self.file.write("@ yaxis tick minor linewidth 0.5\n") 145 self.file.write("@ yaxis tick minor size 0.24\n") 146 self.file.write("@ yaxis ticklabel char size 0.79\n") 147 148 # Frame. 149 self.file.write("@ frame linewidth 0.5\n") 150 151 # Symbols. 152 self.file.write("@ s0 symbol 1\n") 153 self.file.write("@ s0 symbol size 0.35\n") 154 self.file.write("@ s0 symbol fill pattern 1\n") 155 self.file.write("@ s0 symbol linewidth 0.5\n") 156 self.file.write("@ s0 line linestyle 0\n") 157 158 # Error bars. 159 self.file.write("@ s0 errorbar size 0.5\n") 160 self.file.write("@ s0 errorbar linewidth 0.5\n") 161 self.file.write("@ s0 errorbar riser linewidth 0.5\n")
162 163
164 - def view(self, run=None, data_type=None, file=None, dir=None, grace_exe='xmgrace', force=0):
165 """Function for running Grace.""" 166 167 # Write the grace file (if the run in not None). 168 if run != None: 169 self.write(run=run, data_type=data_type, file=file, dir=dir, force=force) 170 171 # File path. 172 self.file_path = self.relax.IO.file_path(file, dir) 173 174 # Run Grace. 175 system(grace_exe + " " + self.file_path + " &")
176 177
178 - def write(self, run=None, data_type=None, file=None, dir=None, force=0):
179 """Function for writing data to a file.""" 180 181 # Arguments. 182 self.run = run 183 self.data_type = data_type 184 185 # Test if the run exists. 186 if not self.run in self.relax.data.run_names: 187 raise RelaxNoRunError, self.run 188 189 # Test if the sequence data is loaded. 190 if not self.relax.data.res.has_key(self.run): 191 raise RelaxNoSequenceError, self.run 192 193 # Open the file for writing. 194 self.file = self.relax.IO.open_write_file(file, dir, force) 195 196 # Function type. 197 function_type = self.relax.data.run_types[self.relax.data.run_names.index(run)] 198 199 # Specific value and error returning function. 200 self.return_value = self.relax.specific_setup.setup('return_value', function_type) 201 202 # Write the header. 203 self.header() 204 205 # Write the data. 206 self.data() 207 208 # Close the file. 209 self.file.close()
210