{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simulate an Interchange with LAMMPS\n", "\n", "In this example, we'll quickly construct an `Interchange` and then run a simulation in LAMMPS. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We need an `Interchange` to get started, so let's put that together quickly. For more explanation on this process, take a look at the [packed_box] and [protein_ligand] examples.\n", "\n", "[packed_box]: https://github.com/openforcefield/openff-interchange/tree/main/examples/packed_box\n", "[protein_ligand]: https://github.com/openforcefield/openff-interchange/tree/main/examples/protein_ligand" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import mdtraj as md\n", "import nglview\n", "from lammps import lammps\n", "from openff.toolkit.topology import Molecule, Topology\n", "from openff.toolkit.typing.engines.smirnoff import ForceField\n", "from openff.toolkit.utils import get_data_file_path\n", "from openmm.app import PDBFile\n", "\n", "from openff.interchange import Interchange\n", "\n", "# Read a structure from the Toolkit's test suite into a Topology\n", "pdbfile = PDBFile(get_data_file_path(\"systems/packmol_boxes/propane_methane_butanol_0.2_0.3_0.5.pdb\"))\n", "molecules = [Molecule.from_smiles(smi) for smi in [\"CCC\", \"C\", \"CCCCO\"]]\n", "off_topology = Topology.from_openmm(pdbfile.topology, unique_molecules=molecules)\n", "\n", "# Construct the Interchange with the OpenFF \"Sage\" force field\n", "interchange = Interchange.from_smirnoff(\n", " force_field=ForceField(\"openff-2.0.0.offxml\"),\n", " topology=off_topology,\n", ")\n", "interchange.positions = pdbfile.positions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tada! A beautiful solvent system:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interchange.visualize(\"nglview\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Run a simulation\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, we export a `.lmp` file that can be read by LAMMPS' `read_data` command:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interchange.to_lammps_datafile(\"interchange.lmp\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we need to write an input file for LAMMPS. Parts of these input files depend on force field parameters, so we should use a sample input file written for our interchange as a starting point. We can generate such a sample file with the `to_lammps_input()` method:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interchange.to_lammps_input(\"interchange_pointenergy.in\", data_file=\"interchange.lmp\")\n", "with open(\"interchange_pointenergy.in\") as f:\n", " print(f.read())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the `read_data` line must match the data file name - in this case, `interchange.lmp`. That's why `to_lammps_input` needs the data file name. We could alternatively use the `to_lammps` method to write both files in a consistent way:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interchange.to_lammps(\"interchange\") # writes interchange.lmp and interchange_pointenergy.in" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That sample file will only perform a single point energy calculation; here's a more complete file that includes the above parameters but will run an actual MD simulation. \n", "\n", "