Mercurial > repos > chemteam > mdanalysis_distance
comparison angle.py @ 0:c33b972fe040 draft
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
author | chemteam |
---|---|
date | Mon, 08 Oct 2018 13:16:12 -0400 |
parents | |
children | 2b1434ec8c7e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c33b972fe040 |
---|---|
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 import matplotlib.pyplot as plt | |
11 | |
12 import numpy as np | |
13 from numpy.linalg import norm | |
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('--output', help='output') | |
32 parser.add_argument('--oangle_plot', help='angle plot') | |
33 return parser.parse_args() | |
34 | |
35 | |
36 args = parse_command_line(sys.argv) | |
37 | |
38 atom1 = "(segid %s and resid %s and name %s)" % \ | |
39 (args.isegid1, args.iresid1, args.iname1) | |
40 atom2 = "(segid %s and resid %s and name %s)" % \ | |
41 (args.isegid2, args.iresid2, args.iname2) | |
42 atom3 = "(segid %s and resid %s and name %s)" % \ | |
43 (args.isegid3, args.iresid3, args.iname3) | |
44 | |
45 | |
46 def theta(u): | |
47 A = u.select_atoms(atom1).center_of_geometry() | |
48 B = u.select_atoms(atom2).center_of_geometry() | |
49 C = u.select_atoms(atom3).center_of_geometry() | |
50 BA = A - B | |
51 BC = C - B | |
52 theta = np.arccos(np.dot(BA, BC)/(norm(BA)*norm(BC))) | |
53 return np.rad2deg(theta) | |
54 | |
55 | |
56 u = mda.Universe(args.ipdb, args.idcd, topology_format="PDB", format="DCD") | |
57 data = np.array([(u.trajectory.frame, theta(u)) for ts in u.trajectory]) | |
58 frame, theta = data.T | |
59 | |
60 with open(args.output, 'w') as f: | |
61 writer = csv.writer(f, delimiter='\t') | |
62 writer.writerows(zip(frame, theta)) | |
63 | |
64 with open(args.output) as f: | |
65 g = [xtmp.strip() for xtmp in f] | |
66 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]] | |
67 time = [xtmp[0] for xtmp in data] | |
68 angle = [xtmp[1] for xtmp in data] | |
69 plt.plot(time, angle) | |
70 plt.xlabel('Frame No.') | |
71 plt.ylabel('Angle (degrees)') | |
72 plt.savefig(args.oangle_plot, format='png') |