Skip to content

vdW section should support different methods for periodic and non-periodic systems #51

Description

@mattwthompson

When creating an openmm.System using a gas-phase system,

  • the prescribed vdW "method" method is "cutoff"
  • the Topology has no box vectors
  • the resulting openmm.NonbondedForce uses NoCutoff
>>> import openmm
>>> from openff.toolkit import ForceField, Molecule
>>> from openff.interchange import Interchange
>>> from openff.units import unit
>>>
>>> force_field = ForceField('openff-2.0.0.offxml')
>>> topology = Molecule.from_smiles("CCO").to_topology()
>>> assert topology.box_vectors is None
>>> interchange = Interchange.from_smirnoff(force_field, topology)
>>> assert interchange.box is None
>>> system = interchange.to_openmm(combine_nonbonded_forces=True)
>>>
>>> for force in system.getForces():
...     if isinstance(force, openmm.NonbondedForce):
...         assert force.getNonbondedMethod() == openmm.NonbondedForce.NoCutoff
...
>>> # (runs with no errors)
>>> print(force_field['vdW'].method)
cutoff

This seems obviously incorrect. Using a cutoff is not the same as not using a cutoff. (SMIRNOFF does not fully describe what "cutoff" means, but whatever it means, it probably does not mean "use NoCutoff.) I've brought this up in the past to mixed reception.

This behavior has been in the toolkit since the beginning and I believe that, as a result, all force fields have been fit with this wart in place. What should the behavior here be @lilyminium? Follow the specification or track the existing reference implementation? Below the divider, I will ramble on with more context, but it can be ignored if there's a clear answer to this question.


Splitting out non-bonded forces is not a solution to the problem of mixing PME electrostatics and cutoff vdW interactions. OpenMM will throw an exception, but Interchange already pre-empts this and forbids this combination from existing:

>>> system = interchange.to_openmm(combine_nonbonded_forces=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mattthompson/mambaforge/envs/smirnoff-plugins-test/lib/python3.9/site-packages/openff/interchange/components/interchange.py", line 349, in to_openmm
    return to_openmm_(self, combine_nonbonded_forces=combine_nonbonded_forces)
  File "/Users/mattthompson/mambaforge/envs/smirnoff-plugins-test/lib/python3.9/site-packages/openff/interchange/interop/openmm/__init__.py", line 89, in to_openmm
    particle_map = _process_nonbonded_forces(
  File "/Users/mattthompson/mambaforge/envs/smirnoff-plugins-test/lib/python3.9/site-packages/openff/interchange/interop/openmm/_nonbonded.py", line 108, in _process_nonbonded_forces
    _func(
  File "/Users/mattthompson/mambaforge/envs/smirnoff-plugins-test/lib/python3.9/site-packages/openff/interchange/interop/openmm/_nonbonded.py", line 743, in _create_multiple_nonbonded_forces
    raise UnsupportedCutoffMethodError(
openff.interchange.exceptions.UnsupportedCutoffMethodError: When using `openmm.CustomNonbondedForce`, vdW and electrostatics cutoff methods must agree on whether or not periodic boundary conditions should be used.OpenMM will throw an error. Found vdw method 1, and electrostatics method 0,

Arguably this is a quirk or OpenMM and maybe there's a workaround I'm unaware of. The fact that vanilla NonbondedForce usage combines PME electrostatics and cutoff vdW interactions is awfully convenient for that case, but doesn't work for other cases, such as when CustomNonbondedForce must be used.

Modifying the non-bonded methods to differ from what is specified in the force field is, in my opinion, a non-starter.

It's possible that using no-cutoff interactions in the gas phase is functionally equivalent to using cutoff interactions in the condensed phase provided an isotropic, assuming that the relevant assumptions are valid and the error introduced by the approximation is sufficiently small. It certainly looks good in papers, but I have no clue if that matches what's observed in the wild. This would mean there's functionally little or no difference between gas-phase no-cutoff calculations used in (valence) fitting and how OpenFF force fields are implemented in the condensed phase. Still, having these quirks cancel each other out is separate from how confusing this is to implement.

OpenMM's NoCutoff method might not have clear analogs in other packages. I think Amber supports it in some sense but the documentation is nearly impossible to search. GROMACS does not properly support gas-phase simulations in versions after 2019 and nobody is actively working on it. I'm not exactly sure about LAMMPS, but there are enough pair styles implemented for me to guess that it can be done. I have no idea about CHARMM, Desmond, etc. nor do I track how it's implemented in the novel ML-based engines.

The number of combinations to consider grows pretty rapidly the more you look. Periodicity, combinations of electrostatics and vdW methods, their implementations in different engines, the use of non-LJ functional forms, maybe the use of implicit solvent, ... the list goes on and is unlikely to be trimmed down without removing sections of SMIRNOFF. The two use cases I think we should be concerned about are using a main-line OpenFF force field (PME + cutoff vdW) with a topology that is either periodic or not, but I want to highlight the background of complexity that is can be introduced when making even a single change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions