-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpknot-analysis.py
More file actions
executable file
·110 lines (91 loc) · 3.29 KB
/
pknot-analysis.py
File metadata and controls
executable file
·110 lines (91 loc) · 3.29 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
#!/usr/bin/env python3
import logging
import os
import os.path
import sys
import subprocess
try:
from projectdata import data
except ImportError:
print('Cannot find projectdata.py Project Descriptiors')
sys.exit()
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
usage = 'Usage: PROJECT_DIR= OUTFILE= ./pknot-analysis.py'
project_dir = os.environ.get('PROJECT_DIR')
outfile = os.environ.get('OUTFILE')
if len(sys.argv) > 1 or not (project_dir and outfile):
print(usage)
sys.exit()
logging.info('PROJECT_DIR = %s', project_dir)
logging.info('OUTFILE = %s', outfile)
with open(outfile, 'w') as logfile:
location, dirs, files = next(os.walk(project_dir))
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 {}'
for xtc in files:
if xtc[-4:] != '.xtc':
print(xtc)
continue
basename = xtc[:-4]
project, run, clone = basename.split('_')
logging.info('Procesing %s %s %s', project, run, clone)
xtc_file = os.path.join(location, xtc)
ndx_file = data[project]['ndx']
tpr_file = data[project]['tpr']
rms_file = basename + '.rms.xvg'
gyrate_file = basename + '.gyrate.xvg'
hbond_file = basename + '.hbond.xvg'
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)
logtemplate = '{:4} {:>3} {:>3} {:>6} {:0<7.6} {:0<7.6}\n'
for time in sorted(rms):
logdata = [
int(project[1:]),
int(run[1:]),
int(clone[1:]),
time,
rms[time],
gyrate[time]
]
logfile.write(logtemplate.format(*logdata))
os.unlink(rms_file)
os.unlink(gyrate_file)
os.unlink(hbond_file)