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

Source Code for Module prompt.value

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