The textbook route writes (S=LL^T) and diagonalises (L^{-1}HL^{-T}). With 37 nearly parallel Gaussians the smallest eigenvalues of (S) are far below double precision relative to the largest; the factorisation either fails or returns noise.
Diagonalise the overlap, (S\,u_i=s_iu_i). Keep only the directions with (s_i>\eta\,s_{\max}) ((\eta=10^{-12})) and form
[ X=\big[u_i/\sqrt{s_i}\big]_{\text{kept}},\qquad X^TSX=1. ]
Then solve the ordinary symmetric problem ((X^THX)\,d=E\,d) and set (c=Xd), which satisfies
(c^TSc=1). Dropping a direction removes one function from the variational space: the result is still an upper
bound, only for a slightly smaller space. This is the whole of src/linalg/gep.cpp.
The number of kept directions is a diagnostic: if it falls far below (n), adding functions no longer helps and only the ranges can.
A fit needs (\partial M/\partial\theta). Differentiate ((H-ES)c=0) and multiply from the left by (c^T). The term with (\partial c) vanishes because (c^T(H-ES)=0), so, since the basis (hence (S)) does not depend on (\theta),
[ \boxed{\frac{\partial E}{\partial\theta}=c^T\frac{\partial H}{\partial\theta}c} . ]
One diagonalisation gives all derivatives; no finite differences are needed.
In the first spin mode the mass is (M=m_1+m_2+E+c^TWc), where (W) (spin–orbit and tensor) is treated in first
order. Then the eigenvector’s derivative matters. Expanding in the other eigenvectors (c_m) (first-order
perturbation theory),
[ \partial c_k=\sum_{m\ne k}c_m\,\frac{c_m^T(\partial H)\,c_k}{E_k-E_m},\qquad \partial M=\partial(m_1+m_2)+c^T\partial Hc+c^T\partial Wc+2\,c^TW\,\partial c . ]
(\partial H/\partial\theta) itself is built alongside (H) by forward-mode automatic differentiation of the scalar prefactors (code).
Between two parameter points levels can cross. A level is followed by the largest overlap (\lvert c_{\rm new}^TS\,c_{\rm ref}\rvert) with its reference vector. In a coupled channel such as ({}^3S_1!-!{}^3D_1) a datum names the dominant partial wave, and the (n)-th level dominated by it is chosen.
Every printed state comes with the norm (c^TSc=1), the probability of each partial wave, the number of radial nodes (which must equal (n) in an uncoupled channel) and the change under basis doubling.