Skip to content

Fix missing last term in B-spline factor for structure factor - #8210

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
Cstandardlib:fix-nbspline
Oct 27, 2026
Merged

mohanchen merged 2 commits into
deepmodeling:developfrom
Cstandardlib:fix-nbspline

Conversation

@Cstandardlib

@Cstandardlib Cstandardlib commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fix missing last term in B-spline deconvolution factor for structure factor (nbspline).

Summary

Fix an error in the B-spline correction coefficients used by Structure_Factor::bsplinecoef.

The previous denominator sum omitted the last nonzero integer sample of the Cardinal B-spline.
This gives incorrect structure factors when nbspline is enabled, with a particularly large error at low orders.
For nbspline = 2, the zero-frequency structure factor is multiplied by 8, which also scales the integrated
atomic-superposition initial density before any subsequent normalization.

Linked Issue

Fix #8092

Unit Tests and/or Case Tests for my changes

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • Example: brief summary of the user-visible or developer-facing change.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:

… by (1-1/N!)^-3

The denominator loop in Structure_Factor::bsplinecoef missed the last integer-point sample M_{N+1}(N) = 1/N! of the Cardinal B-spline, so the G=0 deconvolution factor was 1/(1-1/N!) per direction instead of 1, and S(G=0) -- the integrated electron number -- was scaled by (1-1/N!)^-3 (8x at nbspline=2). The method is exact at G=0 at any order by partition of unity, so this was an off-by-one implementation error, not low-order interpolation error.

Add a unit test asserting b(0)=1 for norder = 2,4,6,10,20 and a low-order OFDFT integration case 35_OF_LPS_bspline; regenerate references of the six existing nbspline=10 cases (energies shift by ~1e-4 eV, the intended behavior change).
@Cstandardlib Cstandardlib changed the title Fix missing last term in structure factor (nbspline) Fix missing last term in B-spline factor for structure factor Oct 25, 2026
@Cstandardlib
Cstandardlib marked this pull request as ready for review October 25, 2026 17:09

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Static review found the endpoint correction consistent with the spline support, phase and FFT normalization on the documented cutoff or odd-full-grid paths. Runtime tests and CI diagnostics were not run; the existing even-full-grid Nyquist limitation remains outside this validation. Two nonblocking follow-ups below.

Comment thread tests/07_OFDFT/25_OF_MD_LDA/result.ref Resolved
Comment thread tests/07_OFDFT/35_OF_LPS_bspline/INPUT Resolved
@mohanchen

Copy link
Copy Markdown
Collaborator

Nice job! However, It would be better to show the results after the fix.

@Cstandardlib

Copy link
Copy Markdown
Collaborator Author

Results after the fix, for the same case as in #8092 (tests/01_PW/032_PW_15_CF_CS_bspline, GaAs, 28 electrons), measured with a binary built from this PR branch:

nbspline $E_{total}$ (eV) electrons from rho (correct: 28)
off -4200.2531231 28
2 -4199.9462376 28
4 -4200.3487691 28
6 -4200.2838809 28
8 -4200.2648614 28
10 -4200.2583591 28
20 -4200.2532790 28
  • The electron number is now exactly 28 at every order: the G = 0 identity S(0) = N_atoms holds for all n. Before the fix it was scaled by (1-1/n!)^-3 (8x at n=2).
  • Energies now converge smoothly to the nbspline-off value as the order increases. The small residual at low n (e.g. +0.31 eV at n=2) is the expected low-order B-spline approximation/conditioning error at G != 0, not the bug.
  • At n=20 the energy is unchanged before/after the fix (difference ~1e-18), consistent with the existing nbspline=20 reference not needing an update; the six nbspline=10 references shift by only ~1e-4 eV and are regenerated in this PR.
  • OFDFT side: the new 35_OF_LPS_bspline case (nbspline = 2) gives E_total = -55.9081454 eV and passes the integration test; before the fix the same input produced +2649.5211930 eV (a 2705 eV deviation).

@mohanchen
mohanchen merged commit 00d74be into deepmodeling:develop Oct 27, 2026
20 checks passed
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Oct 27, 2026
@Cstandardlib
Cstandardlib deleted the fix-nbspline branch October 27, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] nbspline gives wrong structure factors at low orders:

4 participants