Mercurial > repos > chemteam > mdanalysis_ramachandran_plot
annotate hbonds.py @ 2:b348dfa55e0a draft
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 12823af06b7926cc56aaf9b59cfea9f16d342b8c"
author | chemteam |
---|---|
date | Thu, 06 Feb 2020 19:40:37 -0500 |
parents | ce0728b92289 |
children |
rev | line source |
---|---|
0
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
1 #!/usr/bin/env python |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
2 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
3 import argparse |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
4 import csv |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
5 import sys |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
6 |
1
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
7 import MDAnalysis as mda |
0
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
8 import MDAnalysis.analysis.hbonds |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
9 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
10 import pandas as pd |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
11 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
12 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
13 def parse_command_line(argv): |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
14 parser = argparse.ArgumentParser() |
1
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
15 parser.add_argument('--itraj', help='input traj') |
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
16 parser.add_argument('--istr', help='input str') |
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
17 parser.add_argument('--itrajext', help='input traj ext') |
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
18 parser.add_argument('--istrext', help='input str ext') |
0
d710c7f00ae6
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') |
d710c7f00ae6
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') |
d710c7f00ae6
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') |
d710c7f00ae6
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') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
23 parser.add_argument('--output', help='output') |
d710c7f00ae6
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') |
d710c7f00ae6
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') |
d710c7f00ae6
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') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
27 return parser.parse_args() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
28 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
29 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
30 args = parse_command_line(sys.argv) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
31 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
32 selection1 = "segid %s" % args.isegid1 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
33 selection2 = "segid %s" % args.isegid2 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
34 distance = float(args.idistance) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
35 angle = float(args.iangle) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
36 |
1
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
37 u = mda.Universe(args.istr, args.itraj, |
ce0728b92289
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
0
diff
changeset
|
38 topology_format=args.istrext, format=args.itrajext) |
0
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
39 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
40 h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis( |
d710c7f00ae6
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) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
42 h.run() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
43 h.generate_table() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
44 |
d710c7f00ae6
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) |
d710c7f00ae6
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') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
47 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
48 t1 = list(h.count_by_type()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
49 t2 = list(h.count_by_time()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
50 t3 = list(h.timesteps_by_type()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
51 |
d710c7f00ae6
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: |
d710c7f00ae6
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\ |
d710c7f00ae6
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\ |
d710c7f00ae6
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\ |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
56 acceptor_atom\tfrequency\n") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
57 writer = csv.writer(f, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
58 writer.writerows(t1) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
59 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
60 |
d710c7f00ae6
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: |
d710c7f00ae6
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") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
63 writer = csv.writer(f1, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
64 writer.writerows(t2) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
65 |
d710c7f00ae6
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: |
d710c7f00ae6
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\ |
d710c7f00ae6
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\ |
d710c7f00ae6
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\ |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
70 acceptor_atom\ttime_step\n") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
71 writer = csv.writer(f2, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
72 writer.writerows(t3) |