This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/hf/density

Densities, orbital spaces and the SCF error

The SCF state is a density matrix. For a closed shell it is the total density D = 2 C_occ C_occ^T, the convention PySCF's make_rdm1 uses; for UHF and ROHF it is one density per spin, Da = Ca_occ Ca_occ^T and Db = Cb_occ Cb_occ^T. The J/K stage reads them stacked as one array D[ndens, n, n]; the kernels below that work on one matrix take and return [n, n] (or [m, m] in the orthonormal basis).

The orbitals come from the eigenvectors V of F' = X^T F X, so an occupied orbital is c_k = X V[:, k] and

D = w sum_(k occupied) (X V[:, k]) (X V[:, k])^T,       w = 2 or 1.

Every kernel returns a fresh array. A loop that calls them each iteration runs in the memory of one iteration: a compiled loop frees what an iteration allocated and no variable holds.

Checks a converged density must pass, with N electrons in it and w its occupation (2 for a closed-shell total density, 1 for a spin density):

  • Tr(D S) = N: the electron count.
  • D S D = w D: D S / w is a projector, which says the density comes from orthonormal occupied orbitals.
  • F D S - S D F = 0: the density commutes with the Fock matrix (in the S metric), which is the SCF stationarity condition. den_commutator forms the same commutator in the orthonormal basis, F' P' - P' F' with P' = X^T S D S X, which is what DIIS extrapolates on.

The energy of a density and the Fock matrices built from it is

E = E_nuc + (1/2) sum_d Tr(D_d (H + F_d))

for both conventions: with the total density and F = H + J - K/2 it is the RHF energy, and with spin densities and F_s = H + J - K_s it is the UHF energy.

<S^2> of a UHF determinant is

<S^2> = ((Na - Nb)/2)^2 + (Na + Nb)/2 - Tr(Da S Db S),

where the trace counts how far the alpha and beta orbitals are from being the same; it is Nb (and <S^2> = S(S+1)) when every beta orbital is also an alpha one.

Used with import hf.density.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 51–276