Skip to content

PySCFTheory: use total density for the point-charge gradient of unrestricted SCF - #527

Merged
RagnarB83 merged 1 commit into
RagnarB83:masterfrom
Carlos-A-Ramos-G:fix-uhf-pointcharge-gradient
Oct 20, 2026
Merged

RagnarB83 merged 1 commit into
RagnarB83:masterfrom
Carlos-A-Ramos-G:fix-uhf-pointcharge-gradient

Conversation

@Carlos-A-Ramos-G

Copy link
Copy Markdown
Contributor

Fixes #526.

For UHF/UKS, make_rdm1() returns (dm_alpha, dm_beta), and the point-charge gradient (PC_gradient_code = "new") kept only dm[0]. grad_hcore_mm is linear in the density, so the electronic contribution to the forces on the MM charges was missing every beta electron. This PR uses dm[0] + dm[1]. The energy and the QM-atom gradient were already correct and are unchanged, and closed-shell runs (dm.ndim == 2) are unaffected.

Changes

  • ash/interfaces/interface_pyscf.py: one line (+ comment).
  • ash/tests/test_pyscf_pointcharge_gradient.py (new): compares pcgrad with central finite differences of the energy for RHF (H2O) and UHF (OH radical) next to three point charges. It needs only CPU PySCF (skipped if PySCF is missing) and takes about 3 s.

Testing

  • New test: UHF fails on master (max error 0.11 Eh/Bohr) and passes with the fix (< 1e-6). RHF passes on both.
  • ash/tests/test_pyscf_scf_convergence.py still passes.
  • On GPU (gpu4pyscf 1.8.1, A100), the same correction applied to a 36k-atom broken-symmetry [4Fe-4S] QM/MM system. It brings the MM forces into agreement with finite differences and makes NVE dynamics conserve energy (details in the issue).

🤖 Generated with Claude Code

…tricted SCF

For UHF/UKS, make_rdm1() returns (dm_alpha, dm_beta) and the "new" point-charge
gradient code kept only dm[0]. grad_hcore_mm is linear in the density, so the
electronic contribution to the forces on the MM charges was missing all beta
electrons, while the energy and the QM-atom gradient were correct. Use
dm[0] + dm[1].

Adds a finite-difference test of the point-charge gradient for RHF and UHF.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RagnarB83
RagnarB83 merged commit ef3ff64 into RagnarB83:master Oct 20, 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.

PySCFTheory: point-charge (MM) gradient drops the beta density for UHF/UKS

2 participants