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 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 keys = data.keys()
138
139
140 if 'sample_cond_list_label' in keys and sample_conditions and data['sample_cond_list_label'].replace('$', '') != sample_conditions:
141 continue
142
143
144 if 'global_chi2' in keys:
145 setattr(cdp, 'chi2', data['global_chi2'])
146
147
148 N = bmrb.num_spins(data)
149
150
151 if N == 0:
152 continue
153
154
155 mol_names = bmrb.molecule_names(data, N)
156
157
158 if 'atom_names' not in keys or data['atom_names'] == None:
159 data['atom_names'] = [None] * N
160
161
162 bmrb.generate_sequence(N, spin_names=data['atom_names'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names)
163
164
165 table = {'s': 1.0,
166 'ns': 1e-9,
167 'ps': 1e-12}
168 te_scale = 1.0
169 if data['te_units']:
170 te_scale = table[data['te_units']]
171
172
173 if data['tf_units']:
174 tf_scale = table[data['tf_units']]
175 else:
176 tf_scale = te_scale
177
178
179 if data['ts_units']:
180 ts_scale = table[data['ts_units']]
181 else:
182 ts_scale = te_scale
183
184
185 rex_scale = 1.0
186 if hasattr(cdp, 'spectrometer_frq') and len(cdp.spectrometer_frq):
187 rex_scale = 1.0 / (2.0*pi*cdp.spectrometer_frq[cdp.ri_ids[0]])**2
188
189
190 for i in range(N):
191
192 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])
193
194
195 spin = mol_res_spin.return_spin(spin_id)
196
197
198 if spin == None:
199 raise RelaxError("The spin '%s' does not exist." % spin_id)
200
201
202 for j in range(len(mf_params)):
203
204 param = mf_params[j]
205
206
207 if not mf_bmrb_key[j] in keys:
208 continue
209
210
211 if data[mf_bmrb_key[j]] != None:
212
213 value = data[mf_bmrb_key[j]][i]
214
215
216 if value != None:
217 if param == 'te':
218 value = value * te_scale
219 elif param == 'tf':
220 value = value * tf_scale
221 elif param == 'ts':
222 value = value * ts_scale
223 elif param == 'rex':
224 value = value * rex_scale
225
226
227 else:
228 value = None
229
230
231 setattr(spin, param, value)
232
233
234 mf_bmrb_key_err = mf_bmrb_key[j] + '_err'
235 error = None
236 if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None:
237 error = data[mf_bmrb_key_err][i]
238
239
240 if error != None:
241 if param == 'te':
242 error = error * te_scale
243 elif param == 'tf':
244 error = error * tf_scale
245 elif param == 'ts':
246 error = error * ts_scale
247 elif param == 'rex':
248 error = error * rex_scale
249
250
251 mf_param_err = param + '_err'
252 if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None:
253 setattr(spin, mf_param_err, error)
254
255
256 if data['model_fit'] != None and data['model_fit'][i] != None:
257 model = from_bmrb_model(data['model_fit'][i])
258 setattr(spin, 'model', model)
259
260
261 equation, params = model_map(model)
262 setattr(spin, 'equation', equation)
263 setattr(spin, 'params', params)
264
265
266 if hasattr(spin, 'model') and spin.model in ['m5', 'm6', 'm7', 'm8'] and hasattr(spin, 'te') and spin.te != None:
267
268 spin.ts = spin.te
269 if hasattr(spin, 'te_err'):
270 spin.ts_err = spin.te_err
271
272
273 spin.te = None
274 spin.te_err = None
275
276
277 if'atom_types' in keys and data['atom_types'] != None:
278 setattr(spin, 'element', data['atom_types'][i])
279
280
281 if'atom_types' in keys and data['atom_types'] != None and data['atom_types'][i] != None and 'isotope' in keys and data['isotope'] != None:
282
283 iso_num = data['isotope'][i]
284
285
286 iso_table = {'C': 13, 'N': 15}
287 if not data['isotope'][i]:
288 iso_num = iso_table[data['atom_types'][i]]
289
290
291 setattr(spin, 'isotope', str(iso_num) + data['atom_types'][i])
292
293
295 """Convert the model-free model name to the BMRB name.
296
297 @keyword name: The model-free model name.
298 @type name: str
299 @return: The corresponding BMRB model name.
300 @rtype: str
301 """
302
303
304 map = {'m0': '',
305 'm1': 'S2',
306 'm2': 'S2, te',
307 'm3': 'S2, Rex',
308 'm4': 'S2, te, Rex',
309 'm5': 'S2f, S2, ts',
310 'm6': 'S2f, tf, S2, ts',
311 'm7': 'S2f, S2, ts, Rex',
312 'm8': 'S2f, tf, S2, ts, Rex',
313 'm9': 'Rex',
314 'tm0': 'tm',
315 'tm1': 'tm, S2',
316 'tm2': 'tm, S2, te',
317 'tm3': 'tm, S2, Rex',
318 'tm4': 'tm, S2, te, Rex',
319 'tm5': 'tm, S2f, S2, ts',
320 'tm6': 'tm, S2f, tf, S2, ts',
321 'tm7': 'tm, S2f, S2, ts, Rex',
322 'tm8': 'tm, S2f, tf, S2, ts, Rex',
323 'tm9': 'tm, Rex'
324 }
325
326
327 if name not in map.keys():
328 raise RelaxError("The model-free model '%s' is unknown." % name)
329
330
331 return map[name]
332