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