Skip to content

Fixes the atom mapper placing hydrogens on the wrong heavy atom (issue #1032). - #1041

Merged
calvinp0 merged 4 commits into
mainfrom
fix_atom_map_hydrogens_follow_labeled_atoms
Sep 7, 2026
Merged

Fixes the atom mapper placing hydrogens on the wrong heavy atom (issue #1032).#1041
calvinp0 merged 4 commits into
mainfrom
fix_atom_map_hydrogens_follow_labeled_atoms

Conversation

@kfir4444

@kfir4444 kfir4444 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

When a reaction involves a symmetric fragment, several atom-map candidates tie on every geometric score, so the choice was made arbitrarily and then corrected after the fact, glue_maps forced the family template's labeled atoms into position by transposing them, but applied that swap only to the labeled atoms themselves, stranding the hydrogens bonded to them. The result was a map where the carbons are right and their hydrogens are attached to each other's carbon, implying spurious C–H breaks and formations.

The fix moves the template constraint upstream so nothing needs patching afterwards, at the two places the arbitrary choice was being made: fragment pairing now breaks ties between isomorphic cuts in favor of the one sharing the most template tags, and backbone-candidate selection filters to candidates satisfying the labeled-atom assignment before they're scored. Both new parameters are optional and default to the previous behavior, so existing callers are unaffected.

On the issue's two reactions the misplaced-hydrogen count goes 8 → 0, and across a 10-reaction probe spanning Diels_alder_addition, 2+2_cycloaddition, Disproportionation and H_Abstraction, the four cases where the template override previously degraded the map drop to zero — including a degenerate abstraction that main maps as "no reaction at all."

@kfir4444

kfir4444 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Linked issue #1032

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.55%. Comparing base (4d67ad4) to head (d4bb944).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
- Coverage   65.69%   65.55%   -0.14%     
==========================================
  Files         121      121              
  Lines       41015    41073      +58     
  Branches    10548    10566      +18     
==========================================
- Hits        26946    26927      -19     
- Misses      11060    11115      +55     
- Partials     3009     3031      +22     
Flag Coverage Δ
functionaltests 65.55% <ø> (-0.14%) ⬇️
unittests 65.55% <ø> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread arc/mapping/engine.py
if not backbone_constraint:
return candidates
filtered = [c for c in candidates if all(c.get(k) == v for k, v in backbone_constraint.items())]
if not filtered:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

before falling back to unconstrained candidates, could we retyr the backbone search with the template correspondences fixed? like for CH2 + allene -> methylenecyclopropane, it appears there is a valid constraint compatible permutation exists, but the current search misses it.

@calvinp0 calvinp0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, just one suggestion

@calvinp0
calvinp0 merged commit 484c678 into main Sep 7, 2026
7 of 8 checks passed
@calvinp0
calvinp0 deleted the fix_atom_map_hydrogens_follow_labeled_atoms branch September 7, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants