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

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