def test_cutoff_electrostatics():
    ion_ff = ForceField(get_test_file_path("ions.offxml"))
    ions = Topology.from_molecules([
        Molecule.from_smiles("[#3]"),
        Molecule.from_smiles("[#17]"),
    ])
    out = Interchange.from_smirnoff(ion_ff, ions)
    out.box = [4, 4, 4] * unit.nanometer

    gmx = []
    lmp = []

    for d in np.linspace(0.75, 0.95, 5):
        positions = np.zeros((2, 3)) * unit.nanometer
        positions[1, 0] = d * unit.nanometer
        out.positions = positions

        out["Electrostatics"].method = "cutoff"
        gmx.append(
            get_gromacs_energies(out, mdp="auto").energies["Electrostatics"].m)
        lmp.append(
            get_lammps_energies(out).energies["Electrostatics"].m_as(
                unit.kilojoule / unit.mol))

    assert np.sum(np.sqrt(np.square(np.asarray(lmp) - np.asarray(gmx)))) < 1e-3
Example #2
0
def _get_mdp_file(key: str = "auto") -> str:
    if key == "auto":
        return "auto_generated.mdp"

    mapping = {
        "default": "default.mdp",
        "cutoff": "cutoff.mdp",
        "cutoff_hbonds": "cutoff_hbonds.mdp",
        "cutoff_buck": "cutoff_buck.mdp",
    }

    return get_test_file_path(f"mdp/{mapping[key]}")
def test_liquid_argon():
    argon = Molecule.from_smiles("[#18]")
    pdbfile = app.PDBFile(get_test_file_path("packed-argon.pdb"))

    top = Topology.from_openmm(pdbfile.topology, unique_molecules=[argon])

    argon_ff = ForceField(get_test_file_path("argon.offxml"))

    out = Interchange.from_smirnoff(argon_ff, top)
    out.positions = pdbfile.positions

    omm_energies = get_openmm_energies(out)

    gmx_energies = get_gromacs_energies(
        out,
        mdp="auto",
        writer="internal",
    )

    omm_energies.compare(
        gmx_energies,
        custom_tolerances={
            "vdW": 0.008 * simtk_unit.kilojoule_per_mole,
        },
    )

    argon_ff_no_switch = deepcopy(argon_ff)
    argon_ff_no_switch["vdW"].switch_width *= 0

    out_no_switch = Interchange.from_smirnoff(argon_ff_no_switch, top)
    out_no_switch.positions = pdbfile.positions

    lmp_energies = get_lammps_energies(out_no_switch)

    omm_energies.compare(
        lmp_energies,
        custom_tolerances={
            "vdW": 10.5 * simtk_unit.kilojoule_per_mole,
        },
    )
def test_water_dimer():
    tip3p = ForceField(get_test_file_path("tip3p.offxml"))
    water = Molecule.from_smiles("O")
    top = Topology.from_molecules(2 * [water])
    top.mdtop = md.Topology.from_openmm(top.to_openmm())

    pdbfile = openmm.app.PDBFile(get_test_file_path("water-dimer.pdb"))

    positions = pdbfile.positions

    openff_sys = Interchange.from_smirnoff(tip3p, top)
    openff_sys.positions = positions
    openff_sys.box = [10, 10, 10] * unit.nanometer

    omm_energies = get_openmm_energies(
        openff_sys,
        hard_cutoff=True,
        electrostatics=False,
    )

    toolkit_energies = _get_openmm_energies(
        tip3p.create_openmm_system(top),
        openff_sys.box,
        openff_sys.positions,
        hard_cutoff=True,
        electrostatics=False,
    )

    omm_energies.compare(toolkit_energies)

    # TODO: Fix GROMACS energies by handling SETTLE constraints
    # gmx_energies, _ = get_gromacs_energies(openff_sys)
    # compare_gromacs_openmm(omm_energies=omm_energies, gmx_energies=gmx_energies)

    openff_sys["Electrostatics"].method = "cutoff"
    omm_energies_cutoff = get_gromacs_energies(openff_sys)
    lmp_energies = get_lammps_energies(openff_sys)

    lmp_energies.compare(omm_energies_cutoff)
Example #5
0
 def ammonia_ff(self):
     """Fixture that loads an SMIRNOFF XML for ammonia"""
     return ForceField(get_test_file_path("ammonia.offxml"))
Example #6
0
 def argon_ff(self):
     """Fixture that loads an SMIRNOFF XML for argon"""
     return ForceField(get_test_file_path("argon.offxml"))
Example #7
0
            _compare_nonbonded_parameters(
                _get_force(toolkit_sys, openmm.NonbondedForce),
                _get_force(new_sys, openmm.NonbondedForce),
            )
        if "Bond" in str(e):
            raise e
        if "Angle" in str(e):
            raise e


@skip_if_missing("openff.evaluator")
@pytest.mark.timeout(60)
@pytest.mark.slow()
@pytest.mark.parametrize(
    "rdmol",
    Chem.SDMolSupplier(get_test_file_path("MiniDrugBankTrimmed.sdf"), sanitize=False),
)
def test_energy_vs_toolkit(rdmol):

    Chem.SanitizeMol(rdmol)
    mol = Molecule.from_rdkit(rdmol, allow_undefined_stereo=True)

    mol.to_inchi()

    assert mol.n_conformers > 0

    max_n_heavy_atoms = 12
    if len([a for a in mol.atoms if a.atomic_number > 1]) > max_n_heavy_atoms:
        pytest.skip(f"Skipping > {max_n_heavy_atoms} heavy atoms for now")

    # Skip molecules that cause hangs due to the toolkit taking an excessive time