Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hpmc potential energy calculation #1955

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Change Log
(`#1944 <https://github.com/glotzerlab/hoomd-blue/pull/1944>`__).
* Read after write hazard in the GPU implementation of ``hoomd.md.mesh.conservation.Volume``
(`#1953 <https://github.com/glotzerlab/hoomd-blue/pull/1953>`__).
* ``hoomd.hpmc.pair.Pair.energy`` now computes the correct energy when there are multiple pair
potentials with different ``r_cut`` values
(`#1955 <https://github.com/glotzerlab/hoomd-blue/pull/1955>`__).

*Added*

Expand Down
23 changes: 13 additions & 10 deletions hoomd/hpmc/IntegratorHPMCMono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1145,17 +1145,20 @@ double IntegratorHPMCMono<Shape>::computePairEnergy(uint64_t timestep,
if (h_tag.data[i] <= h_tag.data[j])
{
LongReal r_squared = dot(r_ij, r_ij);
if (selected_pair
&& r_squared < selected_pair->getRCutSquaredTotal(typ_i, typ_j))
if (selected_pair)
{
energy += selected_pair->energy(r_squared,
r_ij,
typ_i,
orientation_i,
h_charge.data[i],
typ_j,
orientation_j,
h_charge.data[j]);
if (r_squared
< selected_pair->getRCutSquaredTotal(typ_i, typ_j))
{
energy += selected_pair->energy(r_squared,
r_ij,
typ_i,
orientation_i,
h_charge.data[i],
typ_j,
orientation_j,
h_charge.data[j]);
}
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions hoomd/hpmc/pytest/test_pair_lennard_jones.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ def test_multiple_pair_potentials(mc_simulation_factory):
assert simulation.operations.integrator.pair_energy == pytest.approx(
expected=-3.0, rel=1e-5)

# check that individual energies are computed correctly with varying r_cut
lennard_jones_2.params[('A', 'A')] = dict(epsilon=2.0, sigma=1.0, r_cut=0)
assert simulation.operations.integrator.pair_energy == pytest.approx(
expected=-1.0, rel=1e-5)
assert lennard_jones_1.energy == pytest.approx(expected=-1.0, rel=1e-5)
assert lennard_jones_2.energy == pytest.approx(expected=0.0, abs=1e-5)


def test_logging():
hoomd.conftest.logging_check(
Expand Down