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