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 import specific_fns
37 from user_functions.data import Uf_tables; uf_tables = Uf_tables()
38 from user_functions.objects import Desc_container
39
40
42 """Class containing functions specific to reduced spectral density mapping."""
43
45 """Initialise the class by placing API_common methods into the API."""
46
47
48 super(Jw_mapping, self).__init__()
49
50
51 self.base_data_loop = self._base_data_loop_spin
52 self.create_mc_data = self._create_mc_relax_data
53 self.model_loop = self._model_loop_spin
54 self.return_conversion_factor = self._return_no_conversion_factor
55 self.return_error = self._return_error_relax_data
56 self.return_value = self._return_value_general
57 self.set_param_values = self._set_param_values_spin
58 self.set_selected_sim = self._set_selected_sim_spin
59 self.sim_pack_data = self._sim_pack_relax_data
60
61
62 self.PARAMS.add('j0', scope='spin', string='J(0)', desc='Spectral density value at 0 MHz', py_type=float, set='params', grace_string='\\qJ(0)\\Q', err=True, sim=True)
63 self.PARAMS.add('jwx', scope='spin', string='J(wX)', desc='Spectral density value at the frequency of the heteronucleus', py_type=float, set='params', grace_string='\\qJ(\\xw\\f{}\\sX\\N)\\Q', err=True, sim=True)
64 self.PARAMS.add('jwh', scope='spin', string='J(wH)', desc='Spectral density value at the frequency of the proton', py_type=float, set='params', grace_string='\\qJ(\\xw\\f{}\\sH\\N)\\Q', err=True, sim=True)
65 self.PARAMS.add('r', scope='spin', default=NH_BOND_LENGTH, units='Angstrom', desc='Bond length', py_type=float, grace_string='Bond length')
66 self.PARAMS.add('csa', scope='spin', default=N15_CSA, units='ppm', desc='CSA value', py_type=float, grace_string='\\qCSA\\Q')
67 self.PARAMS.add('heteronuc_type', scope='spin', default='15N', desc='The heteronucleus type', py_type=str)
68 self.PARAMS.add('proton_type', scope='spin', default='1H', desc='The proton type', py_type=str)
69
70
72 """Function for selecting which relaxation data to use in the J(w) mapping."""
73
74
75 pipes.test()
76
77
78 function_type = cdp.pipe_type
79 if function_type != 'jw':
80 raise RelaxFuncSetupError(specific_fns.setup.get_string(function_type))
81
82
83 if hasattr(cdp, 'jw_frq'):
84 raise RelaxError("The frequency has already been set.")
85
86
87 if not hasattr(cdp, 'jw_frq'):
88 cdp.jw_frq = {}
89
90
91 cdp.jw_frq = frq
92
93
94 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
95 """Calculation of the spectral density values.
96
97 @keyword spin_id: The spin identification string.
98 @type spin_id: None or str
99 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity.
100 @type verbosity: int
101 @keyword sim_index: The optional MC simulation index.
102 @type sim_index: None or int
103 """
104
105
106 if not hasattr(cdp, 'jw_frq') or not isinstance(cdp.jw_frq, float):
107 raise RelaxError("The frequency has not been set up.")
108
109
110 if not exists_mol_res_spin_data():
111 raise RelaxNoSequenceError
112
113
114 for spin in spin_loop(spin_id):
115
116 if not spin.select:
117 continue
118
119
120 if not hasattr(spin, 'csa') or spin.csa == None:
121 raise RelaxNoValueError("CSA")
122
123
124 if not hasattr(spin, 'r') or spin.r == None:
125 raise RelaxNoValueError("bond length")
126
127
128 if not hasattr(spin, 'heteronuc_type'):
129 raise RelaxSpinTypeError
130
131
132 if not hasattr(spin, 'proton_type'):
133 raise RelaxProtonTypeError
134
135
136 if cdp.jw_frq not in cdp.frq.values():
137 raise RelaxError("No relaxation data corresponding to the frequency " + repr(cdp.jw_frq) + " has been loaded.")
138
139
140 for spin in spin_loop(spin_id):
141
142 if not spin.select:
143 continue
144
145
146 r1 = None
147 r2 = None
148 noe = None
149
150
151 for ri_id in cdp.ri_ids:
152
153 if cdp.frq[ri_id] != cdp.jw_frq:
154 continue
155
156
157 if cdp.ri_type[ri_id] == 'R1':
158 if sim_index == None:
159 r1 = spin.ri_data[ri_id]
160 else:
161 r1 = spin.ri_data_sim[ri_id][sim_index]
162
163
164 if cdp.ri_type[ri_id] == 'R2':
165 if sim_index == None:
166 r2 = spin.ri_data[ri_id]
167 else:
168 r2 = spin.ri_data_sim[ri_id][sim_index]
169
170
171 if cdp.ri_type[ri_id] == 'NOE':
172 if sim_index == None:
173 noe = spin.ri_data[ri_id]
174 else:
175 noe = spin.ri_data_sim[ri_id][sim_index]
176
177
178 if r1 == None or r2 == None or noe == None:
179 continue
180
181
182 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)
183
184
185 j0, jwx, jwh = self.jw.func(r=spin.r, csa=spin.csa, r1=r1, r2=r2, noe=noe)
186
187
188 if sim_index == None:
189 spin.j0 = j0
190 spin.jwx = jwx
191 spin.jwh = jwh
192
193
194 else:
195
196 self.data_init(spin, sim=1)
197 if spin.j0_sim == None:
198 spin.j0_sim = []
199 spin.jwx_sim = []
200 spin.jwh_sim = []
201
202
203 spin.j0_sim.append(j0)
204 spin.jwx_sim.append(jwx)
205 spin.jwh_sim.append(jwh)
206
207
209 """Initialise the data structures.
210
211 @param data_cont: The data container.
212 @type data_cont: instance
213 @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure.
214 @type sim: bool
215 """
216
217
218 data_names = self.data_names()
219
220
221 for name in data_names:
222
223 if sim:
224
225 name = name + '_sim'
226
227
228 if not hasattr(data_cont, name):
229
230 setattr(data_cont, name, None)
231
232
233 default_value_doc = Desc_container("Reduced spectral density mapping default values")
234 default_value_doc.add_paragraph("These default values are found in the file 'physical_constants.py'.")
235 _table = uf_tables.add_table(label="table: J(w) default values", caption="Reduced spectral density mapping default values.")
236 _table.add_headings(["Data type", "Object name", "Value"])
237 _table.add_row(["Bond length", "'r'", "1.02 * 1e-10"])
238 _table.add_row(["CSA", "'csa'", "-172 * 1e-6"])
239 _table.add_row(["Heteronucleus type", "'heteronuc_type'", "'15N'"])
240 _table.add_row(["Proton type", "'proton_type'", "'1H'"])
241 default_value_doc.add_table(_table.label)
242
243
277
278
279 return_data_name_doc = Desc_container("Reduced spectral density mapping data type string matching patterns")
280 _table = uf_tables.add_table(label="table: J(w) data types", caption="Reduced spectral density mapping data type string matching patterns.")
281 _table.add_headings(["Data type", "Object name"])
282 _table.add_row(["J(0)", "'j0'"])
283 _table.add_row(["J(wX)", "'jwx'"])
284 _table.add_row(["J(wH)", "'jwh'"])
285 _table.add_row(["Bond length", "'r'"])
286 _table.add_row(["CSA", "'csa'"])
287 _table.add_row(["Heteronucleus type", "'heteronuc_type'"])
288 _table.add_row(["Proton type", "'proton_type'"])
289 return_data_name_doc.add_table(_table.label)
290
291
292 set_doc = Desc_container("Reduced spectral density mapping set details")
293 set_doc.add_paragraph("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.")
294
295
296 - def set_error(self, model_info, index, error):
297 """Set the parameter errors.
298
299 @param model_info: The spin container originating from model_loop().
300 @type model_info: SpinContainer instance
301 @param index: The index of the parameter to set the errors for.
302 @type index: int
303 @param error: The error value.
304 @type error: float
305 """
306
307
308 spin = model_info
309
310
311 if index == 0:
312 spin.j0_err = error
313
314
315 if index == 1:
316 spin.jwx_err = error
317
318
319 if index == 2:
320 spin.jwh_err = error
321
322
324 """Return the array of simulation parameter values.
325
326 @param model_info: The spin container originating from model_loop().
327 @type model_info: SpinContainer instance
328 @param index: The index of the parameter to return the array of values for.
329 @type index: int
330 @return: The array of simulation parameter values.
331 @rtype: list of float
332 """
333
334
335 spin = model_info
336
337
338 if not spin.select:
339 return
340
341
342 if index == 0:
343 return spin.j0_sim
344
345
346 if index == 1:
347 return spin.jwx_sim
348
349
350 if index == 2:
351 return spin.jwh_sim
352
353
355 """Return the array of selected simulation flags.
356
357 @param model_info: The spin container originating from model_loop().
358 @type model_info: SpinContainer instance
359 @return: The array of selected simulation flags.
360 @rtype: list of int
361 """
362
363
364 spin = model_info
365
366
367 return spin.select_sim
368