1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """The Molmol and Pymol base macro methods of the specific API for model-free analysis."""
25
26
27 from math import pi
28 from re import search
29
30
31 from colour import linear_gradient
32 from lib.errors import RelaxError, RelaxStyleError, RelaxUnknownDataTypeError
33 from pipe_control.mol_res_spin import spin_loop
34
35
36
38 """The base class for the model-free analysis Molmol and PyMOL macro creation."""
39
40 - def classic_style(self, data_type=None, colour_start=None, colour_end=None, colour_list=None, spin_id=None):
41 """The classic macro style.
42
43 @keyword data_type: The parameter name or data type.
44 @type data_type: str
45 @keyword colour_start: The starting colour (must be a MOLMOL or X11 name).
46 @type colour_start: str
47 @keyword colour_end: The ending colour (must be a MOLMOL or X11 name).
48 @type colour_end: str
49 @keyword colour_list: The colour list used, either 'molmol' or 'x11'.
50 @type colour_list: str
51 @keyword spin_id: The spin identification string.
52 @type spin_id: str
53 """
54
55
56
57
58 self.classic_header()
59
60
61
62
63
64 if data_type == 's2':
65
66 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
67
68 if not spin.select or not hasattr(spin, 'model'):
69 continue
70
71
72 if not hasattr(spin, 's2') or spin.s2 == None:
73 continue
74
75
76 if spin.name == 'N':
77 self.classic_order_param(res_num, spin.s2, colour_start, colour_end, colour_list)
78
79
80
81
82
83 elif data_type == 's2f':
84
85 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
86
87 if not spin.select or not hasattr(spin, 'model'):
88 continue
89
90
91 if spin.name == 'N':
92
93 if not hasattr(spin, 's2f') or spin.s2f == None:
94 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
95
96
97 else:
98 self.classic_order_param(res_num, spin.s2f, colour_start, colour_end, colour_list)
99
100
101
102
103
104 elif data_type == 's2s':
105
106 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
107
108 if not spin.select or not hasattr(spin, 'model'):
109 continue
110
111
112 if spin.name == 'N':
113
114 if not hasattr(spin, 's2s') or spin.s2s == None:
115 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
116
117
118 else:
119 self.classic_order_param(res_num, spin.s2s, colour_start, colour_end, colour_list)
120
121
122
123
124
125 elif data_type == 'amp_fast':
126
127 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
128
129 if not spin.select or not hasattr(spin, 'model'):
130 continue
131
132
133 if search('tm[0-9]', spin.model):
134 model = spin.model[1:]
135 else:
136 model = spin.model
137
138
139 if spin.name == 'N':
140
141 if hasattr(spin, 's2f') and spin.s2f != None:
142 self.classic_order_param(res_num, spin.s2f, colour_start, colour_end, colour_list)
143
144
145 elif model == 'm1' or model == 'm3':
146 self.classic_order_param(res_num, spin.s2, colour_start, colour_end, colour_list)
147
148
149 elif (model == 'm2' or model == 'm4') and spin.te <= 200e-12:
150 self.classic_order_param(res_num, spin.s2, colour_start, colour_end, colour_list)
151
152
153 elif (model == 'm2' or model == 'm4') and spin.te > 200e-12:
154 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
155
156
157
158
159
160 elif data_type == 'amp_slow':
161
162 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
163
164 if not spin.select or not hasattr(spin, 'model'):
165 continue
166
167
168 if search('tm[0-9]', spin.model):
169 model = spin.model[1:]
170 else:
171 model = spin.model
172
173
174 if spin.name == 'N':
175
176 if hasattr(spin, 'ts') and spin.ts != None:
177 self.classic_order_param(res_num, spin.s2, colour_start, colour_end, colour_list)
178
179
180 elif (model == 'm2' or model == 'm4') and spin.te > 200 * 1e-12:
181 self.classic_order_param(res_num, spin.s2, colour_start, colour_end, colour_list)
182
183
184 else:
185 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
186
187
188
189
190 elif data_type == 'te':
191
192 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
193
194 if not spin.select or not hasattr(spin, 'model'):
195 continue
196
197
198 if not hasattr(spin, 'te') or spin.te == None:
199 continue
200
201
202 if spin.name == 'N':
203 self.classic_correlation_time(res_num, spin.te, colour_start, colour_end, colour_list)
204
205
206
207
208
209 elif data_type == 'tf':
210
211 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
212
213 if not spin.select or not hasattr(spin, 'model'):
214 continue
215
216
217 if not hasattr(spin, 'tf') or spin.tf == None:
218 continue
219
220
221 if spin.name == 'N':
222 self.classic_correlation_time(res_num, spin.tf, colour_start, colour_end, colour_list)
223
224
225
226
227
228 elif data_type == 'ts':
229
230 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
231
232 if not spin.select or not hasattr(spin, 'model'):
233 continue
234
235
236 if not hasattr(spin, 'ts') or spin.ts == None:
237 continue
238
239
240 if colour_start == None:
241 colour_start = 'blue'
242 if colour_end == None:
243 colour_end = 'black'
244
245
246 if spin.name == 'N':
247 self.classic_correlation_time(res_num, spin.ts / 10.0, colour_start, colour_end, colour_list)
248
249
250
251
252
253 elif data_type == 'time_fast':
254
255 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
256
257 if not spin.select or not hasattr(spin, 'model'):
258 continue
259
260
261 if search('tm[0-9]', spin.model):
262 model = spin.model[1:]
263 else:
264 model = spin.model
265
266
267 if spin.name == 'N':
268
269 if hasattr(spin, 'tf') and spin.tf != None:
270 self.classic_correlation_time(res_num, spin.tf, colour_start, colour_end, colour_list)
271
272
273 elif (model == 'm2' or model == 'm4') and spin.te <= 200e-12:
274 self.classic_correlation_time(res_num, spin.te, colour_start, colour_end, colour_list)
275
276
277
278 else:
279 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
280
281
282
283
284
285 elif data_type == 'time_slow':
286
287 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
288
289 if not spin.select or not hasattr(spin, 'model'):
290 continue
291
292
293 if search('tm[0-9]', spin.model):
294 model = spin.model[1:]
295 else:
296 model = spin.model
297
298
299 if colour_start == None:
300 colour_start = 'blue'
301 if colour_end == None:
302 colour_end = 'black'
303
304
305 if spin.name == 'N':
306
307 if hasattr(spin, 'ts') and spin.ts != None:
308 self.classic_correlation_time(res_num, spin.ts / 10.0, colour_start, colour_end, colour_list)
309
310
311 elif (model == 'm2' or model == 'm4') and spin.te > 200e-12:
312 self.classic_correlation_time(res_num, spin.te / 10.0, colour_start, colour_end, colour_list)
313
314
315 else:
316 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
317
318
319
320
321
322 elif data_type == 'rex':
323
324 for spin, mol_name, res_num, res_name in spin_loop(spin_id, full_info=True):
325
326 if not spin.select or not hasattr(spin, 'model'):
327 continue
328
329
330 if spin.name == 'N':
331
332 if hasattr(spin, 'rex') and spin.rex != None:
333 self.classic_rex(res_num, spin.rex, colour_start, colour_end, colour_list)
334
335
336 else:
337 self.classic_colour(res_num=res_num, width=0.3, rgb_array=[1, 1, 1])
338
339
340
341
342
343 else:
344 raise RelaxUnknownDataTypeError(data_type)
345
346
348 """Function for generating the bond width and colours for correlation times."""
349
350
351 te = te * 1e12
352
353
354 width = 2.0 - 200.0 / (te + 100.0)
355
356
357 if width <= 0.0:
358 width = 0.001
359
360
361 colour_value = 1.0 / (te / 100.0 + 1.0)
362
363
364 if colour_value < 0.0:
365 colour_value = 0.0
366 elif colour_value > 1.0:
367 colour_value = 1.0
368
369
370 if colour_start == None:
371 colour_start = 'turquoise'
372 if colour_end == None:
373 colour_end = 'blue'
374
375
376 rgb_array = linear_gradient(colour_value, colour_end, colour_start, colour_list)
377
378
379 self.classic_colour(res_num, width, rgb_array)
380
381
383 """Function for generating the bond width and colours for order parameters."""
384
385
386 if s2 <= 0.0:
387 width = 2.0
388 else:
389 width = 2.0 * (1.0 - s2**2)
390
391
392 if width <= 0.0:
393 width = 0.001
394
395
396 colour_value = s2 ** 4
397
398
399 if colour_value < 0.0:
400 colour_value = 0.0
401 elif colour_value > 1.0:
402 colour_value = 1.0
403
404
405 if colour_start == None:
406 colour_start = 'red'
407 if colour_end == None:
408 colour_end = 'yellow'
409
410
411 rgb_array = linear_gradient(colour_value, colour_start, colour_end, colour_list)
412
413
414 self.classic_colour(res_num, width, rgb_array)
415
416
417 - def classic_rex(self, res_num, rex, colour_start, colour_end, colour_list):
418 """Function for generating the bond width and colours for correlation times."""
419
420
421 if not hasattr(cdp, 'spectrometer_frq'):
422 raise RelaxError("No spectrometer frequency information is present in the current data pipe.")
423 if hasattr(cdp, 'ri_ids'):
424 frq = cdp.spectrometer_frq[cdp.ri_ids[0]]
425 else:
426 frqs = sorted(cdp.spectrometer_frq.values())
427 frq = frqs[-1]
428
429
430 rex = rex * (2.0 * pi * frq)**2
431
432
433 width = 2.0 - 2.0 / (rex/5.0 + 1.0)
434
435
436 if width <= 0.0:
437 width = 0.001
438
439
440 colour_value = 1.0 / (rex + 1.0)
441
442
443 if colour_value < 0.0:
444 colour_value = 0.0
445 elif colour_value > 1.0:
446 colour_value = 1.0
447
448
449 if colour_start == None:
450 colour_start = 'yellow'
451 if colour_end == None:
452 colour_end = 'red'
453
454
455 rgb_array = linear_gradient(colour_value, colour_end, colour_start, colour_list)
456
457
458 self.classic_colour(res_num, width, rgb_array)
459
460
461 - def create_macro(self, data_type, style=None, colour_start=None, colour_end=None, colour_list=None, spin_id=None):
462 """Create and return an array of macros of the model-free parameters.
463
464 @param data_type: The parameter name or data type.
465 @type data_type: str
466 @keyword style: The Molmol style.
467 @type style: None or str
468 @keyword colour_start: The starting colour (must be a MOLMOL or X11 name).
469 @type colour_start: str
470 @keyword colour_end: The ending colour (must be a MOLMOL or X11 name).
471 @type colour_end: str
472 @keyword colour_list: The colour list used, either 'molmol' or 'x11'.
473 @type colour_list: str
474 @keyword spin_id: The spin identification string.
475 @type spin_id: str
476 """
477
478
479 self.commands = []
480
481
482 if style == 'classic':
483 self.classic_style(data_type, colour_start, colour_end, colour_list, spin_id)
484
485
486 else:
487 raise RelaxStyleError(style)
488
489
490 return self.commands
491