Skip to content

Commit 36bceb3

Browse files
authored
Merge pull request #2663 from ReactionMechanismGenerator/external_kin_lib
Load a kinetic library not in the RMG database
2 parents de10840 + 6d9a56e commit 36bceb3

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

documentation/source/users/rmg/input.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ by Benson's method.
4949

5050
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::
5151

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

5454
.. [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/
5555
@@ -78,7 +78,7 @@ In the following example, the user has created
7878
a reaction library with a few additional reactions specific to n-butane, and these reactions
7979
are to be used in addition to the Glarborg C3 library::
8080

81-
reactionLibraries = [('Glarborg/C3',False)],
81+
reactionLibraries = [('Glarborg/C3', False)],
8282

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

106106

107+
.. _externallib:
108+
109+
External Libraries
110+
------------------
111+
Users may direct RMG to use thermo and/or kinetic libraries which are not included in the RMG database,
112+
e.g., a library a user created that was intentionally saved to a path different than the conventional
113+
RMG-database location. In such cases, the user can specify the full path to the library in the input file::
114+
115+
thermoLibraries = ['path/to/your/thermo/library/file.py']
116+
117+
or::
118+
119+
reactionLibraries = [(path/to/your/kinetic/library/folder/']
120+
121+
Combinations in any order of RMG's legacy libraries and users' external libraries are allowed,
122+
and the order in which the libraries are specified is the order in which they are loaded and given priority.
123+
107124
.. _seedmechanism:
108125

109126
Seed Mechanisms

rmgpy/data/kinetics/database.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self):
6262
self.recommended_families = {}
6363
self.families = {}
6464
self.libraries = {}
65+
self.external_library_labels = {}
6566
self.library_order = [] # a list of tuples in the format ('library_label', LibraryType),
6667
# where LibraryType is set to either 'Reaction Library' or 'Seed'.
6768
self.local_context = {
@@ -227,17 +228,18 @@ def load_libraries(self, path, libraries=None):
227228
The `path` points to the folder of kinetics libraries in the database,
228229
and the libraries should be in files like :file:`<path>/<library>.py`.
229230
"""
230-
231+
self.external_library_labels = dict()
231232
if libraries is not None:
232233
for library_name in libraries:
233234
library_file = os.path.join(path, library_name, 'reactions.py')
234235
if os.path.exists(library_name):
235236
library_file = os.path.join(library_name, 'reactions.py')
236-
short_library_name = os.path.split(library_name)[-1]
237+
short_library_name = os.path.basename(library_name.rstrip(os.path.sep))
237238
logging.info(f'Loading kinetics library {short_library_name} from {library_name}...')
238239
library = KineticsLibrary(label=short_library_name)
239240
library.load(library_file, self.local_context, self.global_context)
240241
self.libraries[library.label] = library
242+
self.external_library_labels[library_name] = library.label
241243
elif os.path.exists(library_file):
242244
logging.info(f'Loading kinetics library {library_name} from {library_file}...')
243245
library = KineticsLibrary(label=library_name)

rmgpy/rmg/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,12 @@ def add_reaction_library_to_edge(self, reaction_library):
17181718
num_old_edge_reactions = len(self.edge.reactions)
17191719

17201720
logging.info("Adding reaction library {0} to model edge...".format(reaction_library))
1721-
reaction_library = database.kinetics.libraries[reaction_library]
1721+
if reaction_library in database.kinetics.libraries:
1722+
reaction_library = database.kinetics.libraries[reaction_library]
1723+
elif reaction_library in database.kinetics.external_library_labels:
1724+
reaction_library = database.kinetics.libraries[database.kinetics.external_library_labels[reaction_library]]
1725+
else:
1726+
raise ValueError(f'Library {reaction_library} not found.')
17221727

17231728
rxns = reaction_library.get_library_reactions()
17241729
for rxn in rxns:

0 commit comments

Comments
 (0)