1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module for interfacing with Dasha."""
25
26
27 from math import pi
28 from os import F_OK, access, chdir, getcwd, popen3, sep
29 from string import lower
30 import sys
31
32
33 from generic_fns import angles, diffusion_tensor, pipes, relax_data, value
34 from generic_fns.mol_res_spin import exists_mol_res_spin_data, first_residue_num, last_residue_num, residue_loop, spin_loop
35 from relax_errors import RelaxDirError, RelaxError, RelaxFileError, RelaxNoPdbError, RelaxNoSequenceError, RelaxNoTensorError
36 from relax_io import mkdir_nofail, open_write_file, test_binary
37 from specific_fns.setup import model_free_obj
38
39
65
66
67 -def create(algor='LM', dir=None, force=False):
126
127
129 """Create the Dasha script file.
130
131 @param file: The opened file descriptor.
132 @type file: file object
133 @param model_type: The model-free model type.
134 @type model_type: str
135 @param algor: The optimisation algorithm to use. This can be the Levenberg-Marquardt algorithm 'LM' or the Newton-Raphson algorithm 'NR'.
136 @type algor: str
137 """
138
139
140 file.write("# Delete all data.\n")
141 file.write("del 1 10000\n")
142
143
144 file.write("\n# Nucleus type.\n")
145 nucleus = None
146 for spin in spin_loop():
147
148 if nucleus and spin.heteronuc_type != nucleus:
149 raise RelaxError("The nuclei '%s' and '%s' do not match, relax can only handle one nucleus type in Dasha." % (nucleus, spin.heteronuc_type))
150
151
152 if not nucleus:
153 nucleus = spin.heteronuc_type
154
155
156 if nucleus == '15N':
157 nucleus = 'N15'
158 elif nucleus == '13C':
159 nucleus = 'C13'
160 else:
161 raise RelaxError("Cannot handle the nucleus type '%s' within Dasha." % nucleus)
162 file.write("set nucl %s\n" % nucleus)
163
164
165 file.write("\n# Number of frequencies.\n")
166 file.write("set n_freq %s\n" % relax_data.num_frq())
167
168
169 file.write("\n# Frequency values.\n")
170 count = 1
171 for frq in relax_data.frq_loop():
172 file.write("set H1_freq %s %s\n" % (frq / 1e6, count))
173 count += 1
174
175
176 file.write("\n# Set the diffusion tensor.\n")
177 if model_type != 'local_tm':
178
179 if cdp.diff_tensor.type == 'sphere':
180 file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9))
181
182
183 elif cdp.diff_tensor.type == 'spheroid':
184 file.write('set tr %s\n' % (cdp.diff_tensor.tm / 1e-9))
185
186
187 elif cdp.diff_tensor.type == 'ellipsoid':
188
189 Dx, Dy, Dz = diffusion_tensor.return_eigenvalues()
190
191
192 file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9))
193 file.write("set D1/D3 %s\n" % (Dx / Dz))
194 file.write("set D2/D3 %s\n" % (Dy / Dz))
195
196
197 file.write("set alfa %s\n" % (cdp.diff_tensor.alpha / (2.0 * pi) * 360.0))
198 file.write("set betta %s\n" % (cdp.diff_tensor.beta / (2.0 * pi) * 360.0))
199 file.write("set gamma %s\n" % (cdp.diff_tensor.gamma / (2.0 * pi) * 360.0))
200
201
202 file.write("\n# Reading the relaxation data.\n")
203 file.write("echo Reading the relaxation data.\n")
204 noe_index = 1
205 r1_index = 1
206 r2_index = 1
207 for ri_id in cdp.ri_ids:
208
209 if cdp.ri_type[ri_id] == 'NOE':
210
211 number = noe_index
212
213
214 data_type = 'noe'
215
216
217 noe_index = noe_index + 1
218
219
220 elif cdp.ri_type[ri_id] == 'R1':
221
222 number = r1_index
223
224
225 data_type = '1/T1'
226
227
228 r1_index = r1_index + 1
229
230
231 elif cdp.ri_type[ri_id] == 'R2':
232
233 number = r2_index
234
235
236 data_type = '1/T2'
237
238
239 r2_index = r2_index + 1
240
241
242 if number == 1:
243 file.write("\nread < %s\n" % data_type)
244 else:
245 file.write("\nread < %s %s\n" % (data_type, number))
246
247
248 for residue in residue_loop():
249
250 spin = residue.spin[0]
251
252
253 if not spin.select:
254 continue
255
256
257 if len(spin.ri_data) != len(cdp.ri_ids) or spin.ri_data[ri_id] == None:
258 spin.select = False
259 continue
260
261
262 file.write("%s %s %s\n" % (residue.num, spin.ri_data[ri_id], spin.ri_data_err[ri_id]))
263
264
265 file.write("exit\n")
266
267
268 if model_type == 'mf':
269
270 for residue in residue_loop():
271
272 spin = residue.spin[0]
273
274
275 if not spin.select:
276 continue
277
278
279 file.write("\n\n\n# Residue %s\n\n" % residue.num)
280
281
282 file.write("echo Optimisation of residue %s\n" % residue.num)
283
284
285 file.write("\n# Select the residue.\n")
286 file.write("set cres %s\n" % residue.num)
287
288
289 if cdp.diff_tensor.type == 'spheroid':
290 file.write("set teta %s\n" % spin.alpha)
291
292
293 elif cdp.diff_tensor.type == 'ellipsoid':
294 file.write("\n# Setting the spherical angles of the XH vector in the ellipsoid diffusion frame.\n")
295 file.write("set teta %s\n" % spin.theta)
296 file.write("set fi %s\n" % spin.phi)
297
298
299 if 'ts' in spin.params:
300 jmode = 3
301 elif 'te' in spin.params:
302 jmode = 2
303 elif 's2' in spin.params:
304 jmode = 1
305
306
307 if 'rex' in spin.params:
308 exch = True
309 else:
310 exch = False
311
312
313 if cdp.diff_tensor.type == 'sphere':
314 anis = False
315 else:
316 anis = True
317
318
319 if cdp.diff_tensor.type == 'spheroid':
320 sym = True
321 else:
322 sym = False
323
324
325 file.write("\n# Set the jmode.\n")
326 file.write("set def jmode %s" % jmode)
327 if exch:
328 file.write(" exch")
329 if anis:
330 file.write(" anis")
331 if sym:
332 file.write(" sym")
333 file.write("\n")
334
335
336 file.write("\n# Parameter default values.\n")
337 file.write("reset jmode %s\n" % residue.num)
338
339
340 file.write("\n# Bond length.\n")
341 file.write("set r_hx %s\n" % (spin.r / 1e-10))
342
343
344 file.write("\n# CSA value.\n")
345 file.write("set csa %s\n" % (spin.csa / 1e-6))
346
347
348 if not 'tf' in spin.params and jmode == 3:
349 file.write("\n# Fix the tf parameter.\n")
350 file.write("fix tf 0\n")
351
352
353 file.write("\n\n\n# Optimisation of all residues.\n")
354 if algor == 'LM':
355 file.write("lmin %s %s" % (first_residue_num(), last_residue_num()))
356 elif algor == 'NR':
357 file.write("min %s %s" % (first_residue_num(), last_residue_num()))
358
359
360 file.write("\n# Show the results.\n")
361 file.write("echo\n")
362 file.write("show all\n")
363
364
365 file.write("\n# Write the results.\n")
366 file.write("write s2.out S\n")
367 file.write("write s2f.out Sf\n")
368 file.write("write s2s.out Ss\n")
369 file.write("write te.out te\n")
370 file.write("write tf.out tf\n")
371 file.write("write ts.out ts\n")
372 file.write("write rex.out rex\n")
373 file.write("write chi2.out F\n")
374
375 else:
376 raise RelaxError("Optimisation of the parameter set '%s' currently not supported." % model_type)
377
378
380 """Execute Dasha.
381
382 @param dir: The optional directory where the script is located.
383 @type dir: str or None
384 @param force: A flag which if True will cause any pre-existing files to be overwritten by Dasha.
385 @type force: bool
386 @param binary: The name of the Dasha binary file. This can include the path to the binary.
387 @type binary: str
388 """
389
390
391 test_binary(binary)
392
393
394 orig_dir = getcwd()
395
396
397 if dir == None:
398 dir = pipes.cdp_name()
399 if not access(dir, F_OK):
400 raise RelaxDirError('Dasha', dir)
401
402
403 chdir(dir)
404
405
406 try:
407
408 if not access('dasha_script', F_OK):
409 raise RelaxFileError('dasha script', 'dasha_script')
410
411
412 stdin, stdout, stderr = popen3(binary)
413
414
415 script = open('dasha_script')
416 lines = script.readlines()
417 script.close()
418 for line in lines:
419 stdin.write(line)
420
421
422 stdin.close()
423
424
425 for line in stdout.readlines():
426 sys.stdout.write(line)
427 for line in stderr.readlines():
428 sys.stderr.write(line)
429
430
431 except:
432
433 chdir(orig_dir)
434
435
436 raise
437
438
439 chdir(orig_dir)
440
441
442 sys.stdout.write("\n\n")
443
444
446 """Extract the data from the Dasha results files.
447
448 @param dir: The optional directory where the results file is located.
449 @type dir: str or None
450 """
451
452
453 if not exists_mol_res_spin_data():
454 raise RelaxNoSequenceError
455
456
457 if dir == None:
458 dir = pipes.cdp_name()
459 if not access(dir, F_OK):
460 raise RelaxDirError('Dasha', dir)
461
462
463 for param in ['s2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex']:
464
465 file_name = dir + sep + param + '.out'
466
467
468 if not access(file_name, F_OK):
469 raise RelaxFileError('Dasha', file_name)
470
471
472 if param in ['te', 'tf', 'ts']:
473 scaling = 1e-9
474 elif param == 'rex':
475 scaling = 1.0 / (2.0 * pi * cdp.frq[cdp.ri_ids[0]]) ** 2
476 else:
477 scaling = 1.0
478
479
480 value.read(param=param, scaling=scaling, file=file_name, res_num_col=1, res_name_col=None, data_col=2, error_col=3)
481
482
483 for spin in spin_loop():
484
485 if param in spin.params:
486 continue
487
488
489 setattr(spin, lower(param), None)
490
491
492 file_name = dir + sep+'chi2.out'
493
494
495 if not access(file_name, F_OK):
496 raise RelaxFileError('Dasha', file_name)
497
498
499 value.read(param='chi2', file=file_name, res_num_col=1, res_name_col=None, data_col=2, error_col=3)
500