forked from sciexpem/sciexpem
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunOS.py
104 lines (79 loc) · 3.73 KB
/
runOS.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
import argparse
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SciExpeM.settings")
import django
django.setup()
from OpenSmoke.OpenSmoke import OpenSmokeParser, OpenSmokeExecutor
from django.utils import timezone
from CurveMatching.CurveMatching import curveMatchingExecution
from django import db
from OpenSmoke.utils import createFolderSimulation_utils
import ExperimentManager.Models as Model
import subprocess
def execute(exp_id, chemModel_id, execution_id, solver, files):
try:
# Create SandBox
import tempfile
# create a temporary directory
with tempfile.TemporaryDirectory() as sandbox:
createFolderSimulation_utils(exp_id=exp_id, chemModel_id=chemModel_id, folderPath=sandbox)
bashCommand = 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/eramalli/opensmoke++suite-0.13.0/lib && '
bashCommand += ' /home/eramalli/.opensmoke/opensmoke++suite-0.15.0/bin/OpenSMOKEpp_' + solver + ".sh --input " + sandbox + "/input.dic"
# print(bashCommand)
#
# print(sandbox)
#
# import time
# time.sleep(300)
process = subprocess.Popen(bashCommand, shell=True, stdout=subprocess.PIPE)
output, error = process.communicate()
output = output.decode('ascii')
if 'Fatal error' in output:
output = output[output.find('Fatal error:'):]
msg_error = output[12: output.find('\n')].strip()
execution = Model.Execution.objects.get(id=execution_id)
if execution.execution_error:
execution.execution_error = execution.execution_error + '\n' + msg_error
else:
execution.execution_error = msg_error
execution.execution_end = timezone.localtime()
execution.save()
else:
execution = Model.Execution.objects.get(id=execution_id)
execution.execution_end = timezone.localtime()
execution.save()
for file in files:
OpenSmokeExecutor.read_output_OS_from_path(folder=sandbox, file_name=file, execution=execution)
curveMatchingExecution(current_execution=execution)
except Exception as e:
execution = Model.Execution.objects.get(id=execution_id)
execution.execution_end = timezone.localtime()
if execution.execution_error:
execution.execution_error = execution.execution_error + '\n' + str(e)
else:
execution.execution_error = str(e)
execution.save()
finally:
db.close_old_connections()
def main():
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--files', metavar='F', type=str, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--exp', dest='experiment', type=int,
help='sum the integers (default: find the max)')
parser.add_argument('--chem', dest='chemModel', type=int,
help='sum the integers (default: find the max)')
parser.add_argument('--solver', dest='solver', type=str,
help='sum the integers (default: find the max)')
parser.add_argument('--exec', dest='execution', type=int,
help='sum the integers (default: find the max)')
args = parser.parse_args()
exp_id = args.experiment
chemModel_id = args.chemModel
execution_id = args.execution
solver = args.solver
files = args.files
execute(exp_id=exp_id, chemModel_id=chemModel_id, execution_id=execution_id, solver=solver, files=files)
if __name__ == "__main__":
main()