1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from math import sqrt
25 from re import match
26 from warnings import warn
27
28
29 from generic_fns import pipes
30 from generic_fns.mol_res_spin import exists_mol_res_spin_data, spin_loop
31 from relax_errors import RelaxArgNotInListError, RelaxError, RelaxNoSequenceError
32 from relax_warnings import RelaxDeselectWarning
33 from specific_fns.api_common import API_common
34 from user_functions.data import Uf_tables; uf_tables = Uf_tables()
35 from user_functions.objects import Desc_container
36
37
39 """Class containing functions for relaxation data."""
40
41 - def _assign_function(self, spin=None, intensity=None, spectrum_type=None):
42 """Place the peak intensity data into the spin container.
43
44 The intensity data can be either that of the reference or saturated spectrum.
45
46 @keyword spin: The spin container.
47 @type spin: SpinContainer instance
48 @keyword intensity: The intensity value.
49 @type intensity: float
50 @keyword spectrum_type: The type of spectrum, one of 'ref' or 'sat'.
51 @type spectrum_type: str
52 """
53
54
55 if spectrum_type == 'ref':
56 spin.ref = intensity
57 elif spectrum_type == 'sat':
58 spin.sat = intensity
59 else:
60 raise RelaxError("The spectrum type '%s' is unknown." % spectrum_type)
61
62
63 - def _spectrum_type(self, spectrum_type=None, spectrum_id=None):
64 """Set the spectrum type corresponding to the spectrum_id.
65
66 @keyword spectrum_type: The type of NOE spectrum, one of 'ref' or 'sat'.
67 @type spectrum_type: str
68 @keyword spectrum_id: The spectrum id string.
69 @type spectrum_id: str
70 """
71
72
73 pipes.test()
74
75
76 if spectrum_id not in cdp.spectrum_ids:
77 raise RelaxError("The peak intensities corresponding to the spectrum id '%s' does not exist." % spectrum_id)
78
79
80 if not hasattr(cdp, 'spectrum_type'):
81 cdp.spectrum_type = {}
82
83
84 cdp.spectrum_type[spectrum_id] = spectrum_type
85
86
87 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
88 """Calculate the NOE and its error.
89
90 The error for each peak is calculated using the formula::
91 ___________________________________________
92 \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2
93 sd(NOE) = -----------------------------------------------
94 I(unsat)^2
95
96 @keyword spin_id: The spin identification string.
97 @type spin_id: None or str
98 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity.
99 @type verbosity: int
100 @keyword sim_index: The MC simulation index (unused).
101 @type sim_index: None
102 """
103
104
105 pipes.test()
106
107
108 if not hasattr(cdp, 'spectrum_type'):
109 raise RelaxError("The spectrum types have not been set.")
110
111
112 if not 'ref' in cdp.spectrum_type.values() or not 'sat' in cdp.spectrum_type.values():
113 raise RelaxError("The reference and saturated NOE spectra have not been loaded.")
114
115
116 for spin in spin_loop():
117
118 if not spin.select:
119 continue
120
121
122 sat = 0.0
123 sat_err = 0.0
124 ref = 0.0
125 ref_err = 0.0
126 for id in cdp.spectrum_ids:
127
128 if cdp.spectrum_type[id] == 'sat':
129 sat = sat + spin.intensities[id]
130 sat_err = sat_err + spin.intensity_err[id]
131
132
133 if cdp.spectrum_type[id] == 'ref':
134 ref = ref + spin.intensities[id]
135 ref_err = ref_err + spin.intensity_err[id]
136
137
138 spin.noe = sat / ref
139
140
141 spin.noe_err = sqrt((sat_err * ref)**2 + (ref_err * sat)**2) / ref**2
142
143
145 """Deselect spins which have insufficient data to support calculation."""
146
147
148 print("\n\nOver-fit spin deselection.\n")
149
150
151 if not exists_mol_res_spin_data():
152 raise RelaxNoSequenceError
153
154
155 for spin, spin_id in spin_loop(return_id=True):
156
157 if not spin.select:
158 continue
159
160
161 if not hasattr(spin, 'intensities') or not len(spin.intensities) == 2:
162 warn(RelaxDeselectWarning(spin_id, 'insufficient data'))
163 spin.select = False
164
165
166 elif not hasattr(spin, 'intensity_err') or not len(spin.intensity_err) == 2:
167 warn(RelaxDeselectWarning(spin_id, 'missing errors'))
168 spin.select = False
169
170
171 return_data_name_doc = Desc_container("NOE calculation data type string matching patterns")
172 _table = uf_tables.add_table(label="table: NOE data type patterns", caption="NOE data type string matching patterns.")
173 _table.add_headings(["Data type", "Object name"])
174 _table.add_row(["Reference intensity", "'ref'"])
175 _table.add_row(["Saturated intensity", "'sat'"])
176 _table.add_row(["NOE", "'noe'"])
177 return_data_name_doc.add_table(_table.label)
178
179
180 - def return_units(self, param):
181 """Dummy function which returns None as the stats have no units.
182
183 @param param: The name of the parameter to return the units string for.
184 @type param: str
185 @return: Nothing.
186 @rtype: None
187 """
188
189 return None
190