Skip to content

Fix chirality bug in MAPFingerprint using full molecule instead of substructure#525

Merged
j-adamczyk merged 4 commits intoMLCIL:masterfrom
LiudengZhang:fix/map4-chirality-and-variant
Mar 11, 2026
Merged

Fix chirality bug in MAPFingerprint using full molecule instead of substructure#525
j-adamczyk merged 4 commits intoMLCIL:masterfrom
LiudengZhang:fix/map4-chirality-and-variant

Conversation

@LiudengZhang
Copy link
Contributor

Summary

  • Fixes the chirality code path in _find_env() which was calling MolToSmiles(mol, ...) on the full molecule instead of sub_molecule
  • This caused the chirality mode (MAPC) to produce the same SMILES for every atom regardless of local environment
  • Now correctly uses sub_molecule with rootedAtAtom, matching the non-chirality path
  • Added regression test verifying enantiomers (L-alanine vs D-alanine) produce different fingerprints

Partial fix for #519 (addresses the chirality bug; variant parameter and MinHash support can be added in a follow-up)

Test plan

  • All 8 MAP fingerprint tests pass (including new regression test)
  • Verified L/D-alanine produce identical fingerprints without chirality, different with chirality
  • CI passes

…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
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
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't add explicit issue link - this just tests a given functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks. Removed in 3fa7e08.


Regression test for https://github.com/scikit-fingerprints/scikit-fingerprints/issues/519
"""
from rdkit.Chem import MolFromSmiles
Copy link
Member

Choose a reason for hiding this comment

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

Use global import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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
Copy link
Member

Choose a reason for hiding this comment

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

"With" -> "with" (style consistency with other comments)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

j-adamczyk
j-adamczyk previously approved these changes Mar 10, 2026


def test_map_chirality_uses_substructure():
"""Chirality mode should use sub_molecule SMILES, not full molecule SMILES."""
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this docstring is necessary, other comments cover this anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 6773bb7.

@j-adamczyk j-adamczyk merged commit 6c8b6b3 into MLCIL:master Mar 11, 2026
13 checks passed
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.

2 participants