|
37 | 37 | import numpy as np |
38 | 38 |
|
39 | 39 | import rmgpy.constants as constants |
40 | | -from rmgpy.kinetics.arrhenius import Arrhenius, ArrheniusEP, PDepArrhenius, MultiArrhenius, MultiPDepArrhenius |
| 40 | +from rmgpy.kinetics.arrhenius import Arrhenius, ArrheniusEP, ArrheniusBM, PDepArrhenius, MultiArrhenius, MultiPDepArrhenius |
| 41 | +from rmgpy.molecule.molecule import Molecule |
| 42 | +from rmgpy.reaction import Reaction |
| 43 | +from rmgpy.species import Species |
| 44 | +from rmgpy.thermo import NASA, NASAPolynomial |
41 | 45 |
|
42 | 46 |
|
43 | 47 | ################################################################################ |
@@ -404,6 +408,129 @@ def test_change_rate(self): |
404 | 408 | self.assertAlmostEqual(2 * kexp, kact, delta=1e-6 * kexp) |
405 | 409 |
|
406 | 410 |
|
| 411 | +################################################################################ |
| 412 | + |
| 413 | +class TestArrheniusBM(unittest.TestCase): |
| 414 | + """ |
| 415 | + Contains unit tests of the :class:`ArrheniusBM` class. |
| 416 | + """ |
| 417 | + |
| 418 | + def setUp(self): |
| 419 | + """ |
| 420 | + A function run before each unit test in this class. |
| 421 | + """ |
| 422 | + self.A = 8.00037e+12 |
| 423 | + self.n = 0.391734 |
| 424 | + self.w0 = 798000 |
| 425 | + self.E0 = 115905 |
| 426 | + self.Tmin = 300. |
| 427 | + self.Tmax = 2000. |
| 428 | + self.comment = 'rxn001084' |
| 429 | + self.arrhenius_bm = ArrheniusBM( |
| 430 | + A=(self.A, "s^-1"), |
| 431 | + n=self.n, |
| 432 | + w0=(self.w0, 'J/mol'), |
| 433 | + E0=(self.E0, "J/mol"), |
| 434 | + Tmin=(self.Tmin, "K"), |
| 435 | + Tmax=(self.Tmax, "K"), |
| 436 | + comment=self.comment, |
| 437 | + ) |
| 438 | + |
| 439 | + self.rsmi = 'NC(=NC=O)O' |
| 440 | + self.psmi = 'O=CNC(=O)N' |
| 441 | + self.arrhenius = Arrhenius(A=(8.00037e+12,'s^-1'), |
| 442 | + n=0.391734, |
| 443 | + Ea=(94.5149,'kJ/mol'), |
| 444 | + T0=(1,'K'), |
| 445 | + Tmin=(300,'K'), |
| 446 | + Tmax=(2000,'K'), |
| 447 | + comment="""Fitted to 50 data points; dA = *|/ 1.18377, dn = +|- 0.0223855, dEa = +|- 0.115431 kJ/mol""" |
| 448 | + ) |
| 449 | + |
| 450 | + self.r_thermo = NASA(polynomials=[ |
| 451 | + NASAPolynomial(coeffs=[3.90453,0.0068491,0.000125755,-2.92973e-07,2.12971e-10,-45444.2,10.0669], Tmin=(10,'K'), Tmax=(433.425,'K')), |
| 452 | + NASAPolynomial(coeffs=[2.09778,0.0367646,-2.36023e-05,7.24527e-09,-8.51275e-13,-45412,15.8381], Tmin=(433.425,'K'), Tmax=(3000,'K'))], |
| 453 | + Tmin=(10,'K'), Tmax=(3000,'K'), E0=(-377.851,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(232.805,'J/(mol*K)'), |
| 454 | + comment="""Thermo library: Spiekermann_refining_elementary_reactions""" |
| 455 | + ) |
| 456 | + self.p_thermo = NASA(polynomials=[ |
| 457 | + NASAPolynomial(coeffs=[3.88423,0.00825528,0.000133399,-3.31802e-07,2.52823e-10,-51045.1,10.3937], Tmin=(10,'K'), Tmax=(428.701,'K')), |
| 458 | + NASAPolynomial(coeffs=[2.89294,0.0351772,-2.26349e-05,7.00331e-09,-8.2982e-13,-51122.5,12.4424], Tmin=(428.701,'K'), Tmax=(3000,'K'))], |
| 459 | + Tmin=(10,'K'), Tmax=(3000,'K'), E0=(-424.419,'kJ/mol'), Cp0=(33.2579,'J/(mol*K)'), CpInf=(232.805,'J/(mol*K)'), |
| 460 | + comment="""Thermo library: Spiekermann_refining_elementary_reactions""" |
| 461 | + ) |
| 462 | + |
| 463 | + def test_a_factor(self): |
| 464 | + """ |
| 465 | + Test that the ArrheniusBM A property was properly set. |
| 466 | + """ |
| 467 | + self.assertAlmostEqual(self.arrhenius_bm.A.value_si, self.A, delta=1e0) |
| 468 | + |
| 469 | + def test_n(self): |
| 470 | + """ |
| 471 | + Test that the ArrheniusBM n property was properly set. |
| 472 | + """ |
| 473 | + self.assertAlmostEqual(self.arrhenius_bm.n.value_si, self.n, 6) |
| 474 | + |
| 475 | + def test_w0(self): |
| 476 | + """ |
| 477 | + Test that the ArrheniusBM w0 property was properly set. |
| 478 | + """ |
| 479 | + self.assertAlmostEqual(self.arrhenius_bm.w0.value_si, self.w0, 6) |
| 480 | + |
| 481 | + def test_e0(self): |
| 482 | + """ |
| 483 | + Test that the ArrheniusBM E0 property was properly set. |
| 484 | + """ |
| 485 | + self.assertAlmostEqual(self.arrhenius_bm.E0.value_si, self.E0, 6) |
| 486 | + |
| 487 | + def test_temperature_min(self): |
| 488 | + """ |
| 489 | + Test that the ArrheniusBM Tmin property was properly set. |
| 490 | + """ |
| 491 | + self.assertAlmostEqual(self.arrhenius_bm.Tmin.value_si, self.Tmin, 6) |
| 492 | + |
| 493 | + def test_temperature_max(self): |
| 494 | + """ |
| 495 | + Test that the ArrheniusBM Tmax property was properly set. |
| 496 | + """ |
| 497 | + self.assertAlmostEqual(self.arrhenius_bm.Tmax.value_si, self.Tmax, 6) |
| 498 | + |
| 499 | + def test_is_temperature_valid(self): |
| 500 | + """ |
| 501 | + Test the ArrheniusBM.is_temperature_valid() method. |
| 502 | + """ |
| 503 | + Tdata = np.array([200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) |
| 504 | + validdata = np.array([False, True, True, True, True, True, True, True, True, True], np.bool) |
| 505 | + for T, valid in zip(Tdata, validdata): |
| 506 | + valid0 = self.arrhenius_bm.is_temperature_valid(T) |
| 507 | + self.assertEqual(valid0, valid) |
| 508 | + |
| 509 | + def test_fit_to_data(self): |
| 510 | + """ |
| 511 | + Test the ArrheniusBM.fit_to_data() method. |
| 512 | + """ |
| 513 | + reactant = Molecule(smiles=self.rsmi) |
| 514 | + product = Molecule(smiles=self.psmi) |
| 515 | + reaction = Reaction(reactants=[Species(molecule=[reactant], thermo=self.r_thermo,)], |
| 516 | + products=[Species(molecule=[product], thermo=self.p_thermo)], |
| 517 | + kinetics=self.arrhenius, |
| 518 | + ) |
| 519 | + |
| 520 | + arrhenius_bm = ArrheniusBM().fit_to_reactions([reaction], w0=self.w0) |
| 521 | + self.assertAlmostEqual(arrhenius_bm.A.value_si, self.arrhenius_bm.A.value_si, delta=1.5e1) |
| 522 | + self.assertAlmostEqual(arrhenius_bm.n.value_si, self.arrhenius_bm.n.value_si, 1, 4) |
| 523 | + self.assertAlmostEqual(arrhenius_bm.E0.value_si, self.arrhenius_bm.E0.value_si, 1) |
| 524 | + |
| 525 | + def test_get_activation_energy(self): |
| 526 | + """ |
| 527 | + Test the ArrheniusBM.get_activation_energy() method. |
| 528 | + """ |
| 529 | + Hrxn = -44000 # J/mol |
| 530 | + Ea = self.arrhenius_bm.get_activation_energy(Hrxn) |
| 531 | + self.assertAlmostEqual(Ea, 95074, delta=1e1) |
| 532 | + |
| 533 | + |
407 | 534 | ################################################################################ |
408 | 535 |
|
409 | 536 | class TestPDepArrhenius(unittest.TestCase): |
|
0 commit comments