annotate distance_multiple.py @ 6:48d6a6eb438b draft default tip

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit f1c3c88c7395f2e84cbc533199406aadb79c5c07"
author chemteam
date Fri, 13 Nov 2020 19:43:39 +0000
parents e39bc1f90d8f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
1 import argparse
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
2 import sys
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
3
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
4 import MDAnalysis as mda
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
5 from MDAnalysis.analysis import distances
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
6
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
7 import numpy as np
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
8
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
9
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
10 def parse_command_line(argv):
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
11 parser = argparse.ArgumentParser()
e39bc1f90d8f "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')
e39bc1f90d8f "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')
e39bc1f90d8f "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')
e39bc1f90d8f "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')
e39bc1f90d8f "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')
e39bc1f90d8f "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')
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
18 parser.add_argument('--output', help='output')
e39bc1f90d8f "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')
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
20 return parser.parse_args()
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
21
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
22
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
23 args = parse_command_line(sys.argv)
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
24
e39bc1f90d8f "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,
e39bc1f90d8f "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)
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
27
e39bc1f90d8f "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)
e39bc1f90d8f "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)
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
30
e39bc1f90d8f "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]
e39bc1f90d8f "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]
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
33
e39bc1f90d8f "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]),)
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
35
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
36 for ts in u.trajectory:
e39bc1f90d8f "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])
e39bc1f90d8f "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])
e39bc1f90d8f "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])
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
40
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
41 d = np.hstack((
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
42 np.array(np.reshape(np.arange(
e39bc1f90d8f "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
e39bc1f90d8f "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]))
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
45 ))
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
46
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
47 if args.header:
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
48 header = 'Frame\t' + '\t'.join(
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
49 ['-'.join(pair) for pair in zip(
e39bc1f90d8f "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], []),
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
51 list(list2) * len(list1),)]).replace(' ', '_')
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
52 else:
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
53 header = ''
e39bc1f90d8f "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
chemteam
parents:
diff changeset
54
e39bc1f90d8f "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='',
e39bc1f90d8f "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')