Skip to content

Commit 409ace2

Browse files
committed
Rename generate_cantera_files to generate_cantera_files_from_chemkin
1 parent 8480201 commit 409ace2

4 files changed

Lines changed: 155 additions & 9 deletions

File tree

.github/copilot-instructions.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# RMG-Py Copilot Instructions
2+
3+
## Project Overview
4+
RMG-Py is the Reaction Mechanism Generator - an automatic chemical kinetics mechanism generator. It consists of two main components:
5+
- **RMG** (`rmgpy/`): Core mechanism generation engine
6+
- **Arkane** (`arkane/`): Statistical mechanics and transition state theory calculations
7+
8+
## Architecture
9+
10+
### Core Packages
11+
- `rmgpy/molecule/` - Molecular graph representation (`Molecule`, `Atom`, `Bond`, `Group`)
12+
- `rmgpy/thermo/` - Thermodynamic models (NASA, Wilhoit, ThermoData)
13+
- `rmgpy/kinetics/` - Rate coefficient models (Arrhenius, Chebyshev, pressure-dependent)
14+
- `rmgpy/solver/` - ODE solvers for reactor simulations
15+
- `rmgpy/rmg/` - Main RMG algorithm (`main.py`, `model.py`, `react.py`)
16+
- `rmgpy/data/` - Database interfaces for thermo, kinetics, transport
17+
18+
### Key Base Classes
19+
- `RMGObject` (in `rmgpy/rmgobject.pyx`) - Base class providing `as_dict()`/`make_object()` for YAML serialization
20+
- `Graph`/`Vertex`/`Edge` (in `rmgpy/molecule/graph.pyx`) - Graph isomorphism via VF2 algorithm
21+
- `Species` and `Reaction` are central objects connecting molecules to thermodynamics and kinetics
22+
23+
### Cython Architecture
24+
Performance-critical code uses Cython (`.pyx` files) with declaration files (`.pxd`):
25+
- Always pair `.pyx` with `.pxd` for public cdef classes/methods
26+
- Use `cpdef` for methods callable from both Python and Cython
27+
- Use `cimport` for Cython-level imports (e.g., `cimport rmgpy.constants as constants`)
28+
- Register new Cython modules in `setup.py` `ext_modules` list
29+
30+
## Development Commands
31+
```bash
32+
make install # Build Cython extensions and install in editable mode
33+
make test # Run unit tests (excludes functional/database tests)
34+
make test-functional # Run functional tests
35+
make test-database # Run database tests
36+
make test-all # Run all tests
37+
make clean # Remove build artifacts
38+
make decython # Remove .so files for "pure Python" debugging. This target probably broken.
39+
make documentation # Build Sphinx docs
40+
```
41+
42+
## Testing Conventions
43+
- Tests live in `test/` mirroring `rmgpy/` and `arkane/` structure
44+
- Test files: `*Test.py` (e.g., `speciesTest.py`, `reactionTest.py`)
45+
- Test classes: `class TestClassName:` or `class ClassNameTest:`
46+
- Use `pytest` with fixtures (`@pytest.fixture(autouse=True)` for setup)
47+
- Markers: `@pytest.mark.functional`, `@pytest.mark.database`
48+
- Run specific tests: `pytest -k "test_name_pattern"`
49+
50+
## Code Patterns
51+
52+
### Molecular Representations
53+
```python
54+
from rmgpy.molecule import Molecule
55+
mol = Molecule().from_smiles("CC") # From SMILES
56+
mol = Molecule().from_adjacency_list("""...""") # From adjacency list
57+
mol.is_isomorphic(other_mol) # Graph isomorphism check
58+
```
59+
60+
### Species and Reactions
61+
```python
62+
from rmgpy.species import Species
63+
species = Species(label='ethane', molecule=[Molecule().from_smiles("CC")])
64+
species.generate_resonance_structures()
65+
```
66+
67+
## Input Files
68+
- RMG inputs: Python scripts defining `database()`, `species()`, `simpleReactor()`, etc.
69+
- See `examples/rmg/minimal/input.py` for structure
70+
- Arkane inputs: Python scripts with `species()`, `transitionState()`, `reaction()` blocks
71+
72+
## RMG-database Integration
73+
The **RMG-database** is a separate repository containing all thermodynamic, kinetics, and transport data. It's typically cloned alongside RMG-Py in a sibling folder named `RMG-database`.
74+
75+
### Database Structure (in RMG-database repo)
76+
- `thermo/` - Thermodynamic libraries and group additivity data
77+
- `kinetics/families/` - Reaction family templates with rate rules (e.g., `H_Abstraction`, `R_Addition_MultipleBond`)
78+
- `kinetics/libraries/` - Curated rate coefficient libraries
79+
- `solvation/` - Solvent and solute parameters
80+
- `transport/` - Transport properties
81+
82+
### How RMG-Py Loads the Database
83+
The `RMGDatabase` class (`rmgpy/data/rmg.py`) is the central interface:
84+
```python
85+
from rmgpy.data.rmg import RMGDatabase
86+
database = RMGDatabase()
87+
database.load(
88+
path='/path/to/RMG-database',
89+
thermo_libraries=['primaryThermoLibrary'],
90+
kinetics_families='default',
91+
reaction_libraries=[],
92+
)
93+
```
94+
95+
### Key Database Classes
96+
- `ThermoDatabase` (`rmgpy/data/thermo.py`) - Estimates thermo via group additivity or libraries
97+
- `KineticsDatabase` (`rmgpy/data/kinetics/database.py`) - Manages reaction families and libraries
98+
- `KineticsFamily` (`rmgpy/data/kinetics/family.py`) - Template-based reaction generation using `Group` pattern matching
99+
- `Entry` (`rmgpy/data/base.py`) - Base class for database entries with metadata
100+
101+
### Data Flow for Species Thermodynamics
102+
1. `Species.get_thermo_data()``ThermoDatabase.get_thermo_data(species)`
103+
2. First checks thermo libraries for exact match (via graph isomorphism)
104+
3. Falls back to group additivity estimation using functional group contributions
105+
4. Returns `ThermoData`, `NASA`, or `Wilhoit` object
106+
107+
### Data Flow for Reaction Kinetics
108+
1. `KineticsFamily.generate_reactions(reactants)` - Matches reactant molecules to family templates
109+
2. Creates `TemplateReaction` objects with labeled atoms from template matching
110+
3. `KineticsFamily.get_kinetics()` - Estimates rate using rate rules or training reactions
111+
4. Returns `Arrhenius` or pressure-dependent kinetics model
112+
113+
## External Dependencies
114+
- **RMG-database**: Set location via `RMG_DATABASE_BRANCH` env var in CI, or pass path to `database.load()`
115+
- **Julia/RMS**: Optional (recommended) reactor simulation backend (install via `./install_rms.sh`)
116+
- Environment managed via `environment.yml` (conda/mamba)
117+
118+
## Documentation
119+
Documentation lives in `documentation/source/` and is built with Sphinx (`make documentation`).
120+
121+
### User Documentation (`documentation/source/users/`)
122+
- `users/rmg/` - RMG user guide (how to run, configure, interpret output)
123+
- `users/arkane/` - Arkane user guide
124+
- **Critical file**: `users/rmg/input.rst` - Documents all input file options. **Must be updated when changing input file syntax or adding new features.**
125+
126+
### API Reference (`documentation/source/reference/`)
127+
- Auto-generated from docstrings using `sphinx.ext.autodoc`
128+
- Each module has a corresponding `.rst` file (e.g., `reference/species/index.rst``rmgpy/species.py`)
129+
- **Maintenance**: Add new modules to the appropriate `index.rst` toctree. Docstrings in code are automatically extracted.
130+
- Uses reStructuredText format with `.. automodule::` directives
131+
132+
### When to Update Documentation
133+
- **New input file options**: Update `users/rmg/input.rst`
134+
- **New public API**: Ensure docstrings exist; add module to `reference/` if new
135+
- **Changed behavior**: Update relevant user guide section
136+
- **New features**: Add to `users/rmg/features.rst` or create new `.rst` file
137+
138+
## Style Guidelines
139+
- Follow PEP 8
140+
- Docstrings describe purpose, not implementation
141+
- Use `logging` module (not print statements)
142+
- MIT/X11 license header required on all source files

rmgpy/rmg/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,17 +1226,17 @@ def execute(self, initialize=True, **kwargs):
12261226
# generate Cantera files chem.yaml & chem_annotated.yaml in a designated `cantera` output folder
12271227
try:
12281228
if any([s.contains_surface_site() for s in self.reaction_model.core.species]):
1229-
self.generate_cantera_files(
1229+
self.generate_cantera_files_from_chemkin(
12301230
os.path.join(self.output_directory, "chemkin", "chem-gas.inp"),
12311231
surface_file=(os.path.join(self.output_directory, "chemkin", "chem-surface.inp")),
12321232
)
1233-
self.generate_cantera_files(
1233+
self.generate_cantera_files_from_chemkin(
12341234
os.path.join(self.output_directory, "chemkin", "chem_annotated-gas.inp"),
12351235
surface_file=(os.path.join(self.output_directory, "chemkin", "chem_annotated-surface.inp")),
12361236
)
12371237
else: # gas phase only
1238-
self.generate_cantera_files(os.path.join(self.output_directory, "chemkin", "chem.inp"))
1239-
self.generate_cantera_files(os.path.join(self.output_directory, "chemkin", "chem_annotated.inp"))
1238+
self.generate_cantera_files_from_chemkin(os.path.join(self.output_directory, "chemkin", "chem.inp"))
1239+
self.generate_cantera_files_from_chemkin(os.path.join(self.output_directory, "chemkin", "chem_annotated.inp"))
12401240
except EnvironmentError:
12411241
logging.exception("Could not generate Cantera files due to EnvironmentError. Check read\\write privileges in output directory.")
12421242
except Exception:
@@ -1807,7 +1807,7 @@ def process_reactions_to_species(self, obj):
18071807
raise TypeError("improper call, obj input was incorrect")
18081808
return potential_spcs
18091809

1810-
def generate_cantera_files(self, chemkin_file, **kwargs):
1810+
def generate_cantera_files_from_chemkin(self, chemkin_file, **kwargs):
18111811
"""
18121812
Convert a chemkin mechanism chem.inp file to a cantera mechanism file chem.yaml
18131813
and save it in the cantera directory

scripts/rmg2to3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@
10621062
'processToSpeciesNetworks': 'process_to_species_networks',
10631063
'processPdepNetworks': 'process_pdep_networks',
10641064
'processReactionsToSpecies': 'process_reactions_to_species',
1065-
'generateCanteraFiles': 'generate_cantera_files',
1065+
'generateCanteraFiles': 'generate_cantera_files_from_chemkin',
10661066
'initializeReactionThresholdAndReactFlags': 'initialize_reaction_threshold_and_react_flags',
10671067
'updateReactionThresholdAndReactFlags': 'update_reaction_threshold_and_react_flags',
10681068
'saveEverything': 'save_everything',

test/rmgpy/rmg/mainTest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ def teardown_class(cls):
361361
os.remove(os.path.join(cls.test_dir, "RMG.profile.dot.ps2"))
362362

363363

364-
class TestCanteraOutput:
364+
class TestCanteraOutputConversion:
365+
"""
366+
Tests if we can convert Chemkin files to Cantera files without crashing.
367+
(Or raising an exception for bad files.)
368+
"""
365369
def setup_class(self):
366370
self.chemkin_files = {
367371
"""ELEMENTS
@@ -517,10 +521,10 @@ def test_chemkin_to_cantera_conversion(self):
517521
f.close()
518522

519523
if works:
520-
self.rmg.generate_cantera_files(os.path.join(os.getcwd(), "chem001.inp"))
524+
self.rmg.generate_cantera_files_from_chemkin(os.path.join(os.getcwd(), "chem001.inp"))
521525
else:
522526
with pytest.raises(InputError):
523-
self.rmg.generate_cantera_files(os.path.join(os.getcwd(), "chem001.inp"))
527+
self.rmg.generate_cantera_files_from_chemkin(os.path.join(os.getcwd(), "chem001.inp"))
524528

525529
# clean up
526530
os.chdir(originalPath)

0 commit comments

Comments
 (0)