Skip to content

Commit ee81ff6

Browse files
committed
return kinetic library entry when parsing comments
Before this, the kinetics version of extract_source_from_comment returned the library name, but now it returns a tuple of the library name and the library entry. This makes things much easier downstream in the uncertainty tool.
1 parent 11826f6 commit ee81ff6

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

rmgpy/data/kinetics/database.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ def extract_source_from_comments(self, reaction):
695695
A reaction can only be estimated using one of these methods.
696696
697697
source = {'RateRules': (Family_Label, OriginalTemplate, RateRules),
698-
'Library': String_Name_of_Library_Used,
698+
'Library': (String_Name_of_Library_Used, Library_Entry),
699699
'PDep': Network_Index,
700700
'Training': (Family_Label, Training_Reaction_Entry),
701701
}
@@ -715,7 +715,24 @@ def extract_source_from_comments(self, reaction):
715715
source['Rate Rules'] = data_source
716716
elif isinstance(reaction, LibraryReaction):
717717
# This reaction comes from a reaction library or seed mechanism
718-
source['Library'] = reaction.library
718+
library_reactions = self.generate_reactions_from_library(
719+
library=self.libraries[reaction.library],
720+
reactants=reaction.reactants,
721+
products=reaction.products
722+
)
723+
if not library_reactions:
724+
raise ValueError(f'Could not find reaction {reaction} in library {reaction.library} when trying to extract source data from comments.')
725+
entry = self.libraries[reaction.library].entries[library_reactions[0].entry.index]
726+
if len(library_reactions) > 0:
727+
# Library contains multiple reactions of the same type
728+
# pick the one with identical kinetics
729+
for rxn in library_reactions:
730+
if rxn.entry.data.is_similar_to(reaction.kinetics): # units might have been changed, so use is_similar_to instead of direct comparison
731+
entry = self.libraries[reaction.library].entries[rxn.entry.index]
732+
break
733+
else:
734+
raise ValueError(f'Found multiple instances of reaction {reaction} in library {reaction.library}, but none of them have kinetics identical to the reaction kinetics.')
735+
source['Library'] = (reaction.library, entry)
719736

720737
elif isinstance(reaction, PDepReaction):
721738
# This reaction is a pressure-dependent reaction

test/rmgpy/data/kinetics/kineticsTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def test_parse_kinetics(self):
672672
# ------------------------------------------------------------------- #
673673
# Source 0 comes from a kinetics library
674674
assert "Library" in sources[0]
675-
assert sources[0]["Library"] == "GRI-Mech3.0"
675+
assert sources[0]["Library"][0] == "GRI-Mech3.0"
676676

677677
reconstructed_kinetics = self.database.kinetics.reconstruct_kinetics_from_source(reactions[0], sources[0], fix_barrier_height=True)
678678
A = reconstructed_kinetics.A.value_si

0 commit comments

Comments
 (0)