Repository navigation
Conversation
An AOBasis is the AOs of a code on their atoms, with the values and integrals the analysis of AO matrices needs: values at points, overlap, potential and electric field integrals, and, if the code has one, a molecular quadrature grid. Psi4Basis implements it with the Psi4 calls of evaluate, partition, cubes and forces, which move onto it next. Psi4 basis sets are still taken, through as_ao_basis. A backend gives its basis as `basis`, which raises NotImplementedError by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evaluate_* and check_partition_of_unity take an AOBasis or a Psi4 basis set and no longer call Psi4 themselves: the basis values, the potential integrals and the atoms come from the AO basis. Chunking, contractions and the potential of the nuclei stay where they were. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
molecular_grid, hirshfeld_fragment_weights and FragmentOperators.from_grid take an AOBasis or a Psi4 basis set. The grid comes from the code of the basis set, Psi4's DFTGrid for Psi4; its defaults and checks stay in partition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
make_cube, calc_force_at_nuc and calc_force_nuc_nuc take an AOBasis in place of the Psi4 molecule, and make_cube and calc_force_at_nuc as the basis set too. A basis set of another type raises TypeError: it was ignored, and one built from the BASIS option instead. The basis set is logged in one line, where Psi4 printed it, and Psi4's timer is around Dimer.make_cube, through the backend, rather than in make_cube. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
make_cube, evaluate_* and fragment_operators use the basis of the dimer's backend, where they took Psi4's basis set and molecule, and the Hirshfeld weights take the monomer densities from the occupied orbitals, where they read Psi4's wavefunctions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The s-Gaussian basis is a test double of the AO basis contract: contracted s functions in NumPy, as STO-3G has on H and He. A replay dimer with it runs cubes, point values, fragment operators, forces and the density cubes of calc_densities with no call into Psi4, and matches Psi4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
propSAPT is all-electron: the monomer potentials leave out the ECP operators, and Psi4 resets the dimer's nuclear charges to the full ones when it builds the fitting basis sets, so the electrostatic energy is wrong (Xe-He/def2-SVP at 6 bohr: ELST1 +9.3 Eh, on main too). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the review of PR #16: the charges of ECP and ghost atoms are those of `Molecule.to_arrays`; both codes take all elements of a non-symmetric matrix in `potential`; with a damped SCF, `Dimer.fragment_operators` takes the densities of the orbitals, and Psi4's `Da` gives Hirshfeld operators within what the SCF convergence leaves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They imported it through `backends/psi4_basis.py`, which the review of PR #16 found: `as_ao_basis`, `atoms_of`, `atoms_and_basis` and the `BasisLike`/`AtomsLike` aliases move to `backends/ao_basis.py`, which imports Psi4's basis only for Psi4 objects, and recognises those only where Psi4 has been imported. `tests/test_imports.py` imports the SAPT core and the analysis modules in a Python without Psi4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Psi4Basis` kept its `BasisFunctions` for its lifetime, as long as the dimer's: two threads analysing one dimer overwrote each other's values, and a large chunk kept its memory after the call (review of PR #16). `AOBasis.value_blocks` computes the values of a loop over blocks of points, by default with one `values` call per block; `Psi4Basis` makes its objects for the loop, as `evaluate` did on main. The results are bitwise the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fragment weights map grid points to atoms by index, and the nuclear terms and forces read the atoms by index too: a backend's basis on the atoms in another order gave wrong fragment operators without an error (review of PR #16). `Dimer.basis` now raises for a basis whose atoms are not `fragments.coordinates` in their order, or whose size is not the dimer's, and the contract says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1.5a of the backend work: the analysis of AO matrices (point values, fragment operators, cubes, forces) works from a small contract,
AOBasis, instead of a Psi4 basis set and molecule. Psi4 stays the only real backend, its objects are still accepted, and the numbers are the same.AOBasis(prop_sapt/backends/base.py): the AOs of a code on their atoms. It hasnbf,coordinates,charges,values(points),overlap(),potential(dms, points)andfield_integrals(origin).molecular_grid(...)is optional and raisesNotImplementedErrorby default, since the caller can bring another grid.Backend.basisgives a backend'sAOBasis, and raisesNotImplementedErrorby default: energies, properties and density matrices don't need it.AOBasis.value_blocks(points, block_size)gives the values of a loop over blocks of points, by default with onevaluescall per block.Psi4Basis(newprop_sapt/backends/psi4_basis.py): the Psi4 calls that were inevaluate,partition,cubesandforces. It makes Psi4'sBasisFunctionsonce per loop over the points, asevaluatedid onmain: once per block made the AO values about 1.5 times slower.as_ao_basis,atoms_of,atoms_and_basis(newprop_sapt/backends/ao_basis.py): thebasissetandmolarguments of the analysis functions, anAOBasisor a Psi4 object. Psi4's basis is imported only for a Psi4 object.evaluate,partition,cubes,forcesand the partition check inchecks) load without Psi4;tests/test_imports.pyimports them, and the SAPT core, in a Python without Psi4. Chunking, contractions, fragment weights and nuclear terms stay where they were.make_cube,calc_force_at_nucandcalc_force_nuc_nuctake anAOBasisin place of the molecule.Dimer.basis: the basis of the dimer's backend, whichmake_cube,save_cube,evaluate_*andfragment_operatorsuse. It raises aValueErrorfor a basis whose atoms are not the dimer's in the order of its fragments, or whose size is not the dimer's. The Hirshfeld weights take the monomer densities from the occupied orbitals instead ofwfnA.Da(). With a damped SCF, Psi4'sDamixes the last two iterations; Hirshfeld operators from it differ from those of the orbitals by about what the SCF convergence leaves.Changes a user can see:
make_cubeandcalc_force_at_nucraise aTypeErrorfor abasissetthat is not a basis set. They ignored it and used one built from theBASISoption.Dimer.make_cube, throughbackend.timer(), and no longer inprop_sapt.cubes.make_cube.Dimerwarns about a basis set with effective core potentials, and the usage guide lists them under the known limitations. propSAPT is all-electron: the monomer potentials leave out the ECP operators, and Psi4 resets the dimer's nuclear charges to the full ones when it builds the fitting basis sets. So the electrostatic energy is wrong, by 9.3 Eh inELST1for Xe–He/def2-SVP at 6 bohr, as onmain, which doesn't warn. The warning is all this PR does about it.After a code review of this PR, the last commits fix three bugs, with tests that failed before:
psi4_basis.py; the old import test checked direct imports only.Psi4Basiskept itsBasisFunctionsas long as the dimer. Two threads analysing one dimer got each other's values (about 1 call in 400 with two threads), and a largechunk_sizekept its memory after the call.Known limit: matrices of one code with the basis of another give wrong numbers without an error if the sizes match but the AO orders differ.
Dimer.basisavoids this. The tests checkbasis.overlap()against the backend'sS.Out of scope (step 1.5b): the saving paths (bundles,
.npymatrices, the runner's monomer cubes and.fchkfiles, the TREXIO export), the shell data they need, and the log handler'sprint_out. Their pinned error tests are unchanged.Tested:
Against
main, on He–H2/aug-cc-pVTZ, single-threaded: 34 analysis arrays (point values, quadrature grid, Becke and Hirshfeld operators, cubes, forces) and 4 cube files are bitwise equal.output.datdiffers only in the lines described above, timings and date stamps.Without Psi4.
tests/s_gaussian_basis.pyis a test double ofAOBasis, not a basis option: contracted s functions in NumPy, as STO-3G has on H and He. A replay dimer with it runs the following with every Psi4 call blocked (no_psi4_calls), compared with Psi4:calc_densitiesPsi4Basisagainst Psi4 itself (tests/test_ao_basis.py):compute_phi, the potential integrals of a unit charge, the electric field as the gradient of the potential, all elements of a non-symmetric matrix inpotential, and the charges of ECP and ghost atoms.The review fixes change no numbers: 9 of the arrays above are bitwise equal before and after them. The memory kept after a 300,000-point chunk went from 143 MB to 8 MB.
Eight deliberate bugs in the new code, and five more in the review's tests, were each caught by the tests.
The full suite passes locally (682 passed, 2 skipped, 2 xfailed), and the tests of the touched modules and
blackpass on each commit.The docs build without warnings.
🤖 Generated with Claude Code