Skip to content

Commit

Permalink
TST: Add test for combining mixed 1-4 vdW and/or electrostatics
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Jan 24, 2025
1 parent 4edb63a commit 1489f0f
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions openff/interchange/_tests/unit_tests/operations/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from openff.utilities.testing import skip_if_missing

from openff.interchange import Interchange
from openff.interchange._tests import MoleculeWithConformer
from openff.interchange.drivers import get_openmm_energies
from openff.interchange.exceptions import (
CutoffMismatchError,
SwitchingFunctionMismatchError,
UnsupportedCombinationError,
)


Expand All @@ -19,8 +21,7 @@ def test_basic_combination(self, monkeypatch, sage_unconstrained):
"""Test basic use of Interchange.__add__() based on the README example"""
monkeypatch.setenv("INTERCHANGE_EXPERIMENTAL", "1")

mol = Molecule.from_smiles("C")
mol.generate_conformers(n_conformers=1)
mol = MoleculeWithConformer.from_smiles("C")
top = Topology.from_molecules([mol])

interchange = Interchange.from_smirnoff(sage_unconstrained, top)
Expand All @@ -43,14 +44,10 @@ def test_basic_combination(self, monkeypatch, sage_unconstrained):
def test_parameters_do_not_clash(self, monkeypatch, sage_unconstrained):
monkeypatch.setenv("INTERCHANGE_EXPERIMENTAL", "1")

thf = Molecule.from_smiles("C1CCOC1")
ace = Molecule.from_smiles("CC(=O)O")
thf = MoleculeWithConformer.from_smiles("C1CCOC1")
ace = MoleculeWithConformer.from_smiles("CC(=O)O")

thf.generate_conformers(n_conformers=1)
ace.generate_conformers(n_conformers=1)

def make_interchange(molecule: Molecule) -> Interchange:
molecule.generate_conformers(n_conformers=1)
def make_interchange(molecule: MoleculeWithConformer) -> Interchange:
interchange = Interchange.from_smirnoff(
force_field=sage_unconstrained,
topology=[molecule],
Expand Down Expand Up @@ -135,3 +132,35 @@ def test_error_mismatched_switching_function(
sage.create_interchange(basic_top).combine(
sage_modified.create_interchange(basic_top),
)

@pytest.mark.parametrize(
argnames=["vdw", "electrostatics"],
argvalues=[
(True, False),
(False, True),
(True, True),
(False, False),
],
)
def test_dont_combine_mixed_14(self, sage, vdw, electrostatics):
"""
Until it's implemented, error out when any non-bonded collections have non-equal 1-4 scaling factors.
See https://github.com/openforcefield/openff-interchange/issues/380
"""
interchange1 = sage.create_interchange(MoleculeWithConformer.from_smiles("C").to_topology())
interchange2 = sage.create_interchange(MoleculeWithConformer.from_smiles("CCO").to_topology())

if vdw:
interchange2["vdW"].scale_14 = 0.444

if electrostatics:
interchange2["Electrostatics"].scale_14 = 0.444

if vdw or electrostatics:
with pytest.raises(UnsupportedCombinationError, match="1-4.*nonbond"):
interchange2.combine(interchange1)
else:
# if neither are modified, that error shouldn't be raised
interchange2.combine(interchange1)

0 comments on commit 1489f0f

Please sign in to comment.