Skip to content

Commit

Permalink
Merge pull request #159 from ReactionMechanismGenerator/keep_rmg_files
Browse files Browse the repository at this point in the history
Backup key files and folder from an RMG run before restarting it
  • Loading branch information
NellyMitnik committed Aug 18, 2024
2 parents 02a730d + c05b7fc commit 2dbc42a
Show file tree
Hide file tree
Showing 13 changed files with 687 additions and 15 deletions.
59 changes: 44 additions & 15 deletions t3/runners/rmg_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
Should be executed locally on the head node using the t3 environment.
"""

from typing import TYPE_CHECKING, List, Optional, Tuple

import datetime
import os
import shutil
import time
from typing import TYPE_CHECKING, List, Optional, Tuple

from arc.job.local import _determine_job_id, change_mode, execute_command, parse_running_jobs_ids, submit_job
from arc.job.local import (_determine_job_id, change_mode, execute_command,
parse_running_jobs_ids, submit_job)

from t3.imports import local_t3_path, settings, submit_scripts

Expand Down Expand Up @@ -229,18 +230,20 @@ def run_rmg_in_local_queue(project_directory: str,
with open(rmg_input_path, 'r') as f:
content = f.read()
seed_path = os.path.join(project_directory, 'seed')
if restart_rmg and restart_string not in content and os.path.isdir(seed_path) and os.listdir(seed_path):
if os.path.isfile(os.path.join(project_directory, 'restart_from_seed.py')):
if os.path.isfile(os.path.join(project_directory, 'input.py')):
os.rename(src=os.path.join(project_directory, 'input.py'),
dst=os.path.join(project_directory, 'input.py.old'))
os.rename(src=os.path.join(project_directory, 'restart_from_seed.py'),
dst=os.path.join(project_directory, 'input.py'))
elif os.path.isfile(os.path.join(project_directory, 'input.py')):
with open(os.path.join(project_directory, 'input.py'), 'r') as f:
content = f.read()
with open(os.path.join(project_directory, 'input.py'), 'w') as f:
f.write("restartFromSeed(path='seed')\n\n" + content)
if restart_rmg:
backup_rmg_files(project_directory=project_directory)
if restart_string not in content and os.path.isdir(seed_path) and os.listdir(seed_path):
if os.path.isfile(os.path.join(project_directory, 'restart_from_seed.py')):
if os.path.isfile(os.path.join(project_directory, 'input.py')):
os.rename(src=os.path.join(project_directory, 'input.py'),
dst=os.path.join(project_directory, 'input.py.old'))
os.rename(src=os.path.join(project_directory, 'restart_from_seed.py'),
dst=os.path.join(project_directory, 'input.py'))
elif os.path.isfile(os.path.join(project_directory, 'input.py')):
with open(os.path.join(project_directory, 'input.py'), 'r') as f:
content = f.read()
with open(os.path.join(project_directory, 'input.py'), 'w') as f:
f.write("restartFromSeed(path='seed')\n\n" + content)
job_status, job_id = submit_job(project_directory=project_directory,
logger=logger,
memory=memory,
Expand Down Expand Up @@ -380,6 +383,32 @@ def get_new_memory_for_an_rmg_run(job_log_path: str,
return new_mem


def backup_rmg_files(project_directory: str):
"""
Backup the RMG files before restarting from seed.
Args:
project_directory (str): The path to the RMG folder.
"""
restart_backup_dir = os.path.join(project_directory,
f'restart_backup_{datetime.datetime.now().strftime("%b%d_%Y_%H-%M-%S")}')
os.mkdir(restart_backup_dir)
os.mkdir(os.path.join(restart_backup_dir, 'chemkin'))
files = ['RMG.log',
os.path.join('chemkin', 'chem_annotated.inp'),
os.path.join('chemkin', 'chem_edge_annotated.inp'),
]
folders = ['pdep']
for file in files:
if os.path.exists(os.path.join(project_directory, file)):
shutil.copy(src=os.path.join(project_directory, file),
dst=os.path.join(restart_backup_dir, file))
for folder in folders:
if os.path.exists(os.path.join(project_directory, folder)):
shutil.copytree(src=os.path.join(project_directory, folder),
dst=os.path.join(restart_backup_dir, folder))


# def get_names_by_sub_folders(pwd: str) -> List[str]:
# """
# Get the names of the runs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy RMG log file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy chem.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ELEMENTS
H
D /2.014/
T /3.016/
C
CI /13.003/
O
OI /17.999/
N
Ne
Ar
He
Si
S
F
Cl
Br
I
X /195.083/
END

SPECIES
Ar ! Ar
Ne ! Ne
furfuryl(1) ! furfuryl(1)
END



THERM ALL
300.000 1000.000 5000.000

! Thermo library: primaryThermoLibrary
Ar Ar 1 G 200.000 6000.000 1000.00 1
2.50000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 2
-7.45375000E+02 4.37967000E+00 2.50000000E+00 0.00000000E+00 0.00000000E+00 3
0.00000000E+00 0.00000000E+00-7.45375000E+02 4.37967000E+00 4

! Thermo library: primaryThermoLibrary
Ne Ne 1 G 200.000 6000.000 1000.00 1
2.50000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 2
-7.45375000E+02 3.35532000E+00 2.50000000E+00 0.00000000E+00 0.00000000E+00 3
0.00000000E+00 0.00000000E+00-7.45375000E+02 3.35532000E+00 4

! Thermo library: 2FFOH_thermo
furfuryl(1) C 5H 6O 2 G 10.000 3000.000 992.72 1
6.39130000E+00 3.56842000E-02-1.91804000E-05 4.95507000E-09-4.98206000E-13 2
-3.04566000E+04-4.85274000E+00 3.89525000E+00 2.62426000E-02 2.45489000E-05 3
-4.41978000E-08 1.68630000E-11-2.90002000E+04 1.20103000E+01 4

END



REACTIONS KCAL/MOLE MOLES

! Reaction index: Chemkin #1; RMG #1
! Library reaction: C2H2_init
! Flux pairs: acetylene(2), C4H4(17); acetylene(2), C4H4(17);
acetylene(2)+acetylene(2)<=>C4H4(17) 1.000e+00 0.000 0.000
PLOG/ 0.000987 1.280e+54 -12.650 68.650 /
PLOG/ 0.000987 1.770e+88 -24.080 73.900 /
PLOG/ 0.009869 3.090e+36 -7.640 56.790 /
PLOG/ 0.009869 1.490e+62 -14.560 79.730 /
PLOG/ 0.098690 2.690e+52 -11.490 76.010 /
PLOG/ 0.098690 2.480e+41 -9.120 58.940 /
PLOG/ 0.986900 2.640e+44 -8.980 74.000 /
PLOG/ 0.986900 3.000e+33 -6.640 56.150 /
PLOG/ 9.869000 4.300e+23 -3.600 52.310 /
PLOG/ 9.869000 7.660e+33 -5.840 69.450 /
PLOG/ 98.690000 6.500e+26 -3.750 67.720 /
PLOG/ 98.690000 9.560e+11 0.000 47.720 /

! Reaction index: Chemkin #1221; RMG #45542
! PDep reaction: PDepNetwork #226
! Flux pairs: CHCHO(202), C2H2O(15133);
CHCHO(202)(+M)<=>C2H2O(15133)(+M) 1.000e+00 0.000 0.000
TCHEB/ 300.000 2000.000 /
PCHEB/ 0.005 98.692 /
CHEB/ 6 4/
CHEB/ -1.944e+00 2.172e+00 7.470e-04 -1.384e-03 /
CHEB/ 7.878e+00 4.088e-02 1.565e-03 -2.606e-03 /
CHEB/ -1.853e-01 3.476e-02 1.717e-03 -2.170e-03 /
CHEB/ -4.447e-02 2.642e-02 1.817e-03 -1.576e-03 /
CHEB/ -2.767e-02 1.779e-02 1.748e-03 -9.650e-04 /
CHEB/ -2.493e-02 1.046e-02 1.480e-03 -4.577e-04 /

END

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy chem edge file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy chem edge annotated file
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Ar
1 Ar u0 p4 c0

Ne
1 Ne u0 p4 c0

furfuryl(1)
1 O u0 p2 c0 {4,S} {7,S}
2 O u0 p2 c0 {3,S} {13,S}
3 C u0 p0 c0 {2,S} {4,S} {8,S} {9,S}
4 C u0 p0 c0 {1,S} {3,S} {5,D}
5 C u0 p0 c0 {4,D} {6,S} {10,S}
6 C u0 p0 c0 {5,S} {7,D} {11,S}
7 C u0 p0 c0 {1,S} {6,D} {12,S}
8 H u0 p0 c0 {3,S}
9 H u0 p0 c0 {3,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {6,S}
12 H u0 p0 c0 {7,S}
13 H u0 p0 c0 {2,S}

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Ar
1 Ar u0 p4 c0

Ne
1 Ne u0 p4 c0

furfuryl(1)
1 O u0 p2 c0 {4,S} {7,S}
2 O u0 p2 c0 {3,S} {13,S}
3 C u0 p0 c0 {2,S} {4,S} {8,S} {9,S}
4 C u0 p0 c0 {1,S} {3,S} {5,D}
5 C u0 p0 c0 {4,D} {6,S} {10,S}
6 C u0 p0 c0 {5,S} {7,D} {11,S}
7 C u0 p0 c0 {1,S} {6,D} {12,S}
8 H u0 p0 c0 {3,S}
9 H u0 p0 c0 {3,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {6,S}
12 H u0 p0 c0 {7,S}
13 H u0 p0 c0 {2,S}

C8H11O(18549)
multiplicity 2
1 O u0 p2 c0 {2,S} {4,S}
2 C u0 p0 c0 {1,S} {5,S} {6,S} {10,S}
3 C u0 p0 c0 {5,S} {8,S} {11,S} {12,S}
4 C u0 p0 c0 {1,S} {7,S} {13,S} {14,S}
5 C u1 p0 c0 {2,S} {3,S} {15,S}
6 C u0 p0 c0 {2,S} {7,D} {16,S}
7 C u0 p0 c0 {4,S} {6,D} {17,S}
8 C u0 p0 c0 {3,S} {9,D} {18,S}
9 C u0 p0 c0 {8,D} {19,S} {20,S}
10 H u0 p0 c0 {2,S}
11 H u0 p0 c0 {3,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {4,S}
15 H u0 p0 c0 {5,S}
16 H u0 p0 c0 {6,S}
17 H u0 p0 c0 {7,S}
18 H u0 p0 c0 {8,S}
19 H u0 p0 c0 {9,S}
20 H u0 p0 c0 {9,S}

C8H12O2(20177)
1 O u0 p2 c0 {3,S} {6,S}
2 O u0 p2 c0 {10,D}
3 C u0 p0 c0 {1,S} {4,S} {5,S} {8,S}
4 C u0 p0 c0 {3,S} {7,S} {10,S} {11,S}
5 C u0 p0 c0 {3,S} {14,S} {15,S} {19,S}
6 C u0 p0 c0 {1,S} {9,S} {12,S} {13,S}
7 C u0 p0 c0 {4,S} {16,S} {17,S} {18,S}
8 C u0 p0 c0 {3,S} {9,D} {21,S}
9 C u0 p0 c0 {6,S} {8,D} {20,S}
10 C u0 p0 c0 {2,D} {4,S} {22,S}
11 H u0 p0 c0 {4,S}
12 H u0 p0 c0 {6,S}
13 H u0 p0 c0 {6,S}
14 H u0 p0 c0 {5,S}
15 H u0 p0 c0 {5,S}
16 H u0 p0 c0 {7,S}
17 H u0 p0 c0 {7,S}
18 H u0 p0 c0 {7,S}
19 H u0 p0 c0 {5,S}
20 H u0 p0 c0 {9,S}
21 H u0 p0 c0 {8,S}
22 H u0 p0 c0 {10,S}

C3H4O2(20308)
multiplicity 3
1 O u0 p2 c0 {3,S} {9,S}
2 O u0 p2 c0 {5,D}
3 C u0 p0 c0 {1,S} {4,S} {5,S} {6,S}
4 C u1 p0 c0 {3,S} {7,S} {8,S}
5 C u1 p0 c0 {2,D} {3,S}
6 H u0 p0 c0 {3,S}
7 H u0 p0 c0 {4,S}
8 H u0 p0 c0 {4,S}
9 H u0 p0 c0 {1,S}

C4H6O2(20309)
multiplicity 3
1 O u0 p2 c0 {3,S} {12,S}
2 O u0 p2 c0 {6,D}
3 C u0 p0 c0 {1,S} {4,S} {6,S} {7,S}
4 C u0 p0 c0 {3,S} {5,S} {8,S} {9,S}
5 C u1 p0 c0 {4,S} {10,S} {11,S}
6 C u1 p0 c0 {2,D} {3,S}
7 H u0 p0 c0 {3,S}
8 H u0 p0 c0 {4,S}
9 H u0 p0 c0 {4,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {5,S}
12 H u0 p0 c0 {1,S}

C3H7O(20310)
multiplicity 2
1 O u0 p2 c0 {2,S} {11,S}
2 C u0 p0 c0 {1,S} {3,S} {4,S} {5,S}
3 C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
4 C u1 p0 c0 {2,S} {9,S} {10,S}
5 H u0 p0 c0 {2,S}
6 H u0 p0 c0 {3,S}
7 H u0 p0 c0 {3,S}
8 H u0 p0 c0 {3,S}
9 H u0 p0 c0 {4,S}
10 H u0 p0 c0 {4,S}
11 H u0 p0 c0 {1,S}

[CH]CC-2(20311)
multiplicity 3
1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}
2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}
3 C u2 p0 c0 {1,S} {9,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {1,S}
6 H u0 p0 c0 {2,S}
7 H u0 p0 c0 {2,S}
8 H u0 p0 c0 {2,S}
9 H u0 p0 c0 {3,S}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
! Species Shape LJ-depth LJ-diam DiplMom Polzblty RotRelaxNum Data
! Name Index epsilon/k_B sigma mu alpha Zrot Source
Ar 0 136.500 3.330 0.000 0.000 0.000 ! NOx2018
Ne 0 148.600 3.758 0.000 0.000 0.000 ! Epsilon & sigma estimated with fixed Lennard Jones Parameters. This is the fallback method! Try improving transport databases!
furfuryl(1) 2 501.522 6.610 0.000 0.000 0.000 ! Epsilon & sigma estimated with Tc=651.33 K, Pc=32.77 bar (from Joback method)
C2H2O(15133) 2 357.876 4.998 0.000 0.000 0.000 ! Epsilon & sigma estimated with Tc=464.77 K, Pc=54.07 bar (from Joback method)
Loading

0 comments on commit 2dbc42a

Please sign in to comment.