From 8278a4ffbec69e5da54d8e2e7c0c861535721f4a Mon Sep 17 00:00:00 2001 From: = Date: Fri, 22 Mar 2024 16:08:34 -0400 Subject: [PATCH] add energy --- qctools/hydrogen.py | 2 +- tests/test_hydrogen.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/qctools/hydrogen.py b/qctools/hydrogen.py index e3ba1a0..261ea2d 100644 --- a/qctools/hydrogen.py +++ b/qctools/hydrogen.py @@ -86,6 +86,6 @@ def calc_energy(n, Z=1, units='hartree'): elif units == 'eV': return E*27.2114 elif units == 'SI': - return E*4.3597482e-18 + return E*4.35974e-18 else: raise ValueError("Invalid units. Must be 'hartree', 'eV', or 'SI'.") \ No newline at end of file diff --git a/tests/test_hydrogen.py b/tests/test_hydrogen.py index 9e903c2..c79191f 100644 --- a/tests/test_hydrogen.py +++ b/tests/test_hydrogen.py @@ -47,4 +47,20 @@ def test_hydrogenic_wavefunction(): true_answer = np.array([0.+0.j, 0.+0.j, 0.+0.j, -0.+0.j, 0.00661248+0.j, 0.02022248+0.j, 0.+0.j, 0.0049428+0.j, 0.00040025+0.j, 0.01440961+0.j]) - np.testing.assert_allclose(res, true_answer, atol=1e-5, rtol=1e-3) \ No newline at end of file + np.testing.assert_allclose(res, true_answer, atol=1e-5, rtol=1e-3) + +def test_calc_energy(): + """ + testing calc_energy function + """ + E_h = calc_energy(1, Z=1, units='hartree') + E_h_true = -0.5 + np.testing.assert_allclose(E_h, E_h_true, rtol=1e-5, atol=1e-5) + + E_ev = calc_energy(1, Z=1, units='eV') + E_ev_true = -13.605693009 + np.testing.assert_allclose(E_ev, E_ev_true, rtol=1e-5, atol=1e-5) + + E_h = calc_energy(2, Z=1, units='SI') + E_h_true = -2.18e-18 + np.testing.assert_allclose(E_h, E_h_true, rtol=1e-5, atol=1e-5) \ No newline at end of file