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