1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The result creation and processing methods of the specific API for model-free analysis."""
24
25
26 from math import pi
27 from numpy import float64, array, transpose
28 from re import search
29
30
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
40 """Class containing methods specific to the model-free results files."""
41
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
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
61 else:
62 raise RelaxError("Cannot determine the relax version the model-free results file belongs to.")
63
64
65 if verbosity:
66 print("relax " + version + " model-free results file.")
67
68
69 return version
70
71
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
85 if spin_line[col['param_set']] != 'None':
86 model_type = spin_line[col['param_set']]
87 else:
88 return
89
90
91 if model_type == 'local_tm' or model_type == 'mf':
92 diff_fixed = True
93 mf_fixed = False
94
95
96 elif model_type == 'diff':
97 diff_fixed = False
98 mf_fixed = True
99
100
101 elif model_type == 'all':
102 diff_fixed = False
103 mf_fixed = False
104
105
106 elif model_type == 'None':
107 model_type = None
108 diff_fixed = None
109 mf_fixed = None
110
111
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
119 if model_type != 'local_tm' and diff_fixed != None:
120 cdp.diff_tensor.set_fixed(diff_fixed)
121
122
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
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
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
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
164 pipe_control.sequence.generate(mol_name, res_num, res_name, spin_num, spin_name, verbose=False)
165
166
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
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
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
197 if data_set == 'value':
198
199 model = spin_line[col['model']]
200 if model == 'None':
201 model = None
202
203
204 equation = spin_line[col['eqi']]
205 if equation == 'None':
206 equation = None
207
208
209 params = eval(spin_line[col['params']])
210
211
212 if params:
213 for i in range(len(params)):
214
215 if params[i] == 'tm':
216 params[i] = 'local_tm'
217
218
219 params[i] = params[i].lower()
220
221
222 self._model_setup(model=model, equation=equation, params=params, spin_id=spin_id)
223
224
225 model_type = spin_line[col['param_set']]
226
227
228 interatom = return_interatom_list(spin_id)[0]
229
230
231 if data_set == 'value':
232
233 try:
234 spin.s2 = float(spin_line[col['s2']]) * self.return_conversion_factor('s2')
235 except ValueError:
236 spin.s2 = None
237
238
239 try:
240 spin.s2f = float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f')
241 except ValueError:
242 spin.s2f = None
243
244
245 try:
246 spin.s2s = float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s')
247 except ValueError:
248 spin.s2s = None
249
250
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
257 try:
258 spin.te = float(spin_line[col['te']]) * self.return_conversion_factor('te')
259 except ValueError:
260 spin.te = None
261
262
263 try:
264 spin.tf = float(spin_line[col['tf']]) * self.return_conversion_factor('tf')
265 except ValueError:
266 spin.tf = None
267
268
269 try:
270 spin.ts = float(spin_line[col['ts']]) * self.return_conversion_factor('ts')
271 except ValueError:
272 spin.ts = None
273
274
275 try:
276 spin.rex = float(spin_line[col['rex']]) * self.return_conversion_factor('rex')
277 except ValueError:
278 spin.rex = None
279
280
281 try:
282 spin.csa = float(spin_line[col['csa']]) * self.return_conversion_factor('csa')
283 except ValueError:
284 spin.csa = None
285
286
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
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
311 try:
312 interatom.r = float(spin_line[col['r']]) * 1e-10
313 except ValueError:
314 interatom.r = None
315
316
317 if data_set == 'error':
318
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
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
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
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
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
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
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
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
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
373 if data_set == 'sim_0':
374
375 param_names = self.data_names(set='params', scope='spin')
376
377
378 min_names = self.data_names(set='min', scope='spin')
379
380
381 for object_name in param_names:
382
383 sim_object_name = object_name + '_sim'
384
385
386 setattr(spin, sim_object_name, [])
387
388
389 for object_name in min_names:
390
391 sim_object_name = object_name + '_sim'
392
393
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
402 if data_set != 'value' and data_set != 'error':
403
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
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
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
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
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
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
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
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
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
458 if model_type == 'diff' or model_type == 'all':
459
460 index = int(data_set.split('_')[1])
461
462
463 if len(cdp.chi2_sim) == index + 1:
464 return
465
466
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
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
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
508 if data_set == 'error':
509 return
510
511
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
518 if not ri_labels:
519 return
520
521
522 values = []
523 errors = []
524
525
526 for i in range(len(ri_labels)):
527
528 data_col = col['frq'] + i + 1
529 error_col = col['frq'] + len(ri_labels) + i + 1
530
531
532 values.append(eval(spin_line[data_col]))
533 errors.append(eval(spin_line[error_col]))
534
535
536 sim = True
537 if data_set == 'value' or data_set == 'error':
538 sim = False
539
540
541 for i in range(len(ri_labels)):
542
543 ri_id = "%s_%s" % (ri_labels[i], frq_labels[remap_table[i]])
544
545
546 if not hasattr(cdp, 'ri_ids'):
547 cdp.ri_ids = []
548 if not hasattr(cdp, 'ri_type'):
549 cdp.ri_type = {}
550
551
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
558 if sim:
559
560 if not hasattr(spin, 'ri_data_sim'):
561 spin.ri_data_sim = {}
562
563
564 spin.ri_data_sim[ri_id] = values[i]
565
566
567 else:
568
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
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
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
596 pdb = spin_line[col['pdb']]
597
598
599 pdb_model = eval(spin_line[col['pdb_model']])
600
601
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
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
620 header = file_data[0]
621 file_data = file_data[1:]
622
623
624 col = self._read_1_2_col_numbers(header)
625
626
627 if len(col) < 2:
628 raise RelaxInvalidDataError
629
630
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
645 if verbosity:
646 print("\nGenerating the sequence.")
647 for file_line in file_data:
648
649 data_set = file_line[col['data_set']]
650
651
652 if data_set != 'value':
653 break
654
655
656 self._generate_sequence(file_line, col, verbosity)
657
658
659 for file_line in file_data:
660
661 data_set = file_line[col['data_set']]
662
663
664 if data_set != 'value' and data_set != 'error':
665
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
675 for file_line in file_data:
676
677 data_set = file_line[col['data_set']]
678
679
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
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
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
703 spin = return_spin(spin_id)
704
705
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
715 if len(file_line) == 4:
716 continue
717
718
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
731 if data_set != 'value' and data_set != 'error':
732
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
740 if sim_num not in sims:
741
742 sims.append(sim_num)
743 all_select_sim.append([])
744
745
746 all_select_sim[-1].append(bool(file_line[col['select']]))
747
748
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
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
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
766 elif data_set != 'value' and data_set != 'error' and sim_num != diff_sim_set:
767
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
775 if model_type == None:
776 self._fix_params(file_line, col, verbosity)
777
778
779 if not pdb:
780 if self._load_structure(file_line, col, verbosity):
781 pdb = True
782
783
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
788 self._load_relax_data(file_line, col, data_set, spin, verbosity)
789
790
791 self._load_model_free_data(file_line, col, data_set, spin, spin_id, verbosity)
792
793
794 if len(sims):
795
796 all_select_sim = transpose(array(all_select_sim))
797 all_select_sim = all_select_sim.tolist()
798
799
800 pipe_control.monte_carlo.setup(number=len(sims), all_select_sim=all_select_sim)
801
802
803 cdp.sim_state = False
804
805
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
816 col = {}
817
818
819 for i in range(len(header)):
820
821 if header[i] == 'Num':
822 col['num'] = i
823 elif header[i] == 'Name':
824 col['name'] = i
825
826
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
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
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
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
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
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
925 return col
926
927
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
944 diff_type = spin_line[col['diff_type']]
945 if diff_type == 'None':
946 diff_type = None
947
948
949 if diff_type and data_set == 'value' and verbosity:
950 print("\nSetting the diffusion tensor.")
951 print("Diffusion type: " + diff_type)
952
953
954 if diff_type == 'sphere':
955
956 try:
957 tm = float(spin_line[col['tm']])
958 except ValueError:
959
960 if data_set != 'value' and spin_line[col['tm']] == 'None':
961 return
962
963
964 raise RelaxError("The diffusion tensor parameters are not numbers.")
965
966
967 if data_set == 'value':
968 diff_params = tm
969
970
971 elif data_set == 'error':
972 cdp.diff_tensor.set(param='tm', value=tm, category='err')
973
974
975 else:
976
977 cdp.diff_tensor.set(param='tm', value=tm, category='sim', sim_index=sim_num)
978
979
980
981 elif diff_type == 'spheroid' or diff_type == 'oblate' or diff_type == 'prolate':
982
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
990 if data_set != 'value' and spin_line[col['tm']] == 'None':
991 return
992
993
994 raise RelaxError("The diffusion tensor parameters are not numbers.")
995
996
997 if data_set == 'value':
998 diff_params = [tm, Da, theta, phi]
999
1000
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
1008 else:
1009
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
1017 elif diff_type == 'ellipsoid':
1018
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
1028 if data_set != 'value' and spin_line[col['tm']] == 'None':
1029 return
1030
1031
1032 raise RelaxError("The diffusion tensor parameters are not numbers.")
1033
1034
1035 if data_set == 'value':
1036 diff_params = [tm, Da, Dr, alpha, beta, gamma]
1037
1038
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
1048 else:
1049
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
1058 if data_set == 'value' and diff_type:
1059
1060 spheroid_type = None
1061 if diff_type == 'oblate' or diff_type == 'prolate':
1062 spheroid_type = diff_type
1063
1064
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
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
1091 vector = eval(spin_line[col['xh_vect']])
1092 if vector:
1093
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
1100 interatom.vector = vector
1101
1102
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
1114 version = self._determine_version(file_data, verbosity)
1115
1116
1117 if version == '1.2':
1118 self._read_1_2_results(file_data, verbosity)
1119