1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 from re import search
26 from warnings import warn
27
28
29 from api_base import API_base
30 from api_common import API_common
31 from generic_fns.mol_res_spin import exists_mol_res_spin_data, return_spin, spin_loop
32 from generic_fns import pipes
33 from maths_fns.consistency_tests import Consistency
34 from physical_constants import N15_CSA, NH_BOND_LENGTH, h_bar, mu0, return_gyromagnetic_ratio
35 from relax_errors import RelaxError, RelaxFuncSetupError, RelaxNoSequenceError, RelaxNoValueError, RelaxProtonTypeError, RelaxSpinTypeError
36 from relax_warnings import RelaxDeselectWarning
37
38
40 """Class containing functions specific to consistency testing."""
41
43 """Initialise the class by placing API_common methods into the API."""
44
45
46 self.base_data_loop = self._base_data_loop_spin
47 self.create_mc_data = self._create_mc_relax_data
48 self.default_value = self._default_value_spin
49 self.model_loop = self._model_loop_spin
50 self.return_conversion_factor = self._return_no_conversion_factor
51 self.return_data_name = self._return_data_name_spin
52 self.return_error = self._return_error_relax_data
53 self.return_grace_string = self._return_grace_string_spin
54 self.return_units = self._return_units_spin
55 self.return_value = self._return_value_general
56 self.set_param_values = self._set_param_values_spin
57 self.set_selected_sim = self._set_selected_sim_spin
58 self.sim_pack_data = self._sim_pack_relax_data
59
60
61 self.SPIN_PARAMS.add('j0', grace_string='\\qJ(0)\\Q')
62 self.SPIN_PARAMS.add('f_eta', grace_string='\\qF\\s\\xh\\Q')
63 self.SPIN_PARAMS.add('f_r2', grace_string='\\qF\\sR2\\Q')
64 self.SPIN_PARAMS.add('r', default=NH_BOND_LENGTH, units='Angstrom', grace_string='Bond length')
65 self.SPIN_PARAMS.add('csa', default=N15_CSA, units='ppm', grace_string='\\qCSA\\Q')
66 self.SPIN_PARAMS.add('heteronuc_type', default='15N')
67 self.SPIN_PARAMS.add('proton_type', default='1H')
68 self.SPIN_PARAMS.add('orientation', default=15.7, units='degrees', grace_string='\\q\\xq\\Q')
69 self.SPIN_PARAMS.add('tc', default=13 * 1e-9, units='ns', grace_string='\\q\\xt\\f{}c\\Q')
70
71
73 """Function for selecting which relaxation data to use in the consistency tests."""
74
75
76 pipes.test()
77
78
79 function_type = cdp.pipe_type
80 if function_type != 'ct':
81 raise RelaxFuncSetupError(specific_fns.setup.get_string(function_type))
82
83
84 if hasattr(cdp, 'ct_frq'):
85 raise RelaxError("The frequency for the run has already been set.")
86
87
88 if not hasattr(cdp, 'ct_frq'):
89 cdp.ct_frq = {}
90
91
92 cdp.ct_frq = frq
93
94
95 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
96 """Calculation of the consistency functions.
97
98 @keyword spin_id: The spin identification string.
99 @type spin_id: None or str
100 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity.
101 @type verbosity: int
102 @keyword sim_index: The optional MC simulation index.
103 @type sim_index: None or int
104 """
105
106
107 if not hasattr(cdp, 'ct_frq') or not isinstance(cdp.ct_frq, float):
108 raise RelaxError("The frequency has not been set up.")
109
110
111 if not exists_mol_res_spin_data():
112 raise RelaxNoSequenceError
113
114
115 for spin in spin_loop(spin_id):
116
117 if not spin.select:
118 continue
119
120
121 if not hasattr(spin, 'csa') or spin.csa == None:
122 raise RelaxNoValueError("CSA")
123
124
125 if not hasattr(spin, 'r') or spin.r == None:
126 raise RelaxNoValueError("bond length")
127
128
129 if not hasattr(spin, 'orientation') or spin.orientation == None:
130 raise RelaxNoValueError("angle Theta")
131
132
133 if not hasattr(spin, 'tc') or spin.tc == None:
134 raise RelaxNoValueError("correlation time")
135
136
137 if not hasattr(spin, 'heteronuc_type'):
138 raise RelaxSpinTypeError
139
140
141 if not hasattr(spin, 'proton_type'):
142 raise RelaxProtonTypeError
143
144
145 if cdp.ct_frq not in cdp.frq.values():
146 raise RelaxError("No relaxation data corresponding to the frequency %s has been loaded." % cdp.ct_frq)
147
148
149 for spin in spin_loop(spin_id):
150
151 if not spin.select:
152 continue
153
154
155 r1 = None
156 r2 = None
157 noe = None
158
159
160 for ri_id in cdp.ri_ids:
161
162 if cdp.frq[ri_id] != cdp.ct_frq:
163 continue
164
165
166 if cdp.ri_type[ri_id] == 'R1':
167 if sim_index == None:
168 r1 = spin.ri_data[ri_id]
169 else:
170 r1 = spin.ri_data_sim[ri_id][sim_index]
171
172
173 if cdp.ri_type[ri_id] == 'R2':
174 if sim_index == None:
175 r2 = spin.ri_data[ri_id]
176 else:
177 r2 = spin.ri_data_sim[ri_id][sim_index]
178
179
180 if cdp.ri_type[ri_id] == 'NOE':
181 if sim_index == None:
182 noe = spin.ri_data[ri_id]
183 else:
184 noe = spin.ri_data_sim[ri_id][sim_index]
185
186
187 if r1 == None or r2 == None or noe == None:
188 continue
189
190
191 self.ct = Consistency(frq=cdp.ct_frq, gx=return_gyromagnetic_ratio(spin.heteronuc_type), gh=return_gyromagnetic_ratio(spin.proton_type), mu0=mu0, h_bar=h_bar)
192
193
194 j0, f_eta, f_r2 = self.ct.func(orientation=spin.orientation, tc=spin.tc, r=spin.r, csa=spin.csa, r1=r1, r2=r2, noe=noe)
195
196
197 if sim_index == None:
198 spin.j0 = j0
199 spin.f_eta = f_eta
200 spin.f_r2 = f_r2
201
202
203 else:
204
205 self.data_init(spin, sim=1)
206 if spin.j0_sim == None:
207 spin.j0_sim = []
208 spin.f_eta_sim = []
209 spin.f_r2_sim = []
210
211
212 spin.j0_sim.append(j0)
213 spin.f_eta_sim.append(f_eta)
214 spin.f_r2_sim.append(f_r2)
215
216
217
219 """Initialise the data structures.
220
221 @param data_cont: The data container.
222 @type data_cont: instance
223 @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure.
224 @type sim: bool
225 """
226
227
228 data_names = self.data_names()
229
230
231 for name in data_names:
232
233 if sim:
234
235 name = name + '_sim'
236
237
238 if not hasattr(data_cont, name):
239
240 setattr(data_cont, name, None)
241
242
243 - def data_names(self, set=None, error_names=False, sim_names=False):
244 """Return a list of all spin container specific consistency testing object names.
245
246 Description
247 ===========
248
249 The names are as follows:
250
251 - 'r', bond length.
252 - 'csa', CSA value.
253 - 'heteronuc_type', the heteronucleus type.
254 - 'orientation', angle between the 15N-1H vector and the principal axis of the 15N chemical shift tensor.
255 - 'tc', correlation time.
256 - 'j0', spectral density value at 0 MHz (from Farrow et al. (1995) JBNMR, 6: 153-162).
257 - 'f_eta', eta-test (from Fushman et al. (1998) JACS, 120: 10947-10952).
258 - 'f_r2', R2-test (from Fushman et al. (1998) JACS, 120: 10947-10952).
259
260
261 @keyword set: An unused variable.
262 @type set: ignored
263 @keyword error_names: A flag which if True will add the error object names as well.
264 @type error_names: bool
265 @keyword sim_names: A flag which if True will add the Monte Carlo simulation object
266 names as well.
267 @type sim_names: bool
268 @return: The list of object names.
269 @rtype: list of str
270 """
271
272
273 names = []
274
275
276 names.append('r')
277 names.append('csa')
278 names.append('heteronuc_type')
279 names.append('orientation')
280 names.append('tc')
281
282
283 names.append('j0')
284 names.append('f_eta')
285 names.append('f_r2')
286
287
288 return names
289
290
291 default_value_doc = """
292 Consistency testing default values
293 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
294 These default values are found in the file 'physical_constants.py'.
295
296 ______________________________________________________________________________________
297 | | | |
298 | Data type | Object name | Value |
299 |_______________________________________|____________________|_________________________|
300 | | | |
301 | Bond length | 'r' | 1.02 * 1e-10 |
302 | | | |
303 | CSA | 'csa' | -172 * 1e-6 |
304 | | | |
305 | Heteronucleus type | 'heteronuc_type' | '15N' |
306 | | | |
307 | Proton type | 'proton_type' | '1H' |
308 | | | |
309 | Angle Theta | 'orientation' | 15.7 |
310 | | | |
311 | Correlation time | 'tc' | 13 * 1e-9 |
312 |_______________________________________|____________________|_________________________|
313
314 """
315
316
350
351
352 return_data_name_doc = """
353 Consistency testing data type string matching patterns
354 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
355
356 ___________________________________________
357 | | |
358 | Data type | Object name |
359 |_______________________|__________________|
360 | | |
361 | J(0) | 'j0' |
362 | | |
363 | F_eta | 'f_eta' |
364 | | |
365 | F_R2 | 'f_r2' |
366 | | |
367 | Bond length | 'r' |
368 | | |
369 | CSA | 'csa' |
370 | | |
371 | Heteronucleus type | 'heteronuc_type' |
372 | | |
373 | Proton type | 'proton_type' |
374 | | |
375 | Angle Theta | 'orientation' |
376 | | |
377 | Correlation time | 'tc' |
378 |_______________________|__________________|
379 """
380
381
382 set_doc = """
383 Consistency testing set details
384 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
385
386 In consistency testing, only four values can be set, the bond length, CSA, angle
387 Theta ('orientation') and correlation time values. These must be set prior to the
388 calculation of consistency functions.
389
390 """
391
392
393 - def set_error(self, model_info, index, error):
394 """Set the parameter errors.
395
396 @param model_info: The spin container originating from model_loop().
397 @type model_info: SpinContainer instance
398 @param index: The index of the parameter to set the errors for.
399 @type index: int
400 @param error: The error value.
401 @type error: float
402 """
403
404
405 spin = model_info
406
407
408 if index == 0:
409 spin.j0_err = error
410
411
412 if index == 1:
413 spin.f_eta_err = error
414
415
416 if index == 2:
417 spin.f_r2_err = error
418
419
421 """Return the array of simulation parameter values.
422
423 @param model_info: The spin container originating from model_loop().
424 @type model_info: SpinContainer instance
425 @param index: The index of the parameter to return the array of values for.
426 @type index: int
427 @return: The array of simulation parameter values.
428 @rtype: list of float
429 """
430
431
432 spin = model_info
433
434
435 if not spin.select:
436 return
437
438
439 if index == 0:
440 return spin.j0_sim
441
442
443 if index == 1:
444 return spin.f_eta_sim
445
446
447 if index == 2:
448 return spin.f_r2_sim
449
450
452 """Return the array of selected simulation flags.
453
454 @param model_info: The spin container originating from model_loop().
455 @type model_info: SpinContainer instance
456 @return: The array of selected simulation flags.
457 @rtype: list of int
458 """
459
460
461 spin = model_info
462
463
464 return spin.select_sim
465