From 1689be10a67243cd1231f9601e708141e7f2d1d7 Mon Sep 17 00:00:00 2001 From: davidfarinajr Date: Fri, 22 Jan 2021 20:59:42 -0500 Subject: [PATCH] added method and test for changing reference potential for surfaceChargeTransfer --- rmgpy/kinetics/surface.pxd | 2 ++ rmgpy/kinetics/surface.pyx | 11 +++++++++++ rmgpy/kinetics/surfaceTest.py | 22 +++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/rmgpy/kinetics/surface.pxd b/rmgpy/kinetics/surface.pxd index 6f96bbfdbf..07068f66af 100644 --- a/rmgpy/kinetics/surface.pxd +++ b/rmgpy/kinetics/surface.pxd @@ -91,6 +91,8 @@ cdef class SurfaceChargeTransfer(KineticsModel): cpdef change_t0(self, double T0) + cpdef change_v0(self, double V0) + cpdef fit_to_data(self, np.ndarray Tlist, np.ndarray klist, str kunits, double T0=?, np.ndarray weights=?, bint three_params=?) cpdef bint is_identical_to(self, KineticsModel other_kinetics) except -2 diff --git a/rmgpy/kinetics/surface.pyx b/rmgpy/kinetics/surface.pyx index f9a58776dd..2778944d92 100644 --- a/rmgpy/kinetics/surface.pyx +++ b/rmgpy/kinetics/surface.pyx @@ -684,6 +684,17 @@ cdef class SurfaceChargeTransfer(KineticsModel): self._A.value_si /= (self._T0.value_si / T0) ** self._n.value_si self._T0.value_si = T0 + cpdef change_v0(self, double V0): + """ + Changes the reference potential to `V0` in volts, and adjusts the + activation energy `Ea` accordingly. + """ + + if self._ne.value > 0: + self._Ea.value_si = self.get_activation_energy_from_potential(V0, non_negative=False) + + self._V0.value_si = V0 + cpdef fit_to_data(self, np.ndarray Tlist, np.ndarray klist, str kunits, double T0=1, np.ndarray weights=None, bint three_params=False): """ diff --git a/rmgpy/kinetics/surfaceTest.py b/rmgpy/kinetics/surfaceTest.py index dcc68e6c85..2f9bc70031 100644 --- a/rmgpy/kinetics/surfaceTest.py +++ b/rmgpy/kinetics/surfaceTest.py @@ -587,7 +587,6 @@ def test_get_activation_energy_from_potential(self): Ea = self.surfchargerxn_reduction.get_activation_energy_from_potential(V, False) self.assertAlmostEqual(self.surfchargerxn_oxidation.Ea.value_si, Ea, 6) - def test_get_rate_coefficient(self): """ Test that the SurfaceChargeTransfer.to_surface_arrhenius method works @@ -612,6 +611,27 @@ def test_get_rate_coefficient(self): self.assertAlmostEqual(k_oxidation,self.surfchargerxn_oxidation.get_rate_coefficient(T,V)) self.assertAlmostEqual(k_reduction,self.surfchargerxn_reduction.get_rate_coefficient(T,V)) + def test_change_v0(self): + + V0 = self.surfchargerxn_oxidation.V0.value_si + ne = self.surfchargerxn_oxidation.ne.value + for V in (V0 + 1, V0, V0 - 1, V0): + delta = V - self.surfchargerxn_oxidation.V0.value_si + V_i = self.surfchargerxn_oxidation.V0.value_si + Ea_i = self.surfchargerxn_oxidation.Ea.value_si + self.surfchargerxn_oxidation.change_v0(V) + self.assertEqual(self.surfchargerxn_oxidation.V0.value_si, V_i + delta) + self.assertAlmostEqual(self.surfchargerxn_oxidation.Ea.value_si, Ea_i - (ne * constants.F * delta), 6) + + V0 = self.surfchargerxn_reduction.V0.value_si + ne = self.surfchargerxn_reduction.ne.value + for V in (V0 + 1, V0, V0 - 1, V0): + delta = V - self.surfchargerxn_reduction.V0.value_si + V_i = self.surfchargerxn_reduction.V0.value_si + Ea_i = self.surfchargerxn_reduction.Ea.value_si + self.surfchargerxn_reduction.change_v0(V) + self.assertEqual(self.surfchargerxn_reduction.V0.value_si, V_i + delta) + self.assertAlmostEqual(self.surfchargerxn_reduction.Ea.value_si, Ea_i, 6) if __name__ == '__main__': unittest.main(testRunner=unittest.TextTestRunner(verbosity=2)) \ No newline at end of file