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

Fix fused ring mappings #56

Merged
merged 10 commits into from
Nov 14, 2024
Merged

Fix fused ring mappings #56

merged 10 commits into from
Nov 14, 2024

Conversation

jthorton
Copy link
Contributor

@jthorton jthorton commented Nov 6, 2024

An attempt at fixing #44 by enforcing that all rings an atom is present in must be present in the final mapping which should mean that fused rings are handled correctly.

@jthorton
Copy link
Contributor Author

jthorton commented Nov 6, 2024

Some code I have been using in testing while validating the method

from kartograf import SmallMoleculeComponent
from kartograf.atom_aligner import align_mol_shape
from openff.toolkit import Molecule
from rdkit import Chem

# Preprocessing from Smiles - Here you can add your Input!
smiles = ["c1ccccc1-c2ccccc2", "C1Cc2cc(-c3ccccc3)ccc2C1"]
rdmols = [Chem.MolFromSmiles(s) for s in smiles]
rdmols = [Chem.AddHs(m, addCoords=True) for m in rdmols]
[Chem.rdDistGeom.EmbedMolecule(m, useRandomCoords=False, randomSeed = 0) for m in rdmols]

# Build Small Molecule Components
molA, molB = [SmallMoleculeComponent.from_rdkit(m) for m in rdmols]
# Align the mols first - this might not needed, depends on input.
a_molB = align_mol_shape(molB, ref_mol=molA)
from kartograf import KartografAtomMapper
# Build Kartograf Atom Mapper
mapper = KartografAtomMapper(atom_map_hydrogens=True)

# Get Mapping
kartograf_mapping = next(mapper.suggest_mappings(molA, a_molB))
print(kartograf_mapping.componentA_to_componentB) #print mapping
kartograf_mapping

with the changes in this PR we get the following mapping
image
compared with the mapping from the main branch
image

my main concern with this change is that it breaks all of the tests which check the naphtalene->benzene mapping which seems like a small regression so would we want a flag to turn this extra filtering on?

@jthorton jthorton self-assigned this Nov 6, 2024
@RiesBen
Copy link
Contributor

RiesBen commented Nov 7, 2024

Hi @jthorton
my oppinion is: to not make this new filter a standard thing, as it is rather harsh on limiting the atom mapping regions, and I would consider this (depending on your use case) is not always necessary.
I think either adding a flag or just leave the filter in the filter collection, so Users (@JenkeScheen) that want to use this filter, can use it, is the way to go :)

@IAlibay what do you think? :)

@IAlibay
Copy link
Member

IAlibay commented Nov 7, 2024

Re: new filter - I agree, this would be the best way to do a breaking change without removing the old behaviour completely.

Re: default behaviour - this might need more discussion. I can see both viewpoints here. For the current protocols we have, we would want to avoid ring breaks because it's undefined behaviour, but I know @hannahbaumann and I had discussed that there were some cases where it might be worth having an incorrect transformation than none at all.

Main things I'd really away here are:

  1. Let's make this a new filter
  2. Let's discuss that we want the user experience to be

@jthorton
Copy link
Contributor Author

jthorton commented Nov 7, 2024

Thanks for the discussion @RiesBen and @IAlibay, I agree that this does limit the number of mappings but I think this now follows the best practice advice and might be a sensible default in future. An extra filter and an option in the init to use this filter would make sense for now I'll add those. For some more context I looked into theLomapAtomMapper and PersesAtomMapper and found that lomap gave the wrong behaviour and broke the rings
image
and that perses gave the expected behaviour depending on if the allow_ring_breaking flag was set:
allow_ring_breaking=True
image

allow_ring_breaking=False
image

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.60%. Comparing base (2112a89) to head (9d21f25).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
+ Coverage   96.23%   96.60%   +0.36%     
==========================================
  Files          13       13              
  Lines         585      618      +33     
==========================================
+ Hits          563      597      +34     
+ Misses         22       21       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Couple of small things, otherwise lgtm!

src/kartograf/atom_mapper.py Outdated Show resolved Hide resolved
src/kartograf/atom_mapper.py Show resolved Hide resolved
src/kartograf/filters/ring_changes.py Show resolved Hide resolved
src/kartograf/filters/ring_changes.py Outdated Show resolved Hide resolved
src/kartograf/filters/ring_changes.py Show resolved Hide resolved
@jthorton jthorton linked an issue Nov 12, 2024 that may be closed by this pull request
@jthorton jthorton requested a review from IAlibay November 12, 2024 12:05
@jthorton
Copy link
Contributor Author

@IAlibay @hannahbaumann @RiesBen I think this is now ready for a final review, please check that the docs I added make sense to provide more information on this change.

Copy link
Contributor

@hannahbaumann hannahbaumann left a comment

Choose a reason for hiding this comment

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

Thanks @jthorton , just some small comments on the docs, otherwise lgtm!

docs/tutorial/fused_rings.rst Outdated Show resolved Hide resolved
docs/tutorial/fused_rings.rst Outdated Show resolved Hide resolved
docs/tutorial/fused_rings.rst Outdated Show resolved Hide resolved
@@ -101,12 +103,15 @@ def __init__(
_mapping_algorithm : str, optional
mapping_algorithm.linear_sum_assignment - this allows to swap the
optimization algorithm. Not recommended.
allow_partial_fused_rings: bool
If we should allow partially mapped fused rings `True` or not `False`, default `True`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be True or False?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I was trying to make it clear what each option did but maybe I should change it to
If we should allow partially mapped fused rings (True) or not (False)?

Copy link
Member

Choose a reason for hiding this comment

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

The () would be useful visually but not a massive issue. In case Hannah is asking if it should default to False instead - for now we have to leave it to True, but we can deprecate the behaviour and aim for switching to False in the near future.

jthorton and others added 3 commits November 14, 2024 11:11
Co-authored-by: Hannah Baumann <43765638+hannahbaumann@users.noreply.github.com>
Co-authored-by: Hannah Baumann <43765638+hannahbaumann@users.noreply.github.com>
Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Couple of small things to address, otherwise LGTM.

docs/tutorial/fused_rings.rst Outdated Show resolved Hide resolved
@@ -101,12 +103,15 @@ def __init__(
_mapping_algorithm : str, optional
mapping_algorithm.linear_sum_assignment - this allows to swap the
optimization algorithm. Not recommended.
allow_partial_fused_rings: bool
If we should allow partially mapped fused rings `True` or not `False`, default `True`.
Copy link
Member

Choose a reason for hiding this comment

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

The () would be useful visually but not a massive issue. In case Hannah is asking if it should default to False instead - for now we have to leave it to True, but we can deprecate the behaviour and aim for switching to False in the near future.

jthorton and others added 2 commits November 14, 2024 15:24
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
@jthorton jthorton merged commit ca54878 into main Nov 14, 2024
7 checks passed
@jthorton jthorton deleted the ring_mappings branch November 14, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fused ring atom mapping/scoring for single/hybrid topology methods
4 participants