Mercurial > repos > chemteam > mdanalysis_rdf
annotate distance.py @ 4:aabf6858f293 draft
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
| author | chemteam | 
|---|---|
| date | Mon, 07 Oct 2019 12:41:24 -0400 | 
| parents | 935c49339c3b | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
2 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
4 import sys | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
5 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
6 import MDAnalysis as mda | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
7 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
8 import matplotlib | 
| 
1
 
935c49339c3b
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 9b44a37fc1a0c338693f54eaf52b582439ca9f0c
 
chemteam 
parents: 
0 
diff
changeset
 | 
9 matplotlib.use('Agg') # noqa | 
| 
0
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
10 import matplotlib.pyplot as plt | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
11 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
12 import numpy as np | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
13 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
14 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
15 def parse_command_line(argv): | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
16 parser = argparse.ArgumentParser() | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
17 parser.add_argument('--itraj', help='input traj') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
18 parser.add_argument('--istr', help='input str') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
19 parser.add_argument('--itrajext', help='input traj ext') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
20 parser.add_argument('--istrext', help='input str ext') | 
| 
0
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
21 parser.add_argument('--isegid1', help='segid 1') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
22 parser.add_argument('--iresid1', help='resid 1') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
23 parser.add_argument('--iname1', help='name 1') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
24 parser.add_argument('--isegid2', help='segid 2') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
25 parser.add_argument('--iresid2', help='resid 2') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
26 parser.add_argument('--iname2', help='name 2') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
27 parser.add_argument('--output', help='output') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
28 parser.add_argument('--odistance_plot', help='odistance plot') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
29 return parser.parse_args() | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
30 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
31 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
32 args = parse_command_line(sys.argv) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
33 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
34 atom1 = "(segid %s and resid %s and name %s)" % \ | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
35 (args.isegid1, args.iresid1, args.iname1) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
36 atom2 = "(segid %s and resid %s and name %s)" % \ | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
37 (args.isegid2, args.iresid2, args.iname2) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
38 | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
39 u = mda.Universe(args.istr, args.itraj, | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
1 
diff
changeset
 | 
40 topology_format=args.istrext, format=args.itrajext) | 
| 
0
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
41 x = u.select_atoms(atom1) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
42 y = u.select_atoms(atom2) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
43 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
44 with open(args.output, 'w') as f: | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
45 for t in u.trajectory: | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
46 r = x.positions - y.positions | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
47 d = np.linalg.norm(r) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
48 f.write(str(t.frame) + '\t ') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
49 f.write(str(d) + '\n') | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
50 | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
51 with open(args.output) as f: | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
52 g = [xtmp.strip() for xtmp in f] | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
53 data = [tuple(map(float, xtmp.split())) for xtmp in g[0:]] | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
54 time = [xtmp[0] for xtmp in data] | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
55 distance = [xtmp[1] for xtmp in data] | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
56 plt.plot(time, distance) | 
| 
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
57 plt.xlabel('Frame No.') | 
| 
1
 
935c49339c3b
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 9b44a37fc1a0c338693f54eaf52b582439ca9f0c
 
chemteam 
parents: 
0 
diff
changeset
 | 
58 plt.ylabel(r'Distance ($\AA$)') | 
| 
0
 
24e220d91481
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 6a59f07610c28b07f1d2d2b3badf3a9b8aacce50
 
chemteam 
parents:  
diff
changeset
 | 
59 plt.savefig(args.odistance_plot, format='png') | 
