RMG-Py is the Reaction Mechanism Generator - an automatic chemical kinetics mechanism generator. It consists of two main components:
- RMG (
rmgpy/): Core mechanism generation engine - Arkane (
arkane/): Statistical mechanics and transition state theory calculations
rmgpy/molecule/- Molecular graph representation (Molecule,Atom,Bond,Group)rmgpy/thermo/- Thermodynamic models (NASA, Wilhoit, ThermoData)rmgpy/kinetics/- Rate coefficient models (Arrhenius, Chebyshev, pressure-dependent)rmgpy/solver/- ODE solvers for reactor simulationsrmgpy/rmg/- Main RMG algorithm (main.py,model.py,react.py)rmgpy/data/- Database interfaces for thermo, kinetics, transport
RMGObject(inrmgpy/rmgobject.pyx) - Base class providingas_dict()/make_object()for YAML serializationGraph/Vertex/Edge(inrmgpy/molecule/graph.pyx) - Graph isomorphism via VF2 algorithmSpeciesandReactionare central objects connecting molecules to thermodynamics and kinetics
Performance-critical code uses Cython (.pyx files) with declaration files (.pxd):
- Some
.pyfiles are also cythonized — they have a.pxdsibling and are listed insetup.pyext_modules(e.g.rmgpy/species.py,rmgpy/reaction.py,rmgpy/quantity.py,rmgpy/constants.py, and most ofrmgpy/molecule/). The compiled.sois what gets imported, so edits won't take effect until rebuilt. - Always pair
.pyx(or cythonized.py) with.pxdfor public cdef classes/methods - Use
cpdeffor methods callable from both Python and Cython - Use
cimportfor Cython-level imports (e.g.,cimport rmgpy.constants as constants) - Register new Cython modules in
setup.pyext_moduleslist - Remember to re-compile (
make build) after modifying any.pyx,.pxd, or cythonized.pyfile, or if there seem to be weird bugs in them.
make install # First-time pip editable install + Cython build. Writes a .installed sentinel; subsequent `make install` is a no-op until `make clean`.
make build # Incremental in-place Cython rebuild (`setup.py build_ext --inplace`). Fast — use this after editing .pyx/.pxd/cythonized .py.
make # Default target: dep check, install if needed (via sentinel), then `make build`. Safe go-to.
make test # Run unit tests (excludes functional/database tests)
make test-functional # Run functional tests
make test-database # Run database tests
make test-all # Run all tests
make clean # Remove .so/.pyc/.c build artifacts, the build/ dir, the .installed sentinel, and pip-uninstall the package.
make decython # Remove most .so files for "pure Python" debugging (keeps _statmech.so, quantity.so, and rmgpy/solver/*.so). Pure python mode is not reliably tested and might not work.
make documentation # Build Sphinx docs- Tests live in
test/mirroringrmgpy/andarkane/structure - Test files:
*Test.py(e.g.,speciesTest.py,reactionTest.py) - Test classes:
class TestClassName:orclass ClassNameTest: - Use
pytestwith fixtures (@pytest.fixture(autouse=True)for setup) - Markers:
@pytest.mark.functional,@pytest.mark.database - Run specific tests:
pytest -k "test_name_pattern"
from rmgpy.molecule import Molecule
mol = Molecule().from_smiles("CC") # From SMILES
mol = Molecule().from_adjacency_list("""...""") # From adjacency list
mol.is_isomorphic(other_mol) # Graph isomorphism checkfrom rmgpy.species import Species
species = Species(label='ethane', molecule=[Molecule().from_smiles("CC")])
species.generate_resonance_structures()from rmgpy.reaction import Reaction
from rmgpy.kinetics import Arrhenius
# Reaction with Arrhenius kinetics
rxn = Reaction(
reactants=[Species(label='CH3', molecule=[Molecule(smiles='[CH3]')]),
Species(label='O2', molecule=[Molecule(smiles='[O][O]')])],
products=[Species(label='CH3OO', molecule=[Molecule(smiles='CO[O]')])],
kinetics=Arrhenius(A=(2.65e12, 'cm^3/(mol*s)'), n=0.0, Ea=(0.0, 'kJ/mol'), T0=(1, 'K')),
)
# Reaction without kinetics (e.g. for isomorphism checks)
rxn2 = Reaction(
reactants=[Species().from_smiles('[O]'), Species().from_smiles('O=S=O')],
products=[Species().from_smiles('O=S(=O)=O')],
)- RMG inputs: Python scripts defining
database(),species(),simpleReactor(), etc. - See
examples/rmg/minimal/input.pyfor structure andexamples/rmg/commented/input.pyfor a file with detailed comments - Arkane inputs: Python scripts with
species(),transitionState(),reaction()blocks - See
examples/arkane/for examples
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.
thermo/- Thermodynamic libraries and group additivity datakinetics/families/- Reaction family templates with rate rules (e.g.,H_Abstraction,R_Addition_MultipleBond)kinetics/libraries/- Curated rate coefficient librariessolvation/- Solvent and solute parameterstransport/- Transport properties
The RMGDatabase class (rmgpy/data/rmg.py) is the central interface:
from rmgpy.data.rmg import RMGDatabase
database = RMGDatabase()
database.load(
path='/path/to/RMG-database/input',
thermo_libraries=['primaryThermoLibrary'],
kinetics_families='default',
reaction_libraries=[],
)ThermoDatabase(rmgpy/data/thermo.py) - Estimates thermo via group additivity or librariesKineticsDatabase(rmgpy/data/kinetics/database.py) - Manages reaction families and librariesKineticsFamily(rmgpy/data/kinetics/family.py) - Template-based reaction generation usingGrouppattern matchingEntry(rmgpy/data/base.py) - Base class for database entries with metadata
Species.get_thermo_data()→rmgpy.thermo.thermoengine.submit(species)thermoengine.submit()generates resonance structures, then dispatches toThermoDatabase.get_thermo_data(species)ThermoDatabasefirst checks thermo libraries for an exact match (via graph isomorphism)- If no library match is found,
ThermoDatabasefalls back to group additivity estimation using functional group contributions - The resolved result is returned as a
ThermoData,NASA, orWilhoitobject
KineticsFamily.generate_reactions(reactants)- Matches reactant molecules to family templates- Creates
TemplateReactionobjects with labeled atoms from template matching KineticsFamily.get_kinetics()- Estimates rate using rate rules or training reactions- Returns
Arrheniusor pressure-dependent kinetics model
- RMG-database: In CI,
RMG_DATABASE_BRANCHcontrols which RMG-database branch is cloned. Locally, the database location is set viasettings['database.directory'](default../RMG-database/input) ordatabase.directoryin anrmgrcfile; you may also pass an explicit path todatabase.load(). - Julia/RMS: Optional (recommended) reactor simulation backend (install via
./install_rms.sh) - Environment managed via
environment.yml(conda/mamba)
Documentation lives in documentation/source/ and is built with Sphinx (make documentation).
users/rmg/- RMG user guide (how to run, configure, interpret output)users/arkane/- Arkane user guide- Critical file:
users/rmg/input.rst- Documents all input file options. Must be updated when changing input file syntax or adding new features.
- Auto-generated from docstrings using
sphinx.ext.autodoc - Each module has a corresponding
.rstfile (e.g.,documentation/source/reference/species/index.rst→rmgpy/species.py) - Maintenance: Add new modules to the appropriate
index.rsttoctree. Docstrings in code are automatically extracted. - Uses reStructuredText format with
.. automodule::directives
- New input file options: Update
documentation/source/users/rmg/input.rst - New public API: Ensure docstrings exist; add module to
documentation/source/reference/if new - Changed behavior: Update relevant user guide section
- New features: Add to
documentation/source/users/rmg/features.rstor create and link to new.rstfile
- Verify changed behavior is covered by tests, or request targeted tests for uncovered paths.
- Check that user-facing changes include required documentation updates (especially input syntax in
documentation/source/users/rmg/input.rst). - Confirm Cython changes are complete (
.pyx/.pxdparity, required setup wiring, and likely rebuild impact). - Watch for performance regressions in hot paths (
rmgpy/molecule/,rmgpy/solver/, kinetics generation loops).
- If
environment.ymlor.conda/meta.yamlchange, verify they are consistent. - For changes that affect data loading or estimators, verify assumptions against RMG-database integration points in
rmgpy/data/rmg.pyand related loaders.
- Follow PEP 8 for new or modified code, but don't modify code just to fix style
- Docstrings describe purpose, not implementation
- Use
loggingmodule (not print statements) - MIT license header required on all source files