Skip to content

Implement UKS nuclear gradients for Laplacian-dependent meta-GGAs - #229

Merged
wavefunction91 merged 1 commit into
wavefunction91:masterfrom
susilehtola:uks-laplacian-mgga-exc-grad
Nov 25, 2026
Merged

wavefunction91 merged 1 commit into
wavefunction91:masterfrom
susilehtola:uks-laplacian-mgga-exc-grad

Conversation

@susilehtola

Copy link
Copy Markdown
Contributor

Builds on #228 (the Laplacian gradient fix); review that first, or this diff will
look like it contains both.

What

eval_exc_grad refused the spin-polarized case outright:

if(needs_laplacian and is_uks) {
  GAUXC_GENERIC_EXCEPTION("UKS Gradients + Laplacian Dependent MGGAs is Not Yet Implemented");
}

Everything below the assembly was already in place — eval_uvvar_mgga_uks
computes lapl for both spins (lapls, laplz, split into lapl[2i] /
lapl[2i+1]), and lapl/vlapl are allocated per spin — so only the gradient
assembly and the guard were missing.

How

The spin transformation mirrors the LDA, GGA and tau blocks around it:
rho_alpha = (rho_s + rho_z)/2, hence
0.5 (v+ + v-) N + 0.5 (v+ - v-) Z, with fac P lapl(B) built for both the
scalar and the spin density (xLmat, xZLmat; the extra blocks already fit in
host_data.zmat, which is sized 5 * spin_dim_scal when needs_laplacian).

One trap worth flagging for review: the tau branch immediately above
reassigns d2_term_* to the Z hessian term when polarized, and the
laplacian block consumed it directly. Reusing it would have paired the Z hessian
term with the N laplacian contribution — a wrong-index bug of exactly the kind
#228 fixes, sitting behind the exception. This block rebuilds hN_* and hZ_*
explicitly instead.

Verification

eval_exc_grad against a central difference of eval_exc over a displaced
molecule and displaced basis, so the grid and its partition weights ride on
the atoms and the comparison shares no algebra with the gradient code.
Cytosine (doublet) / cc-pVDZ / UltraFine, MGGA_X_R2SCANL+MGGA_C_R2SCANL,
atom 0, h = 1e-4:

d/dx   analytic -1.5224974586e-01   FD -1.5224974458e-01   rel 8.4e-09
d/dy   analytic  3.3558979268e-01   FD  3.3558978846e-01   rel 1.3e-08
d/dz   analytic -7.27e-16           FD -1.07e-10           (both zero; planar)

RKS is unchanged and still verifies at 1.6e-09 (BR89) / 9.4e-08 (r2SCANL).

gauxc_test: all 3640979 assertions in 56 test cases pass.

Not covered

The device path keeps its own, separate restriction
("Device EXC Gradients + Laplacian Dependent MGGAs Not Yet Implemented"),
which this does not touch.

🤖 Generated with Claude Code

exc_grad refused the spin-polarized case outright:

  "UKS Gradients + Laplacian Dependent MGGAs is Not Yet Implemented"

Everything below the assembly was already in place -- eval_uvvar_mgga_uks
computes lapl for both spins, and lapl/vlapl are allocated per spin -- so
only the gradient assembly and the guard were missing.

The spin transformation mirrors the LDA, GGA and tau blocks around it:
rho_alpha = (rho_s + rho_z)/2, hence the 0.5 (v+ + v-) N + 0.5 (v+ - v-) Z
combination, with fac P lapl(B) built for both the scalar and the spin
density.

One trap: the tau branch immediately above reassigns d2_term_* to the Z
hessian term when polarized, and the laplacian block consumed it. Reusing
it here would have paired the Z hessian term with the N laplacian
contribution. This block now rebuilds hN_* and hZ_* explicitly instead.

Verified against a central difference of eval_exc over a displaced
molecule and displaced basis, cytosine (doublet) / cc-pVDZ / UltraFine,
MGGA_X_R2SCANL+MGGA_C_R2SCANL, atom 0:

  d/dx  analytic -1.5224974586e-01  FD -1.5224974458e-01  rel 8.4e-09
  d/dy  analytic  3.3558979268e-01  FD  3.3558978846e-01  rel 1.3e-08
  d/dz  both zero to 1e-10 (planar)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@wavefunction91
wavefunction91 force-pushed the uks-laplacian-mgga-exc-grad branch from 3e035f8 to 0ee264b Compare November 25, 2026 19:03
wavefunction91 added a commit to susilehtola/GauXC that referenced this pull request Nov 25, 2026
Adds artifacts for wavefunction91#174, wavefunction91#224, wavefunction91#230, wavefunction91#210 and wavefunction91#229, and cross-cutting findings (the wavefunction91#218 root
cause in wavefunction91#224, the gau2grid l>=4 third-derivative bug, and eval_exc_grad heap corruption for
off-atom shells).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
wavefunction91 added a commit to susilehtola/GauXC that referenced this pull request Nov 25, 2026
… merged; wavefunction91#229 needs rebase, revise C1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
wavefunction91 added a commit to susilehtola/GauXC that referenced this pull request Nov 25, 2026
… bitwise-identical)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@wavefunction91
wavefunction91 force-pushed the uks-laplacian-mgga-exc-grad branch from 0ee264b to e305e2b Compare November 25, 2026 19:34
@wavefunction91
wavefunction91 merged commit f8f11be into wavefunction91:master Nov 25, 2026
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.

2 participants