comparison angle.py @ 0:469ad3ea5a5f draft

planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
author chemteam
date Wed, 03 Apr 2019 15:48:18 -0400
parents
children 5c38e38dbc35
comparison
equal deleted inserted replaced
-1:000000000000 0:469ad3ea5a5f
1 #!/usr/bin/env python
2
3 import argparse
4 import csv
5 import sys
6
7 import MDAnalysis as mda
8
9 import matplotlib
10 matplotlib.use('Agg') # noqa
11 import matplotlib.pyplot as plt
12
13 import numpy as np
14 from numpy.linalg import norm
15
16
17 def parse_command_line(argv):
18 parser = argparse.ArgumentParser()
19 parser.add_argument('--idcd', help='input dcd')
20 parser.add_argument('--ipdb', help='input pdb')
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('--isegid3', help='segid 3')
28 parser.add_argument('--iresid3', help='resid 3')
29 parser.add_argument('--iname3', help='name 3')
30 parser.add_argument('--output', help='output')
31 parser.add_argument('--oangle_plot', help='angle plot')
32 return parser.parse_args()
33
34
35 args = parse_command_line(sys.argv)
36
37 atom1 = "(segid %s and resid %s and name %s)" % \
38 (args.isegid1, args.iresid1, args.iname1)
39 atom2 = "(segid %s and resid %s and name %s)" % \
40 (args.isegid2, args.iresid2, args.iname2)
41 atom3 = "(segid %s and resid %s and name %s)" % \
42 (args.isegid3, args.iresid3, args.iname3)
43
44
45 def theta(u):
46 A = u.select_atoms(atom1).center_of_geometry()
47 B = u.select_atoms(atom2).center_of_geometry()
48 C = u.select_atoms(atom3).center_of_geometry()
49 BA = A - B
50 BC = C - B
51 theta = np.arccos(np.dot(BA, BC)/(norm(BA)*norm(BC)))
52 return np.rad2deg(theta)
53
54
55 u = mda.Universe(args.ipdb, args.idcd, topology_format="PDB", format="DCD")
56 data = np.array([(u.trajectory.frame, theta(u)) for ts in u.trajectory])
57 frame, theta = data.T
58
59 with open(args.output, 'w') as f:
60 writer = csv.writer(f, delimiter='\t')
61 writer.writerows(zip(frame, theta))
62
63 with open(args.output) as f:
64 g = [xtmp.strip() for xtmp in f]
65 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]]
66 time = [xtmp[0] for xtmp in data]
67 angle = [xtmp[1] for xtmp in data]
68 plt.plot(time, angle)
69 plt.xlabel('Frame No.')
70 plt.ylabel('Angle (degrees)')
71 plt.savefig(args.oangle_plot, format='png')