Skip to content

Commit

Permalink
Merge pull request #852 from openforcefield/openmm-ljpme
Browse files Browse the repository at this point in the history
Better support LJPME in OpenMM export
  • Loading branch information
mattwthompson authored Jan 3, 2024
2 parents 56f551d + 4925027 commit 80483dd
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion devtools/conda-envs/beta_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- pydantic =1
- openmm >=7.6
# OpenFF stack
- openff-toolkit >=0.14.2
- openff-toolkit >=0.14.5
- openff-models
- openff-nagl
- openff-nagl-models
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/dev_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- pydantic
- openmm
# OpenFF stack
- openff-toolkit ==0.14.3
- openff-toolkit ==0.14.5
- openff-interchange-base
- openff-models
- smirnoff-plugins =2023
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/docs_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- pip
- numpy >=1.21
- pydantic =1
- openff-toolkit-base >=0.14.2
- openff-toolkit-base =0.14.5
- openff-models
- openmm >=7.6
- mbuild
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/examples_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- pydantic =1
- openmm >=7.6
# OpenFF stack
- openff-toolkit >=0.14.2
- openff-toolkit >=0.14.5
- openff-nagl ==0.3.1
- openff-nagl-models ==0.1
# Optional features
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- numpy
- pydantic
# OpenFF stack
- openff-toolkit-base >=0.14.3
- openff-toolkit-base >=0.14.5
- openff-units
- openff-models
# Needs to be explicitly listed to not be dropped when AmberTools is removed
Expand Down
1 change: 1 addition & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Please note that all releases prior to a version 1.0.0 are considered pre-releas
### New Features

* #848 Raises a more useful error when `Interchange.minimize` is called while positions are not present.
* #852 Support LJPME in OpenMM export.

### Bugfixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
import pytest
from openff.toolkit import ForceField, Molecule
from openff.units import unit
from openff.utilities import get_data_file_path, has_package
from openff.utilities import get_data_file_path, has_package, skip_if_missing

from openff.interchange import Interchange
from openff.interchange._tests.unit_tests.smirnoff.test_valence import (
TestBondOrderInterpolation,
)
from openff.interchange.drivers.openmm import _get_openmm_energies, get_openmm_energies
from openff.interchange.drivers.openmm import (
_get_openmm_energies,
_process,
get_openmm_energies,
)

if has_package("openmm"):
import openmm
import openmm.app
import openmm.unit


@skip_if_missing("openmm")
class TestBondOrderInterpolationEnergies(TestBondOrderInterpolation):
@pytest.mark.slow()
def test_basic_bond_order_interpolation_energies(self):
forcefield = ForceField(
"test_forcefields/test_forcefield.offxml",
get_data_file_path(
"test_forcefields/test_forcefield.offxml",
"openff.toolkit",
),
self.xml_ff_bo_bonds,
)

Expand All @@ -38,10 +46,19 @@ def test_basic_bond_order_interpolation_energies(self):
out,
combine_nonbonded_forces=True,
).energies["Bond"]
toolkit_bond_energy = _get_openmm_energies(
forcefield.create_openmm_system(top),
box_vectors=[[4, 0, 0], [0, 4, 0], [0, 0, 4]] * openmm.unit.nanometer,
positions=mol.conformers[0],

system = forcefield.create_openmm_system(top)
toolkit_bond_energy = _process(
_get_openmm_energies(
system=system,
box_vectors=[[4, 0, 0], [0, 4, 0], [0, 0, 4]] * openmm.unit.nanometer,
positions=mol.conformers[0].to_openmm(),
round_positions=None,
platform="Reference",
),
system=system,
combine_nonbonded_forces=True,
detailed=False,
).energies["Bond"]

assert abs(interchange_bond_energy - toolkit_bond_energy).m < 1e-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ def test_reaction_field(self, sage, periodic):

@skip_if_missing("openmm")
class TestEwaldSettings:
def test_set_ewald_tolerance(self, sage, basic_top):
@pytest.mark.parametrize("lj_method", ["cutoff", "pme"])
def test_set_ewald_tolerance(self, sage, basic_top, lj_method):
import openmm

if lj_method == "pme":
sage["vdW"].periodic_method = "Ewald3D"

system = sage.create_interchange(basic_top).to_openmm(ewald_tolerance=1.234e-5)

for force in system.getForces():
if isinstance(force, openmm.NonbondedForce):
if lj_method == "pme":
assert force.getNonbondedMethod() == openmm.NonbondedForce.LJPME
elif lj_method == "cutoff":
assert force.getNonbondedMethod() == openmm.NonbondedForce.PME

assert force.getEwaldErrorTolerance() == 1.234e-5

break
else:
pytest.fail("Found no `NonbondedForce`")
10 changes: 8 additions & 2 deletions openff/interchange/smirnoff/_nonbonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ def store_potentials(self, parameter_handler: vdWHandler) -> None:
Populate self.potentials with key-val pairs of [TopologyKey, PotentialKey].
"""
self.periodic_method = parameter_handler.periodic_method.lower()
self.periodic_method = parameter_handler.periodic_method.lower().replace(
"ewald3d",
"pme",
)
self.nonperiodic_method = parameter_handler.nonperiodic_method.lower()
self.cutoff = parameter_handler.cutoff

Expand Down Expand Up @@ -222,7 +225,10 @@ def create(
scale_15=parameter_handler.scale15,
cutoff=parameter_handler.cutoff,
mixing_rule=parameter_handler.combining_rules.lower(),
periodic_method=parameter_handler.periodic_method.lower(),
periodic_method=parameter_handler.periodic_method.lower().replace(
"ewald3d",
"pme",
),
nonperiodic_method=parameter_handler.nonperiodic_method.lower(),
switch_width=parameter_handler.switch_width,
)
Expand Down

0 comments on commit 80483dd

Please sign in to comment.