From efb8e69c1220ec41281120a33a8ee938ef848c72 Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Sat, 18 May 2024 10:15:28 +0300 Subject: [PATCH 1/4] Added external_library_labels attribute to KineticsDatabase --- rmgpy/data/kinetics/database.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rmgpy/data/kinetics/database.py b/rmgpy/data/kinetics/database.py index 41af9a6b55..c3bf6b0804 100644 --- a/rmgpy/data/kinetics/database.py +++ b/rmgpy/data/kinetics/database.py @@ -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 = { @@ -227,7 +228,7 @@ 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:`/.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') @@ -238,6 +239,7 @@ def load_libraries(self, path, libraries=None): 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) From 97f19d0de08dff2a012879b57f082eb930cab5d6 Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Thu, 13 Jun 2024 08:10:08 +0300 Subject: [PATCH 2/4] Strip os.path.sep when extracting the name of an external library --- rmgpy/data/kinetics/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmgpy/data/kinetics/database.py b/rmgpy/data/kinetics/database.py index c3bf6b0804..91b13e3972 100644 --- a/rmgpy/data/kinetics/database.py +++ b/rmgpy/data/kinetics/database.py @@ -234,7 +234,7 @@ def load_libraries(self, path, libraries=None): 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) From 2b153a7fdc566c612975828bd5b32d310cc480da Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Thu, 13 Jun 2024 07:23:11 +0300 Subject: [PATCH 3/4] Replace an external reaction library path with the library label when loading a library, since kinetic libraries are stored in database.kinetics.libraries by their labels --- rmgpy/rmg/model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rmgpy/rmg/model.py b/rmgpy/rmg/model.py index 1d8c581cc0..1ab45dc67c 100644 --- a/rmgpy/rmg/model.py +++ b/rmgpy/rmg/model.py @@ -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: From 6d9a56e636648b93e330fd0afaa294f23c148103 Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Sat, 25 May 2024 13:52:30 +0300 Subject: [PATCH 4/4] Docs: Documented the external library feature --- documentation/source/users/rmg/input.rst | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/documentation/source/users/rmg/input.rst b/documentation/source/users/rmg/input.rst index 099a824c11..38dead4517 100644 --- a/documentation/source/users/rmg/input.rst +++ b/documentation/source/users/rmg/input.rst @@ -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/ @@ -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 @@ -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