Mercurial > repos > chemteam > mdanalysis_dihedral
annotate rdf.py @ 3:554f60da9c8f draft
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
author | chemteam |
---|---|
date | Wed, 03 Apr 2019 15:47:36 -0400 |
parents | cc1d22357daf |
children | d8178fe9aaff |
rev | line source |
---|---|
0
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
2 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
3 import argparse |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
4 import csv |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
5 import sys |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
6 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
7 import MDAnalysis as mda |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
8 from MDAnalysis.analysis.rdf import InterRDF |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
9 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
10 import matplotlib |
1
cc1d22357daf
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 9b44a37fc1a0c338693f54eaf52b582439ca9f0c
chemteam
parents:
0
diff
changeset
|
11 matplotlib.use('Agg') # noqa |
0
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
12 import matplotlib.pyplot as plt |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
13 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
14 import numpy as np |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
15 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
16 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
17 def parse_command_line(argv): |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
18 parser = argparse.ArgumentParser() |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
19 parser.add_argument('--idcd', help='input dcd') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
20 parser.add_argument('--ipdb', help='input pdb') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
21 parser.add_argument('--isegid1', help='segid 1') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
22 parser.add_argument('--iresid1', help='resid 1') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
23 parser.add_argument('--iname1', help='name 1') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
24 parser.add_argument('--isegid2', help='segid 2') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
25 parser.add_argument('--iresid2', help='resid 2') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
26 parser.add_argument('--iname2', help='name 2') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
27 parser.add_argument('--inbins', help='Number of bins in the histogram') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
28 parser.add_argument('--istart', help='Starting Point') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
29 parser.add_argument('--iend', help='End point') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
30 parser.add_argument('--output', help='output') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
31 parser.add_argument('--ordf_plot', help='RDF plot') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
32 return parser.parse_args() |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
33 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
34 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
35 args = parse_command_line(sys.argv) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
36 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
37 atom1 = "(segid %s and resid %s and name %s)" % \ |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
38 (args.isegid1, args.iresid1, args.iname1) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
39 atom2 = "(segid %s and resid %s and name %s)" % \ |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
40 (args.isegid2, args.iresid2, args.iname2) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
41 bins = int(args.inbins) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
42 start = float(args.istart) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
43 end = float(args.iend) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
44 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
45 u = mda.Universe(args.ipdb, args.idcd, topology_format="PDB", format="DCD") |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
46 x = u.select_atoms(atom1) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
47 y = u.select_atoms(atom2) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
48 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
49 rdf = InterRDF(x, y, nbins=bins, range=(start, end)) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
50 rdf.run() |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
51 bins = rdf.bins |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
52 bins = np.around(bins, decimals=3) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
53 RDF = rdf.rdf |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
54 zip(bins, RDF) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
55 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
56 with open(args.output, 'w') as f: |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
57 writer = csv.writer(f, delimiter='\t') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
58 writer.writerows(zip(bins, RDF)) |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
59 |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
60 with open(args.output) as f: |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
61 g = [xtmp.strip() for xtmp in f] |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
62 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]] |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
63 time = [xtmp[0] for xtmp in data] |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
64 rdf = [xtmp[1] for xtmp in data] |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
65 plt.plot(time, rdf) |
1
cc1d22357daf
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 9b44a37fc1a0c338693f54eaf52b582439ca9f0c
chemteam
parents:
0
diff
changeset
|
66 plt.xlabel(r'r ($\AA$)') |
0
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
67 plt.ylabel('g(r)') |
f95d4348ed7c
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
chemteam
parents:
diff
changeset
|
68 plt.savefig(args.ordf_plot, format='png') |