annotate angle.py @ 6:50d06a07297e draft default tip

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 7a25958195ccc8f448dd64ddcc36e8f5e5979d8b"
author chemteam
date Wed, 20 May 2020 16:57:00 +0000
parents f88922781345
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
1 #!/usr/bin/env python
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
2
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
3 import argparse
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
4 import csv
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
5 import sys
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
6
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
7 import MDAnalysis as mda
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
8
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
9 import matplotlib
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
10 import matplotlib.pyplot as plt
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
11
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
12 import numpy as np
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
13 from numpy.linalg import norm
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
14
6
50d06a07297e "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 7a25958195ccc8f448dd64ddcc36e8f5e5979d8b"
chemteam
parents: 4
diff changeset
15 matplotlib.use('Agg') # noqa
50d06a07297e "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 7a25958195ccc8f448dd64ddcc36e8f5e5979d8b"
chemteam
parents: 4
diff changeset
16
0
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
17
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
18 def parse_command_line(argv):
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
19 parser = argparse.ArgumentParser()
4
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
20 parser.add_argument('--itraj', help='input traj')
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
21 parser.add_argument('--istr', help='input str')
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
22 parser.add_argument('--itrajext', help='input traj ext')
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
23 parser.add_argument('--istrext', help='input str ext')
0
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
24 parser.add_argument('--isegid1', help='segid 1')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
25 parser.add_argument('--iresid1', help='resid 1')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
26 parser.add_argument('--iname1', help='name 1')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
27 parser.add_argument('--isegid2', help='segid 2')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
28 parser.add_argument('--iresid2', help='resid 2')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
29 parser.add_argument('--iname2', help='name 2')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
30 parser.add_argument('--isegid3', help='segid 3')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
31 parser.add_argument('--iresid3', help='resid 3')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
32 parser.add_argument('--iname3', help='name 3')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
33 parser.add_argument('--output', help='output')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
34 parser.add_argument('--oangle_plot', help='angle plot')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
35 return parser.parse_args()
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
36
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
37
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
38 args = parse_command_line(sys.argv)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
39
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
40 atom1 = "(segid %s and resid %s and name %s)" % \
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
41 (args.isegid1, args.iresid1, args.iname1)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
42 atom2 = "(segid %s and resid %s and name %s)" % \
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
43 (args.isegid2, args.iresid2, args.iname2)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
44 atom3 = "(segid %s and resid %s and name %s)" % \
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
45 (args.isegid3, args.iresid3, args.iname3)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
46
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
47
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
48 def theta(u):
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
49 A = u.select_atoms(atom1).center_of_geometry()
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
50 B = u.select_atoms(atom2).center_of_geometry()
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
51 C = u.select_atoms(atom3).center_of_geometry()
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
52 BA = A - B
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
53 BC = C - B
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
54 theta = np.arccos(np.dot(BA, BC)/(norm(BA)*norm(BC)))
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
55 return np.rad2deg(theta)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
56
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
57
4
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
58 u = mda.Universe(args.istr, args.itraj,
f88922781345 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 1
diff changeset
59 topology_format=args.istrext, format=args.itrajext)
0
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
60 data = np.array([(u.trajectory.frame, theta(u)) for ts in u.trajectory])
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
61 frame, theta = data.T
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
62
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
63 with open(args.output, 'w') as f:
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
64 writer = csv.writer(f, delimiter='\t')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
65 writer.writerows(zip(frame, theta))
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
66
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
67 with open(args.output) as f:
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
68 g = [xtmp.strip() for xtmp in f]
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
69 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]]
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
70 time = [xtmp[0] for xtmp in data]
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
71 angle = [xtmp[1] for xtmp in data]
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
72 plt.plot(time, angle)
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
73 plt.xlabel('Frame No.')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
74 plt.ylabel('Angle (degrees)')
b8e2e0e7a238 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
chemteam
parents:
diff changeset
75 plt.savefig(args.oangle_plot, format='png')