OpenFreeEnergy / kartograf

This package contains tools for setting up hybrid-topology FE calculations
https://kartograf.readthedocs.io/
MIT License
25 stars 3 forks source link

`filter_hybridization_rings` fails on non-ring atoms #62

Closed jthorton closed 1 week ago

jthorton commented 1 week ago

Describe the bug The filter_hybridization_rings fails when it tries to correct a mapping involving an atom not part of a ring as the filter only stores info on ring atoms.

To Reproduce See this example for the shp2 ligands

from gufe import LigandNetwork, SmallMoleculeComponent
from kartograf import KartografAtomMapper
from kartograf.filters.ring_changes import filter_hybridization_rings

# work around gufe issue 407
def node_to_rdkit(node: SmallMoleculeComponent) -> Chem.Mol:
    """Do some santization to make sure we have the atom hybridization"""
    rdkit_mol = node.to_rdkit()
    Chem.SanitizeMol(rdkit_mol, Chem.SANITIZE_ALL)
    Chem.AssignStereochemistryFrom3D(rdkit_mol)
    Chem.Kekulize(rdkit_mol, clearAromaticFlags=True)
    Chem.SetAromaticity(rdkit_mol, Chem.AromaticityModel.AROMATICITY_MDL)
    return rdkit_mol

mapper = KartografAtomMapper(additional_mapping_filter_functions=[filter_hybridization_rings])
with open("shp2.graphml", "r") as f:
    ligand_network = LigandNetwork.from_graphml(f.read())

for edge in ligand_network.edges:
    if edge.componentA.name == "lig_E6" and edge.componentB.name == "lig_E29":
        edge.componentA._rdkit = node_to_rdkit(edge.componentA)
        edge.componentB._rdkit = node_to_rdkit(edge.componentB)
        mapping = next(mapper.suggest_mappings(edge.componentA, edge.componentB))
        break
mapping

ai_only_arom_sys = atomA_ring_hyb_map[ai] KeyError: 23

Expected behavior This should work on molecules that mix ring and non-ring atoms.

hannahbaumann commented 1 week ago

@jthorton could you maybe add a figure of the 2 ligands here so it's easier to understand what is going on?

jthorton commented 1 week ago

No problem see attached, atom 23 is the methyl carbon in the ligand on the left which the filter has no info about as its not in a ring. image