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