Skip to content

Commit 9dc9f75

Browse files
committed
Refactor ArrheniusBM and ArrheniusChargeTransferBM
To improve activation energy calculations for negative E0 scenarios. These changes shouldn't actually change the result. Just some slight code optimization (eg. x*x instead of x**2) and simplification (eg. do (x/y) instead of (2*x)/(2*y)) Beware of code duplication.
1 parent ad3d8c5 commit 9dc9f75

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

rmgpy/kinetics/arrhenius.pyx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,11 @@ cdef class ArrheniusBM(KineticsModel):
580580
# Negative E0 is unphysical, but could be encountered during optimization.
581581
Ea = E0 + max(dHrxn, 0.0)
582582
else:
583-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
584-
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) ** 2 / (Vp ** 2 - (2 * w0) ** 2 + dHrxn ** 2)
585-
if (dHrxn < 0.0 and Ea < 0.0) or (dHrxn < -4 * E0):
583+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
584+
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
585+
if (Ea < 0.0) or (dHrxn < -4 * E0):
586586
Ea = 0.0
587-
elif (dHrxn > 0.0 and Ea < dHrxn) or (dHrxn > 4 * E0):
587+
elif (Ea < dHrxn) or (dHrxn > 4 * E0):
588588
Ea = dHrxn
589589
return Ea
590590

@@ -632,8 +632,8 @@ cdef class ArrheniusBM(KineticsModel):
632632
Ea = rxn.kinetics.Ea.value_si
633633

634634
def kfcn(E0):
635-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
636-
out = Ea - (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (2 * w0) * (2 * w0) + dHrxn * dHrxn)
635+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
636+
out = Ea - (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
637637
return out
638638

639639
E0 = fsolve(kfcn, w0 / 10.0)[0]
@@ -647,8 +647,8 @@ cdef class ArrheniusBM(KineticsModel):
647647
def kfcn(xs, lnA, n, E0):
648648
T = xs[:,0]
649649
dHrxn = xs[:,1]
650-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
651-
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (2 * w0) * (2 * w0) + dHrxn * dHrxn)
650+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
651+
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
652652
Ea = np.where(dHrxn< -4.0*E0, 0.0, Ea)
653653
Ea = np.where(dHrxn > 4.0*E0, dHrxn, Ea)
654654
return lnA + np.log(T) * n + (-Ea / (8.314472 * T))
@@ -1585,11 +1585,11 @@ cdef class ArrheniusChargeTransferBM(KineticsModel):
15851585
# Negative E0 is unphysical, but could be encountered during optimization.
15861586
Ea = E0 + max(dHrxn, 0.0)
15871587
else:
1588-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
1589-
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (2 * w0) * (2 * w0) + dHrxn * dHrxn)
1590-
if (dHrxn < 0.0 and Ea < 0.0) or (dHrxn < -4 * E0):
1588+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
1589+
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
1590+
if (Ea < 0.0) or (dHrxn < -4 * E0):
15911591
Ea = 0.0
1592-
elif (dHrxn > 0.0 and Ea < dHrxn) or (dHrxn > 4 * E0):
1592+
elif (Ea < dHrxn) or (dHrxn > 4 * E0):
15931593
Ea = dHrxn
15941594
return Ea
15951595

@@ -1636,8 +1636,8 @@ cdef class ArrheniusChargeTransferBM(KineticsModel):
16361636
Ea = rxn.kinetics.Ea.value_si
16371637

16381638
def kfcn(E0):
1639-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
1640-
out = Ea - (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (2 * w0) * (2 * w0) + dHrxn * dHrxn)
1639+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
1640+
out = Ea - (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
16411641
return out
16421642

16431643
E0 = fsolve(kfcn, w0 / 10.0)[0]
@@ -1650,8 +1650,8 @@ cdef class ArrheniusChargeTransferBM(KineticsModel):
16501650
def kfcn(xs, lnA, n, E0):
16511651
T = xs[:,0]
16521652
dHrxn = xs[:,1]
1653-
Vp = 2 * w0 * (2 * w0 + 2 * E0) / (2 * w0 - 2 * E0)
1654-
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (2 * w0) * (2 * w0) + dHrxn * dHrxn)
1653+
Vp = 2 * w0 * (w0 + E0) / (w0 - E0)
1654+
Ea = (w0 + dHrxn / 2.0) * (Vp - 2 * w0 + dHrxn) * (Vp - 2 * w0 + dHrxn) / (Vp * Vp - (4 * w0 * w0) + dHrxn * dHrxn)
16551655
Ea = np.where(dHrxn< -4.0*E0, 0.0, Ea)
16561656
Ea = np.where(dHrxn > 4.0*E0, dHrxn, Ea)
16571657
return lnA + np.log(T) * n + (-Ea / (8.314 * T))

0 commit comments

Comments
 (0)