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

Espaloma cannot use constrained (default) OpenFF force fields #189

Open
mattwthompson opened this issue Oct 5, 2023 · 0 comments
Open

Comments

@mattwthompson
Copy link
Contributor

import espaloma
from openff.toolkit.topology import Molecule

molecule = Molecule.from_smiles("CCO")
graph = espaloma.Graph(molecule)

espaloma_model = espaloma.get_model("latest")
espaloma_model(graph.heterograph)

espaloma.graphs.deploy.openmm_system_from_graph(
    graph,
    forcefield="openff-2.1.0",
)
AssertionError                            Traceback (most recent call last)
Cell In[1], line 10
      7 espaloma_model = espaloma.get_model("latest")
      8 espaloma_model(graph.heterograph)
---> 10 espaloma.graphs.deploy.openmm_system_from_graph(
     11     graph,
     12     forcefield="openff-2.1.0",
     13 )

File ~/mambaforge/envs/espaloma/lib/python3.11/site-packages/espaloma/graphs/deploy.py:131, in openmm_system_from_graph(g, forcefield, suffix, charge_method, create_system_kwargs)
    129 name = force.__class__.__name__
    130 if "HarmonicBondForce" in name:
--> 131     assert force.getNumBonds() * 2 == g.heterograph.number_of_nodes(
    132         "n2"
    133     )
    135     for idx in range(force.getNumBonds()):
    136         idx0, idx1, eq, k = force.getBondParameters(idx)

AssertionError:

This bubbles up because the number of bonds in the openmm.System is not guaranteed to match the number of bonds in the Molecule. Interchange currently does not add bonds to constrained atom pairs; it may or may not have in the past, I don't remember. In general this behavior shouldn't be considered stable since, to my knowledge, it doesn't affect how OpenMM simulations are run.

In [2]: from openff.toolkit import ForceField

In [3]: system = ForceField("openff-2.1.0.offxml").create_openmm_system(molecule.to_topology())

In [4]: system.getForce(3).getNumBonds(), molecule.n_bonds
Out[4]: (2, 8)

In the current stack, the number of bonds in the two objects will only match for toy molecules with no hydrogens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant