Skip to content

Commit

Permalink
Merge branch 'main' into optional_filter_ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay authored Nov 19, 2024
2 parents 0525ac6 + cd226b6 commit 2aea3bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/kartograf/filters/ring_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ def get_atom_ring_hybridization_map(rdmol: Chem.Mol) -> dict[int, bool]:
# Filtering Mapping
filtered_mapping = {}
for ai, aj in mapping.items():
ai_only_arom_sys = atomA_ring_hyb_map[ai]
aj_only_arom_sys = atomB_ring_hyb_map[aj]
# if the atom is not in a ring return False
ai_only_arom_sys = atomA_ring_hyb_map.get(ai, False)
aj_only_arom_sys = atomB_ring_hyb_map.get(aj, False)

if ai_only_arom_sys == aj_only_arom_sys:
filtered_mapping[ai] = aj
Expand Down
24 changes: 23 additions & 1 deletion src/kartograf/tests/test_atom_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from kartograf.atom_mapper import (filter_atoms_h_only_h_mapped,
filter_whole_rings_only)
from kartograf.filters.element_change import filter_hybridization_changes
from kartograf.filters.ring_changes import filter_whole_rings_only
from kartograf.filters.ring_changes import (
filter_whole_rings_only,
filter_hybridization_rings,
)


from .conftest import (
naphtalene_benzene_molecules,
Expand Down Expand Up @@ -312,3 +316,21 @@ def test_hybridization_and_ring_breaks(shp2_hybridization_ligands):
)
# make sure there was no change in the mapping
assert filtered_mapping == mapping.componentA_to_componentB


def test_ring_hybridization_with_non_ring_atoms(shp2_hybridization_ligands):
"""
Make sure this filter does not fail on non-ring atoms see
<https://github.com/OpenFreeEnergy/kartograf/issues/62>
"""
mapper = KartografAtomMapper(
additional_mapping_filter_functions=[filter_hybridization_rings]
)
mapping = next(
mapper.suggest_mappings(
shp2_hybridization_ligands[0],
shp2_hybridization_ligands[1]
)
)
# make sure we have some mapping between the atoms
assert mapping.componentA_to_componentB

0 comments on commit 2aea3bb

Please sign in to comment.