comparison distance.py @ 0:fc7293c6cb6a draft

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