comparison distance_single.py @ 5:b63a8bdb4b90 draft

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