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

Adding a generic atom mapping scorer #306

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
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
2 changes: 1 addition & 1 deletion gufe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from .mapping import (
ComponentMapping, # how individual Components relate
AtomMapping, AtomMapper, # more specific to atom based components
AtomMapping, AtomMapper, AtomMappingScorer, # more specific to atom based components
LigandAtomMapping,
)

Expand Down
1 change: 1 addition & 0 deletions gufe/mapping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from .componentmapping import ComponentMapping
from .atom_mapping import AtomMapping
from .atom_mapper import AtomMapper
from .atom_mapping_scorer import AtomMappingScorer
from .ligandatommapping import LigandAtomMapping
43 changes: 43 additions & 0 deletions gufe/mapping/atom_mapping_scorer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This code is part of kartograf and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/gufe

import abc
from ..tokenization import GufeTokenizable

from . import AtomMapping


class AtomMappingScorer(GufeTokenizable):
"""A generic class for scoring Atom mappings.
this class can be used for example to build graph algorithm based networks.

Implementations of this class can require an arbitrary and non-standardised
number of input arguments to create.

Implementations of this class provide the :meth:`.get_score` method

"""

def __call__(self, mapping: AtomMapping) -> float:
return self.get_score(mapping)

Check warning on line 22 in gufe/mapping/atom_mapping_scorer.py

View check run for this annotation

Codecov / codecov/patch

gufe/mapping/atom_mapping_scorer.py#L22

Added line #L22 was not covered by tests

@abc.abstractmethod
def get_score(self, mapping: AtomMapping) -> float:
""" calculate the score for an :class:`.AtomMapping`
the scoring function returns a value between 0 and 1.
a value close to 1.0 indicates a small distance, a score close to zero indicates a large cost/error.

Parameters
----------
mapping: AtomMapping
the mapping to be scored
args
kwargs

Returns
-------
float
a value between [0,1] where zero is a very bad score and one a very good one.
RiesBen marked this conversation as resolved.
Show resolved Hide resolved

"""
pass

Check warning on line 43 in gufe/mapping/atom_mapping_scorer.py

View check run for this annotation

Codecov / codecov/patch

gufe/mapping/atom_mapping_scorer.py#L43

Added line #L43 was not covered by tests
15 changes: 15 additions & 0 deletions gufe/tests/test_setup_interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/gufe

import pytest
from gufe import AtomMappingScorer, AtomMapper


def test_atom_mapping_scorer():
with pytest.raises(TypeError, match="Can't instantiate abstract class AtomMappingScorer"):
scorer = AtomMappingScorer()


def test_atom_mapper():
with pytest.raises(TypeError, match="Can't instantiate abstract class AtomMapper"):
mapper = AtomMapper()