Skip to content

Commit 05dfe38

Browse files
committed
Configures Arkane to use RMG_DB_PATH
Ensures Arkane and related scripts correctly utilize the RMG_DB_PATH environment variable to locate the RMG database. Adds flexibility by allowing RMG_ENV_NAME to be specified, defaulting to 'rmg_env' if not provided. This ensures that Arkane calculations and tests can locate necessary data files.
1 parent f48ec31 commit 05dfe38

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

arc/statmech/arkane.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from arc.species.species import ARCSpecies
2525

2626

27-
RMG_DB_PATH, RMG_PATH = settings['RMG_DB_PATH'], settings['RMG_PATH']
27+
RMG_DB_PATH = settings['RMG_DB_PATH']
28+
RMG_ENV_NAME = settings.get('RMG_ENV_NAME', 'rmg_env')
2829
logger = get_logger()
2930

3031

@@ -445,12 +446,16 @@ def parse_arkane_thermo_output(self, statmech_dir: str) -> None:
445446
clean_output_directory(os.path.join(self.output_directory, 'Species', species.label))
446447

447448
script_path = os.path.join(ARC_PATH, 'arc', 'scripts', 'save_arkane_thermo.py')
449+
env_name = RMG_ENV_NAME
450+
rmg_db_path = RMG_DB_PATH or ""
448451
commands = [f'cd {statmech_dir}',
449452
'bash -lc "set -euo pipefail; '
453+
f'export RMG_DB_PATH=\\"{rmg_db_path}\\"; '
454+
f'export RMG_DATABASE=\\"{rmg_db_path}\\"; '
450455
'if command -v micromamba >/dev/null 2>&1; then '
451-
f' micromamba run -n rmg_env python {script_path}; '
456+
f' micromamba run -n {env_name} python {script_path}; '
452457
'elif command -v conda >/dev/null 2>&1 || command -v mamba >/dev/null 2>&1; then '
453-
f' conda run -n rmg_env python {script_path}; '
458+
f' conda run -n {env_name} python {script_path}; '
454459
'else '
455460
' echo \'❌ Micromamba/Mamba/Conda required\' >&2; exit 1; '
456461
'fi"',
@@ -514,11 +519,14 @@ def run_arkane(statmech_dir: str) -> None:
514519
if not os.path.isfile(input_file):
515520
logger.error(f'Cannot run Arkane in {statmech_dir} because it does not contain an input.py file.')
516521
return
517-
env_name = 'rmg_env'
518-
arkane_cmd = f'python "{RMG_PATH}/Arkane.py" input.py'
522+
env_name = RMG_ENV_NAME
523+
rmg_db_path = RMG_DB_PATH or ""
524+
arkane_cmd = 'python -m arkane input.py'
519525
arkane_cmd += ' 2> >(tee -a stderr.log >&2) | tee -a stdout.log'
520526
shell_script = rf'''bash -lc 'set -euo pipefail
521527
cd "{statmech_dir}"
528+
export RMG_DB_PATH="{rmg_db_path}"
529+
export RMG_DATABASE="{rmg_db_path}"
522530
523531
if command -v micromamba >/dev/null 2>&1; then
524532
micromamba run -n {env_name} {arkane_cmd}
@@ -710,6 +718,8 @@ def get_arkane_model_chemistry(sp_level: 'Level',
710718
return f"LevelOfTheory(method='{sp_level.method}',software='gaussian')"
711719

712720
qm_corr_file = os.path.join(RMG_DB_PATH, 'input', 'quantum_corrections', 'data.py')
721+
if not os.path.isfile(qm_corr_file):
722+
qm_corr_file = os.path.join(RMG_DB_PATH, 'quantum_corrections', 'data.py')
713723

714724
atom_energies_start = "atom_energies = {"
715725
atom_energies_end = "pbac = {"
@@ -768,6 +778,8 @@ def check_arkane_bacs(sp_level: 'Level',
768778
bool: True if both AECs and BACs are available, False otherwise.
769779
"""
770780
qm_corr_file = os.path.join(RMG_DB_PATH, 'input', 'quantum_corrections', 'data.py')
781+
if not os.path.isfile(qm_corr_file):
782+
qm_corr_file = os.path.join(RMG_DB_PATH, 'quantum_corrections', 'data.py')
771783

772784
atom_energies_start = "atom_energies = {"
773785
atom_energies_end = "pbac = {"

arc/statmech/arkane_test.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from arc.statmech.adapter import StatmechEnum
1717
from arc.statmech.arkane import ArkaneAdapter
1818
from arc.statmech.arkane import _level_to_str, _section_contains_key, get_arkane_model_chemistry
19+
from arc.imports import settings
1920

2021

2122
class TestEnumerationClasses(unittest.TestCase):
@@ -108,8 +109,22 @@ def test__str__(self):
108109
def test_run_statmech_using_molecular_properties(self):
109110
"""Test running statmech using molecular properties."""
110111
self.arkane_3.compute_thermo()
111-
self.assertTrue(os.path.isfile(os.path.join(ARC_PATH, 'arc', 'testing', 'arkane_tests_delete', 'calcs_3',
112-
'statmech', 'thermo', 'plots', 'iC3H7.pdf')))
112+
plot_path = os.path.join(ARC_PATH, 'arc', 'testing', 'arkane_tests_delete', 'calcs_3',
113+
'statmech', 'thermo', 'plots', 'iC3H7.pdf')
114+
if not os.path.isfile(plot_path):
115+
log_dir = os.path.dirname(os.path.dirname(plot_path))
116+
stdout_log = os.path.join(log_dir, 'stdout.log')
117+
stderr_log = os.path.join(log_dir, 'stderr.log')
118+
stdout_text = ''
119+
stderr_text = ''
120+
if os.path.isfile(stdout_log):
121+
with open(stdout_log, 'r') as f:
122+
stdout_text = f.read()
123+
if os.path.isfile(stderr_log):
124+
with open(stderr_log, 'r') as f:
125+
stderr_text = f.read()
126+
self.fail(f'Arkane did not generate {plot_path}.\nstdout.log:\n{stdout_text}\nstderr.log:\n{stderr_text}')
127+
self.assertTrue(os.path.isfile(plot_path))
113128
self.assertAlmostEqual(self.ic3h7.e0, 6.75565e+07)
114129

115130
def test_level_to_str(self):
@@ -123,7 +138,11 @@ def test_level_to_str(self):
123138

124139
def test_section_contains_key(self):
125140
"""Test the _section_contains_key function"""
126-
file_path = os.path.join(os.path.dirname(ARC_PATH), 'RMG-database', 'input', 'quantum_corrections', 'data.py')
141+
rmg_db_path = settings.get('RMG_DB_PATH')
142+
file_path = os.path.join(rmg_db_path, 'input', 'quantum_corrections', 'data.py')
143+
if not os.path.isfile(file_path):
144+
file_path = os.path.join(rmg_db_path, 'quantum_corrections', 'data.py')
145+
self.assertTrue(os.path.isfile(file_path), f'RMG quantum corrections file not found at {file_path}')
127146
self.assertTrue(_section_contains_key(file_path=file_path,
128147
section_start="atom_energies = {",
129148
section_end="pbac = {",

0 commit comments

Comments
 (0)