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

Source Code for Module prompt.grace

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2005 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  import sys 
 24   
 25  from doc_string import regexp_doc 
 26  import help 
 27  from generic_fns.minimise import Minimise 
 28  from specific_fns.model_free import Model_free 
 29  from specific_fns.jw_mapping import Jw_mapping 
 30  from specific_fns.noe import Noe 
 31   
 32   
33 -class Grace:
34 - def __init__(self, relax):
35 # Help. 36 self.__relax_help__ = \ 37 """Class for interfacing with Grace.""" 38 39 # Add the generic help string. 40 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help 41 42 # Place relax in the class namespace. 43 self.__relax__ = relax
44 45
46 - def view(self, file=None, dir='grace', grace_exe='xmgrace'):
47 """Function for running Grace. 48 49 Keyword Arguments 50 ~~~~~~~~~~~~~~~~~ 51 52 file: The name of the file. 53 54 dir: The directory name. 55 56 grace_exe: The Grace executable file. 57 58 59 Description 60 ~~~~~~~~~~~ 61 62 This function can be used to execute Grace to view the specified file the Grace '.agr' file 63 and the execute Grace. If the directory name is set to None, the file will be assumed to be 64 in the current working directory. 65 66 67 Examples 68 ~~~~~~~~ 69 70 To view the file 's2.agr' in the directory 'grace', type: 71 72 relax> grace.view(file='s2.agr') 73 relax> grace.view(file='s2.agr', dir='grace') 74 """ 75 76 # Function intro text. 77 if self.__relax__.interpreter.intro: 78 text = sys.ps3 + "grace.view(" 79 text = text + "file=" + `file` 80 text = text + ", dir=" + `dir` 81 text = text + ", grace_exe=" + `grace_exe` + ")" 82 print text 83 84 # File. 85 if type(file) != str: 86 raise RelaxStrError, ('file name', file) 87 88 # Directory. 89 if dir != None and type(dir) != str: 90 raise RelaxNoneStrError, ('directory name', dir) 91 92 # Grace executable file. 93 if type(grace_exe) != str: 94 raise RelaxStrError, ('Grace executable file', grace_exe) 95 96 # Execute the functional code. 97 self.__relax__.generic.grace.view(file=file, dir=dir, grace_exe=grace_exe)
98 99
100 - def write(self, run=None, x_data_type='res', y_data_type=None, res_num=None, res_name=None, plot_data='value', file=None, dir='grace', force=0):
101 """Function for creating a grace '.agr' file. 102 103 Keyword Arguments 104 ~~~~~~~~~~~~~~~~~ 105 106 run: The name of the run. 107 108 x_data_type: The data type for the X-axis (no regular expression is allowed). 109 110 y_data_type: The data type for the Y-axis (no regular expression is allowed). 111 112 res_num: The residue number (regular expression is allowed). 113 114 res_name: The residue name (regular expression is allowed). 115 116 plot_data: The data to use for the plot. 117 118 file: The name of the file. 119 120 dir: The directory name. 121 122 force: A flag which, if set to 1, will cause the file to be overwritten. 123 124 125 Description 126 ~~~~~~~~~~~ 127 128 This function is designed to be as flexible as possible so that any combination of data can 129 be plotted. The output is in the format of a Grace plot (also known as ACE/gr, Xmgr, and 130 xmgrace) which only supports two dimensional plots. Three types of keyword arguments can 131 be used to create various types of plot. These include the X-axis and Y-axis data types, 132 the residue number and name selection arguments, and an argument for selecting what to 133 actually plot. 134 135 The X-axis and Y-axis data type arguments should be plain strings, regular expression is not 136 allowed. If the X-axis data type argument is not given, the plot will default to having the 137 residue number along the x-axis. The two axes of the Grace plot can be absolutely any of 138 the data types listed in the tables below. The only limitation, currently anyway, is that 139 the data must belong to the same run. 140 141 The residue number and name arguments can be used to limit the residues used in the plot. 142 The default is that all residues will be used, however, these arguments can be used to 143 select a subset of all residues, or a single residue for plots of Monte Carlo simulations, 144 etc. Regular expression is allowed for both the residue number and name, and the number can 145 either be an integer or a string. 146 147 The property which is actually plotted can be controlled by the 'plot_data' argument. It 148 can be one of the following: 149 'value': Plot values (with errors if they exist). 150 'error': Plot errors. 151 'sims': Plot the simulation values. 152 153 154 Examples 155 ~~~~~~~~ 156 157 To write the NOE values for all residues from the run 'noe' to the Grace file 'noe.agr', 158 type: 159 160 relax> grace.write('noe', 'res', 'noe', file='noe.agr') 161 relax> grace.write('noe', y_data_type='noe', file='noe.agr') 162 relax> grace.write('noe', x_data_type='res', y_data_type='noe', file='noe.agr') 163 relax> grace.write(run='noe', y_data_type='noe', file='noe.agr', force=1) 164 165 166 To create a Grace file of 'S2' vs. 'te' for all residues, type: 167 168 relax> grace.write('m2', 'S2', 'te', file='s2_te.agr') 169 relax> grace.write('m2', x_data_type='S2', y_data_type='te', file='s2_te.agr') 170 relax> grace.write(run='m2', x_data_type='S2', y_data_type='te', file='s2_te.agr', force=1) 171 172 173 To create a Grace file of the Monte Carlo simulation values of 'Rex' vs. 'te' for residue 174 123, type: 175 176 relax> grace.write('m4', 'Rex', 'te', res_num=123, plot_data='sims', file='s2_te.agr') 177 relax> grace.write(run='m4', x_data_type='Rex', y_data_type='te', res_num=123, 178 plot_data='sims', file='s2_te.agr') 179 """ 180 181 # Function intro text. 182 if self.__relax__.interpreter.intro: 183 text = sys.ps3 + "grace.write(" 184 text = text + "run=" + `run` 185 text = text + ", x_data_type=" + `x_data_type` 186 text = text + ", y_data_type=" + `y_data_type` 187 text = text + ", res_num=" + `res_num` 188 text = text + ", res_name=" + `res_name` 189 text = text + ", plot_data=" + `plot_data` 190 text = text + ", file=" + `file` 191 text = text + ", dir=" + `dir` 192 text = text + ", force=" + `force` + ")" 193 print text 194 195 # The run name. 196 if type(run) != str: 197 raise RelaxStrError, ('run', run) 198 199 # Data type for x-axis. 200 if type(x_data_type) != str: 201 raise RelaxStrError, ('x data type', x_data_type) 202 203 # Data type for y-axis. 204 if type(y_data_type) != str: 205 raise RelaxStrError, ('y data type', y_data_type) 206 207 # Residue number. 208 if res_num != None and type(res_num) != int and type(res_num) != str: 209 raise RelaxNoneIntStrError, ('residue number', res_num) 210 211 # Residue name. 212 if res_name != None and type(res_name) != str: 213 raise RelaxNoneStrError, ('residue name', res_name) 214 215 # The plot data. 216 if type(plot_data) != str: 217 raise RelaxStrError, ('plot data', plot_data) 218 219 # File. 220 if type(file) != str: 221 raise RelaxStrError, ('file name', file) 222 223 # Directory. 224 if dir != None and type(dir) != str: 225 raise RelaxNoneStrError, ('directory name', dir) 226 227 # The force flag. 228 if type(force) != int or (force != 0 and force != 1): 229 raise RelaxBinError, ('force flag', force) 230 231 # Execute the functional code. 232 self.__relax__.generic.grace.write(run=run, x_data_type=x_data_type, y_data_type=y_data_type, res_num=res_num, res_name=res_name, plot_data=plot_data, file=file, dir=dir, force=force)
233 234 235 236 # Docstring modification. 237 ######################### 238 239 # Write function. 240 write.__doc__ = write.__doc__ + "\n\n" + regexp_doc() + "\n" 241 write.__doc__ = write.__doc__ + Minimise.return_data_name.__doc__ + "\n\n" 242 write.__doc__ = write.__doc__ + Model_free.return_data_name.__doc__ + "\n\n" 243 write.__doc__ = write.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n\n" 244 write.__doc__ = write.__doc__ + Noe.return_data_name.__doc__ + "\n"
245