---
title: "Build a Self-Consistent Hydrogen Molecule Interactive Lab | Sandbox Physics"
description: "How can an electron density agree with the field it creates? Start with a trial density, calculate its mean field, and solve for new orbitals."
canonical_url: "https://sandboxphysics.com/labs/h2-self-consistent-field/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/h2-self-consistent-field/"
---

FR13-A · Electrons determine their own field

# Build a Self-Consistent Hydrogen Molecule

**How can an electron density agree with the field it creates?** Start with a trial density, calculate its mean field, and solve for new orbitals. Repeat until the density changes negligibly and agrees with the field. This finds a self-consistent Hartree–Fock state; its energy still depends on the allowed orbitals.

Pull the two nuclei apart and follow the density as a Hartree–Fock calculation settles. Replay its actual iterations and see how the total energy and self-consistency residual change.

> Interactive simulation: open this page in a web browser to change the parameters and run the model.

Model assumptions

The fixed-nuclei hydrogen molecule uses two contracted STO-3G atomic orbitals. Browser calculations include nuclear repulsion and solve the electronic problem at the chosen separation. Iteration playback shows a numerical algorithm, not the passage of physical time. The density cloud is a three-dimensional density visualization with enlarged nuclei; its brightness is scaled for visibility.

Calculated in your browser · STO-3G

## One density, one self-consistency test

Total energy Residual

Current AO density matrix

$P=\begin{pmatrix}0.603&0.603\\0.603&0.603\end{pmatrix}$

A changing density changes the Fock operator. The residual measures whether the two agree.

Units, density and calculation details

$\operatorname{Tr}(PS)=2$

All total energies include nuclear repulsion. FCI solves the same finite Hamiltonian as HF. The saved calculation includes its geometry, method, density matrices and numerical diagnostics.

The logarithmic plot displays residuals below the following level at that floor; the numerical readout retains the calculated value. $10^{-15}$

[Learn how the calculation works, from orbitals to a broken bond](https://sandboxphysics.com/stories/molecular-electronic/)

Physics tutorial

## Build a Self-Consistent Hydrogen Molecule

**Background** In Hartree–Fock theory, electrons move in a mean field built from the occupied orbitals. Changing an orbital changes that field, so a single diagonalization is usually only the beginning.

**Why it matters** Watching the actual density and residual explains what a converged calculation has achieved.

Start with the essentials

- **Focus question**: How can an electron density agree with the field it creates?
- **One-sentence intuition**: Self-consistency means the occupied orbitals agree with the mean field generated by their own density.

### Core mathematical model

#### Solve in a nonorthogonal atomic basis

$$
FC=SC\varepsilon,\qquad P_{\mu\nu}=2\sum_{i\in\mathrm{occ}}C_{\mu i}C_{\nu i}
$$

The overlap matrix accounts for atomic orbitals that overlap in space. Two electrons occupy each restricted spatial orbital.

#### Check whether density and field agree

$$
r=\tfrac12\lVert FPS-SPF\rVert_{\mathrm F},\qquad N=\operatorname{Tr}(PS)=2
$$

The residual is the root-mean-square matrix commutator for this two-orbital basis. It vanishes at self-consistency. The overlap-weighted trace counts electrons.

### Common difficulties

#### Convergence and accuracy

**Typical misconception** A tiny residual means the molecular energy is exact.

**Better mental model** The residual checks self-consistency inside the chosen Hartree–Fock model. Missing configurations and basis functions still limit the answer.

### Run the experiment

1. 01

   #### Predict before stretching

   Choose Near the energy minimum, then Correlation grows. Say what you expect the density and the energy difference to do before changing the preset.

   **What to observe:** The molecular density separates into two lobes, and the restricted description loses accuracy as the bond stretches.

2. 02

   #### Replay a numerical decision

   Press Replay iterations, then move the iteration slider. Compare an uneven initial guess with a nearly symmetric guess.

   **What to observe:** Different guesses take different paths. The converged restricted density agrees when the same solution is reached.

3. 03

   #### Save a reproducible comparison

   Use Save calculation at two separations. Compare the saved basis, geometry, density matrices and total energies.

   **What to observe:** Every record identifies the finite electronic model. Comparing it with a larger basis tests a separate source of error.

Physical conclusion

A self-consistent density solves a defined approximation; compare the approximation with an independent reference.

## Related experiments and articles

Molecular electrons and breaking bonds · Reading path

### Orbitals, self-consistency, correlation and dissociation

Articles on this path that use this experiment, followed by the other experiments they suggest.

1. [Article **Choosing an orbital for one hydrogen electron**](https://sandboxphysics.com/stories/molecular-electronic/variational-orbitals/)
2. [Article **Turning a molecule into a small matrix problem**](https://sandboxphysics.com/stories/molecular-electronic/basis-and-integrals/)
3. [Article **Making the density and its field agree**](https://sandboxphysics.com/stories/molecular-electronic/self-consistent-field/)

Quantum & fields · Starter path

## Start from a single measurement

Predict an outcome, then count what the measurements actually give. The path starts with one qubit and moves on to wave packets, bound states and two-photon interference.

[Start here → **Quantum State & Born Measurement** Predict a probability, turn the analyzer, then compare your prediction with the measured frequency over many shots. Observe · 15 min](https://sandboxphysics.com/labs/qubit-state/)

1. [1 Quantum State & Born Measurement](https://sandboxphysics.com/labs/qubit-state/)
2. [2 Stern–Gerlach Sequence](https://sandboxphysics.com/labs/stern-gerlach-sequence/)
3. [3 Wave Packet & Uncertainty](https://sandboxphysics.com/labs/wave-packet-uncertainty/)
4. [4 Quantum Harmonic Oscillator](https://sandboxphysics.com/labs/quantum-harmonic-oscillator/)
5. [5 Which Path & Quantum Eraser](https://sandboxphysics.com/labs/quantum-eraser/)
6. [6 Hong–Ou–Mandel Two-Photon Interference](https://sandboxphysics.com/labs/hong-ou-mandel/)

[View the full path →](https://sandboxphysics.com/topics/quantum/#starter-path)
