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