rlaplaza and crew at the IIQ in Seville

SCF in Practice

SCF in Practice

This post is a short, package-agnostic primer on the self-consistent field (SCF) procedure used in routine Hartree–Fock (HF) and Kohn–Sham DFT calculations. The goal is basic intuition: what the loop does, what drives the cost (integrals vs diagonalization, disk vs RAM), how basis sets, XC grids, and implicit solvent enter, how jobs are started and converged, and what gradients and Hessians cost relative to the energy. For program-specific keywords and failure recipes, see the ORCA and Gaussian guides.

What the SCF loop is

In HF and DFT, the electronic energy depends on the occupied molecular orbitals (or equivalently the density matrix). Those orbitals come from diagonalizing an effective one-electron Hamiltonian—the Fock matrix in HF, the Kohn–Sham (KS) matrix in DFT—which itself depends on the density. The SCF procedure closes that loop:

  1. Start from an initial density (or orbital guess).
  2. Build the Fock/KS matrix from that density.
  3. Diagonalize (or otherwise update orbitals) to get a new density.
  4. Repeat until the density, energy, and orbital gradient stop changing within a chosen threshold.

Almost every downstream result—geometry steps, frequencies, and most molecular properties—assumes a converged SCF. A “finished” optimization with a poorly converged electronic structure is not trustworthy.

Basis functions: primitives, contractions, and how $N$ grows

Let $N$ be the number of contracted atomic basis functions in the calculation. That $N$ is the dimension of the Fock/KS and overlap matrices, and it is what appears in the familiar SCF scaling arguments below.

A primitive Gaussian-type orbital (GTO) is a single Gaussian radial factor times an angular factor. A contracted GTO (cGTO) is a fixed linear combination of several primitives that share the same center and angular momentum:

$$ \chi_\mu(\mathbf{r}) = \sum_{k} d_{k\mu}\, g_k(\mathbf{r}). $$

Production HF/DFT bases (def2, Pople, correlation-consistent, …) are almost always contracted: the contraction coefficients $d_{k\mu}$ are frozen, so the SCF works in a smaller space of $N$ cGTOs while each two-electron integral over cGTOs still expands into many primitive integrals. That is the usual efficiency trade-off for SCF: fewer variational degrees of freedom, more work per matrix element.

“Uncontracted” bases (closer to raw primitive GTOs) enlarge $N$ and are more common when radial flexibility matters for correlated wavefunction methods (MP2, CC, …), which need to describe dynamical correlation, not only the mean-field density. For everyday DFT/HF geometry work, contracted sets such as def2-SVP are the default.

How many functions per atom? A def2-SVP sketch

def2-SVP is a polarized valence double-$\zeta$ set. With spherical harmonics (5 $d$ and 7 $f$ functions), typical contracted sizes are:

Atom Electrons treated in the basis Contraction (primitives $\rightarrow$ cGTOs) Spherical $N$ per atom
H all (1) $(4s,1p)\rightarrow[2s,1p]$ 5
C all (6) $(7s,4p,1d)\rightarrow[3s,2p,1d]$ 14
Fe all (26) $(14s,9p,5d,1f)\rightarrow[5s,3p,2d,1f]$ 31
Au valence only (19); 60 in ECP $(7s,6p,5d,1f)\rightarrow[6s,3p,2d,1f]$ 32

Two takeaways:

So for a molecule, $N \approx \sum_{\text{atoms}} n_{\text{basis}}(Z)$, with $n_{\text{basis}}$ jumping at shells and dropping again when an ECP replaces the core.

Diffuse functions: anions vs cations

Standard polarized valence sets (def2-SVP, 6-31G(d), …) are tuned for neutral densities. Charge changes how spatially extended the electron cloud is, and the basis has to follow.

Cost: two-electron integrals vs Fock diagonalization

Each SCF cycle has two different kinds of work:

  1. Build the Fock/KS matrix — dominated by two-electron contributions (Coulomb, and exact exchange for HF/hybrids), plus the XC grid for DFT.
  2. Update orbitals — classically a generalized diagonalization of an $N \times N$ matrix, $$\mathbf{F}\,\mathbf{C} = \mathbf{S}\,\mathbf{C}\,\boldsymbol{\varepsilon},$$ which scales as $O(N^3)$.

Formally, AO two-electron integral work scales as $O(N^4)$ before screening. With density-based screening and locality, the effective Fock-build cost is often closer to $O(N^2)$–$O(N^3)$ for large molecules, but raising the basis quality still hurts: more functions per atom means denser, less local integrals and a heavier XC grid.

Which piece wins? For the system sizes typical in molecular DFT/HF (up to a few thousand basis functions), Fock/KS construction almost always dominates wall time. Diagonalization’s $O(N^3)$ only becomes competitive for very large $N$ or when integral engines and screening are extremely efficient. Hybrid functionals keep a large exact-exchange term, so they stay integral-heavy longer than pure GGAs.

Rules of thumb:

Numerical XC grids

In KS DFT, the exchange–correlation (XC) energy and potential are not computed as analytic AO integrals the way Coulomb and exact exchange are. Instead, the density (and its derivatives for GGAs and beyond) is sampled on a real-space grid—typically a union of atom-centered grids with radial and angular points—and the XC contribution is integrated numerically into the KS matrix every SCF cycle.

Practical consequences:

Implicit solvent in the SCF

Continuum solvation models (PCM, CPCM, SMD, COSMO, …) do not add explicit solvent molecules. They treat the solvent as a polarizable dielectric outside a molecular cavity. The solvent’s reaction field depends on the solute’s charge density, so it must be updated inside the SCF, not bolted on after a gas-phase calculation (unless you deliberately choose a non-self-consistent approximation).

In each cycle the workflow is conceptually:

  1. Build the usual vacuum Fock/KS pieces from the current density.
  2. From that density, compute the solute–solvent interaction (apparent surface charges on the cavity, or an equivalent reaction potential).
  3. Add the corresponding one-electron operator to $\mathbf{F}$ / the KS matrix.
  4. Obtain a new density and repeat until both the electronic structure and the reaction field are consistent.

Consequences for practice:

Integrals in practice: conventional vs direct

Two classical strategies exist for the AO two-electron integrals $(\mu\nu\mid\lambda\sigma)$.

Conventional (in-disk) SCF

Compute the unique integrals once, write them to a scratch file, and read them back every SCF cycle to assemble $\mathbf{F}$.

Consequences on real HPC:

Direct SCF

Recompute screened integral batches every iteration instead of storing the full set. The bottleneck shifts to CPU and RAM:

Modern defaults lean toward direct (or semidirect) SCF once $N$ is large enough that the integral file would be huge or the filesystem would dominate. Whatever the mode, integral and grid accuracy must stay tighter than the SCF convergence threshold: you cannot converge the density below the noise in $\mathbf{F}$.

Initial guesses

The first density decides how hard the early SCF cycles will be. Common options:

A good guess often saves more wall time than raising the maximum number of cycles. A bad guess can send the SCF into oscillation between qualitatively different electronic structures.

Getting to convergence

Plain Roothaan–Hall iteration (build Fock/KS → diagonalize → repeat) frequently oscillates: each new density overcorrects the previous one. Production codes therefore accelerate and stabilize the update:

A practical order of operations: start from a sensible guess, let DIIS (the usual default) work, add damping or a level shift if the energy oscillates, and only then escalate to second-order or package-specific robust SCF modes. Tightening thresholds without fixing the underlying electronic-structure problem mostly burns cycles.

Analytical SCF gradients

Once the HF or DFT density is converged, nuclear gradients

$$ G_{A,\alpha} = \frac{\partial E}{\partial R_{A,\alpha}} $$

can be evaluated analytically. That is much cheaper than numerical differentiation, which would require on the order of $3N_{\mathrm{atoms}}$ extra energy calculations (or twice that for central differences).

An analytical SCF gradient is typically on the order of one extra SCF-like step after convergence. The main pieces are:

Cost still tracks basis-set size in the same broad way as the energy: larger $N$ means heavier derivative-integral and XC work. Gradients are also more sensitive to a loose SCF or a coarse XC grid than a rough single-point energy is—noisy forces slow or mislead geometry optimizations even when the energy looks “almost” converged.

Nuclear Hessians: how they are computed and why they matter

The nuclear Hessian is the matrix of second derivatives of the energy with respect to nuclear coordinates,

$$ H_{A\alpha,B\beta} = \frac{\partial^2 E}{\partial R_{A\alpha}\,\partial R_{B\beta}}. $$

It is what you diagonalize (after mass-weighting) to get vibrational frequencies and normal modes.

Why it matters in practice:

How they are computed:

Practical notes: Hessians inherit all SCF and grid sensitivity of the gradient, amplified—loose SCF thresholds or coarse XC grids produce noisy frequencies and spurious small imaginary modes. Always confirm that the electronic structure is tightly converged before trusting a frequency job.

Where to go next

For keyword-level SCF troubleshooting in the packages used in the group:

Previous post
Local Conda and VS Code Setup
Next post
Molecular Visualization with v, vmol, and xyzrender