Can not make openmm system with no `Nonbonded` force
See original GitHub issueDescribe the bug Trying to create an openmm system with no nonbonded force results in an error due to the post-processing done here. In my case the nonbonded force is replaced by a custom nonbonded force implemented via smirnoff-plugins which creates the exclusions here before the toolkit so missing this step should be fine.
To Reproduce This is not quite the same as I have not added the custom force but the result is the same
from openff.toolkit.typing.engines.smirnoff import ForceField
from openff.toolkit.topology import Molecule
ff = ForceField("openff_unconstrained-1.3.0.offxml")
# remove all nonbonded handlers
del ff._parameter_handlers["ToolkitAM1BCC"]
del ff._parameter_handlers["LibraryCharges"]
del ff._parameter_handlers["Electrostatics"]
del ff._parameter_handlers["vdW"]
water = Molecule.from_smiles("O")
system = ff.create_openmm_system(water.to_topology())
Output
IndexError Traceback (most recent call last) /var/folders/9q/nm__l0v13fggc72v94p0hybw0000gq/T/ipykernel_68062/4179821129.py in <module> ----> 1 system = ff.create_openmm_system(water.to_topology())
~/miniconda3/envs/openff-plugins/lib/python3.8/site-packages/openff/toolkit/typing/engines/smirnoff/forcefield.py in create_openmm_system(self, topology, **kwargs)
1376 # TODO: Can we generalize this to allow for CustomNonbondedForce
implementations too?
1377 forces = [system.getForce(i) for i in range(system.getNumForces())]
-> 1378 nonbonded_force = [f for f in forces if type(f) == openmm.NonbondedForce][0]
1379
1380 nonbonded_force.createExceptionsFromBonds(
IndexError: list index out of range
Computing environment (please complete the following information):
- Operating system osx
- Output of running
conda list
- openff-toolkit
0.10.0+32.gc316bfe0.dirty
- openff-toolkit-base
0.10.0
- smirnoff_plugins
0.0.1+4.g6118a88.dirty
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
The TODO two lines above seems quite relevant as a bit of debt 😅 .
Relates somewhat to discussions around revamping the SMIRNOFF spec, particularly https://github.com/openforcefield/standards/issues/2#issuecomment-930133340. Requiring at least one of
NonbondedForce
orCustomNonbondedForce
seems to fit every use case I can think of. Any obvious pitfalls?When computing gradients by finite difference I usually create a subset of a force field that only contains the relevant handler type. So if I was computing dU / d bond length then I would create a system from a force field only containing the BondHandler. Kind of a weird use case but definitely useful to be able to do.