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

Remove not tested scorer #54

Merged
merged 10 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
54 changes: 0 additions & 54 deletions src/kartograf/atom_mapping_scorer.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was briefly looking at this earlier and was wondering - why are we keeping this file at all? Have we been making folks import things from this location?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a github search it looks like others are using this import path as its the recommended way to get the scorers in the README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks! Let's go with this for now, but let's raise an issue to review if it needs deprecating / removing for an eventual 2.0.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# For details, see https://github.com/OpenFreeEnergy/kartograf

import logging
import numpy as np

from gufe.mapping import AtomMapping

from .mapping_metrics import MappingRMSDScorer
from .mapping_metrics import (
Expand All @@ -13,55 +10,4 @@
)
from .mapping_metrics import MappingVolumeRatioScorer

from .mapping_metrics._abstract_scorer import _AbstractAtomMappingScorer

logger = logging.getLogger(__name__)


class DefaultKartografScorer(_AbstractAtomMappingScorer):
"""
Warning this is highly experimental!
"""

def __init__(self):
""" Mapping Scorer
this could be a future scorer using the here defined metrics?

don't use ;)
"""
self.scorers = [
MappingVolumeRatioScorer(),
MappingShapeOverlapScorer(),
MappingShapeMismatchScorer(),
MappingRMSDScorer(),
]

self.weights = np.array([1, 3, 3, 3])
self.weights = self.weights / np.sum(self.weights)

def get_score(self, mapping: AtomMapping) -> float:
""" Calculate a Score

Under Development

Parameters
----------
mapping : AtomMapping
AtomMapping to be scored

Returns
-------
float
normalized score
"""
logger.info("Kartograf Score:")
scores = []
for weight, scorer in zip(self.weights, self.scorers):
s = scorer.get_score(mapping)
logger.info(f"\t{scorer.__class__.__name__}\t{s}\tweight{weight}")
scores.append(s)

score = np.round(np.average(scores, weights=self.weights), 2)
score = score if (score > 0) else 0.0
logger.info(f"Result: {score}")
return score
2 changes: 1 addition & 1 deletion src/kartograf/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .element_change import (
from .atom_changes import (
filter_atoms_h_only_h_mapped,
filter_element_changes,
filter_hybridization_changes,
Expand Down
30 changes: 16 additions & 14 deletions src/kartograf/tests/test_atom_mapping_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
# For details, see https://github.com/OpenFreeEnergy/kartograf

import pytest
from kartograf.atom_mapping_scorer import DefaultKartografScorer
from kartograf.mapping_metrics import (
MappingRMSDScorer,
MappingShapeMismatchScorer,
MappingShapeOverlapScorer,
MappingVolumeRatioScorer,
MappingRatioMappedAtomsScorer,

)

from kartograf.mapping_metrics.metric_shape_difference import (
Expand All @@ -35,6 +33,7 @@ def test_score_norm_mapping_rmsd(stereo_chem_mapping):
score = scorer.get_rmsd_p(stereo_chem_mapping)
print(score)


def test_score_mapping_volume_ratio(stereo_chem_mapping):
"""
Currently a smoke test
Expand All @@ -52,6 +51,7 @@ def test_score_shape_dist(stereo_chem_mapping):
score = scorer(stereo_chem_mapping)
print(score)


def test_score_shape_overlap(stereo_chem_mapping):
"""
Currently a smoke test
Expand All @@ -60,6 +60,7 @@ def test_score_shape_overlap(stereo_chem_mapping):
score = scorer(stereo_chem_mapping)
print(score)


def test_score_shape_mismatch(stereo_chem_mapping):
"""
Currently a smoke test
Expand All @@ -69,13 +70,13 @@ def test_score_shape_mismatch(stereo_chem_mapping):
print(score)


@pytest.mark.parametrize("scorer_class", [ MappingRMSDScorer,
_MappingShapeDistanceScorer,
MappingShapeMismatchScorer,
MappingShapeOverlapScorer,
MappingVolumeRatioScorer,
MappingRatioMappedAtomsScorer,
DefaultKartografScorer])
@pytest.mark.parametrize("scorer_class", [MappingRMSDScorer,
_MappingShapeDistanceScorer,
MappingShapeMismatchScorer,
MappingShapeOverlapScorer,
MappingVolumeRatioScorer,
MappingRatioMappedAtomsScorer,
])
def test_scorer_identical_molecules(scorer_class, benzene_benzene_mapping):
"""
Currently a smoke test
Expand All @@ -92,25 +93,26 @@ def test_scorer_identical_molecules(scorer_class, benzene_benzene_mapping):
(MappingShapeMismatchScorer, 0),
(MappingShapeOverlapScorer, 0),
(MappingRatioMappedAtomsScorer, 0)])
def test_scorer_empty_mapping(scorer_class, exp:float, benzene_benzene_empty_mapping):
def test_scorer_empty_mapping(scorer_class, exp: float, benzene_benzene_empty_mapping):
"""
Currently a smoke test
"""
scorer = scorer_class()
score = scorer(benzene_benzene_empty_mapping)

assert isinstance(score, float)
assert score == exp, "Score of non-Mapping should be "+str(exp)+" for "+str(scorer_class.__name__)+" but is: "+str(score)
assert score == exp, "Score of non-Mapping should be " + str(exp) + " for " + str(
scorer_class.__name__) + " but is: " + str(score)


@pytest.mark.parametrize("scorer_class, exp", [(MappingVolumeRatioScorer, 1),
(DefaultKartografScorer,1)])
def test_scorer_empty_mapping_err(scorer_class, exp:float, benzene_benzene_empty_mapping):
])
def test_scorer_empty_mapping_err(scorer_class, exp: float, benzene_benzene_empty_mapping):
"""
Currently a smoke test
"""
with pytest.raises(ValueError) as exc:
scorer = scorer_class()
score = scorer(benzene_benzene_empty_mapping)

assert "Mapping is too small to calculate convex hull" in str(exc.value)
assert "Mapping is too small to calculate convex hull" in str(exc.value)
Loading