Mercurial > repos > chemteam > mdanalysis_rdf
comparison rdf.py @ 0:9bb57bd1fdc8 draft
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit c32fe331f438df7760084b27bafad9f78f01edde
author | chemteam |
---|---|
date | Mon, 08 Oct 2018 13:17:18 -0400 |
parents | |
children | 0315b541c74d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9bb57bd1fdc8 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import argparse | |
4 import csv | |
5 import sys | |
6 | |
7 import MDAnalysis as mda | |
8 from MDAnalysis.analysis.rdf import InterRDF | |
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('--inbins', help='Number of bins in the histogram') | |
29 parser.add_argument('--istart', help='Starting Point') | |
30 parser.add_argument('--iend', help='End point') | |
31 parser.add_argument('--output', help='output') | |
32 parser.add_argument('--ordf_plot', help='RDF 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 bins = int(args.inbins) | |
43 start = float(args.istart) | |
44 end = float(args.iend) | |
45 | |
46 u = mda.Universe(args.ipdb, args.idcd, topology_format="PDB", format="DCD") | |
47 x = u.select_atoms(atom1) | |
48 y = u.select_atoms(atom2) | |
49 | |
50 rdf = InterRDF(x, y, nbins=bins, range=(start, end)) | |
51 rdf.run() | |
52 bins = rdf.bins | |
53 bins = np.around(bins, decimals=3) | |
54 RDF = rdf.rdf | |
55 zip(bins, RDF) | |
56 | |
57 with open(args.output, 'w') as f: | |
58 writer = csv.writer(f, delimiter='\t') | |
59 writer.writerows(zip(bins, RDF)) | |
60 | |
61 with open(args.output) as f: | |
62 g = [xtmp.strip() for xtmp in f] | |
63 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]] | |
64 time = [xtmp[0] for xtmp in data] | |
65 rdf = [xtmp[1] for xtmp in data] | |
66 plt.plot(time, rdf) | |
67 plt.xlabel('r ($\AA$)') | |
68 plt.ylabel('g(r)') | |
69 plt.savefig(args.ordf_plot, format='png') |