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

How to use interchange to save espaloma parameterized system? #1824

Closed
amin-sagar opened this issue Feb 14, 2024 · 6 comments
Closed

How to use interchange to save espaloma parameterized system? #1824

amin-sagar opened this issue Feb 14, 2024 · 6 comments

Comments

@amin-sagar
Copy link

Hello.
I am trying to save an espaloma parameterized system in gromacs format to run the simulations using gromacs.
I posted this issue earlier on espaloma repo choderalab/espaloma#145.

I tried the following script

import os
import torch
import espaloma as esp
from openff.toolkit.topology import Molecule
from openmm.app import *
from openmm import *
from openmm.unit import *
from sys import stdout
from openmm.app import Modeller
from simtk import unit
from openmmforcefields.generators import EspalomaTemplateGenerator
from openff.interchange import Interchange
from openff.units.openmm import ensure_quantity

#Load the molecules
molecule = Molecule.from_file("molecule.mol")
## create an Espaloma Graph object to represent the molecule of interest
molecule_graph = esp.Graph(molecule)
# load pretrained model
espaloma_model = esp.get_model("latest")
espaloma_model(molecule_graph.heterograph)
openmm_system = esp.graphs.deploy.openmm_system_from_graph(molecule_graph)
#Load Amber Force Fields 
amber_forcefields = ['amber/protein.ff14SB.xml', 'amber14/tip3pfb.xml']
forcefield = ForceField(*amber_forcefields)
espaloma_generator = EspalomaTemplateGenerator(molecules=molecule, forcefield='espaloma-0.3.1')
openmm_topology = molecule.to_topology().to_openmm()
openmm_positions =  molecule.conformers[0].to_openmm()
#Register Force Field
forcefield.registerTemplateGenerator(espaloma_generator.generator)
#Add water and Ions
modeller = Modeller(openmm_topology, openmm_positions)
modeller.addSolvent(forcefield, model='tip3p', padding=1*nanometer,boxShape='octahedron',ionicStrength=0.15*molar)
system = forcefield.createSystem(modeller.topology, nonbondedMethod=PME,nonbondedCutoff=1.0*nanometer, constraints=HBonds,hydrogenMass=4*amu)

out = Interchange.from_openmm(topology=modeller.topology,system=system, positions=modeller.positions)
# or write to GROMACS files
out.to_gro("out.gro")
out.to_top("out.top")

But I get the following error

 File "/home/amin/mambaforge/envs/espaloma0.3.1/lib/python3.10/site-packages/openff/interchange/components/interchange.py", line 351, in to_gro
    system=_convert(self),
  File "/home/amin/mambaforge/envs/espaloma0.3.1/lib/python3.10/site-packages/openff/interchange/smirnoff/_gromacs.py", line 203, in _convert
    _convert_bonds(molecule, unique_molecule, interchange)
  File "/home/amin/mambaforge/envs/espaloma0.3.1/lib/python3.10/site-packages/openff/interchange/smirnoff/_gromacs.py", line 258, in _convert_bonds
    raise MissingBondError(
openff.interchange.exceptions.MissingBondError: Failed to find parameters for bond with topology indices (2, 3)

I have tried for multiple systems and I always get an error due to missing bond parameters but the simulations run fine.
What am I doing wrong?
I would be grateful for any suggestions.
Amin.

@mattwthompson
Copy link
Member

The short answer, and one I expect will get things working for you now, is here. You can still control bond constraints at runtime in the MDP file.

A more thorough solution would involve allowing the GROMACS writer to write topological bonds that are missing physical interactions. The simple cases seem easy enough but I haven't thought through the trickier cases or written up this behavior. I expect that'll happen in the future but I wouldn't count on it happening immediately.

@amin-sagar
Copy link
Author

Thanks @mattwthompson
I think I understand the origin of the error.
However, if I change

system = forcefield.createSystem(modeller.topology, nonbondedMethod=PME,nonbondedCutoff=1.0*nanometer, constraints=HBonds,hydrogenMass=4*amu)

to

system = forcefield.createSystem(modeller.topology, nonbondedMethod=PME,nonbondedCutoff=1.0*nanometer, constraints=None, hydrogenMass=4*amu)

I still get the same error.
Does this need to be done with forcefield_kwargs and can't be done by just changing the constraints to None as I tried?

@amin-sagar
Copy link
Author

I understand now. The value of rigidWater also needs to be set to False.
So, this works.

system = forcefield.createSystem(modeller.topology, nonbondedMethod=PME,nonbondedCutoff=1.0*nanometer,constraints=None,rigidWater=False)

Thanks for the help.
Amin.

@mattwthompson
Copy link
Member

Hmm ... I'm glad you were able to get it to work but it'd be great if there was a was to use unconstrained bonds and rigid water since TIP3P and its variants are not flexible water models.

@amin-sagar
Copy link
Author

That's true.
Can someone with more experience in gromacs suggest a way to make waters rigid after topology generation, by adding some restraints?

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

2 participants