Skip to content

refactor(aocscf): replace Dz0SCF with average-occupation ROKS - #17

Merged
wtpeter merged 3 commits into
NonDFT:mainfrom
wtpeter:refactor/dz0scf
Sep 26, 2026
Merged

wtpeter merged 3 commits into
NonDFT:mainfrom
wtpeter:refactor/dz0scf

Conversation

@wtpeter

@wtpeter wtpeter commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace the dz0scf reference with an average-occupation ROKS interface while retaining the existing orbital optimization and high-spin gradient definition. This PR intentionally removes the old DZ0SCF API.

Changes relative to Dz0SCF

  • Construct the reference with mol.ROKS(xc=...).average_occ() (also supported on plain SymAdaptedROKS) instead of DZ0SCF(mol, xc=...). Importing nest.aocscf registers the method. The old nest.dz0scf module, DZ0SCF factory, and direct gradient aliases are removed.
  • SCF still optimizes orbitals with the singly occupied orbitals shared equally between alpha and beta. The potential now comes from PySCF's RKS get_veff on the total density and is supplied to ROHF as two identical spin blocks. The old implementation called UKS get_veff with two equal spin densities.
  • During SCF, energy_tot() evaluates the average-occupation energy. After _finalize, mf.e_avg_occ holds that energy and mf.e_tot holds the high-spin energy evaluated with the converged orbitals. Previously mf.e_tot held the average-occupation energy and mf.high_spin_energy() was a separate call. Consequently, mf.energy_tot() and the finalized mf.e_tot have different meanings.
  • Rename the analytic gradient driver to nest.grad.aocscf. Its Z-vector equation, explicit high-spin derivative, and numerical reference tests are retained. The material implementation change is that the intermediate RKS/ROKS evaluators use lib.view(mf, ...) instead of constructing fresh objects and copying selected DFT settings. Both mf.nuc_grad_method() and mf.Gradients() return this driver.
  • Split the old combined Dz0SCF/NTTDA regression tests into AOCSCF energy tests and NTTDA tests. The SVWN/B3LYP reference energies, NTTDA excitation energies, and the two gradient reference arrays and tolerances are unchanged. Add AOCSCF and NTTDA examples, with a link from examples/aocscf to the NTTDA example.

Reviewer focus

Please check the RKS versus equal-spin UKS potential equivalence, the finalized e_tot / energy_tot() contract, and whether the lib.view change preserves the intended high-spin gradient for other XC functionals and symmetry-adapted references. The gradient tests still cover NH2/PBE and triplet CH2/B3LYP; they do not cover the symmetry-adapted gradient.

Verification

  • OMP_NUM_THREADS=2 python -m pytest src/nest/aocscf/tests/test_aocscf.py src/nest/grad/tests/test_aocscf_grad.py src/nest/nttda/tests/test_nttda_aocscf.py -q — 6 passed.
  • Smoke check: mf.Gradients() and mf.nuc_grad_method() both return nest.grad.aocscf.Gradients.
  • python -m ruff check . and git diff --check — passed.

@wtpeter
wtpeter requested review from Betty0621 and a lite review from Copilot September 26, 2026 00:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wtpeter
wtpeter merged commit d048cdb into NonDFT:main Sep 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants