3131This script contains unit tests of the :mod:`rmgpy.kinetics.surface` module.
3232"""
3333
34-
34+ import copy
35+ import pickle
3536import numpy as np
3637
3738from rmgpy .kinetics .surface import StickingCoefficient , SurfaceArrhenius , SurfaceChargeTransfer , SurfaceArrheniusBM
3839from rmgpy .species import Species
40+ from rmgpy .reaction import Reaction
3941from rmgpy .molecule import Molecule
4042import rmgpy .quantity as quantity
4143import rmgpy .constants as constants
44+ import rmgpy .thermo
4245
4346
4447class TestStickingCoefficient :
@@ -150,7 +153,6 @@ def test_pickle(self):
150153 Test that an StickingCoefficient object can be pickled and unpickled with no loss
151154 of information.
152155 """
153- import pickle
154156
155157 stick = pickle .loads (pickle .dumps (self .stick , - 1 ))
156158 assert abs (self .stick .A .value - stick .A .value ) < 1e0
@@ -213,7 +215,6 @@ def test_copy(self):
213215 Test that an StickingCoefficient object can be copied with deepcopy
214216 with no loss of information.
215217 """
216- import copy
217218
218219 stick = copy .deepcopy (self .stick )
219220 assert abs (self .stick .A .value - stick .A .value ) < 1e0
@@ -360,7 +361,6 @@ def test_pickle(self):
360361 Test that an SurfaceArrhenius object can be pickled and unpickled with no loss
361362 of information.
362363 """
363- import pickle
364364
365365 surfarr = pickle .loads (pickle .dumps (self .surfarr , - 1 ))
366366 assert abs (self .surfarr .A .value - surfarr .A .value ) < 1e0
@@ -423,7 +423,6 @@ def test_copy(self):
423423 Test that an SurfaceArrhenius object can be copied with deepcopy
424424 with no loss of information.
425425 """
426- import copy
427426
428427 surfarr = copy .deepcopy (self .surfarr )
429428 assert abs (self .surfarr .A .value - surfarr .A .value ) < 1e0
@@ -604,7 +603,6 @@ def test_pickle(self):
604603 Test that an SurfaceChargeTransfer object can be pickled and unpickled with no loss
605604 of information.
606605 """
607- import pickle
608606 surfchargerxn_reduction = pickle .loads (pickle .dumps (self .surfchargerxn_reduction , - 1 ))
609607 assert abs (self .surfchargerxn_reduction .A .value - surfchargerxn_reduction .A .value ) < 1e0
610608 assert self .surfchargerxn_reduction .A .units == surfchargerxn_reduction .A .units
@@ -651,7 +649,6 @@ def test_copy(self):
651649 Test that an SurfaceChargeTransfer object can be copied with deepcopy
652650 with no loss of information.
653651 """
654- import copy
655652 surfchargerxn_reduction = copy .deepcopy (self .surfchargerxn_reduction )
656653 assert abs (self .surfchargerxn_reduction .A .value - surfchargerxn_reduction .A .value ) < 1e0
657654 assert self .surfchargerxn_reduction .A .units == surfchargerxn_reduction .A .units
@@ -819,6 +816,48 @@ def setup_class(self):
819816 coverage_dependence = self .coverage_dependence ,
820817 )
821818
819+ self .reaction1 = Reaction ()
820+ X = Species ().from_adjacency_list ('1 X u0 p0 c0\n ' )
821+ OX = Species (smiles = 'O=*' )
822+ O2 = Species (smiles = '[O][O]' )
823+ X .thermo = rmgpy .thermo .NASA (
824+ polynomials = [
825+ rmgpy .thermo .NASAPolynomial (coeffs = [
826+ 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 ,
827+ 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 ], Tmin = (298.0 ,'K' ), Tmax = (1000.0 , 'K' )),
828+ rmgpy .thermo .NASAPolynomial (coeffs = [
829+ 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 ,
830+ 0.000000000E+00 , 0.000000000E+00 , 0.000000000E+00 ], Tmin = (1000.0 ,'K' ), Tmax = (3000.0 , 'K' )),
831+ ],
832+ Tmin = (298.0 , 'K' ),
833+ Tmax = (3000.0 , 'K' ),
834+ )
835+ OX .thermo = rmgpy .thermo .NASA (
836+ polynomials = [
837+ rmgpy .thermo .NASAPolynomial (coeffs = [- 2.94475701E-01 , 1.44162624E-02 , - 2.61322704E-05 , 2.19005957E-08 , - 6.98019420E-12 ,
838+ - 1.64619234E+04 , - 1.99445623E-01 ], Tmin = (298.0 , 'K' ), Tmax = (1000.0 , 'K' )),
839+ rmgpy .thermo .NASAPolynomial (coeffs = [2.90244691E+00 , - 3.38584457E-04 , 6.43372619E-07 , - 3.66326660E-10 , 6.90093884E-14 ,
840+ - 1.70497471E+04 , - 1.52559728E+01 ], Tmin = (1000.0 , 'K' ), Tmax = (2000.0 , 'K' )),
841+ ],
842+ Tmin = (298.0 , 'K' ),
843+ Tmax = (2000.0 , 'K' ),
844+ )
845+ O2 .thermo = rmgpy .thermo .NASA (
846+ polynomials = [rmgpy .thermo .NASAPolynomial (coeffs = [3.53732 ,- 0.00121571 ,5.31618e-06 ,- 4.89443e-09 ,1.45845e-12 ,- 1038.59 ,4.68368 ], Tmin = (100 ,'K' ), Tmax = (1074.56 ,'K' )),
847+ rmgpy .thermo .NASAPolynomial (coeffs = [3.15382 ,0.00167804 ,- 7.69971e-07 ,1.51275e-10 ,- 1.08782e-14 ,- 1040.82 ,6.16754 ], Tmin = (1074.56 ,'K' ), Tmax = (5000 ,'K' ))],
848+ Tmin = (100 ,'K' ),
849+ Tmax = (5000 ,'K' )
850+ )
851+ self .reaction1 .reactants = [O2 , X , X ]
852+ self .reaction1 .products = [OX , OX ]
853+ self .reaction1 .kinetics = rmgpy .kinetics .surface .SurfaceArrhenius (
854+ A = (1.89E21 , 'cm^5/(mol^2*s)' ),
855+ n = - 0.5 ,
856+ Ea = (0.0 , 'J/mol' ),
857+ Tmin = (200 , 'K' ),
858+ Tmax = (3000 , 'K' ),
859+ )
860+
822861
823862 def test_A (self ):
824863 """
@@ -896,7 +935,6 @@ def test_pickle(self):
896935 Test that a SurfaceArrheniusBM object can be pickled and unpickled with no loss
897936 of information.
898937 """
899- import pickle
900938
901939 surfarrBM = pickle .loads (pickle .dumps (self .surfarrBM , - 1 ))
902940 assert abs (self .surfarrBM .A .value - surfarrBM .A .value ) < 1e0
@@ -959,7 +997,6 @@ def test_copy(self):
959997 Test that an SurfaceArrheniusBM object can be copied with deepcopy
960998 with no loss of information.
961999 """
962- import copy
9631000
9641001 surfarrBM = copy .deepcopy (self .surfarrBM )
9651002 assert abs (self .surfarrBM .A .value - surfarrBM .A .value ) < 1e0
@@ -996,21 +1033,22 @@ def test_is_identical_to(self):
9961033 """
9971034 assert self .surfarrBM .is_identical_to (self .surfarrBM )
9981035
999- # def test_to_arrhenius(self):
1000- # """
1001- # Test that the SurfaceArrheniusBM.to_arrhenius method works
1002- # """
1003-
1004- # surface_charge_transfer = self.surfarr.to_surface_charge_transfer(2,-2)
1005- # assert isinstance(surface_charge_transfer, SurfaceChargeTransfer)
1006- # surface_charge_transfer0 = SurfaceChargeTransfer(
1007- # A = self.surfarr.A,
1008- # n = self.surfarr.n,
1009- # Ea = self.surfarr.Ea,
1010- # T0 = self.surfarr.T0,
1011- # Tmin = self.surfarr.Tmin,
1012- # Tmax = self.surfarr.Tmax,
1013- # electrons = -2,
1014- # V0 = (2,'V')
1015- # )
1016- # assert surface_charge_transfer.is_identical_to(surface_charge_transfer0)
1036+
1037+ def test_to_and_from_arrhenius (self ):
1038+ """Test going from SurfaceArrhenius to SurfaceArrheniusBM and back again"""
1039+
1040+ reaction1_BM = copy .deepcopy (self .reaction1 )
1041+ reaction1_BM .kinetics = rmgpy .kinetics .surface .SurfaceArrheniusBM ().fit_to_reactions ([self .reaction1 ], w0 = 1e6 )
1042+ return_arrhenius = reaction1_BM .kinetics .to_arrhenius (dHrxn = reaction1_BM .get_enthalpy_of_reaction (298 ))
1043+ assert return_arrhenius .is_similar_to (self .reaction1 .kinetics )
1044+
1045+ # not sure if .is_similar_to is wrong... because as the enthalpy of reaction changes
1046+ # assert self.reaction1.kinetics.is_similar_to(reaction1_BM.kinetics)
1047+ Ts = [500 , 1000 , 1500 , 2000 ]
1048+ for T in Ts :
1049+ k1 = self .reaction1 .kinetics .get_rate_coefficient (T )
1050+ dHrxn = reaction1_BM .get_enthalpy_of_reaction (T )
1051+ k2 = reaction1_BM .kinetics .get_rate_coefficient (T , dHrxn = dHrxn )
1052+ assert np .abs (np .log10 (k1 ) - np .log10 (k2 )) < 0.1
1053+
1054+
0 commit comments