Skip to content

Commit f70b59b

Browse files
committed
KineticsFamily.getKinetics() now also returns isForward data for each result.
When getting the kinetics for a reaction generated from a template, the kinetics could conceivably come in either direction if a match for the reaction is found within a depository (e.g. training), as we don't force these to be stored in the direction the template is defined in. Therefore we need to mark the returned kinetics as being for the forward or reverse direction, so they can be properly interpreted. All kinetics estimated via group additivity or from the rules are by definition for the forward direction, as before. This fixes, among other things, the absurdly-high barrier for CH3 + CH2OH -> CH3CH2OH seen in the PES for issue #44.
1 parent 50fdddd commit f70b59b

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

rmgpy/data/kinetics.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,11 @@ def generateReactions(self, reactants, returnAllKinetics=False):
22472247
)
22482248
reactionList.append(reaction)
22492249

2250+
# Generate the kinetics for each reaction
2251+
# The list of kinetics from getKinetics() could be for either the
2252+
# forward or reverse direction (since we can store kinetics entries in
2253+
# the various depositories in either direction)
2254+
22502255
rxnListToReturn = []
22512256
if not returnAllKinetics:
22522257
"""
@@ -2257,15 +2262,15 @@ def generateReactions(self, reactants, returnAllKinetics=False):
22572262
kineticsList = self.getKinetics(rxn, degeneracy=rxn.degeneracy,
22582263
returnAllKinetics=returnAllKinetics)
22592264
assert len(kineticsList)==1
2260-
kinetics, source, entry = kineticsList[0]
2265+
kinetics, source, entry, isForward = kineticsList[0]
22612266

22622267
if hasattr(rxn,'reverse'):
22632268
# fetch the reverse kinetics, and decide which to keep
22642269
kineticsList = self.getKinetics(rxn.reverse,
22652270
degeneracy=rxn.reverse.degeneracy,
22662271
returnAllKinetics=returnAllKinetics)
22672272
assert len(kineticsList)==1
2268-
rev_kinetics, rev_source, rev_entry = kineticsList[0]
2273+
rev_kinetics, rev_source, rev_entry, rev_isForward = kineticsList[0]
22692274

22702275
if (source is not None and rev_source is None):
22712276
# Only the forward has a source.
@@ -2281,7 +2286,7 @@ def generateReactions(self, reactants, returnAllKinetics=False):
22812286
kinetics = rev_kinetics
22822287
source = rev_source
22832288
entry = rev_entry
2284-
rxnListToReturn.append([rxn,kinetics,source,entry])
2289+
rxnListToReturn.append([rxn,kinetics,source,entry,isForward])
22852290

22862291
else: # returnAllKinetics == True
22872292
"""
@@ -2291,23 +2296,29 @@ def generateReactions(self, reactants, returnAllKinetics=False):
22912296
for rxn in reactionList0:
22922297
kineticsList = self.getKinetics(rxn, degeneracy=rxn.degeneracy,
22932298
returnAllKinetics=returnAllKinetics)
2294-
for kinetics, source, entry in kineticsList:
2295-
rxnListToReturn.append([rxn,kinetics,source,entry])
2299+
for kinetics, source, entry, isForward in kineticsList:
2300+
rxnListToReturn.append([rxn,kinetics,source,entry,isForward])
22962301

22972302
if hasattr(rxn,'reverse'):
22982303
# fetch the reverse kinetics, and add them all
22992304
kineticsList = self.getKinetics(rxn.reverse,
23002305
degeneracy=rxn.reverse.degeneracy,
23012306
returnAllKinetics=returnAllKinetics)
2302-
for kinetics, source, entry in kineticsList:
2303-
rxnListToReturn.append([rxn,kinetics,source,entry])
2307+
for kinetics, source, entry, isForward in kineticsList:
2308+
rxnListToReturn.append([rxn,kinetics,source,entry,isForward])
23042309

23052310
reactionList = []
2306-
for rxn, kinetics, source, entry in rxnListToReturn:
2311+
for rxn, kinetics, source, entry, isForward in rxnListToReturn:
2312+
if isForward:
2313+
reactants = rxn.reactants[:]
2314+
products = rxn.products[:]
2315+
else:
2316+
reactants = rxn.products[:]
2317+
products = rxn.reactants[:]
23072318
if source is not None:
23082319
reaction = DepositoryReaction(
2309-
reactants = rxn.reactants[:],
2310-
products = rxn.products[:],
2320+
reactants = reactants,
2321+
products = products,
23112322
kinetics = kinetics,
23122323
degeneracy = rxn.degeneracy,
23132324
thirdBody = rxn.thirdBody,
@@ -2318,8 +2329,8 @@ def generateReactions(self, reactants, returnAllKinetics=False):
23182329
)
23192330
else:
23202331
reaction = TemplateReaction(
2321-
reactants = rxn.reactants[:],
2322-
products = rxn.products[:],
2332+
reactants = reactants,
2333+
products = products,
23232334
kinetics = kinetics,
23242335
degeneracy = rxn.degeneracy,
23252336
thirdBody = rxn.thirdBody,
@@ -2514,7 +2525,9 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
25142525
"""
25152526
Search the given `depository` in this kinetics family for kinetics
25162527
for the given `reaction`. Returns a list of all of the matching
2517-
kinetics and corresponding entries.
2528+
kinetics, the corresponding entries, and ``True`` if the kinetics
2529+
match the forward direction or ``False`` if they match the reverse
2530+
direction.
25182531
"""
25192532
kineticsList = []
25202533
if depository.label.endswith('rules'):
@@ -2524,8 +2537,8 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
25242537
entryLabels = entry.label.split(';')
25252538
templateLabels = [group.label for group in template]
25262539
if all([group in entryLabels for group in templateLabels]) and all([group in templateLabels for group in entryLabels]):
2527-
kineticsList.append([deepcopy(entry.data), entry])
2528-
for kinetics, entry in kineticsList:
2540+
kineticsList.append([deepcopy(entry.data), entry, True])
2541+
for kinetics, entry, isForward in kineticsList:
25292542
if kinetics is not None:
25302543
# The rules are defined on a per-site basis, so we need to include the degeneracy manually
25312544
assert isinstance(kinetics, ArrheniusEP)
@@ -2535,7 +2548,7 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
25352548
entries = depository.entries.values()
25362549
for entry in entries:
25372550
if reaction.isIsomorphic(entry.item):
2538-
kineticsList.append([deepcopy(entry.data), entry])
2551+
kineticsList.append([deepcopy(entry.data), entry, reaction.isIsomorphic(entry.item, eitherDirection=False)])
25392552

25402553
return kineticsList
25412554

@@ -2557,14 +2570,14 @@ def getKinetics(self, reaction, degeneracy=1, returnAllKinetics=True):
25572570

25582571
# Check the various depositories for kinetics
25592572
for depository in depositories:
2560-
for kinetics, entry in self.getKineticsFromDepository(depository, reaction, template, degeneracy):
2573+
for kinetics, entry, isForward in self.getKineticsFromDepository(depository, reaction, template, degeneracy):
25612574
if not returnAllKinetics:
2562-
return [[kinetics,depository,entry]]
2563-
kineticsList.append([kinetics, depository, entry])
2575+
return [[kinetics,depository,entry,isForward]]
2576+
kineticsList.append([kinetics, depository, entry, isForward])
25642577
# Also generate a group additivity estimate
25652578
kinetics = self.getKineticsForTemplate(template, degeneracy)
25662579
if kinetics:
2567-
kineticsList.append([kinetics, None, None])
2580+
kineticsList.append([kinetics, None, None, True])
25682581
return kineticsList
25692582

25702583
################################################################################

0 commit comments

Comments
 (0)