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