|
| 1 | +// CIS Davidson eigensolver cross-check. |
| 2 | +// |
| 3 | +// Verifies that the iterative `useDavidson: true` path returns the |
| 4 | +// same lowest singlet + triplet excitation energies as the dense |
| 5 | +// `eigsymmetric` path. Davidson avoids building the full A matrix, |
| 6 | +// which scales as O(dim²) memory — important for cc-pVDZ on |
| 7 | +// multi-atom systems where dim grows past a few hundred. |
| 8 | + |
| 9 | +import { describe, expect, test } from "vitest"; |
| 10 | +import { computeMolecularIntegrals } from "../../src/chemistry/cg-molecular.js"; |
| 11 | +import { moleculeToShellsNuclei, type Atom } from "../../src/chemistry/atoms.js"; |
| 12 | +import { runRHFSCF } from "../../src/chemistry/hf-scf.js"; |
| 13 | +import { runCIS } from "../../src/chemistry/cis.js"; |
| 14 | + |
| 15 | +describe("CIS — Davidson vs dense", () => { |
| 16 | + test("H₂O HF/STO-3G — k=3 singlets agree to ≤ 1e-7 Ha", () => { |
| 17 | + const half = (104.52 / 2) * Math.PI / 180; |
| 18 | + const xH = 0.9572 * Math.sin(half); |
| 19 | + const zH = 0.9572 * Math.cos(half); |
| 20 | + const atoms: Atom[] = [ |
| 21 | + { symbol: "O", pos: [0, 0, 0] }, |
| 22 | + { symbol: "H", pos: [ xH, 0, zH] }, |
| 23 | + { symbol: "H", pos: [-xH, 0, zH] }, |
| 24 | + ]; |
| 25 | + const { shells, nuclei, nElectrons } = moleculeToShellsNuclei(atoms); |
| 26 | + const integrals = computeMolecularIntegrals(shells, nuclei); |
| 27 | + const hf = runRHFSCF(integrals, nElectrons, { |
| 28 | + useDIIS: true, maxIter: 200, energyTol: 1e-10, densityTol: 1e-8, |
| 29 | + }); |
| 30 | + |
| 31 | + const dense = runCIS(integrals, hf, { nRoots: 3, spin: "singlet" }); |
| 32 | + const dav = runCIS(integrals, hf, { nRoots: 3, spin: "singlet", useDavidson: true, davidsonTol: 1e-9 }); |
| 33 | + |
| 34 | + expect(dense.singlet.energies.length).toBe(3); |
| 35 | + expect(dav.singlet.energies.length).toBe(3); |
| 36 | + for (let k = 0; k < 3; k++) { |
| 37 | + expect(Math.abs(dav.singlet.energies[k]! - dense.singlet.energies[k]!)).toBeLessThan(1e-6); |
| 38 | + } |
| 39 | + }, 60_000); |
| 40 | + |
| 41 | + test("H₂O HF/STO-3G — k=3 triplets agree to ≤ 1e-6 Ha", () => { |
| 42 | + const half = (104.52 / 2) * Math.PI / 180; |
| 43 | + const xH = 0.9572 * Math.sin(half); |
| 44 | + const zH = 0.9572 * Math.cos(half); |
| 45 | + const atoms: Atom[] = [ |
| 46 | + { symbol: "O", pos: [0, 0, 0] }, |
| 47 | + { symbol: "H", pos: [ xH, 0, zH] }, |
| 48 | + { symbol: "H", pos: [-xH, 0, zH] }, |
| 49 | + ]; |
| 50 | + const { shells, nuclei, nElectrons } = moleculeToShellsNuclei(atoms); |
| 51 | + const integrals = computeMolecularIntegrals(shells, nuclei); |
| 52 | + const hf = runRHFSCF(integrals, nElectrons, { |
| 53 | + useDIIS: true, maxIter: 200, energyTol: 1e-10, densityTol: 1e-8, |
| 54 | + }); |
| 55 | + const dense = runCIS(integrals, hf, { nRoots: 3, spin: "triplet" }); |
| 56 | + const dav = runCIS(integrals, hf, { nRoots: 3, spin: "triplet", useDavidson: true }); |
| 57 | + for (let k = 0; k < 3; k++) { |
| 58 | + expect(Math.abs(dav.triplet.energies[k]! - dense.triplet.energies[k]!)).toBeLessThan(1e-6); |
| 59 | + } |
| 60 | + }, 60_000); |
| 61 | +}); |
0 commit comments