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