diff --git a/rmgpy/data/kinetics/family.py b/rmgpy/data/kinetics/family.py index 5846087b47..90e525a640 100644 --- a/rmgpy/data/kinetics/family.py +++ b/rmgpy/data/kinetics/family.py @@ -1037,20 +1037,14 @@ def addKineticsRulesFromTrainingSet(self, thermoDatabase=None): label = ';'.join([g.label for g in template]), item=Reaction(reactants=[g.item for g in template], products=[]), - data = ArrheniusEP( - A = deepcopy(data.A), - n = deepcopy(data.n), - alpha = 0, - E0 = deepcopy(data.Ea), - Tmin = deepcopy(data.Tmin), - Tmax = deepcopy(data.Tmax), - comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index), - ), + data = data.toArrheniusEP(), rank = entry.rank, reference=entry.reference, shortDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.shortDesc, longDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.longDesc, ) + new_entry.data.comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index) + new_entry.data.A.value_si /= entry.item.degeneracy try: self.rules.entries[new_entry.label].append(new_entry) @@ -1091,20 +1085,14 @@ def addKineticsRulesFromTrainingSet(self, thermoDatabase=None): label = ';'.join([g.label for g in template]), item=Reaction(reactants=[g.item for g in template], products=[]), - data = ArrheniusEP( - A = deepcopy(data.A), - n = deepcopy(data.n), - alpha = 0, - E0 = deepcopy(data.Ea), - Tmin = deepcopy(data.Tmin), - Tmax = deepcopy(data.Tmax), - comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index), - ), + data = data.toArrheniusEP(), rank = entry.rank, reference=entry.reference, shortDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.shortDesc, longDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.longDesc, ) + new_entry.data.comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index) + new_entry.data.A.value_si /= new_degeneracy try: self.rules.entries[new_entry.label].append(new_entry) diff --git a/rmgpy/data/kinetics/rules.py b/rmgpy/data/kinetics/rules.py index 8d94f6e2e8..22c64b7810 100644 --- a/rmgpy/data/kinetics/rules.py +++ b/rmgpy/data/kinetics/rules.py @@ -45,7 +45,7 @@ from rmgpy.quantity import Quantity, ScalarQuantity from rmgpy.reaction import Reaction -from rmgpy.kinetics import ArrheniusEP +from rmgpy.kinetics import ArrheniusEP, Arrhenius from .common import KineticsError, saveEntry ################################################################################ @@ -77,6 +77,8 @@ def loadEntry(self, treeDistances=None ): + if isinstance(kinetics,Arrhenius): + kinetics = kinetics.toArrheniusEP() entry = Entry( index = index, label = label, diff --git a/rmgpy/kinetics/arrhenius.pxd b/rmgpy/kinetics/arrhenius.pxd index a8e487dd38..1e9bc9b46c 100644 --- a/rmgpy/kinetics/arrhenius.pxd +++ b/rmgpy/kinetics/arrhenius.pxd @@ -49,6 +49,8 @@ cdef class Arrhenius(KineticsModel): cpdef changeRate(self, double factor) + cpdef ArrheniusEP toArrheniusEP(self, double alpha=?, double dHrxn=?) + ################################################################################ cdef class ArrheniusEP(KineticsModel): diff --git a/rmgpy/kinetics/arrhenius.pyx b/rmgpy/kinetics/arrhenius.pyx index 42df5d39f1..3b42903af6 100644 --- a/rmgpy/kinetics/arrhenius.pyx +++ b/rmgpy/kinetics/arrhenius.pyx @@ -32,7 +32,6 @@ from libc.math cimport exp, log, sqrt, log10 cimport rmgpy.constants as constants import rmgpy.quantity as quantity - ################################################################################ cdef class Arrhenius(KineticsModel): @@ -249,7 +248,29 @@ cdef class Arrhenius(KineticsModel): # Set the rate parameter to a cantera Arrhenius object ctReaction.rate = self.toCanteraKinetics() - + + cpdef ArrheniusEP toArrheniusEP(self, double alpha=0.0, double dHrxn=0.0): + """ + Converts an Arrhenius object to ArrheniusEP + + If setting alpha, you need to also input dHrxn, which must be given + in J/mol (and vise versa). + """ + + if (bool(alpha) ^ bool(dHrxn)): + raise Exception('If you set alpha or dHrxn in toArrheniusEP, '\ + 'you need to set the other value to non-zero.') + self.changeT0(1) + aep = ArrheniusEP(A = self.A, + n = self.n, + alpha = alpha, + E0 = (self.Ea.value_si-alpha*dHrxn,'J/mol'), + Tmin = self.Tmin, + Tmax = self.Tmax, + Pmin = self.Pmin, + Pmax = self.Pmax, + comment = self.comment) + return aep ################################################################################ cdef class ArrheniusEP(KineticsModel): @@ -367,6 +388,8 @@ cdef class ArrheniusEP(KineticsModel): T0 = (1,"K"), Tmin = self.Tmin, Tmax = self.Tmax, + Pmin = self.Pmin, + Pmax = self.Pmax, comment = self.comment, ) diff --git a/rmgpy/kinetics/arrheniusTest.py b/rmgpy/kinetics/arrheniusTest.py index c7108f0856..8f0c097062 100644 --- a/rmgpy/kinetics/arrheniusTest.py +++ b/rmgpy/kinetics/arrheniusTest.py @@ -217,6 +217,30 @@ def test_toCanteraKinetics(self): self.assertAlmostEqual(ctArrhenius.temperature_exponent, 0.5) self.assertAlmostEqual(ctArrhenius.activation_energy, 41.84e6) + def test_toArrheniusEP(self): + """ + Tests that the Arrhenius object can be converted to ArrheniusEP + """ + arrRate = self.arrhenius.getRateCoefficient(500) + arrEP = self.arrhenius.toArrheniusEP() + arrEPRate = arrEP.getRateCoefficient(500,10) # the second number should not matter + self.assertAlmostEqual(arrRate,arrEPRate) + + def test_toArrheniusEP_with_alpha_and_Hrxn(self): + """ + Tests that the Arrhenius object can be converted to ArrheniusEP given parameters + """ + hrxn = 5 + arrRate = self.arrhenius.getRateCoefficient(500) + arrEP = self.arrhenius.toArrheniusEP(alpha=1, dHrxn=hrxn) + self.assertAlmostEqual(1.,arrEP.alpha.value_si) + arrEPRate = arrEP.getRateCoefficient(500,hrxn) + self.assertAlmostEqual(arrRate,arrEPRate) + + def test_toArrheniusEP_throws_error_with_just_alpha(self): + with self.assertRaises(Exception): + self.arrhenius.toArrheniusEP(alpha=1) + ################################################################################ class TestArrheniusEP(unittest.TestCase):