annotate dihedrals.py @ 4:e7d0075052c9 draft

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
author chemteam
date Mon, 07 Oct 2019 12:51:05 -0400
parents ad135cf42274
children 7c5fd4117a07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
1 #!/usr/bin/env python
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
2
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
3 import argparse
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
4 import csv
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
5 import sys
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
6
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
7 import MDAnalysis as mda
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
8 from MDAnalysis.lib.distances import calc_dihedrals
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
9
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
10 import matplotlib
1
4759026f6ff4 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 9b44a37fc1a0c338693f54eaf52b582439ca9f0c
chemteam
parents: 0
diff changeset
11 matplotlib.use('Agg') # noqa
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
12 import matplotlib.pyplot as plt
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
13
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
14 import numpy as np
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
15
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
16
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
17 def parse_command_line(argv):
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
18 parser = argparse.ArgumentParser()
4
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
19 parser.add_argument('--itraj', help='input traj')
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
20 parser.add_argument('--istr', help='input str')
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
21 parser.add_argument('--itrajext', help='input traj ext')
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
22 parser.add_argument('--istrext', help='input str ext')
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
23 parser.add_argument('--isegid1', help='segid 1')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
24 parser.add_argument('--iresid1', help='resid 1')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
25 parser.add_argument('--iname1', help='name 1')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
26 parser.add_argument('--isegid2', help='segid 2')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
27 parser.add_argument('--iresid2', help='resid 2')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
28 parser.add_argument('--iname2', help='name 2')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
29 parser.add_argument('--isegid3', help='segid 3')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
30 parser.add_argument('--iresid3', help='resid 3')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
31 parser.add_argument('--iname3', help='name 3')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
32 parser.add_argument('--isegid4', help='segid 4')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
33 parser.add_argument('--iresid4', help='resid 4')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
34 parser.add_argument('--iname4', help='name 4')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
35 parser.add_argument('--output', help='output')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
36 parser.add_argument('--odihedral_plot', help='dihedral plot')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
37 return parser.parse_args()
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
38
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
39
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
40 args = parse_command_line(sys.argv)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
41
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
42 atom1 = "(segid %s and resid %s and name %s)" % \
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
43 (args.isegid1, args.iresid1, args.iname1)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
44 atom2 = "(segid %s and resid %s and name %s)" % \
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
45 (args.isegid2, args.iresid2, args.iname2)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
46 atom3 = "(segid %s and resid %s and name %s)" % \
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
47 (args.isegid3, args.iresid3, args.iname3)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
48 atom4 = "(segid %s and resid %s and name %s)" % \
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
49 (args.isegid4, args.iresid4, args.iname4)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
50
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
51
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
52 def psi(u):
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
53 A = u.select_atoms(atom1).positions
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
54 B = u.select_atoms(atom2).positions
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
55 C = u.select_atoms(atom3).positions
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
56 D = u.select_atoms(atom4).positions
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
57 psi = calc_dihedrals(A, B, C, D)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
58 return np.rad2deg(psi)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
59
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
60
4
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
61 u = mda.Universe(args.istr, args.itraj,
e7d0075052c9 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents: 3
diff changeset
62 topology_format=args.istrext, format=args.itrajext)
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
63 data = np.array([(u.trajectory.frame, psi(u)) for ts in u.trajectory])
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
64 frame, psi = data.T
3
ad135cf42274 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents: 1
diff changeset
65 PSI = np.concatenate(psi, axis=0)
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
66
3
ad135cf42274 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents: 1
diff changeset
67 zip(frame, PSI)
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
68
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
69 with open(args.output, 'w') as f:
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
70 writer = csv.writer(f, delimiter='\t')
3
ad135cf42274 planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents: 1
diff changeset
71 writer.writerows(zip(frame, PSI))
0
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
72
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
73 with open(args.output) as f:
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
74 g = [xtmp.strip() for xtmp in f]
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
75 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]]
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
76 time = [xtmp[0] for xtmp in data]
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
77 dihedral = [xtmp[1] for xtmp in data]
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
78 plt.plot(time, dihedral)
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
79 plt.xlabel('Frame No.')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
80 plt.ylabel('Dihedral (degrees)')
fc7293c6cb6a planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff changeset
81 plt.savefig(args.odihedral_plot, format='png')