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