Skip to content

Commit ffe57a3

Browse files
authored
fix(lmp): avoid double qe2f in DPLR efield (deepmodeling#5732)
## Summary - remove the second qe2f multiplication when forming fix dplr efield forces - keep the existing conversion when storing constant and equal-style efield values - add real-unit regressions for constant and equal-style efield paths so qe2f != 1 is covered Closes deepmodeling#5646. ## Tests - git diff --check - /tmp/deepmd-check-venv/bin/ruff check . - /tmp/deepmd-check-venv/bin/ruff format --check . ## Not run - Targeted LAMMPS DPLR pytest tests could not run in the local ad hoc venv: the lammps Python module is not installed there, and pytest startup segfaulted in the temporary environment before collection. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Corrected electric-field force calculations so results are accumulated consistently in real-unit simulations. * Fixed related force and virial contributions to match expected values. * **Tests** * Added coverage for electric-field behavior in real units. * Included checks for both constant and variable field settings to confirm force results remain accurate. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 40d7a49 commit ffe57a3

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

source/lmp/fix_dplr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ void FixDPLR::post_force(int vflag) {
652652
for (int ii = 0; ii < nlocal; ++ii) {
653653
double tmpf[3];
654654
for (int dd = 0; dd < 3; ++dd) {
655-
tmpf[dd] = q[ii] * efield[dd] * force->qe2f;
655+
tmpf[dd] = q[ii] * efield[dd];
656656
}
657657
for (int dd = 0; dd < 3; ++dd) {
658658
dfele[ii * 3 + dd] += tmpf[dd];

source/lmp/tests/test_dplr.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ def lammps_si():
355355
lmp.close()
356356

357357

358+
@pytest.fixture
359+
def lammps_real():
360+
lmp = _lammps(data_file=data_file, units="real")
361+
yield lmp
362+
lmp.close()
363+
364+
358365
def test_pair_deepmd_sr(lammps) -> None:
359366
lammps.pair_style(f"deepmd {pb_file.resolve()}")
360367
lammps.pair_coeff("* *")
@@ -508,6 +515,39 @@ def test_pair_deepmd_lr_efield_variable(lammps) -> None:
508515
)
509516

510517

518+
def test_pair_deepmd_lr_efield_constant_real(lammps_real) -> None:
519+
lammps_real.pair_style(f"deepmd {pb_file.resolve()}")
520+
lammps_real.pair_coeff("* *")
521+
lammps_real.bond_style("zero")
522+
lammps_real.bond_coeff("*")
523+
lammps_real.special_bonds("lj/coul 1 1 1 angle no")
524+
lammps_real.fix(
525+
f"0 all dplr model {pb_file.resolve()} type_associate 1 3 bond_type 1 efield 0 0 1"
526+
)
527+
lammps_real.fix_modify("0 energy yes virial yes")
528+
lammps_real.run(0)
529+
assert lammps_real.eval("f_0") == pytest.approx(
530+
expected_e_efield_constant * constants.ener_metal2real
531+
)
532+
533+
534+
def test_pair_deepmd_lr_efield_variable_real(lammps_real) -> None:
535+
lammps_real.variable("EFIELD_Z equal 1.0")
536+
lammps_real.pair_style(f"deepmd {pb_file.resolve()}")
537+
lammps_real.pair_coeff("* *")
538+
lammps_real.bond_style("zero")
539+
lammps_real.bond_coeff("*")
540+
lammps_real.special_bonds("lj/coul 1 1 1 angle no")
541+
lammps_real.fix(
542+
f"0 all dplr model {pb_file.resolve()} type_associate 1 3 bond_type 1 efield 0 0 v_EFIELD_Z"
543+
)
544+
lammps_real.fix_modify("0 energy yes virial yes")
545+
lammps_real.run(0)
546+
assert lammps_real.eval("f_0") == pytest.approx(
547+
expected_e_efield_constant * constants.ener_metal2real
548+
)
549+
550+
511551
def test_min_dplr(lammps) -> None:
512552
lammps.pair_style(f"deepmd {pb_file.resolve()}")
513553
lammps.pair_coeff("* *")

0 commit comments

Comments
 (0)