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

Source Code for Module prompt.molmol

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004, 2006 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 colour import Colour 
 26  from doc_string import regexp_doc 
 27  import help 
 28  from generic_fns.minimise import Minimise 
 29  from specific_fns.consistency_tests import Consistency_tests 
 30  from specific_fns.model_free import Molmol 
 31  from specific_fns.jw_mapping import Jw_mapping 
 32  from specific_fns.noe import Noe 
 33   
 34   
35 -class Molmol:
36 - def __init__(self, relax):
37 # Help. 38 self.__relax_help__ = \ 39 """Class for interfacing with Molmol.""" 40 41 # Add the generic help string. 42 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help 43 44 # Place relax in the class namespace. 45 self.__relax__ = relax
46 47
48 - def clear_history(self):
49 """Function for clearing the Molmol command history.""" 50 51 # Function intro text. 52 if self.__relax__.interpreter.intro: 53 text = sys.ps3 + "molmol.clear_history()" 54 print text 55 56 # Execute the functional code. 57 self.__relax__.generic.molmol.clear_history()
58 59
60 - def command(self, command):
61 """Function for executing a user supplied Molmol command. 62 63 Example 64 ~~~~~~~ 65 66 relax> molmol.command("InitAll yes") 67 """ 68 69 # Function intro text. 70 if self.__relax__.interpreter.intro: 71 text = sys.ps3 + "molmol.command(" 72 text = text + "command=" + `command` + ")" 73 print text 74 75 # The command argument. 76 if type(command) != str: 77 raise RelaxStrError, ('command', command) 78 79 # Execute the functional code. 80 self.__relax__.generic.molmol.write(command=command)
81 82
83 - def macro_exec(self, run=None, data_type=None, style="classic", colour_start=None, colour_end=None, colour_list=None):
84 """Function for executing Molmol macros. 85 86 Keyword Arguments 87 ~~~~~~~~~~~~~~~~~ 88 89 run: The name of the run. 90 91 data_type: The data type to map to the structure. 92 93 style: The style of the macro. 94 95 colour_start: The starting colour, either an array or string, of the linear colour 96 gradient. 97 98 colour_end: The ending colour, either an array or string, of the linear colour gradient. 99 100 colour_list: The list of colours to match the start and end strings. 101 102 103 Description 104 ~~~~~~~~~~~ 105 106 This function allows residues specific values to be mapped to a structure through Molmol 107 macros. Currently only the 'classic' style, which is described below, is availible. 108 109 110 Colour 111 ~~~~~~ 112 113 The values are coloured based on a linear colour gradient which is specified through the 114 'colour_start' and 'colour_end' arguments. These arguments can either be a string to 115 identify one of the RGB (red, green, blue) colour arrays listed in the tables below, or you 116 can give the RGB vector itself. For example, colour_start='white' and 117 colour_start=[1.0, 1.0, 1.0] both select the same colour. Leaving both arguments at None 118 will select the default colour gradient which for each type of analysis is described below. 119 120 When supplying the colours as strings, two lists of colours can be selected from which to 121 match the strings. These are the default Molmol colour list and the X11 colour list, both 122 of which are described in the tables below. The default behaviour is to first search the 123 Molmol list and then the X11 colour list, raising an error if neither contain the string. 124 To explicitly select these lists, set the 'colour_list' argument to either 'molmol' or 125 'x11'. 126 127 128 Examples 129 ~~~~~~~~ 130 131 To map the order parameter values, S2, of the run 'final' onto the structure using the 132 classic style, type: 133 134 relax> molmol.macro_exec('final', 'S2') 135 relax> molmol.macro_exec('final', data_type='S2') 136 relax> molmol.macro_exec('final', data_type='S2', style="classic") 137 """ 138 139 # Function intro text. 140 if self.__relax__.interpreter.intro: 141 text = sys.ps3 + "molmol.macro_exec(" 142 text = text + "run=" + `run` 143 text = text + ", data_type=" + `data_type` 144 text = text + ", style=" + `style` 145 text = text + ", colour_start=" + `colour_start` 146 text = text + ", colour_end=" + `colour_end` 147 text = text + ", colour_list=" + `colour_list` + ")" 148 print text 149 150 # The run name. 151 if type(run) != str: 152 raise RelaxStrError, ('run', run) 153 154 # Data type for mapping to the structure. 155 if type(data_type) != str: 156 raise RelaxStrError, ('data type', data_type) 157 158 # The style. 159 if type(style) != str: 160 raise RelaxStrError, ('style', style) 161 162 # The starting colour of the linear gradient. 163 if colour_start != None and type(colour_start) != str and type(colour_start) != list: 164 raise RelaxNoneStrListError, ('starting colour of the linear gradient', colour_start) 165 if type(colour_start) == list: 166 for i in xrange(len(colour_start)): 167 if type(colour_start[i]) != float and type(colour_start[i]) != int: 168 raise RelaxListNumError, ('starting colour of the linear gradient', colour_start) 169 170 # The ending colour of the linear gradient. 171 if colour_end != None and type(colour_end) != str and type(colour_end) != list: 172 raise RelaxNoneStrListError, ('ending colour of the linear gradient', colour_end) 173 if type(colour_end) == list: 174 for i in xrange(len(colour_end)): 175 if type(colour_end[i]) != float and type(colour_end[i]) != int: 176 raise RelaxListNumError, ('ending colour of the linear gradient', colour_end) 177 178 # Execute the functional code. 179 self.__relax__.generic.molmol.macro_exec(run=run, data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list)
180 181 182
183 - def view(self, run=None):
184 """Function for viewing the collection of molecules extracted from the PDB file. 185 186 Keyword Arguments 187 ~~~~~~~~~~~~~~~~~ 188 189 run: The name of the run which the PDB belongs to. 190 191 192 Example 193 ~~~~~~~ 194 195 relax> molmol.view('m1') 196 relax> molmol.view(run='pdb') 197 """ 198 199 # Function intro text. 200 if self.__relax__.interpreter.intro: 201 text = sys.ps3 + "molmol.view(" 202 text = text + "run=" + `run` + ")" 203 print text 204 205 # The run argument. 206 if type(run) != str: 207 raise RelaxStrError, ('run', run) 208 209 # Execute the functional code. 210 self.__relax__.generic.molmol.view(run=run)
211 212
213 - def write(self, run=None, data_type=None, style="classic", colour_start=None, colour_end=None, colour_list=None, file=None, dir='molmol', force=0):
214 """Function for creating Molmol macros. 215 216 Keyword Arguments 217 ~~~~~~~~~~~~~~~~~ 218 219 run: The name of the run. 220 221 data_type: The data type to map to the structure. 222 223 style: The style of the macro. 224 225 colour_start: The starting colour, either an array or string, of the linear colour 226 gradient. 227 228 colour_end: The ending colour, either an array or string, of the linear colour gradient. 229 230 colour_list: The list of colours to match the start and end strings. 231 232 file: The name of the file. 233 234 dir: The directory name. 235 236 force: A flag which, if set to 1, will cause the file to be overwritten. 237 238 239 Description 240 ~~~~~~~~~~~ 241 242 This function allows residues specific values to be mapped to a structure through the 243 creation of a Molmol '*.mac' macro which can be executed in Molmol by clicking on 'File, 244 Macro, Execute User...'. Currently only the 'classic' style, which is described below, is 245 availible. 246 247 248 Colour 249 ~~~~~~ 250 251 The values are coloured based on a linear colour gradient which is specified through the 252 'colour_start' and 'colour_end' arguments. These arguments can either be a string to 253 identify one of the RGB (red, green, blue) colour arrays listed in the tables below, or you 254 can give the RGB vector itself. For example, colour_start='white' and 255 colour_start=[1.0, 1.0, 1.0] both select the same colour. Leaving both arguments at None 256 will select the default colour gradient which for each type of analysis is described below. 257 258 When supplying the colours as strings, two lists of colours can be selected from which to 259 match the strings. These are the default Molmol colour list and the X11 colour list, both 260 of which are described in the tables below. The default behaviour is to first search the 261 Molmol list and then the X11 colour list, raising an error if neither contain the string. 262 To explicitly select these lists, set the 'colour_list' argument to either 'molmol' or 263 'x11'. 264 265 266 Examples 267 ~~~~~~~~ 268 269 To create a Molmol macro mapping the order parameter values, S2, of the run 'final' onto the 270 structure using the classic style, type: 271 272 relax> molmol.write('final', 'S2') 273 relax> molmol.write('final', data_type='S2') 274 relax> molmol.write('final', data_type='S2', style="classic", file='s2.mac', dir='molmol') 275 """ 276 277 # Function intro text. 278 if self.__relax__.interpreter.intro: 279 text = sys.ps3 + "molmol.write(" 280 text = text + "run=" + `run` 281 text = text + ", data_type=" + `data_type` 282 text = text + ", style=" + `style` 283 text = text + ", colour_start=" + `colour_start` 284 text = text + ", colour_end=" + `colour_end` 285 text = text + ", colour_list=" + `colour_list` 286 text = text + ", file=" + `file` 287 text = text + ", dir=" + `dir` 288 text = text + ", force=" + `force` + ")" 289 print text 290 291 # The run name. 292 if type(run) != str: 293 raise RelaxStrError, ('run', run) 294 295 # Data type for mapping to the structure. 296 if type(data_type) != str: 297 raise RelaxStrError, ('data type', data_type) 298 299 # The style. 300 if type(style) != str: 301 raise RelaxStrError, ('style', style) 302 303 # The starting colour of the linear gradient. 304 if colour_start != None and type(colour_start) != str and type(colour_start) != list: 305 raise RelaxNoneStrListError, ('starting colour of the linear gradient', colour_start) 306 if type(colour_start) == list: 307 for i in xrange(len(colour_start)): 308 if type(colour_start[i]) != float and type(colour_start[i]) != int: 309 raise RelaxListNumError, ('starting colour of the linear gradient', colour_start) 310 311 # The ending colour of the linear gradient. 312 if colour_end != None and type(colour_end) != str and type(colour_end) != list: 313 raise RelaxNoneStrListError, ('ending colour of the linear gradient', colour_end) 314 if type(colour_end) == list: 315 for i in xrange(len(colour_end)): 316 if type(colour_end[i]) != float and type(colour_end[i]) != int: 317 raise RelaxListNumError, ('ending colour of the linear gradient', colour_end) 318 319 # File. 320 if file != None and type(file) != str: 321 raise RelaxNoneStrError, ('file name', file) 322 323 # Directory. 324 if dir != None and type(dir) != str: 325 raise RelaxNoneStrError, ('directory name', dir) 326 327 # The force flag. 328 if type(force) != int or (force != 0 and force != 1): 329 raise RelaxBinError, ('force flag', force) 330 331 # Execute the functional code. 332 self.__relax__.generic.molmol.write(run=run, data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list, file=file, dir=dir, force=force)
333 334 335 336 # Docstring modification. 337 ######################### 338 339 # Write function. 340 write.__doc__ = write.__doc__ + "\n\n" + Molmol.classic.__doc__ + "\n\n" 341 342 # Molmol RGB colour list. 343 write.__doc__ = write.__doc__ + "\n\n" + Colour.molmol_colours.__doc__ + "\n\n" 344 345 # X11 RGB colour list. 346 write.__doc__ = write.__doc__ + "\n\n" + Colour.x11_colours.__doc__ + "\n\n"
347