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

Source Code for Module prompt.value

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-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.diffusion_tensor import Diffusion_tensor 
 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 Value:
34 - def __init__(self, relax):
35 # Help. 36 self.__relax_help__ = \ 37 """Class for setting data values.""" 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 copy(self, run1=None, run2=None, param=None):
47 """Function for copying residue specific data values from run1 to run2. 48 49 Keyword Arguments 50 ~~~~~~~~~~~~~~~~~ 51 52 run1: The name of the run to copy from. 53 54 run2: The name of the run to copy to. 55 56 param: The parameter to copy. 57 58 59 Description 60 ~~~~~~~~~~~ 61 62 Only one parameter may be selected, therefore the 'param' argument should be a string. 63 64 If this function is used to change values of previously minimised runs, then the 65 minimisation statistics (chi-squared value, iteration count, function count, gradient count, 66 and Hessian count) will be reset to None. 67 68 69 Examples 70 ~~~~~~~~ 71 72 To copy the CSA values from the run 'm1' to 'm2', type: 73 74 relax> value.copy('m1', 'm2', 'CSA') 75 """ 76 77 # Function intro text. 78 if self.__relax__.interpreter.intro: 79 text = sys.ps3 + "value.copy(" 80 text = text + "run1=" + `run1` 81 text = text + ", run2=" + `run2` 82 text = text + ", param=" + `param` + ")" 83 print text 84 85 # The run1 argument. 86 if type(run1) != str: 87 raise RelaxStrError, ('run1', run1) 88 89 # The run2 argument. 90 if type(run2) != str: 91 raise RelaxStrError, ('run2', run2) 92 93 # The parameter. 94 if type(param) != str: 95 raise RelaxStrError, ('parameter', param) 96 97 # Execute the functional code. 98 self.__relax__.generic.value.copy(run1=run1, run2=run2, param=param)
99 100
101 - def display(self, run=None, param=None):
102 """Function for displaying residue specific data values. 103 104 Keyword Arguments 105 ~~~~~~~~~~~~~~~~~ 106 107 run: The name of the run. 108 109 param: The parameter to display. 110 111 112 Description 113 ~~~~~~~~~~~ 114 115 Only one parameter may be selected, therefore the 'param' argument should be a string. 116 117 118 Examples 119 ~~~~~~~~ 120 121 To show all CSA values for the run 'm1', type: 122 123 relax> value.display('m1', 'CSA') 124 """ 125 126 # Function intro text. 127 if self.__relax__.interpreter.intro: 128 text = sys.ps3 + "value.display(" 129 text = text + "run=" + `run` 130 text = text + ", param=" + `param` + ")" 131 print text 132 133 # The run name. 134 if type(run) != str: 135 raise RelaxStrError, ('run', run) 136 137 # The parameter. 138 if type(param) != str: 139 raise RelaxStrError, ('parameter', param) 140 141 # Execute the functional code. 142 self.__relax__.generic.value.display(run=run, param=param)
143 144
145 - def read(self, run=None, param=None, scaling=1.0, file=None, num_col=0, name_col=1, data_col=2, error_col=3, sep=None):
146 """Function for reading residue specific data values from a file. 147 148 Keyword Arguments 149 ~~~~~~~~~~~~~~~~~ 150 151 run: The name of the run. 152 153 param: The parameter. 154 155 scaling: The factor to scale parameters by. 156 157 file: The name of the file containing the relaxation data. 158 159 num_col: The residue number column (the default is 0, ie the first column). 160 161 name_col: The residue name column (the default is 1). 162 163 data_col: The relaxation data column (the default is 2). 164 165 error_col: The experimental error column (the default is 3). 166 167 sep: The column separator (the default is white space). 168 169 170 Description 171 ~~~~~~~~~~~ 172 173 Only one parameter may be selected, therefore the 'param' argument should be a string. If 174 the file only contains values and no errors, set the error column argument to None. 175 176 If this function is used to change values of previously minimised runs, then the 177 minimisation statistics (chi-squared value, iteration count, function count, gradient count, 178 and Hessian count) will be reset to None. 179 180 181 Examples 182 ~~~~~~~~ 183 184 To load CSA values for the run 'm1' from the file 'csa_values' in the directory 'data', type 185 any of the following: 186 187 relax> value.read('m1', 'CSA', 'data/csa_value') 188 relax> value.read('m1', 'CSA', 'data/csa_value', 0, 1, 2, 3, None, 1) 189 relax> value.read(run='m1', param='CSA', file='data/csa_value', num_col=0, name_col=1, 190 data_col=2, error_col=3, sep=None) 191 """ 192 193 # Function intro text. 194 if self.__relax__.interpreter.intro: 195 text = sys.ps3 + "value.read(" 196 text = text + "run=" + `run` 197 text = text + ", param=" + `param` 198 text = text + ", scaling=" + `scaling` 199 text = text + ", file=" + `file` 200 text = text + ", num_col=" + `num_col` 201 text = text + ", name_col=" + `name_col` 202 text = text + ", data_col=" + `data_col` 203 text = text + ", error_col=" + `error_col` 204 text = text + ", sep=" + `sep` + ")" 205 print text 206 207 # The run name. 208 if type(run) != str: 209 raise RelaxStrError, ('run', run) 210 211 # The parameter. 212 if type(param) != str: 213 raise RelaxStrError, ('parameter', param) 214 215 # The scaling factor. 216 if type(scaling) != float: 217 raise RelaxFloatError, ('scaling', scaling) 218 219 # The file name. 220 if type(file) != str: 221 raise RelaxStrError, ('file', file) 222 223 # The number column. 224 if type(num_col) != int: 225 raise RelaxIntError, ('residue number column', num_col) 226 227 # The name column. 228 if name_col != None and type(name_col) != int: 229 raise RelaxNoneIntError, ('residue name column', name_col) 230 231 # The data column. 232 if type(data_col) != int: 233 raise RelaxIntError, ('data column', data_col) 234 235 # The error column. 236 if error_col != None and type(error_col) != int: 237 raise RelaxNoneIntError, ('error column', error_col) 238 239 # Column separator. 240 if sep != None and type(sep) != str: 241 raise RelaxNoneStrError, ('column separator', sep) 242 243 # Execute the functional code. 244 self.__relax__.generic.value.read(run=run, param=param, scaling=scaling, file=file, num_col=num_col, name_col=name_col, data_col=data_col, error_col=error_col, sep=sep)
245 246
247 - def set(self, run=None, value=None, param=None, res_num=None, res_name=None):
248 """Function for setting residue specific data values. 249 250 Keyword arguments 251 ~~~~~~~~~~~~~~~~~ 252 253 run: The run to assign the values to. 254 255 value: The value(s). 256 257 param: The parameter(s). 258 259 res_num: The residue number. 260 261 res_name: The residue name. 262 263 264 Description 265 ~~~~~~~~~~~ 266 267 If this function is used to change values of previously minimised runs, then the 268 minimisation statistics (chi-squared value, iteration count, function count, gradient count, 269 and Hessian count) will be reset to None. 270 271 272 The value argument can be None, a single value, or an array of values while the parameter 273 argument can be None, a string, or array of strings. The choice of which combination 274 determines the behaviour of this function. The following table describes what occurs in 275 each instance. The Value column refers to the 'value' argument while the Param column refers 276 to the 'param' argument. In these columns, 'None' corresponds to None, '1' corresponds 277 to either a single value or single string, and 'n' corresponds to either an array of values 278 or an array of strings. 279 280 ____________________________________________________________________________________________ 281 | | | | 282 | Value | Param | Description | 283 |_______|_______|__________________________________________________________________________| 284 | | | | 285 | None | None | This case is used to set the model parameters prior to minimisation or | 286 | | | calculation. The model parameters are set to the default values. | 287 | | | | 288 | 1 | None | Invalid combination. | 289 | | | | 290 | n | None | This case is used to set the model parameters prior to minimisation or | 291 | | | calculation. The length of the value array must be equal to the number | 292 | | | of model parameters for an individual residue. The parameters will be | 293 | | | set to the corresponding number. | 294 | | | | 295 | None | 1 | The parameter matching the string will be set to the default value. | 296 | | | | 297 | 1 | 1 | The parameter matching the string will be set to the supplied number. | 298 | | | | 299 | n | 1 | Invalid combination. | 300 | | | | 301 | None | n | Each parameter matching the strings will be set to the default values. | 302 | | | | 303 | 1 | n | Each parameter matching the strings will be set to the supplied number. | 304 | | | | 305 | n | n | Each parameter matching the strings will be set to the corresponding | 306 | | | number. Both arrays must be of equal length. | 307 |_______|_______|__________________________________________________________________________| 308 309 310 Residue number and name argument 311 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 312 313 If the 'res_num' and 'res_name' arguments are left as the defaults of None, then the 314 function will be applied to all residues. Otherwise the residue number can be set to either 315 an integer for selecting a single residue or a python regular expression string for 316 selecting multiple residues. The residue name argument must be a string and can use regular 317 expression as well. If the data is global non-residue specific data, such as diffusion 318 tensor parameters, supplying the residue number and name will terminate the program with an 319 error. 320 321 322 Examples 323 ~~~~~~~~ 324 325 To set the parameter values for the run 'test' to the default values, for all residues, 326 type: 327 328 relax> value.set('test') 329 330 331 To set the parameter values of residue 10, which is the model-free run 'm4' and has the 332 parameters {S2, te, Rex}, the following can be used. Rex term is the value for the first 333 given field strength. 334 335 relax> value.set('m4', [0.97, 2.048*1e-9, 0.149], res_num=10) 336 relax> value.set('m4', value=[0.97, 2.048*1e-9, 0.149], res_num=10) 337 338 339 To set the CSA value for the model-free run 'tm3' to the default value, type: 340 341 relax> value.set('tm3', param='csa') 342 343 344 To set the CSA value of all residues in the reduced spectral density mapping run '600MHz' to 345 -170 ppm, type: 346 347 relax> value.set('600MHz', -170 * 1e-6, 'csa') 348 relax> value.set('600MHz', value=-170 * 1e-6, param='csa') 349 350 351 To set the NH bond length of all residues in the model-free run 'm5' to 1.02 Angstroms, 352 type: 353 354 relax> value.set('m5', 1.02 * 1e-10, 'bond_length') 355 relax> value.set('m5', value=1.02 * 1e-10, param='r') 356 357 358 To set both the bond length and the CSA value for the run 'new' to the default values, type: 359 360 relax> value.set('new', param=['bond length', 'csa']) 361 362 363 To set both tf and ts in the model-free run 'm6' to 100 ps, type: 364 365 relax> value.set('m6', 100e-12, ['tf', 'ts']) 366 relax> value.set('m6', value=100e-12, param=['tf', 'ts']) 367 368 369 To set the S2 and te parameter values for model-free run 'm4' which has the parameters 370 {S2, te, Rex} to 0.56 and 13 ps, type: 371 372 relax> value.set('m4', [0.56, 13e-12], ['S2', 'te'], 10) 373 relax> value.set('m4', value=[0.56, 13e-12], param=['S2', 'te'], res_num=10) 374 relax> value.set(run='m4', value=[0.56, 13e-12], param=['S2', 'te'], res_num=10) 375 """ 376 377 # Function intro text. 378 if self.__relax__.interpreter.intro: 379 text = sys.ps3 + "value.set(" 380 text = text + "run=" + `run` 381 text = text + ", value=" + `value` 382 text = text + ", param=" + `param` 383 text = text + ", res_num=" + `res_num` 384 text = text + ", res_name=" + `res_name` + ")" 385 print text 386 387 # The run name. 388 if type(run) != str: 389 raise RelaxStrError, ('run', run) 390 391 # The value. 392 if value != None and type(value) != float and type(value) != int and type(value) != list: 393 raise RelaxNoneFloatListError, ('value', value) 394 if type(value) == list: 395 for i in xrange(len(value)): 396 if type(value[i]) != float and type(value[i]) != int: 397 raise RelaxListFloatError, ('value', value) 398 399 # The parameter. 400 if param != None and type(param) != str and type(param) != list: 401 raise RelaxNoneStrListError, ('parameter', param) 402 if type(param) == list: 403 for i in xrange(len(param)): 404 if type(param[i]) != str: 405 raise RelaxListStrError, ('parameter', param) 406 407 # The invalid combination of a single value and no param argument. 408 if (type(value) == float or type(value) == int) and param == None: 409 raise RelaxError, "Invalid value and parameter argument combination, for details by type 'help(value.set)'" 410 411 # The invalid combination of an array of values and a single param string. 412 if type(value) == list and type(param) == str: 413 raise RelaxError, "Invalid value and parameter argument combination, for details by type 'help(value.set)'" 414 415 # Value array and parameter array of equal length. 416 if type(value) == list and type(param) == list and len(value) != len(param): 417 raise RelaxError, "Both the value array and parameter array must be of equal length." 418 419 # Residue number. 420 if res_num != None and type(res_num) != int and type(res_num) != str: 421 raise RelaxNoneIntStrError, ('residue number', res_num) 422 423 # Residue name. 424 if res_name != None and type(res_name) != str: 425 raise RelaxNoneStrError, ('residue name', res_name) 426 427 # Execute the functional code. 428 self.__relax__.generic.value.set(run=run, value=value, param=param, res_num=res_num, res_name=res_name)
429 430
431 - def write(self, run=None, param=None, file=None, dir=None, force=0):
432 """Function for writing residue specific data values to a file. 433 434 Keyword Arguments 435 ~~~~~~~~~~~~~~~~~ 436 437 run: The name of the run. 438 439 param: The parameter. 440 441 file: The name of the file. 442 443 dir: The directory name. 444 445 force: A flag which, if set to 1, will cause the file to be overwritten. 446 447 448 Description 449 ~~~~~~~~~~~ 450 451 If no directory name is given, the file will be placed in the current working directory. 452 453 The parameter argument should be a string. 454 455 456 Examples 457 ~~~~~~~~ 458 459 To write the CSA values for the run 'm1' to the file 'csa.txt', type: 460 461 relax> value.write('m1', 'CSA', 'csa.txt') 462 relax> value.write(run='m1', param='CSA', file='csa.txt') 463 464 465 To write the NOE values from the run 'noe' to the file 'noe', type: 466 467 relax> value.write('noe', 'noe', 'noe.out') 468 relax> value.write('noe', param='noe', file='noe.out') 469 relax> value.write(run='noe', param='noe', file='noe.out') 470 relax> value.write(run='noe', param='noe', file='noe.out', force=1) 471 """ 472 473 # Function intro text. 474 if self.__relax__.interpreter.intro: 475 text = sys.ps3 + "value.write(" 476 text = text + "run=" + `run` 477 text = text + ", param=" + `param` 478 text = text + ", file=" + `file` 479 text = text + ", dir=" + `dir` 480 text = text + ", force=" + `force` + ")" 481 print text 482 483 # The run name. 484 if type(run) != str: 485 raise RelaxStrError, ('run', run) 486 487 # The parameter. 488 if type(param) != str: 489 raise RelaxStrError, ('parameter', param) 490 491 # File. 492 if type(file) != str: 493 raise RelaxStrError, ('file name', file) 494 495 # Directory. 496 if dir != None and type(dir) != str: 497 raise RelaxNoneStrError, ('directory name', dir) 498 499 # The force flag. 500 if type(force) != int or (force != 0 and force != 1): 501 raise RelaxBinError, ('force flag', force) 502 503 # Execute the functional code. 504 self.__relax__.generic.value.write(run=run, param=param, file=file, dir=dir, force=force)
505 506 507 # Docstring modification. 508 ######################### 509 510 # Copy function. 511 copy.__doc__ = copy.__doc__ + "\n\n" + regexp_doc() + "\n" 512 copy.__doc__ = copy.__doc__ + Model_free.set.__doc__ + "\n\n" 513 copy.__doc__ = copy.__doc__ + Model_free.return_data_name.__doc__ + "\n" 514 copy.__doc__ = copy.__doc__ + Jw_mapping.set.__doc__ + "\n" 515 copy.__doc__ = copy.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n" 516 517 # Display function. 518 display.__doc__ = display.__doc__ + "\n\n" + regexp_doc() + "\n" 519 display.__doc__ = display.__doc__ + Model_free.return_data_name.__doc__ + "\n\n" 520 display.__doc__ = display.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n" 521 522 # Read function. 523 read.__doc__ = read.__doc__ + "\n\n" + regexp_doc() + "\n" 524 read.__doc__ = read.__doc__ + Model_free.set.__doc__ + "\n\n" 525 read.__doc__ = read.__doc__ + Model_free.return_data_name.__doc__ + "\n" 526 read.__doc__ = read.__doc__ + Jw_mapping.set.__doc__ + "\n" 527 read.__doc__ = read.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n" 528 529 # Set function. 530 set.__doc__ = set.__doc__ + "\n\n" + regexp_doc() + "\n" 531 set.__doc__ = set.__doc__ + Model_free.set.__doc__ + "\n" 532 set.__doc__ = set.__doc__ + Model_free.return_data_name.__doc__ + "\n" 533 set.__doc__ = set.__doc__ + Model_free.default_value.__doc__ + "\n\n" 534 set.__doc__ = set.__doc__ + Jw_mapping.set.__doc__ + "\n" 535 set.__doc__ = set.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n" 536 set.__doc__ = set.__doc__ + Jw_mapping.default_value.__doc__ + "\n" 537 set.__doc__ = set.__doc__ + Diffusion_tensor.set.__doc__ + "\n" 538 set.__doc__ = set.__doc__ + Diffusion_tensor.return_data_name.__doc__ + "\n" 539 set.__doc__ = set.__doc__ + Diffusion_tensor.default_value.__doc__ + "\n\n" 540 541 # Write function. 542 write.__doc__ = write.__doc__ + "\n\n" + regexp_doc() + "\n" 543 write.__doc__ = write.__doc__ + Model_free.return_data_name.__doc__ + "\n\n" 544 write.__doc__ = write.__doc__ + Jw_mapping.return_data_name.__doc__ + "\n\n" 545 write.__doc__ = write.__doc__ + Noe.return_data_name.__doc__ + "\n"
546