1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing functions for the handling of chemical shifts."""
24
25
26
27 import sys
28 from warnings import warn
29
30
31 from lib.errors import RelaxError, RelaxNoSequenceError
32 from lib.io import write_data
33 from lib.spectrum.peak_list import read_peak_list
34 from lib.warnings import RelaxNoSpinWarning
35 from pipe_control.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_unique, return_spin
36 from pipe_control.pipes import check_pipe
37
38
39 -def read(file=None, dir=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, verbose=True):
40 """Read the peak intensity data.
41
42 @keyword file: The name of the file containing the peak intensities.
43 @type file: str
44 @keyword dir: The directory where the file is located.
45 @type dir: str
46 @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none.
47 @type spin_id_col: int or None
48 @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
49 @type mol_name_col: int or None
50 @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
51 @type res_name_col: int or None
52 @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
53 @type res_num_col: int or None
54 @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
55 @type spin_name_col: int or None
56 @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
57 @type spin_num_col: int or None
58 @keyword sep: The column separator which, if None, defaults to whitespace.
59 @type sep: str or None
60 @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins. If 'auto' is provided for a NMRPipe seriesTab formatted file, the ID's are auto generated in form of Z_Ai.
61 @type spin_id: None or str
62 @keyword verbose: A flag which if True will cause all chemical shift data loaded to be printed out.
63 @type verbose: bool
64 """
65
66
67 check_pipe()
68
69
70 if not exists_mol_res_spin_data():
71 raise RelaxNoSequenceError
72
73
74 if file == None:
75 raise RelaxError("The file name must be supplied.")
76
77
78 peak_list = read_peak_list(file=file, dir=dir, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id)
79
80
81 data = []
82 data_flag = False
83 for assign in peak_list:
84
85 for i in range(peak_list.dimensionality):
86
87 spin_id = generate_spin_id_unique(res_num=assign.res_nums[i], spin_name=assign.spin_names[i])
88
89
90 spin = return_spin(spin_id)
91 if not spin:
92 warn(RelaxNoSpinWarning(spin_id))
93 continue
94
95
96 if not spin.select:
97 continue
98
99
100 spin.chemical_shift = assign.shifts[i]
101
102
103 data_flag = True
104
105
106 data.append([spin_id, repr(spin.chemical_shift)])
107
108
109 if not data_flag:
110 raise RelaxError("No chemical shifts could be loaded from the peak list")
111
112
113 if verbose:
114 print("\nThe following chemical shifts have been loaded into the relax data store:\n")
115 write_data(out=sys.stdout, headings=["Spin_ID", "Chemical shift"], data=data)
116