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 all 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
48 changes: 48 additions & 0 deletions gufe/ligand_network_planner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import abc
from typing import Iterable

from . import SmallMoleculeComponent, LigandNetwork
from . import AtomMapper
from .mapping.atom_mapping_scorer import AtomMappingScorer

class LigandNetworkPlanner(abc.ABC):
"""A generic class for calculating :class:`.LigandNetworks`.

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 __init__(self, mapper: AtomMapper, scorer:AtomMappingScorer, *args, *kwargs):
""" Generate a Ligand Network Planner. This class in general needs a mapper and a scorer.

Parameters
----------
mapper: AtomMapper
scorer: AtomMappingScorer
args
kwargs
"""
self.mapper = mapper
self.scorer = scorer


def __call__(self, ligands: Iterable[SmallMoleculeComponent])-> LigandNetwork:
return self.generate_ligand_network(*args, **kwargs)

@abc.abstractmethod
def generate_ligand_network(self, ligands: Iterable[SmallMoleculeComponent])->LigandNetwork:
"""Plan a Network which connects all ligands with minimal cost

Parameters
----------
ligands : Iterable[SmallMoleculeComponent]
the ligands to include in the Network

Returns
-------
LigandNetwork
A Network, that connects all ligands with each other.
"""
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)

@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 change, a score close to zero indicates a large cost/change.

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
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()
Loading