A from-scratch density-functional theory (DFT) calculation of the helium
ground-state energy in Python, using only numpy and matplotlib. Every
numerical method — the radial Schrödinger solver, the Poisson solver for the
Hartree potential, the self-consistent-field (SCF) loop, and the
exchange–correlation functionals — is hand-written and commented, so each
line can be explained rather than treated as a black box.
Starting from nothing but the nuclear charge, the program climbs the standard ladder of approximations and reaches the local-density-approximation (LDA) answer of −2.83 Ha, against an exact value of −2.90 Ha.
All quantities are in atomic units (
📖 New here? Start with the User Guide. A step-by-step, plain-language walkthrough — how to run the program, what to enter, and how to read the results and the graphs. No coding background needed.
| Approximation | This work (Ha) | Reference (Ha) | Error vs exact |
|---|---|---|---|
| Self-consistent Hartree (≡ restricted Hartree–Fock) | −2.8616 | −2.86 | 0.042 |
| + Slater LDA exchange | −2.7236 | −2.72 | 0.180 |
| + Perdew–Zunger correlation (full LDA) | −2.8342 | −2.83 | 0.070 |
| Hartree–Fock (reference) | — | −2.8617 | 0.042 |
| Exact (non-relativistic) | — | −2.9037 | — |
Warm-up checks (single electron, bare nucleus, no electron–electron term):
| Check | This work (Ha) | Exact |
|---|---|---|
| Hydrogen 1s ( |
−0.499996 | −0.5 |
| He⁺ 1s ( |
−1.999937 | −2.0 ( |
With one electron, an atom is solvable by hand. With two, the electrons repel
each other, and the mutual repulsion makes the problem analytically unsolvable.
DFT sidesteps this by tracking the electron density
The radial Schrödinger equation for the spherically symmetric 1s state, with
1. Hydrogen-like radial solver (the core engine).
2. Hartree potential (electron-cloud repulsion).
The electrostatic repulsion of the cloud,
Validated against the exact hydrogen result
3. Self-consistent Hartree (≡ Hartree–Fock for the helium singlet).
The SCF loop solves
This equals restricted Hartree–Fock (−2.86), and that is correct: for a two-electron closed-shell singlet the self-interaction-removed Hartree potential coincides exactly with the RHF potential, because HF exchange only cancels the self-interaction — with one occupied orbital,
$(2J-K)\phi = J\phi$ .
4. LDA with Slater exchange.
Switch to the full two-electron density
5. Full LDA: + Perdew–Zunger correlation.
Add the Ceperley–Alder correlation in the Perdew–Zunger parametrisation, a
function of the Wigner–Seitz radius
SCF convergence — the three models converging; note that adding LDA exchange (orange) is less bound than Hartree/HF (blue), and correlation (green) pulls it back down:
Converged orbital and electron density (full LDA):
The effective potential and its pieces — the deep nuclear
dft-helium/
├── dft.py # the physics engine (grid, integrator, Numerov solver,
│ # root finder, Poisson solver, the three SCF variants)
├── helium_dft.ipynb # narrative notebook: explanation + demos + plots
├── tests/
│ └── test_dft.py # one pytest test per validation target
└── figures/ # publication figures (PNG + PDF) and the results table
├── fig1_scf_convergence.{png,pdf}
├── fig2_orbital_density.{png,pdf}
├── fig3_potentials.{png,pdf}
├── fig4_energy_comparison.{png,pdf}
└── results_table.{csv,tex}
The validated physics lives in dft.py; the notebook and the tests import the
same code, so what you read in the notebook is exactly what is tested.
Requirements: Python 3, numpy, matplotlib (plus pytest and jupyter to
run the tests and the notebook).
pip install numpy matplotlib pytest jupyterReproduce the numbers (fast):
import dft
r = dft.make_grid() # uniform radial grid, h=0.001, r_max=25 Bohr
print(dft.scf_no_xc(Z=2.0, r=r, verbose=False)["E"]) # -2.8616 (Hartree = HF)
print(dft.scf_lda_x (Z=2.0, r=r, verbose=False)["E"]) # -2.7236 (+ Slater exchange)
print(dft.scf_lda_xc(Z=2.0, r=r, verbose=False)["E"]) # -2.8342 (full LDA)Run the notebook top to bottom for the full narrative, all checks, and the figures:
jupyter nbconvert --to notebook --execute --inplace helium_dft.ipynbEvery stage has a test mirroring its target; run pytest -v:
| Test | Asserts |
|---|---|
test_integrator_known_value |
the Simpson integrator reproduces |
test_hydrogen_ground_state_energy |
|
test_hydrogen_ground_state_wavefunction |
|
test_helium_bare_nucleus_energy |
|
test_hartree_potential_hydrogen_analytic |
|
test_scf_hartree_equals_hf |
self-consistent Hartree |
test_scf_lda_slater_exchange_energy |
+ Slater exchange |
test_scf_full_lda_energy |
full LDA |
All 8 pass (tolerance ~$10^{-2}$ Ha on the SCF energies, ~$10^{-3}$ on the checks).
-
Grid: uniform,
$r = h, 2h, \dots, r_{\max}$ with$h = 0.001$ Bohr and$r_{\max} = 25$ Bohr (25,000 points). The grid starts at$r=h$ , not$0$ , to avoid the$1/r$ singularity. The fine step is needed to resolve the steep$e^{-2r}$ cusp of the$Z=2$ orbital. - Integration: composite Simpson's rule.
-
Eigenvalue search: scan for the lowest sign change of the extrapolated
$u(0)$ , then bisect; the SCF loops warm-start the search at the previous eigenvalue. -
SCF: linear potential mixing with
$w = 0.3$ ; the exchange/correlation runs ramp the interaction in from zero for a stable start.
- W. Kohn, L. J. Sham, Self-Consistent Equations Including Exchange and Correlation Effects, Phys. Rev. 140, A1133 (1965).
- D. M. Ceperley, B. J. Alder, Ground State of the Electron Gas by a Stochastic Method, Phys. Rev. Lett. 45, 566 (1980).
- J. P. Perdew, A. Zunger, Self-interaction correction to density-functional approximations for many-electron systems, Phys. Rev. B 23, 5048 (1981).
- C. L. Pekeris, Ground State of Two-Electron Atoms, Phys. Rev. 115, 1216 (1959). (exact non-relativistic value)
- E. Clementi, C. Roetti, Roothaan-Hartree-Fock Atomic Wavefunctions, At. Data Nucl. Data Tables 14, 177 (1974). (Hartree-Fock limit)
- J. M. Thijssen, Computational Physics, 2nd ed., Cambridge University Press (2007). (Numerov method)
Source code in this repository is released under the MIT License. The accompanying manuscript is shared under CC-BY 4.0.
If you use this code or its results, please cite the archived version:
Dehigaspitiyage Don, S. Y. (2026). A Real-Space Density-Functional Theory Program for the Ground-State Energy of the Helium Atom: Staged Construction, Validation, and the Self-Interaction Error. Zenodo. https://doi.org/10.5281/zenodo.20734925
A machine-readable CITATION.cff is included, so GitHub also shows a
"Cite this repository" button.



