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