Skip to content

Commit

Permalink
Merge pull request #2663 from ReactionMechanismGenerator/external_kin…
Browse files Browse the repository at this point in the history
…_lib

Load a kinetic library not in the RMG database
  • Loading branch information
JacksonBurns authored Jun 18, 2024
2 parents de10840 + 6d9a56e commit 36bceb3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
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 @@ def add_reaction_library_to_edge(self, reaction_library):
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]]
else:
raise ValueError(f'Library {reaction_library} not found.')

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

0 comments on commit 36bceb3

Please sign in to comment.