fix(biochem): use a high-salience mapping palette so rxn00018 groups are visually distinct - #237
Open
VibhavSetlur wants to merge 3 commits into
Open
Conversation
…m glyphs Visual experiment requested by Sam Seaver for the atom-mapping display. Adds two pure SVG post-processing helpers in lib/utils/moleculeHighlights.ts: - applyMoleculeBackground: recolours RDKit's unclassed background rect from #FFFFFF to off-white #F5F5F5, inserting one when absent. - applyAtomGlyphOutline: gives every atom letter path a thin #333333 stroke (width 1.0) with paint-order='stroke', so the outline paints beneath the fill and each atom keeps its mapping colour while staying distinct from the lighter canvas. Both are applied once in MoleculeRenderer, after the existing colour passes and immediately before the SVG is committed to state. Only <path> elements whose class is anchored atom-N are outlined, so highlight ellipses, bond paths and unclassed geometry are untouched. Fallback, PNG and error branches are unchanged. Stroke width chosen from rendered-pixel measurement: RDKit's viewBox equals the pixel size, so 1.0 is a constant 0.5px visible rim at both the 134px inline molecule and the 360px enlarged preview, darkening the outline without fattening the glyphs.
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.
Problem
Sam reported that reaction
rxn00018still shows visually similar atom-mapping colours after #236: three carbon groups that differ technically but look alike, oxygen green/blue too close, and light purple / light orange / light brown insufficiently distinguishable.Two root causes were found:
rxn00018has 7 colourable mapping groups against an 8-colour palette, soselectMappingColorsreturns almost the whole palette and has nothing left to optimise. The prior change improved the numbers for small group counts only.A third defect nobody reported was also found: mapped colour
#D55E00sat only ΔE76 16.5 from RDKit's unmapped phosphorus colour#FF7F00, which is literally on screen in this bisphosphate reaction. That is almost certainly part of the "light orange / light brown" report.Change
Replaces
MAPPING_PALETTEwith a curated, optimiser-verified 8-colour set spanning six hue families, where same-family pairs are separated by ~31 L* so they read as "dark green vs bright green", "deep blue vs sky blue":The palette was chosen by constrained search maximising the minimum normal-vision ΔE76 subject to a hard colour-blind floor, WCAG non-text contrast, and a clearance margin from every RDKit default atom colour. The warm band is deliberately excluded: on a white canvas a >=3:1 contrast requirement forces warm hues dark, and dark warm is brown — which is exactly what Sam was seeing.
No algorithm changed.
selectMappingColors,buildAtomMappingColorPlan, component grouping, group ordering, and theindex % lengthcycling are untouched. Mapping computation and atom-label behaviour are unchanged.Measured result on the colours
rxn00018actually rendersPer complaint: light-purple pair
#CC79A7#960A82(40.2) removed — the purple family is now a single violet; the light-orange/brown pair#D55E00#FA3C5A(44.8) removed with the warm family; the two blues#0072B2~#0A5AE6are replaced by blues split by 31 L*.Colour-blind safety improves rather than regresses, and no safety threshold in the test suite was lowered.
Verification
Real Chromium render of
/biochem/reactions/rxn00018against this branch, compared to the same region on staging: all 7 rendered mapping colours confirmed painting real ink (min 138 px at 3x DPI), no old-palette hex remaining.Full CI mirror, all exit 0:
npm run lint·npx tsc --noEmit·npm run test:run(364 passed, 4 skipped) ·npm run build·npm audit --omit=dev --audit-level=high·git diff --check.New regression test
addresses the rxn00018 high-salience mapping colour reportpins the exact selected hexes, asserts every pair clears ΔE76 45 under normal vision, asserts every entry clears ΔE76 25 from each RDKit default (the previously untested phosphorus clash), and asserts over-capacity reuse rather than falsely claiming uniqueness.One pre-existing assertion was adjusted, not weakened: the blanket "optimal subset strictly beats the naive prefix" check now names the counts where it is strict
{2,3,4,5,7}and allows equality at 6 and 8, where the leading palette run is itself an optimal subset. Aslice(0, count)stub still fails the strict counts, so the check retains its power.Release
Patch bump 3.5.1 -> 3.5.2 (
fix-only) acrossVERSION.md,package.json, andCHANGELOG.md.