annotate distance_multiple.py @ 5:62ce73c9d737 draft

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
author chemteam
date Thu, 06 Feb 2020 19:41:27 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
1 import argparse
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
2 import sys
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
3
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
4 import MDAnalysis as mda
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
5 from MDAnalysis.analysis import distances
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
6
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
7 import numpy as np
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
8
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
9
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
10 def parse_command_line(argv):
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
11 parser = argparse.ArgumentParser()
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
12 parser.add_argument('--itraj', help='input traj')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
13 parser.add_argument('--istr', help='input str')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
14 parser.add_argument('--itrajext', help='input traj ext')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
15 parser.add_argument('--istrext', help='input str ext')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
16 parser.add_argument('--list1', help='list 2')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
17 parser.add_argument('--list2', help='list 2')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
18 parser.add_argument('--output', help='output')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
19 parser.add_argument('--header', dest='header', action='store_true')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
20 return parser.parse_args()
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
21
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
22
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
23 args = parse_command_line(sys.argv)
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
24
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
25 u = mda.Universe(args.istr, args.itraj,
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
26 topology_format=args.istrext, format=args.itrajext)
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
27
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
28 list1 = np.loadtxt(args.list1, dtype=str, delimiter="\t", ndmin=1)
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
29 list2 = np.loadtxt(args.list2, dtype=str, delimiter="\t", ndmin=1)
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
30
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
31 sel1 = [u.select_atoms(selection) for selection in list1]
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
32 sel2 = [u.select_atoms(selection) for selection in list2]
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
33
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
34 d = np.empty((u.trajectory.n_frames, list1.shape[0], list2.shape[0]),)
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
35
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
36 for ts in u.trajectory:
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
37 c_o_m1 = np.array([selection.center_of_mass() for selection in sel1])
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
38 c_o_m2 = np.array([selection.center_of_mass() for selection in sel2])
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
39 distances.distance_array(c_o_m1, c_o_m2, result=d[ts.frame])
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
40
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
41 d = np.hstack((
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
42 np.array(np.reshape(np.arange(
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
43 0, d.shape[0]), (d.shape[0], 1)), dtype=int), # add column w frame
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
44 np.reshape(d, (d.shape[0], d.shape[1] * d.shape[2]))
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
45 ))
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
46
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
47 if args.header:
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
48 header = 'Frame\t' + '\t'.join(
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
49 ['-'.join(pair) for pair in zip(
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
50 sum([[n, ] * len(list2) for n in list1], []),
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
51 list(list2) * len(list1),)]).replace(' ', '_')
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
52 else:
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
53 header = ''
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
54
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
55 np.savetxt(args.output, d, header=header, comments='',
62ce73c9d737 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
56 fmt=['%d'] + ['%f'] * (d.shape[1] - 1), delimiter='\t')