Skip to content

Commit a504aa7

Browse files
authored
RMG Installation Update (#820)
2 parents d03b56a + fd0ba8b commit a504aa7

File tree

14 files changed

+318
-180
lines changed

14 files changed

+318
-180
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,6 @@ jobs:
7171
echo "::endgroup::"
7272
julia --version # Check that Julia is installed correctly
7373
74-
- name: Set RMG-Py + database in PATH and PYTHONPATH
75-
shell: micromamba-shell {0}
76-
working-directory: ARC
77-
run: |
78-
# bash devtools/install_rmg.sh
79-
echo "RMG_PY_PATH=$(realpath ../RMG-Py)" >> $GITHUB_ENV
80-
echo "RMG_DB_PATH=$(realpath ../RMG-database)" >> $GITHUB_ENV
81-
echo "PATH=$(realpath ../RMG-Py):$PATH" >> $GITHUB_ENV
82-
echo "PYTHONPATH=$(realpath ../RMG-Py):$PYTHONPATH" >> $GITHUB_ENV
83-
84-
- name: Cache RMG-Py source
85-
uses: actions/cache@v4
86-
with:
87-
path: RMG-Py
88-
key: ${{ runner.os }}-rmgpy-${{ hashFiles('ARC/devtools/install_rmg.sh') }}
89-
restore-keys: ${{ runner.os }}-rmgpy-
90-
9174
- name: Install all extras - CI
9275
shell: micromamba-shell {0}
9376
working-directory: ARC

.github/workflows/gh-pages.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,17 @@ jobs:
2020
path: ARC
2121
fetch-depth: 1
2222

23-
# ── pull RMG sources ────────────────────────────────────────
24-
- name: Checkout RMG‑Py
25-
uses: actions/checkout@v4
26-
with:
27-
repository: ReactionMechanismGenerator/RMG-Py
28-
path: RMG-Py
29-
fetch-depth: 1
30-
31-
- name: Checkout RMG‑database
32-
uses: actions/checkout@v4
33-
with:
34-
repository: ReactionMechanismGenerator/RMG-database
35-
path: RMG-database
36-
fetch-depth: 1
37-
38-
# ── build‑only env ───────────────────────────────────────────
23+
# ── rmg_env for Arkane/database availability ───────────────
3924
- name: Set up micromamba (rmg_env)
4025
uses: mamba-org/setup-micromamba@v2
4126
with:
4227
environment-name: rmg_env
43-
environment-file: RMG-Py/environment.yml
28+
create-args: >-
29+
-c rmg -c conda-forge python=3.9 numpy<2 rmg=3.3.0 connie::symmetry
4430
cache-environment: true
4531
cache-downloads: true
4632
generate-run-shell: false
4733

48-
- name: Build RMG‑Py in rmg_env
49-
run: micromamba run -n rmg_env make -C RMG-Py -j"$(nproc)"
50-
5134
# ── docs env (wrapper shell) ────────────────────────────────
5235
- name: Set up micromamba (arc_env)
5336
uses: mamba-org/setup-micromamba@v2
@@ -77,9 +60,8 @@ jobs:
7760
# ── build HTML docs ─────────────────────────────────────────
7861
- name: Set env vars & Build docs
7962
run: |
80-
export RMG_PATH="$GITHUB_WORKSPACE/RMG-Py"
81-
export RMG_DB_PATH="$GITHUB_WORKSPACE/RMG-database"
82-
export PYTHONPATH="$GITHUB_WORKSPACE/RMG-Py:$GITHUB_WORKSPACE/ARC:$PYTHONPATH"
63+
export RMG_DB_PATH="$MAMBA_ROOT_PREFIX/envs/rmg_env/share/RMG-database"
64+
export PYTHONPATH="$GITHUB_WORKSPACE/ARC:$PYTHONPATH"
8365
export PATH="$GITHUB_WORKSPACE/ARC:$PATH"
8466
make -C ARC/docs html
8567
shell: micromamba-shell {0}

.github/workflows/update-cache.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,6 @@ jobs:
2121
- name: Checkout ARC
2222
uses: actions/checkout@v4
2323

24-
# ────────── RMG‑Py ──────────
25-
- name: Cache RMG
26-
id: cache-rmg
27-
uses: actions/cache@v4
28-
with:
29-
path: RMG-Py
30-
key: ${{ runner.os }}-rmg-main
31-
restore-keys: |
32-
${{ runner.os }}-rmg-
33-
- name: Checkout RMG-Py
34-
if: steps.cache-rmg.outputs.cache-hit != 'true'
35-
uses: actions/checkout@v4
36-
with:
37-
repository: ReactionMechanismGenerator/RMG-Py
38-
path: RMG-Py
39-
ref: 55464c54d1fa61b531e865682df598d33718597d
40-
fetch-depth: 1
41-
42-
# ────────── RMG‑database ──────────
43-
- name: Cache RMG-database
44-
id: cache-rmg-db
45-
uses: actions/cache@v4
46-
with:
47-
path: RMG-database
48-
key: ${{ runner.os }}-rmgdb-main
49-
restore-keys: |
50-
${{ runner.os }}-rmgdb-
51-
- name: Checkout RMG-database
52-
if: steps.cache-rmg-db.outputs.cache-hit != 'true'
53-
uses: actions/checkout@v4
54-
with:
55-
repository: ReactionMechanismGenerator/RMG-database
56-
path: RMG-database
57-
ref: main
58-
fetch-depth: 1
59-
6024
# ────────── AutoTST ──────────
6125
- name: Cache AutoTST
6226
id: cache-autotst

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ build/*
6767

6868
*.log
6969
*.xml
70+
71+
# AI Agent files
72+
AGENTS.md

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DEVTOOLS_DIR := devtools
88

99
.PHONY: all help clean test test-unittests test-functional test-all \
10-
install-all install-ci install-pyrdl install-rmgdb install-autotst install-gcn \
10+
install-all install-ci install-pyrdl install-rmg install-rmgdb install-autotst install-gcn \
1111
install-gcn-cpu install-kinbot install-sella install-xtb install-torchani install-ob \
1212
lite check-env compile
1313

@@ -28,6 +28,7 @@ help:
2828
@echo " install Install all external dependencies"
2929
@echo " install-ci Install all external dependencies for CI (no clean)"
3030
@echo " install-pyrdl Install PyRDL"
31+
@echo " install-rmg Install RMG (default: packaged, override via RMG_ARGS=...)"
3132
@echo " install-rmgdb Install RMG-database"
3233
@echo " install-autotst Install AutoTST"
3334
@echo " install-gcn Install TS-GCN (GPU)"
@@ -75,6 +76,9 @@ install-lite:
7576
install-pyrdl:
7677
bash $(DEVTOOLS_DIR)/install_pyrdl.sh
7778

79+
install-rmg:
80+
bash $(DEVTOOLS_DIR)/install_rmg.sh $(RMG_ARGS)
81+
7882
install-rmgdb:
7983
bash $(DEVTOOLS_DIR)/install_rmgdb.sh
8084

arc/family/family.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323
logger = get_logger()
2424

2525

26+
def get_rmg_db_subpath(*parts: str, must_exist: bool = False) -> str:
27+
"""Return a path under the RMG database, handling both source and packaged layouts."""
28+
if RMG_DB_PATH is None:
29+
if must_exist:
30+
raise FileNotFoundError('RMG_DB_PATH is not set; cannot locate the RMG database.')
31+
return os.path.join('input', *parts)
32+
candidates = [
33+
os.path.join(RMG_DB_PATH, 'input', *parts),
34+
os.path.join(RMG_DB_PATH, *parts),
35+
]
36+
if must_exist:
37+
for candidate in candidates:
38+
if os.path.exists(candidate):
39+
return candidate
40+
return candidates[0]
41+
42+
2643
class ReactionFamily(object):
2744
"""
2845
A class for representing a reaction family.
@@ -72,7 +89,7 @@ def get_groups_file_as_lines(self, consider_arc_families: bool = True) -> List[s
7289
Returns:
7390
List[str]: The groups file as a list of lines.
7491
"""
75-
groups_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', self.label, 'groups.py')
92+
groups_path = get_rmg_db_subpath('kinetics', 'families', self.label, 'groups.py', must_exist=True)
7693
if not os.path.isfile(groups_path):
7794
if consider_arc_families:
7895
groups_path = os.path.join(ARC_FAMILIES_PATH, f'{self.label}.py')
@@ -605,7 +622,7 @@ def get_rmg_recommended_family_sets() -> Dict[str, str]:
605622
Dict[str, str]: The recommended RMG family sets.
606623
"""
607624
family_sets = dict()
608-
recommended_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', 'recommended.py')
625+
recommended_path = get_rmg_db_subpath('kinetics', 'families', 'recommended.py', must_exist=True)
609626
if not os.path.isfile(recommended_path):
610627
raise FileNotFoundError(f'Could not find the recommended RMG families file at {recommended_path}')
611628
with open(recommended_path, 'r') as f:

arc/family/family_test.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from arc.family.family import (ReactionFamily,
1313
ARC_FAMILIES_PATH,
1414
RMG_DB_PATH,
15+
get_rmg_db_subpath,
1516
add_labels_to_molecule,
1617
check_product_isomorphism,
1718
descent_complex_group,
@@ -50,8 +51,10 @@ def setUpClass(cls):
5051

5152
def test_rmgdb_path(self):
5253
"""Test finding the RMG-database path"""
53-
self.assertIn('RMG-database', RMG_DB_PATH)
5454
self.assertTrue(os.path.isdir(RMG_DB_PATH))
55+
self.assertTrue(any(token in RMG_DB_PATH for token in ('RMG-database', 'rmgdatabase', 'rmg_database')))
56+
self.assertTrue(os.path.isdir(os.path.join(RMG_DB_PATH, 'input'))
57+
or os.path.isdir(os.path.join(RMG_DB_PATH, 'kinetics')))
5558

5659
def test_arc_families_path(self):
5760
"""Test finding the ARC families folder path"""
@@ -920,14 +923,14 @@ def test_get_product_num(self):
920923
def test_get_reactant_groups_from_template(self):
921924
"""Test getting reactant groups from a template"""
922925
fam_1 = ReactionFamily('6_membered_central_C-C_shift')
923-
groups_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', fam_1.label, 'groups.py')
926+
groups_path = get_rmg_db_subpath('kinetics', 'families', fam_1.label, 'groups.py', must_exist=True)
924927
with open(groups_path, 'r') as f:
925928
groups = f.readlines()
926929
reactants_1 = get_reactant_groups_from_template(groups)
927930
self.assertEqual(reactants_1, [['1_5_unsaturated_hexane']])
928931

929932
fam_2 = ReactionFamily('H_Abstraction')
930-
groups_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', fam_2.label, 'groups.py')
933+
groups_path = get_rmg_db_subpath('kinetics', 'families', fam_2.label, 'groups.py', must_exist=True)
931934
with open(groups_path, 'r') as f:
932935
groups = f.readlines()
933936
reactants_2 = get_reactant_groups_from_template(groups)
@@ -936,7 +939,7 @@ def test_get_reactant_groups_from_template(self):
936939
self.assertEqual(reactants_2, expected_reactants)
937940

938941
fam_3 = ReactionFamily('1,2-Birad_to_alkene')
939-
groups_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', fam_3.label, 'groups.py')
942+
groups_path = get_rmg_db_subpath('kinetics', 'families', fam_3.label, 'groups.py', must_exist=True)
940943
with open(groups_path, 'r') as f:
941944
groups = f.readlines()
942945
reactants_3 = get_reactant_groups_from_template(groups)
@@ -988,7 +991,7 @@ def test_get_recipe_actions(self):
988991
['LOSE_RADICAL', '*3', '1']])
989992

990993
fam_1 = ReactionFamily('6_membered_central_C-C_shift')
991-
groups_path = os.path.join(RMG_DB_PATH, 'input', 'kinetics', 'families', fam_1.label, 'groups.py')
994+
groups_path = get_rmg_db_subpath('kinetics', 'families', fam_1.label, 'groups.py', must_exist=True)
992995
with open(groups_path, 'r') as f:
993996
groups = f.readlines()
994997
actions = get_recipe_actions(groups)

arc/processor.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import arc.plotter as plotter
1010
from arc.common import ARC_PATH, get_logger, read_yaml_file, save_yaml_file
11+
from arc.imports import settings
1112
from arc.level import Level
1213
from arc.job.local import execute_command
1314
from arc.statmech.factory import statmech_factory
@@ -246,11 +247,15 @@ def compare_thermo(species_for_thermo_lib: list,
246247
species_thermo_path = os.path.join(output_directory, 'RMG_thermo.yml')
247248
save_yaml_file(path=species_thermo_path,
248249
content=[{'label': spc.label, 'adjlist': spc.mol.copy(deep=True).to_adjacency_list()} for spc in species_for_thermo_lib])
250+
env_name = settings.get('RMG_ENV_NAME', 'rmg_env')
251+
rmg_db_path = settings.get('RMG_DB_PATH') or ""
249252
commands = ['bash -lc "set -euo pipefail; '
253+
f'export RMG_DB_PATH=\\"{rmg_db_path}\\"; '
254+
f'export RMG_DATABASE=\\"{rmg_db_path}\\"; '
250255
'if command -v micromamba >/dev/null 2>&1; then '
251-
f' micromamba run -n rmg_env python {THERMO_SCRIPT_PATH} {species_thermo_path}; '
256+
f' micromamba run -n {env_name} python {THERMO_SCRIPT_PATH} {species_thermo_path}; '
252257
'elif command -v conda >/dev/null 2>&1 || command -v mamba >/dev/null 2>&1; then '
253-
f' conda run -n rmg_env python {THERMO_SCRIPT_PATH} {species_thermo_path}; '
258+
f' conda run -n {env_name} python {THERMO_SCRIPT_PATH} {species_thermo_path}; '
254259
'else '
255260
' echo \'❌ Micromamba/Mamba/Conda required\' >&2; exit 1; '
256261
'fi"',
@@ -300,7 +305,8 @@ def compare_rates(rxns_for_kinetics_lib: list,
300305
'family': rxn.family,
301306
} for rxn in rxns_for_kinetics_lib],
302307
)
303-
env_name = 'rmg_env'
308+
env_name = settings.get('RMG_ENV_NAME', 'rmg_env')
309+
rmg_db_path = settings.get('RMG_DB_PATH') or ""
304310
shell_script = f"""if command -v micromamba &> /dev/null; then
305311
eval "$(micromamba shell hook --shell=bash)"
306312
micromamba activate {env_name}
@@ -313,6 +319,8 @@ def compare_rates(rxns_for_kinetics_lib: list,
313319
else
314320
exit 1
315321
fi
322+
export RMG_DB_PATH="{rmg_db_path}"
323+
export RMG_DATABASE="{rmg_db_path}"
316324
python {KINETICS_SCRIPT_PATH} {reactions_kinetics_path} > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)
317325
"""
318326
o, e = execute_command(command=shell_script,

0 commit comments

Comments
 (0)