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 re import search
25 from warnings import warn
26
27
28 from api_base import API_base
29 from api_common import API_common
30 from generic_fns.mol_res_spin import exists_mol_res_spin_data, return_spin, spin_loop
31 from generic_fns import pipes
32 from maths_fns.jw_mapping import Mapping
33 from physical_constants import N15_CSA, NH_BOND_LENGTH, h_bar, mu0, return_gyromagnetic_ratio
34 from relax_errors import RelaxError, RelaxFuncSetupError, RelaxNoSequenceError, RelaxNoValueError, RelaxProtonTypeError, RelaxSpinTypeError
35 from relax_warnings import RelaxDeselectWarning
36
37
39 """Class containing functions specific to reduced spectral density mapping."""
40
42 """Initialise the class by placing API_common methods into the API."""
43
44
45 self.base_data_loop = self._base_data_loop_spin
46 self.create_mc_data = self._create_mc_relax_data
47 self.default_value = self._default_value_spin
48 self.model_loop = self._model_loop_spin
49 self.return_conversion_factor = self._return_no_conversion_factor
50 self.return_data_name = self._return_data_name_spin
51 self.return_error = self._return_error_relax_data
52 self.return_grace_string = self._return_grace_string_spin
53 self.return_units = self._return_units_spin
54 self.return_value = self._return_value_general
55 self.set_param_values = self._set_param_values_spin
56 self.set_selected_sim = self._set_selected_sim_spin
57 self.sim_pack_data = self._sim_pack_relax_data
58
59
60 self.SPIN_PARAMS.add('j0', string='J(0)', grace_string='\\qJ(0)\\Q')
61 self.SPIN_PARAMS.add('jwx', grace_string='\\qJ(\\xw\\f{}\\sX\\N)\\Q')
62 self.SPIN_PARAMS.add('jwh', grace_string='\\qJ(\\xw\\f{}\\sH\\N)\\Q')
63 self.SPIN_PARAMS.add('r', default=NH_BOND_LENGTH, units='Angstrom', grace_string='Bond length')
64 self.SPIN_PARAMS.add('csa', default=N15_CSA, units='ppm', grace_string='\\qCSA\\Q')
65 self.SPIN_PARAMS.add('heteronuc_type', default='15N')
66 self.SPIN_PARAMS.add('proton_type', default='1H')
67
68
70 """Function for selecting which relaxation data to use in the J(w) mapping."""
71
72
73 pipes.test()
74
75
76 function_type = cdp.pipe_type
77 if function_type != 'jw':
78 raise RelaxFuncSetupError(specific_fns.setup.get_string(function_type))
79
80
81 if hasattr(cdp, 'jw_frq'):
82 raise RelaxError("The frequency has already been set.")
83
84
85 if not hasattr(cdp, 'jw_frq'):
86 cdp.jw_frq = {}
87
88
89 cdp.jw_frq = frq
90
91
92 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
93 """Calculation of the spectral density values.
94
95 @keyword spin_id: The spin identification string.
96 @type spin_id: None or str
97 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity.
98 @type verbosity: int
99 @keyword sim_index: The optional MC simulation index.
100 @type sim_index: None or int
101 """
102
103
104 if not hasattr(cdp, 'jw_frq') or not isinstance(cdp.jw_frq, float):
105 raise RelaxError("The frequency has not been set up.")
106
107
108 if not exists_mol_res_spin_data():
109 raise RelaxNoSequenceError
110
111
112 for spin in spin_loop(spin_id):
113
114 if not spin.select:
115 continue
116
117
118 if not hasattr(spin, 'csa') or spin.csa == None:
119 raise RelaxNoValueError("CSA")
120
121
122 if not hasattr(spin, 'r') or spin.r == None:
123 raise RelaxNoValueError("bond length")
124
125
126 if not hasattr(spin, 'heteronuc_type'):
127 raise RelaxSpinTypeError
128
129
130 if not hasattr(spin, 'proton_type'):
131 raise RelaxProtonTypeError
132
133
134 if cdp.jw_frq not in cdp.frq.values():
135 raise RelaxError("No relaxation data corresponding to the frequency " + repr(cdp.jw_frq) + " has been loaded.")
136
137
138 for spin in spin_loop(spin_id):
139
140 if not spin.select:
141 continue
142
143
144 r1 = None
145 r2 = None
146 noe = None
147
148
149 for ri_id in cdp.ri_ids:
150
151 if cdp.frq[ri_id] != cdp.jw_frq:
152 continue
153
154
155 if cdp.ri_type[ri_id] == 'R1':
156 if sim_index == None:
157 r1 = spin.ri_data[ri_id]
158 else:
159 r1 = spin.ri_data_sim[ri_id][sim_index]
160
161
162 if cdp.ri_type[ri_id] == 'R2':
163 if sim_index == None:
164 r2 = spin.ri_data[ri_id]
165 else:
166 r2 = spin.ri_data_sim[ri_id][sim_index]
167
168
169 if cdp.ri_type[ri_id] == 'NOE':
170 if sim_index == None:
171 noe = spin.ri_data[ri_id]
172 else:
173 noe = spin.ri_data_sim[ri_id][sim_index]
174
175
176 if r1 == None or r2 == None or noe == None:
177 continue
178
179
180 self.jw = Mapping(frq=cdp.jw_frq, gx=return_gyromagnetic_ratio(spin.heteronuc_type), gh=return_gyromagnetic_ratio(spin.proton_type), mu0=mu0, h_bar=h_bar)
181
182
183 j0, jwx, jwh = self.jw.func(r=spin.r, csa=spin.csa, r1=r1, r2=r2, noe=noe)
184
185
186 if sim_index == None:
187 spin.j0 = j0
188 spin.jwx = jwx
189 spin.jwh = jwh
190
191
192 else:
193
194 self.data_init(spin, sim=1)
195 if spin.j0_sim == None:
196 spin.j0_sim = []
197 spin.jwx_sim = []
198 spin.jwh_sim = []
199
200
201 spin.j0_sim.append(j0)
202 spin.jwx_sim.append(jwx)
203 spin.jwh_sim.append(jwh)
204
205
207 """Initialise the data structures.
208
209 @param data_cont: The data container.
210 @type data_cont: instance
211 @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure.
212 @type sim: bool
213 """
214
215
216 data_names = self.data_names()
217
218
219 for name in data_names:
220
221 if sim:
222
223 name = name + '_sim'
224
225
226 if not hasattr(data_cont, name):
227
228 setattr(data_cont, name, None)
229
230
231 - def data_names(self, set=None, error_names=False, sim_names=False):
232 """Return a list of all spin container specific J(w) mapping object names.
233
234 Description
235 ===========
236
237 The names are as follows:
238
239 - 'r', bond length.
240 - 'csa', CSA value.
241 - 'heteronuc_type', the heteronucleus type.
242 - 'j0', spectral density value at 0 MHz.
243 - 'jwx', spectral density value at the frequency of the heteronucleus.
244 - 'jwh', spectral density value at the frequency of the heteronucleus.
245
246
247 @keyword set: An unused variable.
248 @type set: ignored
249 @keyword error_names: A flag which if True will add the error object names as well.
250 @type error_names: bool
251 @keyword sim_names: A flag which if True will add the Monte Carlo simulation object
252 names as well.
253 @type sim_names: bool
254 @return: The list of object names.
255 @rtype: list of str
256 """
257
258
259 names = []
260
261
262 names.append('r')
263 names.append('csa')
264 names.append('heteronuc_type')
265
266
267 names.append('j0')
268 names.append('jwx')
269 names.append('jwh')
270
271
272 return names
273
274
275 default_value_doc = ["Reduced spectral density mapping default values", """
276 These default values are found in the file 'physical_constants.py'.
277
278 _______________________________________________________________________________________
279 | | | |
280 | Data type | Object name | Value |
281 |_______________________________________|____________________|________________________|
282 | | | |
283 | Bond length | 'r' | 1.02 * 1e-10 |
284 | | | |
285 | CSA | 'csa' | -172 * 1e-6 |
286 | | | |
287 | Heteronucleus type | 'heteronuc_type' | '15N' |
288 | | | |
289 | Proton type | 'proton_type' | '1H' |
290 |_______________________________________|____________________|________________________|
291
292 """]
293
294
328
329
330 return_data_name_doc = ["Reduced spectral density mapping data type string matching patterns", """
331 _____________________________________________
332 | | |
333 | Data type | Object name |
334 |________________________|__________________|
335 | | |
336 | J(0) | 'j0' |
337 | | |
338 | J(wX) | 'jwx' |
339 | | |
340 | J(wH) | 'jwh' |
341 | | |
342 | Bond length | 'r' |
343 | | |
344 | CSA | 'csa' |
345 | | |
346 | Heteronucleus type | 'heteronuc_type' |
347 | | |
348 | Proton type | 'proton_type' |
349 |________________________|__________________|
350
351 """]
352
353
354 set_doc = ["Reduced spectral density mapping set details", """
355 In reduced spectral density mapping, three values must be set prior to the calculation of spectral density values: the bond length, CSA, and heteronucleus type.
356 """]
357
358
359 - def set_error(self, model_info, index, error):
360 """Set the parameter errors.
361
362 @param model_info: The spin container originating from model_loop().
363 @type model_info: SpinContainer instance
364 @param index: The index of the parameter to set the errors for.
365 @type index: int
366 @param error: The error value.
367 @type error: float
368 """
369
370
371 spin = model_info
372
373
374 if index == 0:
375 spin.j0_err = error
376
377
378 if index == 1:
379 spin.jwx_err = error
380
381
382 if index == 2:
383 spin.jwh_err = error
384
385
387 """Return the array of simulation parameter values.
388
389 @param model_info: The spin container originating from model_loop().
390 @type model_info: SpinContainer instance
391 @param index: The index of the parameter to return the array of values for.
392 @type index: int
393 @return: The array of simulation parameter values.
394 @rtype: list of float
395 """
396
397
398 spin = model_info
399
400
401 if not spin.select:
402 return
403
404
405 if index == 0:
406 return spin.j0_sim
407
408
409 if index == 1:
410 return spin.jwx_sim
411
412
413 if index == 2:
414 return spin.jwh_sim
415
416
418 """Return the array of selected simulation flags.
419
420 @param model_info: The spin container originating from model_loop().
421 @type model_info: SpinContainer instance
422 @return: The array of selected simulation flags.
423 @rtype: list of int
424 """
425
426
427 spin = model_info
428
429
430 return spin.select_sim
431