“Know how to solve every problem that has been solved.” “What I cannot create, I do not understand.” — Richard Feynman

A PySCF tutorial, taught by the diff

Quantum Chemistry

PySCF is built so that the basic quantum-chemistry calculations differ from one another by almost nothing — define a molecule, then bolt a method onto it with the same .kernel() verb every time. That makes it a perfect subject for a dictionary of programs: each step below changes one line or adds one method, and the diff is the lesson. Every program is complete and runnable; every number in the output panels is what PySCF actually printed when I ran it (water, run on your machine in seconds).

The chain goes: build a molecule → Hartree-Fock → change the basis → MP2 → CCSD → DFT. Step through with the arrows; changed lines are marked . Hover a line with a left-bar for its rationale.

1 / 6
Define a molecule
starting point
from pyscf import gto
 
mol = gto.M(
atom="O 0 0 0; H 0 -0.757 0.587; H 0 0.757 0.587",
basis="sto-3g",
)
 
print("electrons:", mol.nelectron)
print("basis functions:", mol.nao)
print(f"nuclear repulsion: {mol.energy_nuc():.6f} Ha")
the starting point
Everything starts with a Mole object: geometry plus a basis set. gto.M builds it in one call. Before any quantum chemistry, the molecule already knows concrete facts — how many electrons it has, how many basis functions span its orbitals, and the classical nucleus-nucleus repulsion. Those are the fixed scaffolding every later method sits on.
hover a marked line (left bar) for its rationale
what it prints
electrons: 10
basis functions: 7
nuclear repulsion: 9.188258 Ha

Reading the energies

Three things the numbers teach, none of which needs you to trust me — they're in the output panels:

Stated as a citeable, falsifiable claim: increasing the basis-set size lowers (or holds) the Hartree-Fock energy, because HF is variational in the basis. The experiment is steps 2→3 above; it would be falsified by a basis enlargement that raised the RHF energy, which the variational principle forbids for a properly nested basis.

Read next