-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_analysis.localVersion.py
More file actions
executable file
·128 lines (109 loc) · 4.1 KB
/
data_analysis.localVersion.py
File metadata and controls
executable file
·128 lines (109 loc) · 4.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
from __future__ import print_function
import mdtraj as md
import numpy as np
import sys
import os
import logging
import subprocess
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')
def process_file(data_file):
# <TIME, METRIC> hashtable in ps v. nm
metric = {}
with open(data_file, 'r') as data:
for line in iter(data.readline, ''):
# Skip Header Information
if line[0] is '@' or line[0] is '#':
continue
# Grab significant data from line
raw_time, raw_metric = line.split()[:2]
time = int(float(raw_time))
radius = 10 * float(raw_metric)
metric[time] = radius
return metric
def unique_frames(traj):
times = []
for x in range(0, traj.n_frames):
if round(traj[x].time[0]) not in times:
times.append(round(traj[x].time[0]))
yield x
del times
def water_number(traj, angstrom_cutoff):
frames = unique_frames(traj)
cutoff = angstrom_cutoff / 10.00
for frame in frames:
print("Processing Frame: %s" % (str(frame)))
topology = traj[frame].topology
ow_atoms = topology.select('name O and water')
rna_atoms = [atom.index for atom in topology.atoms if
('Na+' not in atom.residue.name and "HOH" not in atom.residue.name)]
water_count = 0
for comp_atom in ow_atoms:
for rna in rna_atoms:
a = traj.xyz[frame, comp_atom, :]
b = traj.xyz[frame, rna, :]
dist = np.linalg.norm(a - b)
if dist <= cutoff:
water_count += 1
break
print("Count: %s" % str(water_count))
yield (int(round(traj.time[frame])), water_count)
with open('logfile.txt', mode='w') as logfile:
xtc_file = "P1796_R0_C0.xtc"
basename = xtc_file[:-4]
ndx_file = "native_FAH_luteo.ndx"
tpr_file = "frame0.tpr"
rms_file = basename + '.rms.xvg'
gyrate_file = basename + '.gyrate.xvg'
hbond_file = basename + '.hbond.xvg'
rms_cmd = 'echo 1 1 | g_rms -noxvgr -s {} -f {} -n {} -o {}'
gyrate_cmd = 'echo 1 | g_gyrate -noxvgr -s {} -f {} -n {} -o {}'
hbond_cmd = 'echo 1 1 | g_hbond -noxvgr -s {} -f {} -n {} -num {}'
try:
subprocess.check_call(
rms_cmd.format(tpr_file, xtc_file, ndx_file, rms_file),
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL
)
subprocess.check_call(
gyrate_cmd.format(tpr_file, xtc_file, ndx_file, gyrate_file),
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL
)
subprocess.check_call(
hbond_cmd.format(tpr_file, xtc_file, ndx_file, hbond_file),
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL
)
except subprocess.CalledProcessError:
logging.fatal('ERROR: GROMACS not Loaded')
sys.exit()
rms = process_file(rms_file)
gyrate = process_file(gyrate_file)
hbond = process_file(hbond_file)
traj = md.load(xtc_file, top='native_FAH_luteo.pdb')
logtemplate = '{:4} {:>3} {:>3} {:>6} {:0<7.6} {:0<7.6} {:<5}\n'
logfile.write(logtemplate.format('P', 'R', 'C', 't(ps)', 'RMSD', 'RS', 'H'))
for time, count in water_number(traj, 3.00):
logdata = [
1796,
0,
0,
time,
rms[time],
gyrate[time],
count
]
logfile.write('{:<5}\t{:<5}\t{:<5}\t{:<5}\t{:<5}\n'.format(*logdata))
os.unlink(rms_file)
os.unlink(gyrate_file)
os.unlink(hbond_file)
# DIRECTORY = '/home/xavier/LUTEO/luteo-xtcs-withwater'
# for project_number in os.listdir(DIRECTORY):
# for run_number in os.listdir('%s/%s' % (DIRECTORY, project_number)):
# for clone_number in os.listdir('%s/%s/%s' % (DIRECTORY, project_number, run_number)):
# for xtc in os.listdir('%s/%s/%s/%s' % (DIRECTORY, project_number, run_number, clone_number)):
# print(xtc)