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