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
ENH: Better handling of box data
  • Loading branch information
mattwthompson committed Nov 11, 2020
commit b186b9933368db855cbf6605715b4824332ebc4d
10 changes: 5 additions & 5 deletions openff/system/components/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Config:
def validate_box(cls, val):
if val is None:
return val
if type(val) == omm_unit.Quantity:
val = simtk_to_pint(val)
if val.shape == (3, 3):
pass
return val
elif val.shape == (3,):
val *= np.eye(3)
val = val * np.eye(3)
return val
else:
raise ValueError # InvalidBoxError
if type(val) == omm_unit.Quantity:
val = simtk_to_pint(val)
return val


System.to_parmed = to_parmed
9 changes: 6 additions & 3 deletions openff/system/interop/parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ def to_parmed(off_system: Any) -> pmd.Structure:

def _convert_box(box: unit.Quantity, structure: pmd.Structure) -> None:
# TODO: Convert box vectors to box lengths + angles
lengths = box.to(unit("angstrom")).diagonal().magnitude
angles = 3 * [90]
structure.box = np.hstack([lengths, angles])
if box is None:
structure.box = [0, 0, 0, 90, 90, 90]
else:
lengths = box.to(unit("angstrom")).diagonal().magnitude
angles = 3 * [90]
structure.box = np.hstack([lengths, angles])


def _lj_params_from_potential(potential):
Expand Down
18 changes: 15 additions & 3 deletions openff/system/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Monkeypatching external classes with custom functionality
"""
import functools
from typing import Optional, Union

from openforcefield.topology.topology import Topology
from openforcefield.typing.engines.smirnoff import ForceField
Expand All @@ -12,6 +13,7 @@
ProperTorsionHandler,
vdWHandler,
)
from simtk import unit as omm_unit

from openff.system.components.potentials import PotentialHandler
from openff.system.components.smirnoff import (
Expand All @@ -22,9 +24,15 @@
SMIRNOFFvdWHandler,
)
from openff.system.components.system import System
from openff.system.types import UnitArray


def to_openff_system(self, topology: Topology, **kwargs) -> System:
def to_openff_system(
self,
topology: Topology,
box: Optional[Union[omm_unit.Quantity, UnitArray]] = None,
**kwargs,
) -> System:
"""
A method, patched onto ForceField, that creates a System object

Expand All @@ -50,9 +58,13 @@ def to_openff_system(self, topology: Topology, **kwargs) -> System:
)
sys_out.handlers.update({"Electrostatics": charges})

sys_out.box = sys_out.validate_box(topology.box_vectors)
if box is None:
sys_out.box = sys_out.validate_box(topology.box_vectors)
else:
sys_out.box = sys_out.validate_box(box)

sys_out.topology = topology
assert "topology" in dir(sys_out)

return sys_out


Expand Down
6 changes: 3 additions & 3 deletions openff/system/tests/test_interop/test_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


class TestParmedConversion(BaseTest):
@pytest.mark.skip
def test_box(self, argon_ff, argon_top):
sys_out = argon_ff.create_openff_system(argon_top)
box = UnitArray(np.array([4, 4, 4]), units="nanometer")
sys_out = argon_ff.create_openff_system(topology=argon_top, box=box)
sys_out.positions = UnitArray(
np.zeros(
shape=(argon_top.n_topology_atoms, 3),
Expand All @@ -23,7 +23,7 @@ def test_box(self, argon_ff, argon_top):

assert np.allclose(
struct.box[:3],
argon_top.box_vectors.value_in_unit(omm_unit.angstrom).diagonal(),
[40, 40, 40],
)

def test_basic_conversion_argon(self, argon_ff, argon_top):
Expand Down