Skip to content

Commit

Permalink
ENH: Add Interchange.to_amber
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Aug 19, 2024
1 parent 3a043ed commit dab2834
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
14 changes: 10 additions & 4 deletions docs/using/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ openmm_box: openmm.unit.Quantity = interchange.box.to_openmm()
An `Interchange` object can be written to Amber parameter/topology, coordinate, and SANDER run input files with [`Interchange.to_prmtop()`], [`Interchange.to_inpcrd()`], and [`Interchange.to_sander_input()`]:

```python
interchange.to_prmtop("out.prmtop")
interchange.to_inpcrd("out.inpcrd")
interchange.to_sander_input("out_pointenergy.in")
interchange.to_prmtop("mysim.prmtop")
interchange.to_inpcrd("mysim.inpcrd")
interchange.to_sander_input("mysim_pointenergy.in")
```

Note that the SANDER input file generated is configured for a single-point energy calculation and must be modified to run other simulations. Interchange cannot currently produce PMEMD input files. Amber does not implement a switching function as [commonly used](https://openforcefield.github.io/standards/standards/smirnoff/#vdw) by SMIRNOFF force fields, so these force fields will produce different results in Amber than in OpenMM or GROMACS.
The [`Interchange.to_amber()`] convenience method produces all three files in one invocation:

```python
interchange.to_amber("mysim") # Produces the same three files
```

Note that the input file generated is configured for a single-point energy calculation with sander and must be modified to run other simulations. Interchange cannot currently produce PMEMD input files. Amber does not implement a switching function as [commonly used](https://openforcefield.github.io/standards/standards/smirnoff/#vdw) by SMIRNOFF force fields, so these force fields will produce different results in Amber than in OpenMM or GROMACS.

<!--
## CHARMM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
import numpy
import pytest
from openff.toolkit import Molecule, Quantity, Topology, unit
Expand Down Expand Up @@ -428,6 +429,18 @@ def test_from_openmm_called(self, monkeypatch, simple_interchange):
box_vectors=box,
)

def test_to_amber(self, simple_interchange):
simple_interchange.to_amber(prefix='blargh')

# Just make sure it returns a non-zero error code
subprocess.check_output(
"sander -i blargh_pointenergy.in "
"-c blargh.inpcrd "
"-p blargh.prmtop "
"-o out.mdout -O",
shell=True,
)

def test_from_gromacs_called(self, monkeypatch, simple_interchange):
monkeypatch.setenv("INTERCHANGE_EXPERIMENTAL", "1")

Expand Down
44 changes: 34 additions & 10 deletions openff/interchange/components/interchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,6 @@ def to_openmm_simulation(

return simulation

def to_prmtop(self, file_path: Path | str, writer="internal"):
"""Export this Interchange to an Amber .prmtop file."""
if writer == "internal":
from openff.interchange.interop.amber import to_prmtop

to_prmtop(self, file_path)

else:
raise UnsupportedExportError

@requires_package("openmm")
def to_pdb(self, file_path: Path | str, include_virtual_sites: bool = False):
"""Export this Interchange to a .pdb file."""
Expand Down Expand Up @@ -686,6 +676,40 @@ def to_crd(self, file_path: Path | str):
"""Export this Interchange to a CHARMM-style .crd file."""
raise UnsupportedExportError

def to_amber(
self,
prefix: str,
):
"""
Export this Interchange object to Amber files.
Parameters
----------
prefix: str
The prefix to use for the Amber parameter/topology, coordinate, and run files, i.e.
"foo" will produce "foo.top", "foo.gro", and "foo_pointenergy.in".
Notes
-----
The run input file is configured for a single-point energy calculation with sander. It is
likely portable to pmemd with little or no work.
"""
self.to_prmtop(f"{prefix}.prmtop")
self.to_inpcrd(f"{prefix}.inpcrd")

self.to_sander_input(f"{prefix}_pointenergy.in")

def to_prmtop(self, file_path: Path | str, writer="internal"):
"""Export this Interchange to an Amber .prmtop file."""
if writer == "internal":
from openff.interchange.interop.amber import to_prmtop

to_prmtop(self, file_path)

else:
raise UnsupportedExportError

def to_inpcrd(self, file_path: Path | str, writer="internal"):
"""Export this Interchange to an Amber .inpcrd file."""
if writer == "internal":
Expand Down

0 comments on commit dab2834

Please sign in to comment.