-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbond_analysis.py
53 lines (40 loc) · 1.11 KB
/
hbond_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import mdtraj as md
import sys
import os
'''
conda install -c conda-forge mdtraj pytraj ambertools
'''
if len(sys.argv[:]) != 3:
print('Usage : python hbond_analysis.py <trajectory> <topology>')
exit(0)
traj_file = sys.argv[1]
top_file = sys.argv[2]
cpptraj_md = '''parm temp/top.pdb
trajin temp/traj.nc
hbond Backbone avgout BB_hbond.txt series
runanalysis'''
if __name__ == '__main__':
traj = md.load(traj_file, top=top_file)
if not os.path.exists('temp'):
os.mkdir('temp')
traj.save('temp/traj.nc')
traj[0].save('temp/top.pdb')
with open('temp/cpptraj_md', 'w') as f:
f.write(cpptraj_md)
cmd = 'cpptraj < temp/cpptraj_md'
os.system(cmd)
cmd_rm = 'rm -rf temp'
os.system(cmd_rm)
final_lines = []
with open('BB_hbond.txt', 'r') as f:
lines = f.readlines()
for line in lines:
line = line.split()
line.append('\n')
line = ','.join(line)
final_lines.append(line)
final_str = ''.join(final_lines)
with open('hbond.csv', 'w') as f:
f.write(final_str)
cmd_rm = 'rm BB_hbond.txt'
os.system(cmd_rm)