Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load a kinetic library not in the RMG database #2663

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions documentation/source/users/rmg/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ by Benson's method.

For example, if you wish to use the GRI-Mech 3.0 mechanism [GRIMech3.0]_ as a ThermoLibrary in your model, the syntax will be::

thermoLibraries = ['primaryThermoLibrary','GRI-Mech3.0']
thermoLibraries = ['primaryThermoLibrary', 'GRI-Mech3.0']

.. [GRIMech3.0] Gregory P. Smith, David M. Golden, Michael Frenklach, Nigel W. Moriarty, Boris Eiteneer, Mikhail Goldenberg, C. Thomas Bowman, Ronald K. Hanson, Soonho Song, William C. Gardiner, Jr., Vitali V. Lissianski, and Zhiwei Qin http://combustion.berkeley.edu/gri-mech/
Expand Down Expand Up @@ -78,7 +78,7 @@ In the following example, the user has created
a reaction library with a few additional reactions specific to n-butane, and these reactions
are to be used in addition to the Glarborg C3 library::

reactionLibraries = [('Glarborg/C3',False)],
reactionLibraries = [('Glarborg/C3', False)],

The keyword False/True permits user to append all unused reactions (= kept in the edge) from this library to the chemkin file.
True means those reactions will be appended. Using just the string inputs would lead to
Expand All @@ -104,6 +104,23 @@ given in each mechanism, the different mechanisms can have different units.
Library.


.. _externallib:

External Libraries
------------------
Users may direct RMG to use thermo and/or kinetic libraries which are not included in the RMG database,
e.g., a library a user created that was intentionally saved to a path different than the conventional
RMG-database location. In such cases, the user can specify the full path to the library in the input file::

thermoLibraries = ['path/to/your/thermo/library/file.py']

or::

reactionLibraries = [(path/to/your/kinetic/library/folder/']

Combinations in any order of RMG's legacy libraries and users' external libraries are allowed,
and the order in which the libraries are specified is the order in which they are loaded and given priority.

.. _seedmechanism:

Seed Mechanisms
Expand Down
6 changes: 4 additions & 2 deletions rmgpy/data/kinetics/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self):
self.recommended_families = {}
self.families = {}
self.libraries = {}
self.external_library_labels = {}
self.library_order = [] # a list of tuples in the format ('library_label', LibraryType),
# where LibraryType is set to either 'Reaction Library' or 'Seed'.
self.local_context = {
Expand Down Expand Up @@ -227,17 +228,18 @@ def load_libraries(self, path, libraries=None):
The `path` points to the folder of kinetics libraries in the database,
and the libraries should be in files like :file:`<path>/<library>.py`.
"""

self.external_library_labels = dict()
if libraries is not None:
for library_name in libraries:
library_file = os.path.join(path, library_name, 'reactions.py')
if os.path.exists(library_name):
library_file = os.path.join(library_name, 'reactions.py')
short_library_name = os.path.split(library_name)[-1]
short_library_name = os.path.basename(library_name.rstrip(os.path.sep))
logging.info(f'Loading kinetics library {short_library_name} from {library_name}...')
library = KineticsLibrary(label=short_library_name)
library.load(library_file, self.local_context, self.global_context)
self.libraries[library.label] = library
self.external_library_labels[library_name] = library.label
elif os.path.exists(library_file):
logging.info(f'Loading kinetics library {library_name} from {library_file}...')
library = KineticsLibrary(label=library_name)
Expand Down
7 changes: 6 additions & 1 deletion rmgpy/rmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,12 @@
num_old_edge_reactions = len(self.edge.reactions)

logging.info("Adding reaction library {0} to model edge...".format(reaction_library))
reaction_library = database.kinetics.libraries[reaction_library]
if reaction_library in database.kinetics.libraries:
reaction_library = database.kinetics.libraries[reaction_library]
elif reaction_library in database.kinetics.external_library_labels:
reaction_library = database.kinetics.libraries[database.kinetics.external_library_labels[reaction_library]]

Check warning on line 1724 in rmgpy/rmg/model.py

View check run for this annotation

Codecov / codecov/patch

rmgpy/rmg/model.py#L1723-L1724

Added lines #L1723 - L1724 were not covered by tests
else:
raise ValueError(f'Library {reaction_library} not found.')

Check warning on line 1726 in rmgpy/rmg/model.py

View check run for this annotation

Codecov / codecov/patch

rmgpy/rmg/model.py#L1726

Added line #L1726 was not covered by tests

rxns = reaction_library.get_library_reactions()
for rxn in rxns:
Expand Down
Loading