Mercurial > repos > chemteam > mdanalysis_ramachandran_plot
annotate hbonds.py @ 0:d710c7f00ae6 draft
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
author | chemteam |
---|---|
date | Wed, 03 Apr 2019 15:46:32 -0400 |
parents | |
children | ce0728b92289 |
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 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
7 import MDAnalysis.analysis.hbonds |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
8 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
9 import pandas as pd |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
10 |
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 def parse_command_line(argv): |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
13 parser = argparse.ArgumentParser() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
14 parser.add_argument('--idcd', help='input dcd') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
15 parser.add_argument('--ipdb', help='input pdb') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 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
|
20 parser.add_argument('--output', help='output') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 return parser.parse_args() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
25 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
26 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
27 args = parse_command_line(sys.argv) |
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 selection1 = "segid %s" % args.isegid1 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
30 selection2 = "segid %s" % args.isegid2 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
31 distance = float(args.idistance) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
32 angle = float(args.iangle) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
33 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
34 u = MDAnalysis.Universe( |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
35 args.ipdb, args.idcd, topology_format="PDB", format="DCD") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
36 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
37 h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis( |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
38 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
|
39 h.run() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
40 h.generate_table() |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
41 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
42 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
|
43 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
|
44 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
45 t1 = list(h.count_by_type()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
46 t2 = list(h.count_by_time()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
47 t3 = list(h.timesteps_by_type()) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
48 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 acceptor_atom\tfrequency\n") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
54 writer = csv.writer(f, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
55 writer.writerows(t1) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
56 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
57 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
58 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
|
59 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
|
60 writer = csv.writer(f1, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
61 writer.writerows(t2) |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
62 |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 acceptor_atom\ttime_step\n") |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
68 writer = csv.writer(f2, delimiter='\t') |
d710c7f00ae6
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
chemteam
parents:
diff
changeset
|
69 writer.writerows(t3) |