Mercurial > repos > chemteam > mdanalysis_rdf
annotate hbonds.py @ 6:fb2b84481239 draft default tip
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 7a25958195ccc8f448dd64ddcc36e8f5e5979d8b"
| author | chemteam | 
|---|---|
| date | Wed, 20 May 2020 16:56:07 +0000 | 
| parents | aabf6858f293 | 
| children | 
| rev | line source | 
|---|---|
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
2 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
4 import csv | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
5 import sys | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
6 | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
7 import MDAnalysis as mda | 
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
8 import MDAnalysis.analysis.hbonds | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
9 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
10 import pandas as pd | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
11 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
12 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
13 def parse_command_line(argv): | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
14 parser = argparse.ArgumentParser() | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
15 parser.add_argument('--itraj', help='input traj') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
16 parser.add_argument('--istr', help='input str') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
17 parser.add_argument('--itrajext', help='input traj ext') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
18 parser.add_argument('--istrext', help='input str ext') | 
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
19 parser.add_argument('--isegid1', help='segid 1') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
20 parser.add_argument('--isegid2', help='segid 2') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
21 parser.add_argument('--idistance', help='cutoff distance') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
22 parser.add_argument('--iangle', help='ctoff angle') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
23 parser.add_argument('--output', help='output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
24 parser.add_argument('--ofreq_output', help='frequency output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
25 parser.add_argument('--onumber_output', help='number of hbond output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
26 parser.add_argument('--otime_output', help='time steps output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
27 return parser.parse_args() | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
28 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
29 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
30 args = parse_command_line(sys.argv) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
31 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
32 selection1 = "segid %s" % args.isegid1 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
33 selection2 = "segid %s" % args.isegid2 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
34 distance = float(args.idistance) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
35 angle = float(args.iangle) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
36 | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
37 u = mda.Universe(args.istr, args.itraj, | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
38 topology_format=args.istrext, format=args.itrajext) | 
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
39 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
40 h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis( | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
41 u, selection1, selection2, distance=distance, angle=angle) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
42 h.run() | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
43 h.generate_table() | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
44 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
45 df = pd.DataFrame.from_records(h.table) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
46 df.to_csv(args.output, sep='\t') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
47 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
48 t1 = list(h.count_by_type()) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
49 t2 = list(h.count_by_time()) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
50 t3 = list(h.timesteps_by_type()) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
51 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
52 with open(args.ofreq_output, 'w') as f: | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
53 f.write("donor_index\tacceptor_index\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
54 donor_resname\tdonor_resid\tdonor_atom\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
55 hydrogen_atom\tacceptor_reansme\tacceptor_resid\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
56 acceptor_atom\tfrequency\n") | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
57 writer = csv.writer(f, delimiter='\t') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
58 writer.writerows(t1) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
59 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
60 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
61 with open(args.onumber_output, 'w') as f1: | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
62 f1.write("time_step\tno_of_h_bonds\n") | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
63 writer = csv.writer(f1, delimiter='\t') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
64 writer.writerows(t2) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
65 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
66 with open(args.otime_output, 'w') as f2: | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
67 f2.write("donor_index\tacceptor_index\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
68 donor_resname\tdonor_resid\tdonor_atom\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
69 hydrogen_atom\tacceptor_reansme\tacceptor_resid\t\ | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
70 acceptor_atom\ttime_step\n") | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
71 writer = csv.writer(f2, delimiter='\t') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
72 writer.writerows(t3) | 
