comparison rdf.py @ 0:469ad3ea5a5f draft

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