The variational principle

Quantum Chemistry

On the previous page we computed the energy of the H-atom trial wavefunction at five values of , and the row came out lowest at exactly the textbook ground-state energy. That wasn't a coincidence. It was the variational principle, the single most important idea in computational quantum chemistry, doing what it always does. This page makes the principle the program's job — instead of sampling a few values of by hand, the program finds the optimum.


The principle

For any normalized trial wavefunction , the expectation value of the Hamiltonian is an upper bound on the exact ground-state energy:

The proof is one line. Expand in the eigenstates of : , with and . Then

where the last step uses normalization . Equality holds only when for every , i.e., when the trial wavefunction is the exact ground state. Otherwise the energy is strictly above .

The implication is the engine of every method we build. Pick a family of trial wavefunctions parametrized by some knobs. Evaluate the energy for any setting of the knobs and you get an upper bound on the ground-state energy. Find the setting that minimizes the energy and you get the tightest upper bound the family can produce. Make the family richer, you get a tighter bound. The method is correct in the sense that more effort never makes the answer worse.


For our 1s Slater family

The trial family on this page is parametrized by a single number: the orbital exponent . The energy as a function of is the parabola

Differentiate, set the derivative to zero, solve:

The minimum is at and the energy there is Hartree, which happens to be the exact ground-state energy of hydrogen. That's because the exact ground state of the H atom is a 1s Slater orbital with — the truth lives inside our trial family. When that happens, the variational minimum doesn't just bound the ground-state energy; it equals it.

This is the trivial case. The non-trivial case is when the trial family doesn't contain the exact ground state. Then the minimum is strictly higher than , and the only way to improve is to enrich the family. We'll see exactly that on the next page when we switch from Slater orbitals to a finite-Gaussian basis.


The code (new this page)

On the previous page the program just evaluated at five hand-picked values. This page hands the minimization to scipy.optimize.minimize_scalar and asks for the optimum.

from scipy.optimize import minimize_scalar


def optimise_hydrogen():
    """Find the zeta that minimizes the trial energy.

    Returns (zeta_opt, E_opt). For the H atom in the 1s Slater family the
    answer is exactly zeta = 1, E = -0.5 Hartree, because the exact ground
    state IS a 1s Slater orbital with zeta = 1.
    """
    result = minimize_scalar(hydrogen_energy, bracket=(0.5, 1.5))
    return result.x, result.fun

scipy.optimize.minimize_scalar takes a callable and a bracket — three points known to enclose the minimum. We hand it hydrogen_energy and a bracket that contains . It returns a result object with the optimal in .x and the minimum energy in .fun. For this one-dimensional convex problem the minimization is trivial; we'll need much heavier machinery once the trial space gets bigger.


Run it

Energy as a function of zeta (the variational principle in action):
  zeta = 0.50    E = -0.375000 Hartree
  zeta = 0.80    E = -0.480000 Hartree
  zeta = 1.00    E = -0.500000 Hartree
  zeta = 1.20    E = -0.480000 Hartree
  zeta = 2.00    E = +0.000000 Hartree

Variational minimum: zeta = 1.000000    E = -0.500000 Hartree
Exact ground state:                     E = -0.500000 Hartree

Two things to confirm. (1) The five-row sweep is unchanged from the previous page — every row is still an upper bound on . (2) The minimization lands on and , matching the analytic answer. The computer found the optimum the same way we did with calculus.


The full file

"""qc.py — Computational QC from scratch.
Step 2: find the variationally optimal energy by minimizing over zeta.
"""

from scipy.optimize import minimize_scalar


def kinetic_1s(zeta):
    """<1s|T|1s> for a normalized 1s Slater orbital with exponent zeta."""
    return 0.5 * zeta ** 2


def nuclear_attraction_1s(zeta):
    """<1s|V|1s> for the same orbital, V = -1/r centred on the nucleus."""
    return -zeta


def hydrogen_energy(zeta):
    """Total energy E = T + V for the trial wavefunction."""
    return kinetic_1s(zeta) + nuclear_attraction_1s(zeta)


def optimise_hydrogen():
    """Find the zeta that minimizes the trial energy."""
    result = minimize_scalar(hydrogen_energy, bracket=(0.5, 1.5))
    return result.x, result.fun


if __name__ == "__main__":
    print("Energy as a function of zeta (the variational principle in action):")
    for zeta in (0.5, 0.8, 1.0, 1.2, 2.0):
        E = hydrogen_energy(zeta)
        print(f"  zeta = {zeta:>4.2f}    E = {E:>+.6f} Hartree")

    print()

    zeta_opt, E_opt = optimise_hydrogen()
    print(f"Variational minimum: zeta = {zeta_opt:.6f}    E = {E_opt:+.6f} Hartree")
    print(f"Exact ground state:                     E = {-0.5:+.6f} Hartree")

Why is the variational principle even true?

Because the Hamiltonian is Hermitian and bounded below. A Hermitian operator has a complete orthonormal eigenbasis with real eigenvalues; bounded below means there's a smallest one, . Any state vector decomposes into that eigenbasis, and the expectation value is the weighted average of the eigenvalues — and the average of a list of numbers is always at least the smallest number on the list. That's the whole proof. No quantum mechanics specific to the structure of H = T + V; just spectral theory.

Does the principle work for excited states?

Almost. The basic principle bounds the lowest eigenvalue, full stop. To bound the k-th excited state, you need a trial wavefunction orthogonal to the lower k eigenstates, and then the variational energy bounds from above. The Ritz variational method generalizes this to find approximate excited states by diagonalizing H in a finite trial subspace. The eigenvalues are upper bounds on the corresponding exact eigenvalues, in order. We won't use this for ground-state Hartree-Fock, but it's the same idea applied to the whole spectrum at once.

If the principle gives an upper bound, why don't we always get the exact answer?

Because the trial family rarely contains the exact ground state. For hydrogen with 1s Slater orbitals it does (lucky us). For every other system in this series it won't. The 1s STO-3G basis on the next page is a finite-Gaussian approximation to a Slater orbital — not exact. The H2 calculation on the final page uses a finite basis on each atom, no electron correlation past the mean-field, no relativistic corrections. The variational principle still applies; the answer it produces is a strict upper bound, not the truth. Tightening the bound is what the rest of computational quantum chemistry is about.