qrunch.chemistry.qrackle.scf.orbital_rotation.orbital_rotation_utils
Backend-independent orbital rotations and stability analysis.
Functions
Find the lowest orbital Hessian eigenpairs in a compact occupied-virtual representation. |
|
|
Build elementary occupied-virtual rotations as stability trial vectors. |
|
Return eigenpairs with compact Ritz vectors expanded into generators, consuming the compact vectors. |
|
Gram-Schmidt orthonormalize a candidate against a basis under the Frobenius inner product. |
|
Do a spectral projection of an orthonormal-basis density onto the nearest rank N idempotent density. |
|
Return the natural orbitals as columns ordered by descending occupation. |
|
Project an antisymmetric generator onto the non-redundant occupied-virtual space. |
|
Assemble the orbital Hessian-vector product from a response Fock matrix. |
|
Return a human-readable diagnostic string for an orthonormal-basis density. |
|
Diagonalize the orbital Hessian in the subspace spanned by trial directions. |
|
Apply the orbital rotation to the density: \(D' = \exp(-X) D \exp(X)\). |
Classes
Lowest eigenpairs of the orbital Hessian from a subspace stability analysis. |
- class OrbitalHessianEigenpairs
Bases:
Generic[TSCFMatrix]Lowest eigenpairs of the orbital Hessian from a subspace stability analysis.
- Parameters:
eigenvalues – Lowest Hessian eigenvalues in ascending order.
eigenvectors – Corresponding unit-Frobenius-norm eigenvectors. The Davidson search returns compact occupied-virtual blocks; the single-shot analysis and
expand_compact_eigenpairs()return full antisymmetric generators in the orthonormal basis. The caller owns these and must free them. Expansion consumes its compact inputs.converged – Whether all requested Davidson pairs passed the residual test. Always true for a single-shot diagonalization in the supplied span.
- __init__(*, eigenvalues: list[float], eigenvectors: list[TSCFMatrix], converged: bool = True) None
- Parameters:
eigenvalues (list[float])
eigenvectors (list[TSCFMatrix])
converged (bool)
- Return type:
None
- converged: bool = True
- eigenvalues: list[float]
- eigenvectors: list[TSCFMatrix]
- davidson_hessian_lowest_compact_eigenpairs(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], hessian_vector_product: OrbitalHessianVectorProduct[TSCFMatrix], compact_representation: OccupiedVirtualCompactRepresentation[TSCFMatrix], preconditioner: OccupiedVirtualBlockPreconditioner[TSCFMatrix], starts: list[TSCFMatrix], number_of_eigenpairs: int, *, residual_tolerance: float = 1e-06, maximum_subspace_size: int = 100) OrbitalHessianEigenpairs[TSCFMatrix]
Find the lowest orbital Hessian eigenpairs in a compact occupied-virtual representation.
The compact starts are orthonormalized into a basis that is expanded with preconditioned residuals until the requested Ritz pairs converge. A Davidson expansion cannot leave the symmetry blocks spanned by the starts, and stops once the lowest Ritz pairs converge, even if other starts overlap lower modes. A single start overlapping every symmetry block avoids both.
Directions and Hessian-vector products are stored in the compact representation, with \((N - N_{\mathrm{occ}}) N_{\mathrm{occ}}\) rather than \(N^{2}\) entries per spin channel. Only the Hessian-vector product batch is expanded into full generators.
The solver takes ownership of
startsand returns compact Ritz vectors, which the caller owns.expand_compact_eigenpairs()consumes these compact vectors and returns full antisymmetric generators.- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
hessian_vector_product (OrbitalHessianVectorProduct[TSCFMatrix]) – The injected orbital Hessian-vector product.
compact_representation (OccupiedVirtualCompactRepresentation[TSCFMatrix]) – Conversion between full generators and their compact occupied-virtual representation.
preconditioner (OccupiedVirtualBlockPreconditioner[TSCFMatrix]) – Approximate shifted inverse Hessian on the compact representation.
starts (list[TSCFMatrix]) – Owned compact starting directions; those beyond
maximum_subspace_sizeare discarded.number_of_eigenpairs (int) – Number of lowest eigenpairs to return.
residual_tolerance (float) – Frobenius norm of \(H x - \theta x\) at which a Ritz pair is converged. Keep it well below the curvatures that must be resolved: a looser residual can stop on a positive Ritz value while a soft negative mode is still missing from the subspace.
maximum_subspace_size (int) – Maximum number of Davidson directions, and hence Hessian-vector products, kept in memory.
- Return type:
OrbitalHessianEigenpairs[TSCFMatrix]
- elementary_occupied_virtual_rotations(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_density: TSCFMatrix, orbital_occupation: OrbitalOccupation, occupied_window: int = 8, virtual_window: int = 8) list[TSCFMatrix]
Build elementary occupied-virtual rotations as stability trial vectors.
The natural orbitals are obtained from the density and elementary rotations are built between the top
occupied_windowoccupied and bottomvirtual_windowvirtual orbitals in each spin channel independently. Natural orbitals with the same occupation are degenerate and are not energy ordered, so a limited window need not contain the lowest Hessian mode. Full windows span all real rotations allowed by the selected restricted or unrestricted spin treatment.- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_density (TSCFMatrix) – Density projector \(D_{o}\) in the orthonormal basis.
orbital_occupation (OrbitalOccupation) – Electron occupation giving the number of occupied orbitals.
occupied_window (int) – Number of frontier occupied orbitals to include.
virtual_window (int) – Number of frontier virtual orbitals to include.
- Return type:
list[TSCFMatrix]
- expand_compact_eigenpairs(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], compact_representation: OccupiedVirtualCompactRepresentation[TSCFMatrix], eigenpairs: OrbitalHessianEigenpairs[TSCFMatrix]) OrbitalHessianEigenpairs[TSCFMatrix]
Return eigenpairs with compact Ritz vectors expanded into generators, consuming the compact vectors.
The input eigenvectors are freed and must not be reused. The caller owns the returned full antisymmetric generators.
- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
compact_representation (OccupiedVirtualCompactRepresentation[TSCFMatrix]) – Conversion between full generators and their compact occupied-virtual representation.
eigenpairs (OrbitalHessianEigenpairs[TSCFMatrix]) – Owned eigenpairs with compact eigenvectors.
- Return type:
OrbitalHessianEigenpairs[TSCFMatrix]
- frobenius_orthonormalize(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], candidate: TSCFMatrix, basis: list[TSCFMatrix], relative_tolerance: float = 1e-06, absolute_tolerance: float = 1e-14) TSCFMatrix | None
Gram-Schmidt orthonormalize a candidate against a basis under the Frobenius inner product.
Two modified Gram-Schmidt passes are used for numerical stability. Returns
None(and frees the candidate) when the candidate is linearly dependent on the existing basis.- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
candidate (TSCFMatrix) – Candidate direction (consumed/freed by this function).
basis (list[TSCFMatrix]) – Existing orthonormal directions.
relative_tolerance (float) – Candidate is considered dependent if its orthogonal part, relative to its original norm, falls below this.
absolute_tolerance (float) – Candidate is considered dependent if its norm or orthogonal part falls below this.
- Return type:
TSCFMatrix | None
- idempotent_projection(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_density: TSCFMatrix, orbital_occupation: OrbitalOccupation) TSCFMatrix
Do a spectral projection of an orthonormal-basis density onto the nearest rank N idempotent density.
The orbital-rotation formulation requires the reference density to be a correctly occupied projector. An arbitrary fractional-occupation guess – for instance a superposition-of-atomic-densities (SAD) guess – can have a vanishing commutator without being a valid determinant. McWeeny purification corrects roundoff near a projector but does not guarantee the requested electron count for such a guess.
This routine restores idempotency by keeping the natural orbitals with the largest occupation and rebuilding the Aufbau projector over them. It is an exact no-op when the input is already a projector with the correct occupation.
- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_density (TSCFMatrix) – Density matrix \(D_{o}\) in the orthonormal basis.
orbital_occupation (OrbitalOccupation) – Electron occupation giving the number of occupied orbitals per spin channel.
- Return type:
TSCFMatrix
- natural_orbitals(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_density: TSCFMatrix) TSCFMatrix
Return the natural orbitals as columns ordered by descending occupation.
The leading columns of each spin channel are therefore the occupied natural orbitals. The caller owns the result and must free it.
- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_density (TSCFMatrix) – Density matrix \(D_{o}\) in the orthonormal basis.
- Return type:
TSCFMatrix
- occupied_virtual_projection(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], generator: TSCFMatrix, orthonormal_density: TSCFMatrix) TSCFMatrix
Project an antisymmetric generator onto the non-redundant occupied-virtual space.
Only the occupied-virtual block of an orbital rotation changes the energy: a rotation \(X\) that commutes with the density projector is redundant and has both zero gradient and zero Hessian action. Restricting trial vectors to
\[X_{ov} = P X (I - P) + (I - P) X P,\]where \(P = D_{o} / c\) is the density projector (occupation \(c = 2\) restricted, \(c = 1\) per spin), removes that null space so a subspace Hessian diagonalization cannot be polluted by spurious zero eigenvalues. The result is antisymmetric whenever
generatoris.- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
generator (TSCFMatrix) – Antisymmetric generator \(X\) in the orthonormal basis.
orthonormal_density (TSCFMatrix) – Density projector \(D_{o}\) in the orthonormal basis.
- Return type:
TSCFMatrix
- orbital_sigma_from_response(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_fock: TSCFMatrix, orthonormal_density: TSCFMatrix, density_perturbation: TSCFMatrix, response_fock: TSCFMatrix) TSCFMatrix
Assemble the orbital Hessian-vector product from a response Fock matrix.
Implements
\[H[X] = [[D_{o}, X], F_{o}] + [D_{o}, \delta F_{o}]\]where the first term is the (cheap) Roothaan-Hall base Hessian and the second term carries the electronic-response information.
density_perturbationis the already-computed \(\delta D_{o} = [D_{o}, X]\).- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_fock (TSCFMatrix) – Fock matrix \(F_{o}\) in the orthonormal basis.
orthonormal_density (TSCFMatrix) – Density matrix \(D_{o}\) in the orthonormal basis.
density_perturbation (TSCFMatrix) – The density variation \(\delta D_{o} = [D_{o}, X]\).
response_fock (TSCFMatrix) – The response Fock matrix \(\delta F_{o}\) in the orthonormal basis.
- Return type:
TSCFMatrix
- orthonormal_density_diagnostics(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_density: TSCFMatrix) str
Return a human-readable diagnostic string for an orthonormal-basis density.
A valid single-determinant density in the Lowdin orthonormal basis is a (scaled) projector: \(D_{o}^{2} = c\,D_{o}\) with \(c = 1\) for a per-spin density and \(c = 2\) for a restricted (spin-summed) density. The trace equals the electron count. Both quantities are invariant under an exact orbital rotation, so any drift signals a broken step (loss of idempotency or particle number), which lets the energy fall below the true variational minimum.
- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_density (TSCFMatrix) – Density matrix \(D_{o}\) in the orthonormal basis.
- Return type:
str
- reduced_hessian_lowest_eigenpairs(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], hessian_vector_product: OrbitalHessianVectorProduct[TSCFMatrix], orthonormal_density: TSCFMatrix, trial_directions: list[TSCFMatrix], number_of_eigenpairs: int) OrbitalHessianEigenpairs[TSCFMatrix]
Diagonalize the orbital Hessian in the subspace spanned by trial directions.
Each trial direction is projected onto the non-redundant occupied-virtual space and orthonormalized into a small basis, the Hessian is projected onto that basis via the injected Hessian-vector product (\(H_{ij} = \langle b_i, H b_j\rangle\)), and the small symmetric matrix is diagonalized. A negative returned eigenvalue signals an orbital instability and its eigenvector is the descent (symmetry-breaking) direction.
This is a single-shot analysis: the lowest Ritz pair reproduces the true lowest Hessian eigenpair only when the trial set spans the instability. Use
davidson_hessian_lowest_compact_eigenpairs()to search beyond that span.The input
trial_directionsare not freed (the caller owns them).- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
hessian_vector_product (OrbitalHessianVectorProduct[TSCFMatrix]) – The injected orbital Hessian-vector product.
orthonormal_density (TSCFMatrix) – Density projector \(D_{o}\) in the orthonormal basis.
trial_directions (list[TSCFMatrix]) – Antisymmetric trial generators in the orthonormal basis.
number_of_eigenpairs (int) – Number of lowest eigenpairs to return.
- Return type:
OrbitalHessianEigenpairs[TSCFMatrix]
- rotate_density(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], orthonormal_density: TSCFMatrix, step: TSCFMatrix) TSCFMatrix
Apply the orbital rotation to the density: \(D' = \exp(-X) D \exp(X)\).
The similarity transform preserves the density’s occupations and trace in exact arithmetic. A single
_mcweeny_purify()step then removes accumulated symmetry and idempotency roundoff from both the exponential and the products. The reference density must already be a correctly occupied determinant; the ARH and TRAH steppers useidempotent_projection()to restore one from an invalid density.- Parameters:
module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module.
orthonormal_density (TSCFMatrix) – Current density \(D_{o}\) in the orthonormal basis.
step (TSCFMatrix) – Antisymmetric rotation generator \(X\) in the orthonormal basis.
- Return type:
TSCFMatrix