-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_drivers.py
275 lines (223 loc) · 8.37 KB
/
job_drivers.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"""
Job drivers
"""
import subprocess
import os
import sys
import update_settings as us
import parse_spe_reaction_info as psri
import prepare_path_name_time as ppnt
import naming
import trajectory
import global_settings
def update_terminal_species_setting(data_dir, terminal_spe=None):
"""
update settings.json, primarily for terminal species
"""
us.update_terminal_species_setting(data_dir, terminal_spe=terminal_spe)
def update_chattering_species_setting(data_dir, atom_followed="C"):
"""
update settings.json, primarily for chattering species and fast reactions
"""
us.update_chattering_species_setting(data_dir, atom_followed)
def copy_sohr_files(data_dir, species_path=False):
"""
copy SOHR files from C++ routine
"""
naming.copy_sohr_files(data_dir, species_path=species_path)
def symbolic_path_2_real_path(data_dir, top_n=50, flag="", end_s_idx=None, species_path=False, max_rows=5000):
"""
convert symbolic pathway to real pathway with real species name and real reaction name
flag indicates a specific job, for example, pathway end time = 1.0, the j-th run,
any unique symbol shall work
"""
prefix = ""
if species_path is True:
prefix = "species_"
if flag == "":
out_file_name = prefix + "pathname_prob.csv"
else:
out_file_name = prefix + "pathname_prob_" + str(flag) + ".csv"
path_stat_fn = prefix + "pathway_stat.csv"
psri.symbolic_path_2_real_path(
data_dir,
os.path.join(
data_dir, "output", path_stat_fn),
os.path.join(
data_dir, "output", out_file_name),
top_n, end_s_idx, max_rows=max_rows)
# path from file
def symbolic_path_2_real_path_pff(data_dir, fn):
"""
convert symbolic pathway to real pathway with real species name and real reaction name
"""
out_fn = fn[0:-4] + "_real_path" + ".csv"
psri.symbolic_path_2_real_path(
data_dir,
os.path.join(
data_dir, "output", fn),
os.path.join(
data_dir, "output", out_fn),
10000000, None)
def delete_non_dlsode_files(data_dir):
"""
delete none dlsode files
"""
os.chdir(data_dir)
cmd = ["find", "./output", "-type", "f",
"!", "-name", "*dlsode*", "-delete"]
# Open/Create the output file
out_file = open(os.path.join(
data_dir, 'output', 'output_all.txt'), 'ab+')
error_file = open(os.path.join(
data_dir, 'output', 'error_all.txt'), 'ab+')
try:
result = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=error_file)
except subprocess.CalledProcessError as error:
print(error)
exit(1)
if result.stdout is not None:
out = result.stdout.read()
out_file.write(out)
out_file.close()
error_file.close()
def make_run(src_dir, data_dir):
"""
make run
"""
os.chdir(src_dir)
cmd = ["make", "run"]
# Open/Create the output file
out_file = open(os.path.join(
data_dir, 'output', 'output_all.txt'), 'ab+')
error_file = open(os.path.join(
data_dir, 'output', 'error_all.txt'), 'ab+')
try:
result = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=error_file)
except subprocess.CalledProcessError as error:
print(error)
exit(1)
if result.stdout is not None:
out = result.stdout.read()
out_file.write(out)
out_file.close()
error_file.close()
def make_run_timeout(src_dir, data_dir, timeout=None):
"""
make run with timeout functionaliry
https://stackoverflow.com/questions/1191374/using-module-subprocess-with-timeout
"""
os.chdir(src_dir)
cmd = ["make", "run"]
# Open/Create the output file
out_file = open(os.path.join(
data_dir, 'output', 'output_all.txt'), 'ab+')
error_file = open(os.path.join(
data_dir, 'output', 'error_all.txt'), 'ab+')
try:
subprocess.check_call(
cmd, stdout=out_file, stderr=error_file,
timeout=timeout)
status = 0
except subprocess.TimeoutExpired:
status = -1
except subprocess.CalledProcessError:
status = -1
out_file.close()
error_file.close()
if status == 0:
return True
else:
return False
def run_dlsode(src_dir, data_dir, max_time, critical_time):
"""
Run dlsode
"""
os.chdir(src_dir)
us.update_dlsode_setting(data_dir, max_time, critical_time)
make_run(src_dir, data_dir)
def spe_concentration_at_time_w2f(src_dir, data_dir, tau=10.0, end_t=1.0):
"""
write species concentration at a time to file
"""
os.chdir(src_dir)
us.update_spe_concentration_at_time_w2f(data_dir, tau=tau, end_t=end_t)
make_run(src_dir, data_dir)
def run_mc_trajectory(src_dir, data_dir, n_traj=1000000, atom_followed="C", init_spe=114,
tau=10.0, begin_t=0.0, end_t=1.0, species_path=False):
"""
Run mc trajectory
"""
os.chdir(src_dir)
us.update_mc_trajectory_setting(
data_dir, n_traj=n_traj, atom_followed=atom_followed, init_spe=init_spe,
tau=tau, begin_t=begin_t, end_t=end_t, species_path=species_path)
make_run(src_dir, data_dir)
def evaluate_pathway_probability(src_dir, data_dir, top_n=5, num_t=1, flag="", n_traj=10000,
atom_followed="C", init_spe=114, traj_max_t=100.0,
tau=10.0, begin_t=0.0, end_t=1.0, top_n_s=10,
spe_oriented=True, end_s_idx=None, species_path=False):
"""
evaluate pathway probability
top_n_s is top N species number
num_t is number of time points
"""
os.chdir(src_dir)
if spe_oriented is True:
us.update_eval_path_integral(
data_dir, top_n=top_n * top_n_s, n_traj=n_traj,
atom_followed=atom_followed, init_spe=init_spe,
tau=tau, begin_t=begin_t, end_t=end_t, species_path=species_path)
if end_s_idx is None or end_s_idx is []:
end_s_idx, _, _ = trajectory.get_species_with_top_n_concentration(
data_dir, exclude=None, top_n=top_n_s, traj_max_t=traj_max_t,
tau=tau, end_t=end_t, tag="M", atoms=[atom_followed])
ppnt.prepare_pathway_name(
data_dir, top_n=top_n, flag=flag, end_s_idx=end_s_idx, species_path=species_path)
ppnt.prepare_pathway_time(
data_dir, top_n=top_n * top_n_s, num=num_t, flag=flag,
begin_t=begin_t, end_t=end_t, species_path=species_path)
else:
us.update_eval_path_integral(
data_dir, top_n=top_n, n_traj=n_traj, atom_followed=atom_followed, init_spe=init_spe,
tau=tau, begin_t=begin_t, end_t=end_t, species_path=species_path)
ppnt.prepare_pathway_name(
data_dir, top_n=top_n, flag=flag, end_s_idx=end_s_idx, species_path=species_path)
ppnt.prepare_pathway_time(
data_dir, top_n=top_n, num=num_t, flag=flag, begin_t=begin_t, end_t=end_t, species_path=species_path)
make_run(src_dir, data_dir)
def send_email(data_dir):
"""
send email to elliot.srbai@gmail.com
"""
os.chdir(data_dir)
cmd = ["sendemail", "-f", "elliot.srbai@gmail.com", "-t", "bunnysirah@hotmail.com",
"-u", "RUNNING JOB", "-m", "JOB FINISHED." + "\n" + data_dir,
"-a", os.path.join(data_dir, "output", "output_all.txt")]
# Open/Create the output file
out_file = open(os.path.join(
data_dir, 'output', 'output_all.txt'), 'ab+')
error_file = open(os.path.join(
data_dir, 'output', 'error_all.txt'), 'ab+')
try:
result = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=error_file)
except subprocess.CalledProcessError as error:
print(error)
exit(1)
if result.stdout is not None:
out = result.stdout.read()
out_file.write(out)
out_file.close()
error_file.close()
if __name__ == '__main__':
SRC_DIR = os.path.abspath(os.path.join(os.path.realpath(
sys.argv[0]), os.pardir, os.pardir, os.pardir))
DATA_DIR = os.path.abspath(os.path.join(os.path.realpath(
sys.argv[0]), os.pardir, os.pardir, os.pardir, os.pardir, "SOHR_DATA"))
G_S = global_settings.get_setting(DATA_DIR)
# symbolic_path_2_real_path_pff(DATA_DIR, "heuristic_pathname_O_10_10_3.csv")
spe_concentration_at_time_w2f(
SRC_DIR, DATA_DIR, tau=G_S['tau'], end_t=0.00022854295)