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

Source Code for Module specific_analyses.model_free.back_compat

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