Mercurial > repos > chemteam > mdanalysis_distance
annotate distance_single.py @ 5:d540ea77b909 draft
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
author | chemteam |
---|---|
date | Thu, 06 Feb 2020 19:43:03 -0500 |
parents | |
children | aa4090b50e7b |
rev | line source |
---|---|
5
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
1 #!/usr/bin/env python |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
2 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
3 import argparse |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
4 import sys |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
5 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
6 import MDAnalysis as mda |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
7 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
8 import matplotlib |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
9 matplotlib.use('Agg') # noqa |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
10 import matplotlib.pyplot as plt |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
11 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
12 import numpy as np |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
13 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
14 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
15 def parse_command_line(argv): |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
16 parser = argparse.ArgumentParser() |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
27 parser.add_argument('--output', help='output') |
d540ea77b909
"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') |
d540ea77b909
"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') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
30 return parser.parse_args() |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
31 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
32 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
33 args = parse_command_line(sys.argv) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
34 |
d540ea77b909
"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)" % \ |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
36 (args.isegid1, args.iresid1, args.iname1) |
d540ea77b909
"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)" % \ |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
38 (args.isegid2, args.iresid2, args.iname2) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
39 |
d540ea77b909
"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, |
d540ea77b909
"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) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
42 x = u.select_atoms(atom1) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
43 y = u.select_atoms(atom2) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
44 |
d540ea77b909
"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: |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
46 if args.header: |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
47 f.write('Frame\tDistance') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
48 for t in u.trajectory: |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
49 r = x.positions - y.positions |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
50 d = np.linalg.norm(r) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
51 f.write(str(t.frame) + '\t ') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
52 f.write(str(d) + '\n') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
53 |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
54 with open(args.output) as f: |
d540ea77b909
"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] |
d540ea77b909
"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:]] |
d540ea77b909
"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] |
d540ea77b909
"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] |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
59 plt.plot(time, distance) |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
60 plt.xlabel('Frame No.') |
d540ea77b909
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff
changeset
|
61 plt.ylabel(r'Distance ($\AA$)') |
d540ea77b909
"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') |