comparison distance.py @ 0:d710c7f00ae6 draft

planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
author chemteam
date Wed, 03 Apr 2019 15:46:32 -0400
parents
children ce0728b92289
comparison
equal deleted inserted replaced
-1:000000000000 0:d710c7f00ae6
1 #!/usr/bin/env python
2
3 import argparse
4 import sys
5
6 import MDAnalysis as mda
7
8 import matplotlib
9 matplotlib.use('Agg') # noqa
10 import matplotlib.pyplot as plt
11
12 import numpy as np
13
14
15 def parse_command_line(argv):
16 parser = argparse.ArgumentParser()
17 parser.add_argument('--idcd', help='input dcd')
18 parser.add_argument('--ipdb', help='input pdb')
19 parser.add_argument('--isegid1', help='segid 1')
20 parser.add_argument('--iresid1', help='resid 1')
21 parser.add_argument('--iname1', help='name 1')
22 parser.add_argument('--isegid2', help='segid 2')
23 parser.add_argument('--iresid2', help='resid 2')
24 parser.add_argument('--iname2', help='name 2')
25 parser.add_argument('--output', help='output')
26 parser.add_argument('--odistance_plot', help='odistance plot')
27 return parser.parse_args()
28
29
30 args = parse_command_line(sys.argv)
31
32 atom1 = "(segid %s and resid %s and name %s)" % \
33 (args.isegid1, args.iresid1, args.iname1)
34 atom2 = "(segid %s and resid %s and name %s)" % \
35 (args.isegid2, args.iresid2, args.iname2)
36
37 u = mda.Universe(args.ipdb, args.idcd, topology_format="PDB", format="DCD")
38 x = u.select_atoms(atom1)
39 y = u.select_atoms(atom2)
40
41 with open(args.output, 'w') as f:
42 for t in u.trajectory:
43 r = x.positions - y.positions
44 d = np.linalg.norm(r)
45 f.write(str(t.frame) + '\t ')
46 f.write(str(d) + '\n')
47
48 with open(args.output) as f:
49 g = [xtmp.strip() for xtmp in f]
50 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]]
51 time = [xtmp[0] for xtmp in data]
52 distance = [xtmp[1] for xtmp in data]
53 plt.plot(time, distance)
54 plt.xlabel('Frame No.')
55 plt.ylabel(r'Distance ($\AA$)')
56 plt.savefig(args.odistance_plot, format='png')