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/transform

Moving integrals from Cartesian to spherical functions

lib/hf/cart2sph builds M, the block-diagonal matrix whose column m holds the unit-Cartesian coefficients of spherical function m. The integral kernels produce everything in unit-Cartesian functions; this module moves the results into the spherical basis.

A one-electron matrix has one function on each side, so it picks up one M on each side:

X_sph[p, q] = sum_ab M[a, p] X[a, b] M[b, q],     X_sph = M^T X M

An electron repulsion integral (ij|kl) has four functions, so it picks up four:

G_sph[p, q, r, s] = sum_ijkl M[i, p] M[j, q] M[k, r] M[l, s] G[i, j, k, l]

Done as written, that last sum costs n^8. Done one index at a time (sum over l first, keep the result, then k, then j, then i) it costs four passes of n^5. Those are the quarter transformations of tr4_quarter.

Two forms each. The dense forms (tr2_dense, tr4_quarter) treat M as a full matrix and never look at the shell structure. The per-block forms (tr2_blocks, tr4_blocks) use the fact that M is zero between shells: a spherical function of shell a is built only from Cartesian components of shell a, so the spherical block of shells (a, b) comes from the Cartesian block of the same shells and nothing else. For the integrals, each shell quartet is read out of the packed vector, transformed with four small M_l blocks, and written back into the packed spherical vector. The per-block forms do far less arithmetic; the dense forms are simpler to trust. They share no loops, so agreement between them checks both.

All four take the transform-stage signature (X: Arr, M: Arr, shells: Arr) -> Arr, so a registry of them runs through sweep3_arr. The ERI forms take and return packed-8 vectors. The two tr2_back_* forms go the other way, M D M^T: a spherical density becomes the Cartesian one whose contraction with Cartesian integrals gives the same energy, which is what a Cartesian J/K build needs.

The tests hold the transforms to PySCF's own spherical integrals for water in 6-31G*, cc-pVDZ and def2-SVP, within 1e-13.

Used with import hf.transform, after lib/hf/basis, lib/hf/eri_store and lib/hf/cart2sph.

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 49–389