1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The model-free analysis BMRB functions."""
24
25
26 from math import pi
27
28
29 from lib.errors import RelaxError
30 from pipe_control import bmrb, mol_res_spin
31 from specific_analyses.model_free.model import model_map
32
33
35 """The model-free model name to BMRB name mapping.
36
37 @keyword name: The BMRB model name.
38 @type name: str
39 @return: The corresponding model-free model name.
40 @rtype: str
41 """
42
43
44 if name in ['m0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm0', 'tm1', 'tm2', 'tm3', 'tm4', 'tm5', 'tm6', 'tm7', 'tm8', 'tm9']:
45 return name
46
47
48 if name in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
49 return 'm' + name
50
51
52 map = {'': 'm0',
53 'S2': 'm1',
54 'S2, te': 'm2',
55 'S2, Rex': 'm3',
56 'S2, te, Rex': 'm4',
57 'S2, te, S2f': 'm5',
58 'S2f, S2, ts': 'm5',
59 'S2f, tf, S2, ts': 'm6',
60 'S2f, S2, ts, Rex': 'm7',
61 'S2f, tf, S2, ts, Rex': 'm8',
62 'Rex': 'm9',
63 'tm': 'tm0',
64 'tm, S2': 'tm1',
65 'tm, S2, te': 'tm2',
66 'tm, S2, Rex': 'tm3',
67 'tm, S2, te, Rex': 'tm4',
68 'tm, S2f, S2, ts': 'tm5',
69 'tm, S2f, tf, S2, ts': 'tm6',
70 'tm, S2f, S2, ts, Rex': 'tm7',
71 'tm, S2f, tf, S2, ts, Rex': 'tm8',
72 'tm, Rex': 'tm9'
73 }
74
75
76 for item in list(map.items()):
77
78 if item[0] == name:
79 return item[1]
80
81
82 if item[0].replace(' ', '') == name:
83 return item[1]
84
85
86 if name:
87 raise RelaxError("The BMRB model-free model '%s' is unknown." % name)
88
89
119
120
122 """Fill the spin containers with the model-free data from the saveframe records.
123
124 @param star: The NMR-STAR dictionary object.
125 @type star: NMR_STAR instance
126 @keyword sample_conditions: The sample condition label to read. Only one sample condition can be read per data pipe.
127 @type sample_conditions: None or str
128 """
129
130
131 mf_bmrb_key = ['bond_length', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2']
132 mf_params = ['r', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2']
133
134
135 for data in star.model_free.loop():
136
137 if 'sample_cond_list_label' in data and sample_conditions and data['sample_cond_list_label'].replace('$', '') != sample_conditions:
138 continue
139
140
141 if 'global_chi2' in data:
142 setattr(cdp, 'chi2', data['global_chi2'])
143
144
145 N = bmrb.num_spins(data)
146
147
148 if N == 0:
149 continue
150
151
152 mol_names = bmrb.molecule_names(data, N)
153
154
155 if 'atom_names' not in data or data['atom_names'] == None:
156 data['atom_names'] = [None] * N
157
158
159 bmrb.generate_sequence(N, spin_names=data['atom_names'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names)
160
161
162 table = {'s': 1.0,
163 'ns': 1e-9,
164 'ps': 1e-12}
165 te_scale = 1.0
166 if data['te_units']:
167 te_scale = table[data['te_units']]
168
169
170 if data['tf_units']:
171 tf_scale = table[data['tf_units']]
172 else:
173 tf_scale = te_scale
174
175
176 if data['ts_units']:
177 ts_scale = table[data['ts_units']]
178 else:
179 ts_scale = te_scale
180
181
182 rex_scale = 1.0
183 if hasattr(cdp, 'spectrometer_frq') and len(cdp.spectrometer_frq):
184 rex_scale = 1.0 / (2.0*pi*cdp.spectrometer_frq[cdp.ri_ids[0]])**2
185
186
187 for i in range(N):
188
189 spin_id = mol_res_spin.generate_spin_id_unique(mol_name=mol_names[i], res_name=data['res_names'][i], res_num=data['res_nums'][i], spin_name=data['atom_names'][i])
190
191
192 spin = mol_res_spin.return_spin(spin_id)
193
194
195 if spin == None:
196 raise RelaxError("The spin '%s' does not exist." % spin_id)
197
198
199 for j in range(len(mf_params)):
200
201 param = mf_params[j]
202
203
204 if not mf_bmrb_key[j] in data:
205 continue
206
207
208 if data[mf_bmrb_key[j]] != None:
209
210 value = data[mf_bmrb_key[j]][i]
211
212
213 if value != None:
214 if param == 'te':
215 value = value * te_scale
216 elif param == 'tf':
217 value = value * tf_scale
218 elif param == 'ts':
219 value = value * ts_scale
220 elif param == 'rex':
221 value = value * rex_scale
222
223
224 else:
225 value = None
226
227
228 setattr(spin, param, value)
229
230
231 mf_bmrb_key_err = mf_bmrb_key[j] + '_err'
232 error = None
233 if mf_bmrb_key_err in data and data[mf_bmrb_key_err] != None:
234 error = data[mf_bmrb_key_err][i]
235
236
237 if error != None:
238 if param == 'te':
239 error = error * te_scale
240 elif param == 'tf':
241 error = error * tf_scale
242 elif param == 'ts':
243 error = error * ts_scale
244 elif param == 'rex':
245 error = error * rex_scale
246
247
248 mf_param_err = param + '_err'
249 if mf_bmrb_key_err in data and data[mf_bmrb_key_err] != None:
250 setattr(spin, mf_param_err, error)
251
252
253 if data['model_fit'] != None and data['model_fit'][i] != None:
254 model = from_bmrb_model(data['model_fit'][i])
255 setattr(spin, 'model', model)
256
257
258 equation, params = model_map(model)
259 setattr(spin, 'equation', equation)
260 setattr(spin, 'params', params)
261
262
263 if hasattr(spin, 'model') and spin.model in ['m5', 'm6', 'm7', 'm8'] and hasattr(spin, 'te') and spin.te != None:
264
265 spin.ts = spin.te
266 if hasattr(spin, 'te_err'):
267 spin.ts_err = spin.te_err
268
269
270 spin.te = None
271 spin.te_err = None
272
273
274 if'atom_types' in data and data['atom_types'] != None:
275 setattr(spin, 'element', data['atom_types'][i])
276
277
278 if'atom_types' in data and data['atom_types'] != None and data['atom_types'][i] != None and 'isotope' in data and data['isotope'] != None:
279
280 iso_num = data['isotope'][i]
281
282
283 iso_table = {'C': 13, 'N': 15}
284 if not data['isotope'][i]:
285 iso_num = iso_table[data['atom_types'][i]]
286
287
288 setattr(spin, 'isotope', str(iso_num) + data['atom_types'][i])
289
290
292 """Convert the model-free model name to the BMRB name.
293
294 @keyword name: The model-free model name.
295 @type name: str
296 @return: The corresponding BMRB model name.
297 @rtype: str
298 """
299
300
301 map = {'m0': '',
302 'm1': 'S2',
303 'm2': 'S2, te',
304 'm3': 'S2, Rex',
305 'm4': 'S2, te, Rex',
306 'm5': 'S2f, S2, ts',
307 'm6': 'S2f, tf, S2, ts',
308 'm7': 'S2f, S2, ts, Rex',
309 'm8': 'S2f, tf, S2, ts, Rex',
310 'm9': 'Rex',
311 'tm0': 'tm',
312 'tm1': 'tm, S2',
313 'tm2': 'tm, S2, te',
314 'tm3': 'tm, S2, Rex',
315 'tm4': 'tm, S2, te, Rex',
316 'tm5': 'tm, S2f, S2, ts',
317 'tm6': 'tm, S2f, tf, S2, ts',
318 'tm7': 'tm, S2f, S2, ts, Rex',
319 'tm8': 'tm, S2f, tf, S2, ts, Rex',
320 'tm9': 'tm, Rex'
321 }
322
323
324 if name not in map:
325 raise RelaxError("The model-free model '%s' is unknown." % name)
326
327
328 return map[name]
329