Skip to content

Commit 2ac5b2d

Browse files
Document how to opt in to pseudo-vaccum approximation (#1362)
* DOC: Document how to opt in to pseudo-vaccum approximation * FIX: Update exception name, add test * DOC: Add section header * LINT: Disable `markdownlint` where Sphinx needs non-blank lines * Update docs/using/edges.md Co-authored-by: Josh A. Mitchell <yoshanuikabundi@gmail.com> * DOC: Add note on vdW cut-off in vacuum --------- Co-authored-by: Josh A. Mitchell <yoshanuikabundi@gmail.com>
1 parent a760ff9 commit 2ac5b2d

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

docs/using/edges.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# Sharp edges
22

3+
(no-cutoff-support)=
4+
## Some MM engines do not support "no-cutoff" non-bonded methods <!-- markdownlint-disable-line -->
5+
6+
SMIRNOFF force fields support a non-bonded treatment in which, for non-periodic systems, the vdW interactions are not truncated. OpenFF force fields commonly use this option (`nonperiodic_method="no-cutoff"`).
7+
8+
OpenMM supports this with its `NoCutoff` method in `openmm.NonbondedForce` and similar forces. There is, however, no clear analog in GROMACS (with versions after 2020) or Amber. A common approach is to use the "pseudo-vacuum" approximation in which a very large box is used, i.e. 10 nm cubic box lengths for a system of a single small molecule.
9+
10+
This approach is an approximation and therefore must be opted into by defining a periodic box, either on the input topology:
11+
12+
```python
13+
from openff.toolkit import Quantity, ForceField, Topology
14+
15+
# do normal topology preparation ...
16+
my_topology = Topology.from_pdb("my_system.pdb")
17+
18+
# ... and then set box vectors before `Interchange` creation
19+
my_topology.box_vectors = Quantity([10, 10, 10], "nanometer")
20+
21+
my_interchange = ForceField("openff-2.0.0.offxml").create_interchange(my_topology)
22+
```
23+
24+
or the created `Interchange` object:
25+
26+
```python
27+
# do normal `Interchange` preparation ...
28+
my_topology = Topology.from_pdb("my_system.pdb")
29+
my_interchange = ForceField("openff-2.0.0.offxml").create_interchange(my_topology)
30+
31+
# ... and then set the box after creating an `Interchange` object:
32+
my_interchange.box = Quantity([10, 10, 10], "nanometer")
33+
```
34+
35+
You may also wish to make the vdW cut-off distance longer. This is typically accessible at `my_interchange['vdW'].cutoff`.
36+
337
## Quirks of charge assignment
438

539
### Charge assignment hierarchy

openff/interchange/_tests/test_issues.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
from openff.utilities import get_data_file_path, has_executable, skip_if_missing
99

1010
from openff.interchange import Interchange
11-
from openff.interchange._tests import MoleculeWithConformer, shuffle_topology
11+
from openff.interchange._tests import MoleculeWithConformer, needs_gmx, shuffle_topology
1212
from openff.interchange.components._packmol import pack_box
1313
from openff.interchange.drivers import get_openmm_energies
14+
from openff.interchange.exceptions import NonperiodicNoCutoffNotSupportedError
1415

1516

1617
def test_issue_723():
@@ -167,3 +168,27 @@ def test_issue_1337(water):
167168
# just make sure this doesn't crash (original issue)
168169
# more extensive tests in openff/interchange/_tests/unit_tests/interop/openmm/test_constraints.py
169170
ff14sb_tip3p.create_interchange(water.to_topology())
171+
172+
173+
@needs_gmx
174+
def test_issue_1361_gromacs(caffeine, sage, tmp_path):
175+
"""Test that the 'how to opt in to pseudo-vacuum' message is communicated."""
176+
interchange = sage.create_interchange(caffeine.to_topology())
177+
178+
with pytest.raises(
179+
NonperiodicNoCutoffNotSupportedError,
180+
match=r"GROMACS versions 2020 and newer do not support systems without periodicity",
181+
):
182+
interchange.to_gromacs(prefix="foo")
183+
184+
185+
@pytest.mark.skipif(not has_executable("sander"), reason="sander not installed")
186+
def test_issue_1361_amber(caffeine, sage, tmp_path):
187+
"""Test that the 'how to opt in to pseudo-vacuum' message is communicated."""
188+
interchange = sage.create_interchange(caffeine.to_topology())
189+
190+
with pytest.raises(
191+
NonperiodicNoCutoffNotSupportedError,
192+
match=r"vdW method no-cutoff not supported",
193+
):
194+
interchange.to_amber(prefix="bar")

openff/interchange/components/mdconfig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from openff.interchange._annotations import _DistanceQuantity
1212
from openff.interchange.constants import _PME
1313
from openff.interchange.exceptions import (
14+
NonperiodicNoCutoffNotSupportedError,
1415
UnsupportedCutoffMethodError,
1516
UnsupportedExportError,
1617
)
@@ -458,7 +459,7 @@ def write_sander_input_file(
458459
vdw_cutoff = round(self.vdw_cutoff.m_as("angstrom"), 4)
459460
sander.write(f"cut={vdw_cutoff},\n")
460461
else:
461-
raise UnsupportedExportError(
462+
raise NonperiodicNoCutoffNotSupportedError(
462463
f"vdW method {self.vdw_method} not supported",
463464
)
464465

openff/interchange/exceptions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ class UnsupportedExportError(InterchangeException):
104104
"""
105105

106106

107+
class NonperiodicNoCutoffNotSupportedError(UnsupportedExportError):
108+
"""
109+
Exception for when an engine does not support "no-cutoff" non-bonded methods in non-periodic system.
110+
"""
111+
112+
def __init__(self, message):
113+
super().__init__(
114+
message
115+
+ "\nFor more see: https://docs.openforcefield.org/projects/interchange/en/stable/using/edges.html#no-cutoff-support",
116+
)
117+
118+
107119
class UnsupportedCombinationError(InterchangeException):
108120
"""General exception for something going wrong in Interchange object combination."""
109121

openff/interchange/interop/gromacs/export/_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy
66
from openff.toolkit import Quantity
77

8-
from openff.interchange.exceptions import MissingPositionsError, UnsupportedExportError
8+
from openff.interchange.exceptions import MissingPositionsError, NonperiodicNoCutoffNotSupportedError
99
from openff.interchange.interop.gromacs.models.models import (
1010
GROMACSSystem,
1111
GROMACSVirtualSite2,
@@ -487,7 +487,7 @@ def _write_gro(self, gro, decimal: int):
487487
count += 1
488488

489489
if self.system.box is None:
490-
raise UnsupportedExportError(
490+
raise NonperiodicNoCutoffNotSupportedError(
491491
"GROMACS versions 2020 and newer do not support systems without periodicity/box vectors.",
492492
)
493493
else:

0 commit comments

Comments
 (0)