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