@@ -2247,6 +2247,11 @@ def generateReactions(self, reactants, returnAllKinetics=False):
2247
2247
)
2248
2248
reactionList .append (reaction )
2249
2249
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
+
2250
2255
rxnListToReturn = []
2251
2256
if not returnAllKinetics :
2252
2257
"""
@@ -2257,15 +2262,15 @@ def generateReactions(self, reactants, returnAllKinetics=False):
2257
2262
kineticsList = self .getKinetics (rxn , degeneracy = rxn .degeneracy ,
2258
2263
returnAllKinetics = returnAllKinetics )
2259
2264
assert len (kineticsList )== 1
2260
- kinetics , source , entry = kineticsList [0 ]
2265
+ kinetics , source , entry , isForward = kineticsList [0 ]
2261
2266
2262
2267
if hasattr (rxn ,'reverse' ):
2263
2268
# fetch the reverse kinetics, and decide which to keep
2264
2269
kineticsList = self .getKinetics (rxn .reverse ,
2265
2270
degeneracy = rxn .reverse .degeneracy ,
2266
2271
returnAllKinetics = returnAllKinetics )
2267
2272
assert len (kineticsList )== 1
2268
- rev_kinetics , rev_source , rev_entry = kineticsList [0 ]
2273
+ rev_kinetics , rev_source , rev_entry , rev_isForward = kineticsList [0 ]
2269
2274
2270
2275
if (source is not None and rev_source is None ):
2271
2276
# Only the forward has a source.
@@ -2281,7 +2286,7 @@ def generateReactions(self, reactants, returnAllKinetics=False):
2281
2286
kinetics = rev_kinetics
2282
2287
source = rev_source
2283
2288
entry = rev_entry
2284
- rxnListToReturn .append ([rxn ,kinetics ,source ,entry ])
2289
+ rxnListToReturn .append ([rxn ,kinetics ,source ,entry , isForward ])
2285
2290
2286
2291
else : # returnAllKinetics == True
2287
2292
"""
@@ -2291,23 +2296,29 @@ def generateReactions(self, reactants, returnAllKinetics=False):
2291
2296
for rxn in reactionList0 :
2292
2297
kineticsList = self .getKinetics (rxn , degeneracy = rxn .degeneracy ,
2293
2298
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 ])
2296
2301
2297
2302
if hasattr (rxn ,'reverse' ):
2298
2303
# fetch the reverse kinetics, and add them all
2299
2304
kineticsList = self .getKinetics (rxn .reverse ,
2300
2305
degeneracy = rxn .reverse .degeneracy ,
2301
2306
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 ])
2304
2309
2305
2310
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 [:]
2307
2318
if source is not None :
2308
2319
reaction = DepositoryReaction (
2309
- reactants = rxn . reactants [:] ,
2310
- products = rxn . products [:] ,
2320
+ reactants = reactants ,
2321
+ products = products ,
2311
2322
kinetics = kinetics ,
2312
2323
degeneracy = rxn .degeneracy ,
2313
2324
thirdBody = rxn .thirdBody ,
@@ -2318,8 +2329,8 @@ def generateReactions(self, reactants, returnAllKinetics=False):
2318
2329
)
2319
2330
else :
2320
2331
reaction = TemplateReaction (
2321
- reactants = rxn . reactants [:] ,
2322
- products = rxn . products [:] ,
2332
+ reactants = reactants ,
2333
+ products = products ,
2323
2334
kinetics = kinetics ,
2324
2335
degeneracy = rxn .degeneracy ,
2325
2336
thirdBody = rxn .thirdBody ,
@@ -2514,7 +2525,9 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
2514
2525
"""
2515
2526
Search the given `depository` in this kinetics family for kinetics
2516
2527
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.
2518
2531
"""
2519
2532
kineticsList = []
2520
2533
if depository .label .endswith ('rules' ):
@@ -2524,8 +2537,8 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
2524
2537
entryLabels = entry .label .split (';' )
2525
2538
templateLabels = [group .label for group in template ]
2526
2539
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 :
2529
2542
if kinetics is not None :
2530
2543
# The rules are defined on a per-site basis, so we need to include the degeneracy manually
2531
2544
assert isinstance (kinetics , ArrheniusEP )
@@ -2535,7 +2548,7 @@ def getKineticsFromDepository(self, depository, reaction, template, degeneracy):
2535
2548
entries = depository .entries .values ()
2536
2549
for entry in entries :
2537
2550
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 ) ])
2539
2552
2540
2553
return kineticsList
2541
2554
@@ -2557,14 +2570,14 @@ def getKinetics(self, reaction, degeneracy=1, returnAllKinetics=True):
2557
2570
2558
2571
# Check the various depositories for kinetics
2559
2572
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 ):
2561
2574
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 ])
2564
2577
# Also generate a group additivity estimate
2565
2578
kinetics = self .getKineticsForTemplate (template , degeneracy )
2566
2579
if kinetics :
2567
- kineticsList .append ([kinetics , None , None ])
2580
+ kineticsList .append ([kinetics , None , None , True ])
2568
2581
return kineticsList
2569
2582
2570
2583
################################################################################
0 commit comments