Package specific_fns :: Package model_free :: Module results
[hide private]
[frames] | no frames]

Source Code for Module specific_fns.model_free.results

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2003-2012 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  # Module docstring. 
  24  """Module for the creation and processing of model-free results files.""" 
  25   
  26  # Python module imports. 
  27  from data.diff_tensor import DiffTensorSimList 
  28  from math import pi 
  29  from numpy import float64, array, transpose 
  30  from re import search 
  31  from string import lower, replace, split 
  32  import sys 
  33   
  34  # relax module imports. 
  35  import generic_fns 
  36  from generic_fns.mol_res_spin import generate_spin_id, return_spin, spin_loop 
  37  from generic_fns import pipes 
  38  from relax_errors import RelaxError, RelaxInvalidDataError 
  39   
  40   
  41   
42 -class Results:
43 """Class containing methods specific to the model-free results files.""" 44
45 - def _determine_version(self, file_data, verbosity=1):
46 """Determine which relax version the results file belongs to. 47 48 @param file_data: The processed results file data. 49 @type file_data: list of lists of str 50 @keyword verbosity: A variable specifying the amount of information to print. The higher 51 the value, the greater the verbosity. 52 @type verbosity: int 53 @return: The relax version number. 54 @rtype: str 55 @raises RelaxError: If the relax version the model-free results file belongs to cannot be 56 determined. 57 """ 58 59 # relax 1.2 results file (test for the 1.2 header line). 60 if len(file_data[0]) > 9 and file_data[0][0:8] == ['Num', 'Name', 'Selected', 'Data_set', 'Nucleus', 'Model', 'Equation', 'Params']: 61 version = '1.2' 62 63 # Can't determine the file version. 64 else: 65 raise RelaxError("Cannot determine the relax version the model-free results file belongs to.") 66 67 # Print out. 68 if verbosity: 69 print(("relax " + version + " model-free results file.")) 70 71 # Return the version. 72 return version
73 74
75 - def _fix_params(self, spin_line, col, verbosity=1):
76 """Fix certain parameters depending on the model type. 77 78 @param spin_line: The line of data for a single spin. 79 @type spin_line: list of str 80 @param col: The column indices. 81 @type col: dict of int 82 @keyword verbosity: A variable specifying the amount of information to print. The higher 83 the value, the greater the verbosity. 84 @type verbosity: int 85 """ 86 87 # Extract the model type if it exists, otherwise return. 88 if spin_line[col['param_set']] != 'None': 89 model_type = spin_line[col['param_set']] 90 else: 91 return 92 93 # Local tm and model-free only model types. 94 if model_type == 'local_tm' or model_type == 'mf': 95 diff_fixed = True 96 mf_fixed = False 97 98 # Diffusion tensor model type. 99 elif model_type == 'diff': 100 diff_fixed = False 101 mf_fixed = True 102 103 # 'all' model type. 104 elif model_type == 'all': 105 diff_fixed = False 106 mf_fixed = False 107 108 # No model type. 109 elif model_type == 'None': 110 model_type = None 111 diff_fixed = None 112 mf_fixed = None 113 114 # Print out. 115 if verbosity >= 2: 116 print("\nFixing parameters based on the model type.") 117 print(("Model type: " + model_type)) 118 print(("Diffusion tensor fixed: " + repr(diff_fixed))) 119 print(("Model-free parameters fixed: " + repr(mf_fixed))) 120 121 # Set the diffusion tensor fixed flag. 122 if model_type != 'local_tm' and diff_fixed != None: 123 cdp.diff_tensor.fixed = diff_fixed 124 125 # Set the spin specific fixed flags. 126 for spin in spin_loop(): 127 if mf_fixed != None: 128 spin.fixed = mf_fixed
129 130
131 - def _generate_sequence(self, spin_line, col, verbosity=1):
132 """Generate the sequence. 133 134 @param spin_line: The line of data for a single spin. 135 @type spin_line: list of str 136 @param col: The column indices. 137 @type col: dict of int 138 @keyword verbosity: A variable specifying the amount of information to print. The higher 139 the value, the greater the verbosity. 140 @type verbosity: int 141 """ 142 143 # The spin info (for relax 1.2). 144 if 'num' in col: 145 mol_name = None 146 res_num = int(spin_line[col['num']]) 147 res_name = spin_line[col['name']] 148 spin_num = None 149 spin_name = None 150 151 # The spin info. 152 else: 153 mol_name = spin_line[col['mol_name']] 154 res_num = int(spin_line[col['res_num']]) 155 res_name = spin_line[col['res_name']] 156 spin_num = int(spin_line[col['spin_num']]) 157 spin_name = spin_line[col['spin_name']] 158 159 # Generate the sequence. 160 generic_fns.sequence.generate(mol_name, res_num, res_name, spin_num, spin_name, verbose=False) 161 162 # Get the spin identification string. 163 spin_id = generate_spin_id(mol_name, res_num, res_name, spin_num, spin_name) 164 165 # Set the selection status. 166 select = bool(int(spin_line[col['select']])) 167 if select: 168 generic_fns.selection.sel_spin(spin_id) 169 else: 170 generic_fns.selection.desel_spin(spin_id)
171 172
173 - def _get_spin_id(self, spin_line, col, verbosity=1):
174 """Get the spin identification string corresponding to spin_line. 175 176 @param spin_line: The line of data for a single spin. 177 @type spin_line: list of str 178 @param col: The column indices. 179 @type col: dict of int 180 @keyword verbosity: A variable specifying the amount of information to print. The higher 181 the value, the greater the verbosity. 182 @type verbosity: int 183 """ 184 185 # The spin info (for relax 1.2). 186 if 'num' in col: 187 mol_name = None 188 res_num = int(spin_line[col['num']]) 189 res_name = spin_line[col['name']] 190 spin_num = None 191 spin_name = None 192 193 # The spin info. 194 else: 195 mol_name = spin_line[col['mol_name']] 196 res_num = int(spin_line[col['res_num']]) 197 res_name = spin_line[col['res_name']] 198 spin_num = int(spin_line[col['spin_num']]) 199 spin_name = spin_line[col['spin_name']] 200 201 # Return the spin container. 202 return generate_spin_id(mol_name, res_num, res_name, spin_num, spin_name)
203 204
205 - def _load_model_free_data(self, spin_line, col, data_set, spin, spin_id, verbosity=1):
206 """Read the model-free data for the spin. 207 208 @param spin_line: The line of data for a single spin. 209 @type spin_line: list of str 210 @param col: The column indices. 211 @type col: dict of int 212 @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is 213 a number). 214 @type data_set: str 215 @param spin: The spin container. 216 @type spin: SpinContainer instance 217 @param spin_id: The spin identification string. 218 @type spin_id: str 219 @keyword verbosity: A variable specifying the amount of information to print. The higher 220 the value, the greater the verbosity. 221 @type verbosity: int 222 """ 223 224 # Set up the model-free models. 225 if data_set == 'value': 226 # Get the model-free model. 227 model = spin_line[col['model']] 228 if model == 'None': 229 model = None 230 231 # Get the model-free equation. 232 equation = spin_line[col['eqi']] 233 if equation == 'None': 234 equation = None 235 236 # Get the model-free parameters. 237 params = eval(spin_line[col['params']]) 238 239 # Loop over and convert the parameters. 240 if params: 241 for i in xrange(len(params)): 242 # Fix for the 1.2 relax versions whereby the parameter 'tm' was renamed to 'local_tm' (which occurred in version 1.2.5). 243 if params[i] == 'tm': 244 params[i] = 'local_tm' 245 246 # Lower case conversion. 247 params[i] = lower(params[i]) 248 249 # Set up the model-free model. 250 self._model_setup(model=model, equation=equation, params=params, spin_id=spin_id) 251 252 # The model type. 253 model_type = spin_line[col['param_set']] 254 255 # Values. 256 if data_set == 'value': 257 # S2. 258 try: 259 spin.s2 = float(spin_line[col['s2']]) * self.return_conversion_factor('s2') 260 except ValueError: 261 spin.s2 = None 262 263 # S2f. 264 try: 265 spin.s2f = float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f') 266 except ValueError: 267 spin.s2f = None 268 269 # S2s. 270 try: 271 spin.s2s = float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s') 272 except ValueError: 273 spin.s2s = None 274 275 # Local tm. 276 try: 277 spin.local_tm = float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm') 278 except ValueError: 279 spin.local_tm = None 280 281 # te. 282 try: 283 spin.te = float(spin_line[col['te']]) * self.return_conversion_factor('te') 284 except ValueError: 285 spin.te = None 286 287 # tf. 288 try: 289 spin.tf = float(spin_line[col['tf']]) * self.return_conversion_factor('tf') 290 except ValueError: 291 spin.tf = None 292 293 # ts. 294 try: 295 spin.ts = float(spin_line[col['ts']]) * self.return_conversion_factor('ts') 296 except ValueError: 297 spin.ts = None 298 299 # Rex. 300 try: 301 spin.rex = float(spin_line[col['rex']]) * self.return_conversion_factor('rex') 302 except ValueError: 303 spin.rex = None 304 305 # Bond length. 306 try: 307 spin.r = float(spin_line[col['r']]) * self.return_conversion_factor('r') 308 except ValueError: 309 spin.r = None 310 311 # CSA. 312 try: 313 spin.csa = float(spin_line[col['csa']]) * self.return_conversion_factor('csa') 314 except ValueError: 315 spin.csa = None 316 317 # Minimisation details (global minimisation results). 318 if model_type == 'diff' or model_type == 'all': 319 cdp.chi2 = eval(spin_line[col['chi2']]) 320 cdp.iter = eval(spin_line[col['iter']]) 321 cdp.f_count = eval(spin_line[col['f_count']]) 322 cdp.g_count = eval(spin_line[col['g_count']]) 323 cdp.h_count = eval(spin_line[col['h_count']]) 324 if spin_line[col['warn']] == 'None': 325 cdp.warning = None 326 else: 327 cdp.warning = replace(spin_line[col['warn']], '_', ' ') 328 329 # Minimisation details (individual residue results). 330 else: 331 spin.chi2 = eval(spin_line[col['chi2']]) 332 spin.iter = eval(spin_line[col['iter']]) 333 spin.f_count = eval(spin_line[col['f_count']]) 334 spin.g_count = eval(spin_line[col['g_count']]) 335 spin.h_count = eval(spin_line[col['h_count']]) 336 if spin_line[col['warn']] == 'None': 337 spin.warning = None 338 else: 339 spin.warning = replace(spin_line[col['warn']], '_', ' ') 340 341 # Errors. 342 if data_set == 'error': 343 # S2. 344 try: 345 spin.s2_err = float(spin_line[col['s2']]) * self.return_conversion_factor('s2') 346 except ValueError: 347 spin.s2_err = None 348 349 # S2f. 350 try: 351 spin.s2f_err = float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f') 352 except ValueError: 353 spin.s2f_err = None 354 355 # S2s. 356 try: 357 spin.s2s_err = float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s') 358 except ValueError: 359 spin.s2s_err = None 360 361 # Local tm. 362 try: 363 spin.local_tm_err = float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm') 364 except ValueError: 365 spin.local_tm_err = None 366 367 # te. 368 try: 369 spin.te_err = float(spin_line[col['te']]) * self.return_conversion_factor('te') 370 except ValueError: 371 spin.te_err = None 372 373 # tf. 374 try: 375 spin.tf_err = float(spin_line[col['tf']]) * self.return_conversion_factor('tf') 376 except ValueError: 377 spin.tf_err = None 378 379 # ts. 380 try: 381 spin.ts_err = float(spin_line[col['ts']]) * self.return_conversion_factor('ts') 382 except ValueError: 383 spin.ts_err = None 384 385 # Rex. 386 try: 387 spin.rex_err = float(spin_line[col['rex']]) * self.return_conversion_factor('rex') 388 except ValueError: 389 spin.rex_err = None 390 391 # Bond length. 392 try: 393 spin.r_err = float(spin_line[col['r']]) * self.return_conversion_factor('r') 394 except ValueError: 395 spin.r_err = None 396 397 # CSA. 398 try: 399 spin.csa_err = float(spin_line[col['csa']]) * self.return_conversion_factor('csa') 400 except ValueError: 401 spin.csa_err = None 402 403 404 # Construct the simulation data structures. 405 if data_set == 'sim_0': 406 # Get the parameter object names. 407 param_names = self.data_names(set='params') 408 409 # Get the minimisation statistic object names. 410 min_names = self.data_names(set='min') 411 412 # Loop over all the parameter names. 413 for object_name in param_names: 414 # Name for the simulation object. 415 sim_object_name = object_name + '_sim' 416 417 # Create the simulation object. 418 setattr(spin, sim_object_name, []) 419 420 # Loop over all the minimisation object names. 421 for object_name in min_names: 422 # Name for the simulation object. 423 sim_object_name = object_name + '_sim' 424 425 # Create the simulation object. 426 if model_type == 'diff' or model_type == 'all': 427 setattr(cdp, sim_object_name, []) 428 object = getattr(cdp, sim_object_name) 429 object = [] 430 else: 431 setattr(spin, sim_object_name, []) 432 433 # Simulations. 434 if data_set != 'value' and data_set != 'error': 435 # S2. 436 try: 437 spin.s2_sim.append(float(spin_line[col['s2']]) * self.return_conversion_factor('s2')) 438 except ValueError: 439 spin.s2_sim.append(None) 440 441 # S2f. 442 try: 443 spin.s2f_sim.append(float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f')) 444 except ValueError: 445 spin.s2f_sim.append(None) 446 447 # S2s. 448 try: 449 spin.s2s_sim.append(float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s')) 450 except ValueError: 451 spin.s2s_sim.append(None) 452 453 # Local tm. 454 try: 455 spin.local_tm_sim.append(float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm')) 456 except ValueError: 457 spin.local_tm_sim.append(None) 458 459 # te. 460 try: 461 spin.te_sim.append(float(spin_line[col['te']]) * self.return_conversion_factor('te')) 462 except ValueError: 463 spin.te_sim.append(None) 464 465 # tf. 466 try: 467 spin.tf_sim.append(float(spin_line[col['tf']]) * self.return_conversion_factor('tf')) 468 except ValueError: 469 spin.tf_sim.append(None) 470 471 # ts. 472 try: 473 spin.ts_sim.append(float(spin_line[col['ts']]) * self.return_conversion_factor('ts')) 474 except ValueError: 475 spin.ts_sim.append(None) 476 477 # Rex. 478 try: 479 spin.rex_sim.append(float(spin_line[col['rex']]) * self.return_conversion_factor('rex')) 480 except ValueError: 481 spin.rex_sim.append(None) 482 483 # Bond length. 484 try: 485 spin.r_sim.append(float(spin_line[col['r']]) * self.return_conversion_factor('r')) 486 except ValueError: 487 spin.r_sim.append(None) 488 489 # CSA. 490 try: 491 spin.csa_sim.append(float(spin_line[col['csa']]) * self.return_conversion_factor('csa')) 492 except ValueError: 493 spin.csa_sim.append(None) 494 495 # Minimisation details (global minimisation results). 496 if model_type == 'diff' or model_type == 'all': 497 # The simulation index. 498 index = int(split(data_set, '_')[1]) 499 500 # Already loaded. 501 if len(cdp.chi2_sim) == index + 1: 502 return 503 504 # Set the values. 505 cdp.chi2_sim.append(eval(spin_line[col['chi2']])) 506 cdp.iter_sim.append(eval(spin_line[col['iter']])) 507 cdp.f_count_sim.append(eval(spin_line[col['f_count']])) 508 cdp.g_count_sim.append(eval(spin_line[col['g_count']])) 509 cdp.h_count_sim.append(eval(spin_line[col['h_count']])) 510 if spin_line[col['warn']] == 'None': 511 cdp.warning_sim.append(None) 512 else: 513 cdp.warning_sim.append(replace(spin_line[col['warn']], '_', ' ')) 514 515 # Minimisation details (individual residue results). 516 else: 517 spin.chi2_sim.append(eval(spin_line[col['chi2']])) 518 spin.iter_sim.append(eval(spin_line[col['iter']])) 519 spin.f_count_sim.append(eval(spin_line[col['f_count']])) 520 spin.g_count_sim.append(eval(spin_line[col['g_count']])) 521 spin.h_count_sim.append(eval(spin_line[col['h_count']])) 522 if spin_line[col['warn']] == 'None': 523 spin.warning_sim.append(None) 524 else: 525 spin.warning_sim.append(replace(spin_line[col['warn']], '_', ' '))
526 527
528 - def _load_relax_data(self, spin_line, col, data_set, spin, verbosity=1):
529 """Load the relaxation data. 530 531 @param spin_line: The line of data for a single spin. 532 @type spin_line: list of str 533 @param col: The column indices. 534 @type col: dict of int 535 @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is 536 a number). 537 @type data_set: str 538 @param spin: The spin container. 539 @type spin: SpinContainer instance 540 @keyword verbosity: A variable specifying the amount of information to print. The higher 541 the value, the greater the verbosity. 542 @type verbosity: int 543 """ 544 545 # Skip the error 'data_set'. 546 if data_set == 'error': 547 return 548 549 # Relaxation data structures. 550 ri_labels = eval(spin_line[col['ri_labels']]) 551 remap_table = eval(spin_line[col['remap_table']]) 552 frq_labels = eval(spin_line[col['frq_labels']]) 553 frq = eval(spin_line[col['frq']]) 554 555 # No relaxation data. 556 if not ri_labels: 557 return 558 559 # Initialise the value and error arrays. 560 values = [] 561 errors = [] 562 563 # Loop over the relaxation data of the residue. 564 for i in xrange(len(ri_labels)): 565 # Determine the data and error columns for this relaxation data set. 566 data_col = col['frq'] + i + 1 567 error_col = col['frq'] + len(ri_labels) + i + 1 568 569 # Append the value and error. 570 values.append(eval(spin_line[data_col])) 571 errors.append(eval(spin_line[error_col])) 572 573 # Simulations. 574 sim = True 575 if data_set == 'value' or data_set == 'error': 576 sim = False 577 578 # Loop over the relaxation data sets. 579 for i in range(len(ri_labels)): 580 # The ID string. 581 ri_id = "%s_%s" % (ri_labels[i], frq_labels[remap_table[i]]) 582 583 # Initialise the global structures if necessary. 584 if not hasattr(cdp, 'ri_ids'): 585 cdp.ri_ids = [] 586 if not hasattr(cdp, 'ri_type'): 587 cdp.ri_type = {} 588 if not hasattr(cdp, 'frq'): 589 cdp.frq = {} 590 591 # Update the global structures if necessary. 592 if ri_id not in cdp.ri_ids: 593 cdp.ri_ids.append(ri_id) 594 cdp.ri_type[ri_id] = ri_labels[i] 595 cdp.frq[ri_id] = frq[remap_table[i]] 596 597 # Simulation data. 598 if sim: 599 # Initialise. 600 if not hasattr(spin, 'ri_data_sim'): 601 spin.ri_data_sim = {} 602 603 # Set the value. 604 spin.ri_data_sim[ri_id] = values[i] 605 606 # Normal data. 607 else: 608 # Initialise. 609 if not hasattr(spin, 'ri_data'): 610 spin.ri_data = {} 611 if not hasattr(spin, 'ri_data_err'): 612 spin.ri_data_err = {} 613 614 # Set the value. 615 if values[i] != None: 616 spin.ri_data[ri_id] = values[i] 617 if errors[i] != None: 618 spin.ri_data_err[ri_id] = errors[i]
619 620
621 - def _load_structure(self, spin_line, col, verbosity=1):
622 """Load the structure back into the current data pipe. 623 624 @param spin_line: The line of data for a single spin. 625 @type spin_line: list of str 626 @param col: The column indices. 627 @type col: dict of int 628 @keyword verbosity: A variable specifying the amount of information to print. The higher 629 the value, the greater the verbosity. 630 @type verbosity: int 631 @return: True if the structure was loaded, False otherwise. 632 @rtype: bool 633 """ 634 635 # File name. 636 pdb = spin_line[col['pdb']] 637 638 # PDB model. 639 pdb_model = eval(spin_line[col['pdb_model']]) 640 641 # Read the PDB file (if it exists). 642 if not pdb == 'None': 643 generic_fns.structure.main.read_pdb(file=pdb, set_model_num=pdb_model, fail=False, verbosity=verbosity) 644 return True 645 else: 646 return False
647 648
649 - def _read_1_2_results(self, file_data, verbosity=1):
650 """Read the relax 1.2 model-free results file. 651 652 @param file_data: The processed results file data. 653 @type file_data: list of lists of str 654 @keyword verbosity: A variable specifying the amount of information to print. The higher 655 the value, the greater the verbosity. 656 @type verbosity: int 657 """ 658 659 # Extract and remove the header. 660 header = file_data[0] 661 file_data = file_data[1:] 662 663 # Sort the column numbers. 664 col = self._read_col_numbers(header) 665 666 # Test the file. 667 if len(col) < 2: 668 raise RelaxInvalidDataError 669 670 # Initialise some data structures and flags. 671 sim_num = None 672 sims = [] 673 all_select_sim = [] 674 diff_data_set = False 675 diff_error_set = False 676 diff_sim_set = None 677 model_type = None 678 pdb = False 679 pdb_model = None 680 pdb_heteronuc = None 681 pdb_proton = None 682 ri_labels = None 683 684 # Generate the sequence. 685 if verbosity: 686 print("\nGenerating the sequence.") 687 for file_line in file_data: 688 # The data set. 689 data_set = file_line[col['data_set']] 690 691 # Stop creating the sequence once the data_set is no longer 'value'. 692 if data_set != 'value': 693 break 694 695 # Sequence. 696 self._generate_sequence(file_line, col, verbosity) 697 698 699 # Loop over the lines of the file data. 700 for file_line in file_data: 701 # The data set. 702 data_set = file_line[col['data_set']] 703 704 # Get the spin container. 705 spin_id = self._get_spin_id(file_line, col, verbosity) 706 spin = return_spin(spin_id) 707 708 # Backwards compatibility for the reading of the results file from versions 1.2.0 to 1.2.9. 709 if len(file_line) == 4: 710 continue 711 712 # Set the heteronucleus and proton types (absent from the 1.2 results file). 713 if data_set == 'value': 714 if file_line[col['nucleus']] != 'None': 715 if search('N', file_line[col['nucleus']]): 716 generic_fns.value.set(val='15N', param='heteronuc_type', spin_id=spin_id, reset=False) 717 elif search('C', file_line[col['nucleus']]): 718 generic_fns.value.set(val='13C', param='heteronuc_type', spin_id=spin_id, reset=False) 719 generic_fns.value.set(val='1H', param='proton_type', spin_id=spin_id, reset=False) 720 721 # Simulation number. 722 if data_set != 'value' and data_set != 'error': 723 # Extract the number from the data_set string. 724 sim_num = split(data_set, '_') 725 try: 726 sim_num = int(sim_num[1]) 727 except: 728 raise RelaxError("The simulation number '%s' is invalid." % sim_num) 729 730 # A new simulation number. 731 if sim_num not in sims: 732 # Update the sims array and append an empty array to the selected sims array. 733 sims.append(sim_num) 734 all_select_sim.append([]) 735 736 # Selected simulations. 737 all_select_sim[-1].append(bool(file_line[col['select']])) 738 739 # Initial print out for the simulation. 740 if verbosity: 741 if diff_sim_set == None: 742 print("\nLoading simulations.") 743 if sim_num != diff_sim_set: 744 print(data_set) 745 746 # Diffusion tensor data. 747 if data_set == 'value' and not diff_data_set: 748 self._set_diff_tensor(file_line, col, data_set, verbosity) 749 diff_data_set = True 750 751 # Diffusion tensor errors. 752 elif data_set == 'error' and not diff_error_set: 753 self._set_diff_tensor(file_line, col, data_set, verbosity) 754 diff_error_set = True 755 756 # Diffusion tensor simulation data. 757 elif data_set != 'value' and data_set != 'error' and sim_num != diff_sim_set: 758 self._set_diff_tensor(file_line, col, data_set, verbosity) 759 diff_sim_set = sim_num 760 761 # Model type. 762 if model_type == None: 763 self._fix_params(file_line, col, verbosity) 764 765 # PDB. 766 if not pdb: 767 if self._load_structure(file_line, col, verbosity): 768 pdb = True 769 770 # XH vector, heteronucleus, and proton. 771 if data_set == 'value': 772 self._set_xh_vect(file_line, col, spin, verbosity) 773 774 # Relaxation data. 775 self._load_relax_data(file_line, col, data_set, spin, verbosity) 776 777 # Model-free data. 778 self._load_model_free_data(file_line, col, data_set, spin, spin_id, verbosity) 779 780 # Set up the simulations. 781 if len(sims): 782 # Convert the selected simulation array of arrays into a Numeric matrix, transpose it, then convert back to a Python list. 783 all_select_sim = transpose(array(all_select_sim)) 784 all_select_sim = all_select_sim.tolist() 785 786 # Set up the Monte Carlo simulations. 787 generic_fns.monte_carlo.setup(number=len(sims), all_select_sim=all_select_sim) 788 789 # Turn the simulation state to off! 790 cdp.sim_state = False
791 792
793 - def _read_col_numbers(self, header):
794 """Determine the column indices from the header line. 795 796 @param header: The header line. 797 @type header: list of str 798 @return: The column indices. 799 @rtype: dictionary of int 800 """ 801 802 # Initialise the dictionary of column indices. 803 col = {} 804 805 # Loop over the columns. 806 for i in xrange(len(header)): 807 # Residue info (for relax 1.2). 808 if header[i] == 'Num': 809 col['num'] = i 810 elif header[i] == 'Name': 811 col['name'] = i 812 813 # Spin information. 814 elif header[i] == 'Spin_id': 815 col['spin_id'] = i 816 elif header[i] == 'Selected': 817 col['select'] = i 818 elif header[i] == 'Data_set': 819 col['data_set'] = i 820 elif header[i] == 'Nucleus': 821 col['nucleus'] = i 822 elif header[i] == 'Model': 823 col['model'] = i 824 elif header[i] == 'Equation': 825 col['eqi'] = i 826 elif header[i] == 'Params': 827 col['params'] = i 828 elif header[i] == 'Param_set': 829 col['param_set'] = i 830 831 # Parameters. 832 elif header[i] == 'S2': 833 col['s2'] = i 834 elif header[i] == 'S2f': 835 col['s2f'] = i 836 elif header[i] == 'S2s': 837 col['s2s'] = i 838 elif search('^Local_tm', header[i]): 839 col['local_tm'] = i 840 elif search('^te', header[i]): 841 col['te'] = i 842 elif search('^tf', header[i]): 843 col['tf'] = i 844 elif search('^ts', header[i]): 845 col['ts'] = i 846 elif search('^Rex', header[i]): 847 col['rex'] = i 848 elif search('^Bond_length', header[i]): 849 col['r'] = i 850 elif search('^CSA', header[i]): 851 col['csa'] = i 852 853 # Minimisation info. 854 elif header[i] == 'Chi-squared': 855 col['chi2'] = i 856 elif header[i] == 'Iter': 857 col['iter'] = i 858 elif header[i] == 'f_count': 859 col['f_count'] = i 860 elif header[i] == 'g_count': 861 col['g_count'] = i 862 elif header[i] == 'h_count': 863 col['h_count'] = i 864 elif header[i] == 'Warning': 865 col['warn'] = i 866 867 # Diffusion tensor (for relax 1.2). 868 elif header[i] == 'Diff_type': 869 col['diff_type'] = i 870 elif header[i] == 'tm_(s)': 871 col['tm'] = i 872 elif header[i] == 'Da_(1/s)': 873 col['da'] = i 874 elif header[i] == 'theta_(deg)': 875 col['theta'] = i 876 elif header[i] == 'phi_(deg)': 877 col['phi'] = i 878 elif header[i] == 'Da_(1/s)': 879 col['da'] = i 880 elif header[i] == 'Dr_(1/s)': 881 col['dr'] = i 882 elif header[i] == 'alpha_(deg)': 883 col['alpha'] = i 884 elif header[i] == 'beta_(deg)': 885 col['beta'] = i 886 elif header[i] == 'gamma_(deg)': 887 col['gamma'] = i 888 889 # PDB and XH vector (for relax 1.2). 890 elif header[i] == 'PDB': 891 col['pdb'] = i 892 elif header[i] == 'PDB_model': 893 col['pdb_model'] = i 894 elif header[i] == 'PDB_heteronuc': 895 col['pdb_heteronuc'] = i 896 elif header[i] == 'PDB_proton': 897 col['pdb_proton'] = i 898 elif header[i] == 'XH_vector': 899 col['xh_vect'] = i 900 901 # Relaxation data (for relax 1.2). 902 elif header[i] == 'Ri_labels': 903 col['ri_labels'] = i 904 elif header[i] == 'Remap_table': 905 col['remap_table'] = i 906 elif header[i] == 'Frq_labels': 907 col['frq_labels'] = i 908 elif header[i] == 'Frequencies': 909 col['frq'] = i 910 911 # Return the column indices. 912 return col
913 914
915 - def _set_diff_tensor(self, spin_line, col, data_set, verbosity=1):
916 """Set up the diffusion tensor. 917 918 @param spin_line: The line of data for a single spin. 919 @type spin_line: list of str 920 @param col: The column indices. 921 @type col: dict of int 922 @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is 923 a number). 924 @type data_set: str 925 @keyword verbosity: A variable specifying the amount of information to print. The higher 926 the value, the greater the verbosity. 927 @type verbosity: int 928 """ 929 930 # The diffusion tensor type. 931 diff_type = spin_line[col['diff_type']] 932 if diff_type == 'None': 933 diff_type = None 934 935 # Print out. 936 if diff_type and data_set == 'value' and verbosity: 937 print("\nSetting the diffusion tensor.") 938 print(("Diffusion type: " + diff_type)) 939 940 # Sphere. 941 if diff_type == 'sphere': 942 # Convert the parameters to floating point numbers. 943 try: 944 tm = float(spin_line[col['tm']]) 945 except ValueError: 946 # Errors or simulation values set to None. 947 if data_set != 'value' and spin_line[col['tm']] == 'None': 948 return 949 950 # Genuine error. 951 raise RelaxError("The diffusion tensor parameters are not numbers.") 952 953 # Values. 954 if data_set == 'value': 955 diff_params = tm 956 957 # Errors. 958 elif data_set == 'error': 959 cdp.diff.tm_err = tm 960 961 # Simulation values. 962 else: 963 # Create the data structure if it doesn't exist. 964 if not hasattr(cdp.diff_tensor, 'tm_sim'): 965 cdp.diff.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor) 966 967 # Append the value. 968 cdp.diff_tensor.tm_sim.append(tm) 969 970 971 # Spheroid. 972 elif diff_type == 'spheroid' or diff_type == 'oblate' or diff_type == 'prolate': 973 # Convert the parameters to floating point numbers. 974 try: 975 tm = float(spin_line[col['tm']]) 976 Da = float(spin_line[col['da']]) 977 theta = float(spin_line[col['theta']]) / 360.0 * 2.0 * pi 978 phi = float(spin_line[col['phi']]) / 360.0 * 2.0 * pi 979 except ValueError: 980 # Errors or simulation values set to None. 981 if data_set != 'value' and spin_line[col['tm']] == 'None': 982 return 983 984 # Genuine error. 985 raise RelaxError("The diffusion tensor parameters are not numbers.") 986 987 # Values. 988 if data_set == 'value': 989 diff_params = [tm, Da, theta, phi] 990 991 # Errors. 992 elif data_set == 'error': 993 cdp.diff_tensor.tm_err = tm 994 cdp.diff_tensor.Da_err = Da 995 cdp.diff_tensor.theta_err = theta 996 cdp.diff_tensor.phi_err = phi 997 998 # Simulation values. 999 else: 1000 # Create the data structure if it doesn't exist. 1001 if not hasattr(cdp.diff, 'tm_sim'): 1002 cdp.diff_tensor.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor) 1003 if not hasattr(cdp.diff, 'Da_sim'): 1004 cdp.diff_tensor.Da_sim = DiffTensorSimList('Da', cdp.diff_tensor) 1005 if not hasattr(cdp.diff, 'theta_sim'): 1006 cdp.diff_tensor.theta_sim = DiffTensorSimList('theta', cdp.diff_tensor) 1007 if not hasattr(cdp.diff, 'phi_sim'): 1008 cdp.diff_tensor.phi_sim = DiffTensorSimList('phi', cdp.diff_tensor) 1009 1010 # Append the value. 1011 cdp.diff_tensor.tm_sim.append(tm) 1012 cdp.diff_tensor.Da_sim.append(Da) 1013 cdp.diff_tensor.theta_sim.append(theta) 1014 cdp.diff_tensor.phi_sim.append(phi) 1015 1016 1017 # Ellipsoid. 1018 elif diff_type == 'ellipsoid': 1019 # Convert the parameters to floating point numbers. 1020 try: 1021 tm = float(spin_line[col['tm']]) 1022 Da = float(spin_line[col['da']]) 1023 Dr = float(spin_line[col['dr']]) 1024 alpha = float(spin_line[col['alpha']]) / 360.0 * 2.0 * pi 1025 beta = float(spin_line[col['beta']]) / 360.0 * 2.0 * pi 1026 gamma = float(spin_line[col['gamma']]) / 360.0 * 2.0 * pi 1027 except ValueError: 1028 # Errors or simulation values set to None. 1029 if data_set != 'value' and spin_line[col['tm']] == 'None': 1030 return 1031 1032 # Genuine error. 1033 raise RelaxError("The diffusion tensor parameters are not numbers.") 1034 1035 # Values. 1036 if data_set == 'value': 1037 diff_params = [tm, Da, Dr, alpha, beta, gamma] 1038 1039 # Errors. 1040 elif data_set == 'error': 1041 cdp.diff_tensor.tm_err = tm 1042 cdp.diff_tensor.Da_err = Da 1043 cdp.diff_tensor.Dr_err = Dr 1044 cdp.diff_tensor.alpha_err = alpha 1045 cdp.diff_tensor.beta_err = beta 1046 cdp.diff_tensor.gamma_err = gamma 1047 1048 # Simulation values. 1049 else: 1050 # Create the data structure if it doesn't exist. 1051 if not hasattr(cdp.diff_tensor, 'tm_sim'): 1052 cdp.diff_tensor.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor) 1053 if not hasattr(cdp.diff_tensor, 'Da_sim'): 1054 cdp.diff_tensor.Da_sim = DiffTensorSimList('Da', cdp.diff_tensor) 1055 if not hasattr(cdp.diff_tensor, 'Dr_sim'): 1056 cdp.diff_tensor.Dr_sim = DiffTensorSimList('Dr', cdp.diff_tensor) 1057 if not hasattr(cdp.diff_tensor, 'alpha_sim'): 1058 cdp.diff_tensor.alpha_sim = DiffTensorSimList('alpha', cdp.diff_tensor) 1059 if not hasattr(cdp.diff_tensor, 'beta_sim'): 1060 cdp.diff_tensor.beta_sim = DiffTensorSimList('beta', cdp.diff_tensor) 1061 if not hasattr(cdp.diff_tensor, 'gamma_sim'): 1062 cdp.diff_tensor.gamma_sim = DiffTensorSimList('gamma', cdp.diff_tensor) 1063 1064 # Append the value. 1065 cdp.diff_tensor.tm_sim.append(tm) 1066 cdp.diff_tensor.Da_sim.append(Da) 1067 cdp.diff_tensor.Dr_sim.append(Dr) 1068 cdp.diff_tensor.alpha_sim.append(alpha) 1069 cdp.diff_tensor.beta_sim.append(beta) 1070 cdp.diff_tensor.gamma_sim.append(gamma) 1071 1072 1073 # Set the diffusion tensor. 1074 if data_set == 'value' and diff_type: 1075 # Sort out the spheroid type. 1076 spheroid_type = None 1077 if diff_type == 'oblate' or diff_type == 'prolate': 1078 spheroid_type = diff_type 1079 1080 # Set the diffusion tensor. 1081 generic_fns.diffusion_tensor.init(params=diff_params, angle_units='rad', spheroid_type=spheroid_type)
1082 1083
1084 - def _set_xh_vect(self, spin_line, col, spin, verbosity=1):
1085 """Set the XH unit vector and the attached proton name. 1086 1087 @param spin_line: The line of data for a single spin. 1088 @type spin_line: list of str 1089 @param col: The column indices. 1090 @type col: dict of int 1091 @param spin: The spin container. 1092 @type spin: SpinContainer instance 1093 @keyword verbosity: A variable specifying the amount of information to print. The higher 1094 the value, the greater the verbosity. 1095 @type verbosity: int 1096 """ 1097 1098 # The vector. 1099 xh_vect = eval(spin_line[col['xh_vect']]) 1100 if xh_vect: 1101 # numpy array format. 1102 try: 1103 xh_vect = array(xh_vect, float64) 1104 except: 1105 raise RelaxError("The XH unit vector " + spin_line[col['xh_vect']] + " is invalid.") 1106 1107 # Set the vector. 1108 spin.xh_vect = xh_vect 1109 1110 # The attached proton name. 1111 spin.attached_proton = spin_line[col['pdb_proton']] 1112 if spin.attached_proton == 'None': 1113 spin.attached_proton = None
1114 1115
1116 - def read_columnar_results(self, file_data, verbosity=1):
1117 """Read the columnar formatted model-free results file. 1118 1119 @param file_data: The processed results file data. 1120 @type file_data: list of lists of str 1121 @keyword verbosity: A variable specifying the amount of information to print. The higher 1122 the value, the greater the verbosity. 1123 @type verbosity: int 1124 """ 1125 1126 # Determine the results file version. 1127 version = self._determine_version(file_data, verbosity) 1128 1129 # Execute the version specific methods. 1130 if version == '1.2': 1131 self._read_1_2_results(file_data, verbosity)
1132