comparison distance_single.py @ 0:0f270722aca6 draft

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 1b23e024af45cc0999d9142d07de6897d4189ec2"
author chemteam
date Mon, 24 Aug 2020 16:27:56 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0f270722aca6
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') # noqa
14
15
16 def parse_command_line(argv):
17 parser = argparse.ArgumentParser()
18 parser.add_argument('--itraj', help='input traj')
19 parser.add_argument('--istr', help='input str')
20 parser.add_argument('--itrajext', help='input traj ext')
21 parser.add_argument('--istrext', help='input str ext')
22 parser.add_argument('--isegid1', help='segid 1')
23 parser.add_argument('--iresid1', help='resid 1')
24 parser.add_argument('--iname1', help='name 1')
25 parser.add_argument('--isegid2', help='segid 2')
26 parser.add_argument('--iresid2', help='resid 2')
27 parser.add_argument('--iname2', help='name 2')
28 parser.add_argument('--output', help='output')
29 parser.add_argument('--odistance_plot', help='odistance plot')
30 parser.add_argument('--header', dest='header', action='store_true')
31 return parser.parse_args()
32
33
34 args = parse_command_line(sys.argv)
35
36 atom1 = "(segid %s and resid %s and name %s)" % \
37 (args.isegid1, args.iresid1, args.iname1)
38 atom2 = "(segid %s and resid %s and name %s)" % \
39 (args.isegid2, args.iresid2, args.iname2)
40
41 u = mda.Universe(args.istr, args.itraj,
42 topology_format=args.istrext, format=args.itrajext)
43 x = u.select_atoms(atom1)
44 y = u.select_atoms(atom2)
45
46 with open(args.output, 'w') as f:
47 if args.header:
48 f.write('Frame\tDistance')
49 for t in u.trajectory:
50 r = x.positions - y.positions
51 d = np.linalg.norm(r)
52 f.write(str(t.frame) + '\t ')
53 f.write(str(d) + '\n')
54
55 with open(args.output) as f:
56 g = [xtmp.strip() for xtmp in f]
57 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]]
58 time = [xtmp[0] for xtmp in data]
59 distance = [xtmp[1] for xtmp in data]
60 plt.plot(time, distance)
61 plt.xlabel('Frame No.')
62 plt.ylabel(r'Distance ($\AA$)')
63 plt.savefig(args.odistance_plot, format='png')