Fix chirality bug in MAPFingerprint using full molecule instead of substructure#525
Merged
j-adamczyk merged 4 commits intoMLCIL:masterfrom Mar 11, 2026
Merged
Conversation
…bstructure The chirality code path in _find_env() was calling MolToSmiles on the full molecule instead of the sub_molecule, producing the same SMILES for all atoms regardless of their local environment. This made the chirality mode (MAPC) effectively broken. Use sub_molecule with rootedAtAtom like the non-chirality path, so that each atom's environment is correctly captured with isomeric SMILES. Added regression test verifying that enantiomers produce different fingerprints when include_chirality=True. Partial fix for MLCIL#519
j-adamczyk
requested changes
Mar 10, 2026
tests/fingerprints/map.py
Outdated
Comment on lines
+119
to
+121
| """Chirality mode should use sub_molecule SMILES, not full molecule SMILES. | ||
|
|
||
| Regression test for https://github.com/scikit-fingerprints/scikit-fingerprints/issues/519 |
Member
There was a problem hiding this comment.
I wouldn't add explicit issue link - this just tests a given functionality
tests/fingerprints/map.py
Outdated
|
|
||
| Regression test for https://github.com/scikit-fingerprints/scikit-fingerprints/issues/519 | ||
| """ | ||
| from rdkit.Chem import MolFromSmiles |
tests/fingerprints/map.py
Outdated
| fp_l = map_fp._calculate_single_mol_fingerprint(l_ala) | ||
| fp_d = map_fp._calculate_single_mol_fingerprint(d_ala) | ||
|
|
||
| # With chirality enabled, enantiomers should produce different fingerprints |
Member
There was a problem hiding this comment.
"With" -> "with" (style consistency with other comments)
j-adamczyk
previously approved these changes
Mar 10, 2026
tests/fingerprints/map.py
Outdated
|
|
||
|
|
||
| def test_map_chirality_uses_substructure(): | ||
| """Chirality mode should use sub_molecule SMILES, not full molecule SMILES.""" |
Member
There was a problem hiding this comment.
I don't think this docstring is necessary, other comments cover this anyway
j-adamczyk
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_find_env()which was callingMolToSmiles(mol, ...)on the full molecule instead ofsub_moleculesub_moleculewithrootedAtAtom, matching the non-chirality pathPartial fix for #519 (addresses the chirality bug;
variantparameter and MinHash support can be added in a follow-up)Test plan