comparison dihedrals.py @ 0:fc7293c6cb6a draft

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