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

Add center-of-mass motion remover in OpenMM export #1133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
if: ${{ matrix.openeye == true && matrix.openmm == true }}
run: |
micromamba install "deepdiff =5" rich click -c conda-forge
python -m pip install git+https://github.com/openforcefield/interchange-regression-testing.git@fa07b62824c39af591142b402bd68103f4043f8b
python -m pip install git+https://github.com/openforcefield/interchange-regression-testing.git@83067d7cce37a0f21b028651a7d98ec063572063

create_openmm_systems \
--input "regression_tests/small-molecule/input-topologies.json" \
Expand Down
4 changes: 4 additions & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Please note that all releases prior to a version 1.0.0 are considered pre-releas

## Current development

### Behavior changes

* #1132 Methods that return an `openmm.System` object now include a `openmm.CMMotionRemover` "force" within it.

### New features

* #1053 Logs, at the level of `logging.INFO`, how charges are assigned by SMIRNOFF force fields to each atom and virtual site.
Expand Down
4 changes: 4 additions & 0 deletions docs/using/edges.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For more, see [issue #1005](https://github.com/openforcefield/openff-interchange

Keywords: OpenMM, GROMACS, constraints, bond constraints, rigid water

### Center-of-mass motion remover ignored

If present, an `openmm.CMMotionRemover` "force" is ignored when loading a system. An `Interchange` object does not store this information. Note that exported systems from `Interchange.to_openmm_system` include this force by default.

## Quirks with GROMACS

### Residue indices must begin at 1
Expand Down
14 changes: 7 additions & 7 deletions openff/interchange/_tests/interoperability_tests/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,22 @@ def test_openmm_no_valence_forces_with_no_handler(self, sage, ethanol):
original_system = Interchange.from_smirnoff(sage, [ethanol]).to_openmm(
combine_nonbonded_forces=True,
)
assert original_system.getNumForces() == 4
assert original_system.getNumForces() == 5

sage.deregister_parameter_handler("Constraints")
sage.deregister_parameter_handler("Bonds")

no_bonds = Interchange.from_smirnoff(sage, [ethanol]).to_openmm(
combine_nonbonded_forces=True,
)
assert no_bonds.getNumForces() == 3
assert no_bonds.getNumForces() == 4

sage.deregister_parameter_handler("Angles")

no_angles = Interchange.from_smirnoff(sage, [ethanol]).to_openmm(
combine_nonbonded_forces=True,
)
assert no_angles.getNumForces() == 2
assert no_angles.getNumForces() == 3

def test_openmm_only_electrostatics_no_vdw(self):
force_field_only_charges = ForceField(get_test_file_path("no_vdw.offxml"))
Expand Down Expand Up @@ -605,10 +605,10 @@ def test_valence_term_paticle_index_offsets(self, water, tip5p):
combine_nonbonded_forces=True,
)

# NonbondedForce and HarmonicBondForce; no HarmonicAngleForce (even if there were force
# field parameters added, the current implementation would not add an angle force because
# H-O-H is fully constrained)
assert out.getNumForces() == 2
# NonbondedForce, HarmonicBondForce, CMMotionRemover; no HarmonicAngleForce (even if there
# were force field parameters added, the current implementation would not add an angle
# force because H-O-H is fully constrained)
assert out.getNumForces() == 3

# Particle indexing is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
# O, H, H, O, H, H, VS, VS, VS, VS
Expand Down
10 changes: 10 additions & 0 deletions openff/interchange/_tests/unit_tests/interop/openmm/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def compare(smiles: str) -> float:

@skip_if_missing("openmm")
class TestToOpenMM:
def test_cmm_remover_included(self, sage, basic_top):
import openmm

system = sage.create_interchange(basic_top).to_openmm_system()

assert isinstance(
system.getForce(system.getNumForces() - 1),
openmm.CMMotionRemover,
)

def test_combine_nonbonded_forces_vdw_14(self, sage_unconstrained):
molecule = Molecule.from_mapped_smiles("[C:2](#[C:3][Br:4])[Br:1]")
molecule.generate_conformers(n_conformers=1)
Expand Down
3 changes: 3 additions & 0 deletions openff/interchange/_tests/unit_tests/interop/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

if has_package("openmm"):
from openmm import (
CMMotionRemover,
HarmonicAngleForce,
HarmonicBondForce,
NonbondedForce,
Expand Down Expand Up @@ -46,6 +47,8 @@ def test_no_nonbonded_force(self, sage):
assert force.getNumBonds() == 4
elif isinstance(force, HarmonicAngleForce):
assert force.getNumAngles() == 6
elif isinstance(force, CMMotionRemover):
pass
else:
pytest.fail(f"Unexpected force found, type: {type(force)}")

Expand Down
4 changes: 4 additions & 0 deletions openff/interchange/components/interchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ def from_openmm(
interchange : Interchange
An Interchange object representing the contents of the OpenMM objects.

Notes
-----
An `openmm.CMMotionRemover` force, if present, is ignored.

"""
from openff.interchange.interop.openmm._import._import import from_openmm

Expand Down
2 changes: 2 additions & 0 deletions openff/interchange/interop/openmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def to_openmm_system(
except NotImplementedError:
continue

system.addForce(openmm.CMMotionRemover())

return system


Expand Down
Loading