Skip to content

Commit

Permalink
update perses atom mapper to use openff units
Browse files Browse the repository at this point in the history
  • Loading branch information
jthorton committed Sep 10, 2024
1 parent 3fe9d43 commit 79de2e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions openfe/setup/atom_mapping/perses_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"""

from openmm import unit
from openfe.utils import requires_package
from openff.models.types import FloatQuantity
from openff.units import unit
from openff.units.openmm import to_openmm

from ...utils.silence_root_logging import silence_root_logging
try:
Expand All @@ -25,15 +27,15 @@ class PersesAtomMapper(LigandAtomMapper):
allow_ring_breaking: bool
preserve_chirality: bool
use_positions: bool
coordinate_tolerance: unit.Quantity
coordinate_tolerance: FloatQuantity['angstrom']

def _to_dict(self) -> dict:
# strip units but record values
return {

Check warning on line 34 in openfe/setup/atom_mapping/perses_mapper.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/atom_mapping/perses_mapper.py#L34

Added line #L34 was not covered by tests
"allow_ring_breaking": self.allow_ring_breaking,
"preserve_chirality": self.preserve_chirality,
"use_positions": self.use_positions,
"coordinate_tolerance": self.coordinate_tolerance.value_in_unit(
"coordinate_tolerance": self.coordinate_tolerance.m_as(
unit.angstrom
),
"_tolerance_unit": "angstrom"
Expand Down Expand Up @@ -67,7 +69,7 @@ def __init__(self, allow_ring_breaking: bool = True,
if mappings must strictly preserve chirality, default: True
use_positions: bool, optional
this option defines, if the
coordinate_tolerance: openmm.unit.Quantity, optional
coordinate_tolerance: openff.units.unit.Quantity, optional
tolerance on how close coordinates need to be, such they
can be mapped, default: 0.25*unit.angstrom
Expand All @@ -81,7 +83,7 @@ def _mappings_generator(self, componentA, componentB):
# Construct Perses Mapper
_atom_mapper = AtomMapper(
use_positions=self.use_positions,
coordinate_tolerance=self.coordinate_tolerance,
coordinate_tolerance=to_openmm(self.coordinate_tolerance),
allow_ring_breaking=self.allow_ring_breaking)

# Try generating a mapping
Expand Down
7 changes: 6 additions & 1 deletion openfe/tests/setup/atom_mapping/test_perses_atommapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# For details, see https://github.com/OpenFreeEnergy/openfe
import pytest
from openfe.setup.atom_mapping import PersesAtomMapper, LigandAtomMapping
from openff.units import unit

pytest.importorskip('perses')
pytest.importorskip('openeye')
Expand Down Expand Up @@ -54,6 +55,10 @@ def test_empty_atommappings(mol_pair_to_shock_perses_mapper):

def test_dict_round_trip():

Check warning on line 56 in openfe/tests/setup/atom_mapping/test_perses_atommapper.py

View check run for this annotation

Codecov / codecov/patch

openfe/tests/setup/atom_mapping/test_perses_atommapper.py#L56

Added line #L56 was not covered by tests
# use some none defaults
mapper1 = PersesAtomMapper(allow_ring_breaking=False, preserve_chirality=False)
mapper1 = PersesAtomMapper(

Check warning on line 58 in openfe/tests/setup/atom_mapping/test_perses_atommapper.py

View check run for this annotation

Codecov / codecov/patch

openfe/tests/setup/atom_mapping/test_perses_atommapper.py#L58

Added line #L58 was not covered by tests
allow_ring_breaking=False,
preserve_chirality=False,
coordinate_tolerance=0.01 * unit.nanometer
)
mapper2 = PersesAtomMapper.from_dict(mapper1.to_dict())
assert mapper2.to_dict() == mapper1.to_dict()

Check warning on line 64 in openfe/tests/setup/atom_mapping/test_perses_atommapper.py

View check run for this annotation

Codecov / codecov/patch

openfe/tests/setup/atom_mapping/test_perses_atommapper.py#L63-L64

Added lines #L63 - L64 were not covered by tests

0 comments on commit 79de2e8

Please sign in to comment.