Skip to content

Commit

Permalink
add energy
Browse files Browse the repository at this point in the history
  • Loading branch information
RichRick1 committed Mar 22, 2024
1 parent bb2755d commit 8278a4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qctools/hydrogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'.")
18 changes: 17 additions & 1 deletion tests/test_hydrogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)

0 comments on commit 8278a4f

Please sign in to comment.