Skip to content

Derive the default PPPM spacing of qNEP models from the radial cutoff - #1823

Draft
erhart1 wants to merge 5 commits into
masterfrom
fix/pppm-spacing-alpha
Draft

erhart1 wants to merge 5 commits into
masterfrom
fix/pppm-spacing-alpha

Conversation

@erhart1

@erhart1 erhart1 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

For qNEP models, NEP_Charge sets the Ewald splitting parameter to alpha = pi / rc_radial, while the default PPPM mesh spacing is a fixed 1 Å. The reciprocal-space part grows with alpha, and for a short radial cutoff the 1 Å mesh does not resolve it. GPUMD also prints the mesh without any estimate of its error.

This MR sets the default spacing to min(1, rc_radial / 6) Å in NEP_Charge::check_ewald_pppm. The default keeps the product of alpha and the target spacing at or below pi / 6, which is its value at rc_radial = 6 Å. Models with rc_radial of 6 Å or more keep the 1 Å mesh. An explicit kspace pppm <spacing> takes precedence over the default.

This MR adds an estimate of the root-mean-square PPPM force error, which PPPM::print_mesh prints after the mesh line at the first force evaluation. It is the estimate of Deserno and Holm, J. Chem. Phys. 109, 7694 (1998), for ik differentiation and five-point charge assignment, with the coefficients of PPPM::estimate_ik_error in LAMMPS and the charges of that step. tests_regression/pppm_checks.py accepts the new line.

This MR ports the PPPM mesh selection of gpumd to gpumd_replica. The replica accepts kspace pppm [spacing] with the validation of gpumd, applies the same default, rounds the mesh up to 2, 3, 5, 7-smooth sizes, grows it with the box, enforces the limit of 512^3 points, and prints the mesh line and the estimate. A Kspace_Setting struct replaces the kspace_method string in the replica code. The PRD and REMD restarts record the requested spacing in a pppm_spacing key.

doc/gpumd/input_parameters/kspace.rst states the default and the estimate, and states that a kspace line applies to every run wherever it appears in run.in. The replica pages kspace.rst and restart.rst state the spacing, the estimate and the restart check.

This MR changes the PPPM energies and forces of models with rc_radial below 6 Å. For the rc_radial = 4 Å water model in tests_pytest/fixtures/models/qnep_mode1_water.txt on a 1701-atom cell, the mesh rises from 28 x 40 x 20 to 40 x 56 x 28. The PPPM energy minus the Ewald energy is reduced from -0.353 to -0.0016 meV/atom, and the RMS force difference per component is reduced from 2.25 to 0.19 meV/Å. The speed is 2.51e6 atom*step/s against 2.53e6 with the 1 Å mesh, corresponding to about 1 percent. The finer mesh reaches the limit of 512^3 points in smaller boxes: an rc_radial = 4 Å model stops with "PPPM mesh is too large" in a cubic box of 345 Å, which runs with kspace pppm 1.0.

On the same water cell, the ratio of the estimate to the RMS force difference between PPPM and Ewald is 0.97, 1.13 and 1.20 at spacings of 0.5, 0.7 and 1.0 Å. For the mode-2 water model it is between 1.27 and 1.53 at spacings of 0.7 to 1.5 Å. At 0.5 Å it is 0.28, where the measured difference is 2.6e-5 eV/Å. The estimate assumes randomly distributed charges. For a 1080-atom BaTiO3 crystal it exceeds the measured difference by factors of 1.8 to 31, which the documentation states.

This MR brings gpumd_replica in line with gpumd. For a 1512-atom cell of the rc_radial = 4 Å water model, both executables choose a 40 x 40 x 40 mesh and print an estimate of 2.342e-04 eV/A. The step-0 potential energy is -6311.92918 eV from gpumd_replica and -6311.92894 eV from gpumd. With master, gpumd_replica gave -6312.0474 eV. The remaining difference of 2.4e-4 eV is of the size of the Ewald difference between the two executables, 2.0e-4 eV.

Breaking changes

The PRD restart format version rises from 6 to 7, and the REMD restart format version from 5 to 6. Restart files written by earlier builds of gpumd_replica are rejected as an unsupported format. A resume with a kspace spacing that differs from the restart is rejected with "restart pppm_spacing does not match the input". A second kspace line in a replica run.in now raises "kspace can only appear once.", the message of gpumd.

Testing

test_pppm_spacing in tests_pytest/test_kspace_consistency.py reads the target spacing from the PPPM mesh line of gpumd. It covers a model with rc_radial = 4 Å without a kspace line, models with rc_radial = 4, 6 and 8 Å with kspace pppm, and kspace pppm 0.9 before and after run. The rc_radial = 4 Å cases fail on master, and the rc_radial = 8 Å case fails with the uncapped rc_radial / 6.

test_pppm_force_error_estimate in the same file compares the printed estimate with the RMS force difference between PPPM and Ewald on the 1701-atom water cell at 0.5, 0.7 and 1.0 Å, within 25 percent. test_force_error_estimate in tests_regression/test_pppm_checks.py checks that the checker accepts one estimate line after the mesh line and rejects a misplaced, repeated or negative one.

tests_regression/replica/test_replica.py adds three tests. test_qnep_pppm_spacing_and_force_error_estimate checks the default spacing for rc_radial = 4 and 8 Å, an explicit spacing, and one mesh line and one estimate line. test_qnep_pppm_spacing_input_validation checks the messages for an invalid spacing, a spacing after ewald, and an extra argument. test_restart_pppm_spacing_validation checks that PRD and REMD record the spacing and reject a resume with another spacing, the default, or no kspace line. All three fail on master.

  • pytest -m "not slow" in tests_pytest: 671 passed, 478 skipped.
  • run_regression.py --suite pppm with a -DDEBUG build of this branch on both sides: 37 passed, 0 failed, relations 2 passed, 23 skipped.
  • python -m unittest test_runner test_manifest test_post_checks test_pppm_checks in tests_regression: 27 tests OK.
  • tests_regression/replica/test_replica.py: 15 tests OK.
  • sphinx-build -b html doc: 0 warnings.
  • git clang-format against master: no changes in src/force. In src/main_replica it would rewrite the leading-comma initializer lists of the replica constructors, which keep the style of the surrounding code.

A run of run_regression.py with master as the baseline shows the new estimate line as a stdout difference in the PPPM cases.

The Ewald splitting parameter of qNEP models is alpha = pi / rc_radial.
The default PPPM spacing is rc_radial / 6, which keeps alpha * spacing at pi / 6.
An explicit spacing in kspace pppm takes precedence.
The default spacing is min(1, rc_radial / 6) A.
Models with rc_radial above 6 A keep the 1 A mesh.
The test covers an absent kspace line and a kspace line after run.
@erhart1 erhart1 self-assigned this Oct 11, 2026
@erhart1
erhart1 requested a review from brucefan1983 as a code owner October 11, 2026 10:19
@erhart1 erhart1 added the bug label Oct 11, 2026
@erhart1
erhart1 marked this pull request as draft October 11, 2026 10:47
A kspace line anywhere in run.in applies to every run.
At the first force evaluation, PPPM prints the root-mean-square force error
estimate of Deserno and Holm for ik differentiation and five-point charge
assignment, using the charges of that step.
The regression checker accepts the new line after the mesh line.
gpumd_replica accepts kspace pppm [spacing] with the validation of gpumd.
The default spacing is min(1, rc_radial / 6) A.
The replica PPPM rounds the mesh up to 2, 3, 5, 7-smooth sizes, grows it
with the box, enforces the 512^3 limit, and prints the mesh and the force
error estimate from the first stream.
The PRD and REMD restarts record the requested spacing and reject a resume
with a different one.
@erhart1

erhart1 commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

@brucefan1983 this PR is built up from several commits that allow one to cherry pick changes.

  • The basic change is very limited and comprises the first three commits up to 708f6b2. These commits simply make the k-spacing consistent with the cutoff of the real-space sum.
  • The fourth commit (8028160) adds an estimate of the PPPM-vs-Ewald error based on Deserno and Holm, J. Chem. Phys. 109, 7694 (1998).
  • The fifth commit (5537bb0) extends the change to the gpumd_replic executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant