Skip to content

Commit

Permalink
Merge pull request #972 from openforcefield/from-openmm-cutoffs
Browse files Browse the repository at this point in the history
Ensure electrostatics "cutoff" is set in `from_openmm`
  • Loading branch information
mattwthompson authored Apr 23, 2024
2 parents 47e04df + 6f4d1af commit 0afa0b3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
exclude: openff/interchange/_version.py|setup.py
args: ["--py310-plus"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
rev: v0.4.1
hooks:
- id: ruff
args: ["check", "--select", "NPY"]
Expand Down
4 changes: 4 additions & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Dates are given in YYYY-MM-DD format.

Please note that all releases prior to a version 1.0.0 are considered pre-releases and many API changes will come before a stable release.

## Current development

* #972 Fixes a bug in which PME electrostatics "cutoffs" were not parsed in `from_openmm`.

## 0.3.26 - 2024-04-16

* #952 Drops support for Python 3.9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,39 @@ def test_openmm_native_roundtrip_metadata(self, monkeypatch, sage):
del off_atom_metadata["match_info"]
assert roundtrip_atom.metadata == off_atom_metadata

def test_electrostatics_cutoff_not_ignored(self, monkeypatch, ethanol):
pytest.importorskip("openmmforcefields")

import openmm.app
import openmm.unit
from openmmforcefields.generators import GAFFTemplateGenerator

monkeypatch.setenv("INTERCHANGE_EXPERIMENTAL", "1")

topology = ethanol.to_topology()
topology.box_vectors = Quantity([4, 4, 4], "nanometer")

gaff = GAFFTemplateGenerator(molecules=ethanol)
force_field = openmm.app.ForceField()

force_field.registerTemplateGenerator(gaff.generator)

system = force_field.createSystem(
topology=topology.to_openmm(),
nonbondedMethod=openmm.app.PME,
nonbondedCutoff=1.2345 * openmm.unit.nanometer,
)

interchange = Interchange.from_openmm(
system=system,
topology=topology.to_openmm(),
)

assert interchange["Electrostatics"].cutoff.m_as(
unit.nanometer,
) == pytest.approx(1.2345)
assert interchange["vdW"].cutoff.m_as(unit.nanometer) == pytest.approx(1.2345)

@needs_gmx
def test_fill_in_rigid_water_parameters(self, water_dimer, monkeypatch):
import openmm.app
Expand Down
1 change: 1 addition & 0 deletions openff/interchange/interop/openmm/_import/_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def _convert_nonbonded_force(

if force.getNonbondedMethod() == 4:
vdw.cutoff = force.getCutoffDistance()
electrostatics.cutoff = force.getCutoffDistance()
else:
raise UnsupportedImportError(
f"Parsing a non-bonded force of type {type(force)} with {force.getNonbondedMethod()} not yet supported.",
Expand Down

0 comments on commit 0afa0b3

Please sign in to comment.