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

Update ParmEd converter for new components #45

Merged
merged 16 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
LINT: Cleanup
  • Loading branch information
mattwthompson committed Nov 17, 2020
commit a28c7ff00ede99db7f211dc057c6ffa7f809a236
14 changes: 6 additions & 8 deletions openff/system/interop/parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def to_parmed(off_system: Any) -> pmd.Structure:
bond_handler = off_system.handlers["Bonds"]
bond_map = dict()
for bond_slot, smirks in bond_handler.slot_map.items():
idx_1, idx_2 = bond_slot
idx_1, idx_2 = eval(bond_slot)
try:
bond_type = bond_map[smirks]
except KeyError:
Expand All @@ -58,12 +58,10 @@ def to_parmed(off_system: Any) -> pmd.Structure:
)
del bond_type, idx_1, idx_2, smirks, bond_slot

assert structure.bonds[0].type.req > 1.5

if "Angles" in off_system.handlers.keys():
angle_term = off_system.handlers["Angles"]
for angle, smirks in angle_term.slot_map.items():
idx_1, idx_2, idx_3 = angle
idx_1, idx_2, idx_3 = eval(angle)
pot = angle_term.potentials[smirks]
# TODO: Look at cost of redundant conversions, to ensure correct units of .m
k = pot.parameters["k"].magnitude / 2 # kcal/mol/rad**2
Expand Down Expand Up @@ -92,7 +90,7 @@ def to_parmed(off_system: Any) -> pmd.Structure:
if "ProperTorsions" in off_system.handlers.keys():
proper_term = off_system.handlers["ProperTorsions"]
for proper, smirks in proper_term.slot_map.items():
idx_1, idx_2, idx_3, idx_4 = proper
idx_1, idx_2, idx_3, idx_4 = eval(proper)
pot = proper_term.potentials[smirks]
for n in range(pot.parameters["n_terms"]):
k = pot.parameters["k"][n].to(kcal_mol).magnitude
Expand All @@ -115,8 +113,8 @@ def to_parmed(off_system: Any) -> pmd.Structure:
)
)
structure.dihedral_types.append(dihedral_type)
vdw1 = vdw_handler.potentials[vdw_handler.slot_map[(idx_1,)]]
vdw4 = vdw_handler.potentials[vdw_handler.slot_map[(idx_4,)]]
vdw1 = vdw_handler.potentials[vdw_handler.slot_map[str((idx_1,))]]
vdw4 = vdw_handler.potentials[vdw_handler.slot_map[str((idx_4,))]]
sig1, eps1 = _lj_params_from_potential(vdw1)
sig4, eps4 = _lj_params_from_potential(vdw4)
sig = (sig1 + sig4) * 0.5
Expand Down Expand Up @@ -155,7 +153,7 @@ def to_parmed(off_system: Any) -> pmd.Structure:

vdw_handler = off_system.handlers["vdW"]
for pmd_idx, pmd_atom in enumerate(structure.atoms):
smirks = vdw_handler.slot_map[(pmd_idx,)]
smirks = vdw_handler.slot_map[str((pmd_idx,))]
potential = vdw_handler.potentials[smirks]
element = pmd.periodic_table.Element[pmd_atom.element]
sigma, epsilon = _lj_params_from_potential(potential)
Expand Down
19 changes: 0 additions & 19 deletions openff/system/stubs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Monkeypatching external classes with custom functionality
"""
import functools
from typing import Optional, Union

from openforcefield.topology.topology import Topology
Expand All @@ -15,7 +14,6 @@
)
from simtk import unit as omm_unit

from openff.system.components.potentials import PotentialHandler
from openff.system.components.smirnoff import (
SMIRNOFFAngleHandler,
SMIRNOFFBondHandler,
Expand Down Expand Up @@ -147,30 +145,13 @@ def create_charges(
return handler


def create_potential_handler(
self,
topology: Topology,
handler_class: PotentialHandler,
**kwargs,
) -> PotentialHandler:
handler = handler_class()
handler.store_matches(parameter_handler=self, topology=topology)
handler.store_potentials(parameter_handler=self)
return functools.partial(handler_class, topology=topology)


mapping = {
BondHandler: SMIRNOFFBondHandler,
AngleHandler: SMIRNOFFAngleHandler,
ProperTorsionHandler: SMIRNOFFProperTorsionHandler,
vdWHandler: SMIRNOFFvdWHandler,
}

# for potential_handler, parameter_handler in mapping.items():
# parameter_handler.create_potential = functools.partialmethod(
# create_potential_handler, handler_class=potential_handler
# )

BondHandler.create_potential = create_bond_potential_handler
AngleHandler.create_potential = create_angle_potential_handler
ProperTorsionHandler.create_potential = create_proper_torsion_potential_handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def openff_pmd_gmx(
struct.save(prefix + ".top")


# @pytest.mark.parametrize("smiles", ["C", "CC", "CCO"])
@pytest.mark.parametrize("smiles", ["CC"])
# TODO: Also test CC, CCO, etc.
@pytest.mark.parametrize("smiles", ["C"])
def test_parmed_openmm(tmpdir, smiles):
tmpdir.chdir()

Expand Down