5656import java .util .Collection ;
5757import java .util .Collections ;
5858import java .util .HashMap ;
59+ import java .util .HashSet ;
5960import java .util .List ;
6061import java .util .Map ;
62+ import java .util .Set ;
6163import java .util .TreeMap ;
6264
6365/**
@@ -513,6 +515,18 @@ public Depiction depict(IReaction rxn) throws CDKException {
513515 private Map <IChemObject , Color > makeHighlightAtomMap (List <IAtomContainer > reactants ,
514516 List <IAtomContainer > products ) {
515517
518+ // only highlight atom-maps that appear in both the reactant+product
519+ Set <Integer > reactantMapIdxs = new HashSet <>();
520+ Set <Integer > productMapIdxs = new HashSet <>();
521+ for (IAtomContainer mol : reactants ) {
522+ for (IAtom atom : mol .atoms ())
523+ reactantMapIdxs .add (accessAtomMap (atom ));
524+ }
525+ for (IAtomContainer mol : products ) {
526+ for (IAtom atom : mol .atoms ())
527+ productMapIdxs .add (accessAtomMap (atom ));
528+ }
529+
516530 Map <IChemObject , Color > colorMap = new HashMap <>();
517531 Map <Integer , Color > mapToColor = new HashMap <>();
518532 Map <Integer , IAtom > amap = new TreeMap <>();
@@ -521,7 +535,7 @@ private Map<IChemObject, Color> makeHighlightAtomMap(List<IAtomContainer> reacta
521535 int prevPalletIdx = colorIdx ;
522536 for (IAtom atom : mol .atoms ()) {
523537 int mapidx = accessAtomMap (atom );
524- if (mapidx > 0 ) {
538+ if (mapidx > 0 && productMapIdxs . contains ( mapidx ) ) {
525539 if (prevPalletIdx == colorIdx ) {
526540 colorIdx ++; // select next color
527541 if (colorIdx >= atomMapColors .length )
@@ -548,7 +562,7 @@ private Map<IChemObject, Color> makeHighlightAtomMap(List<IAtomContainer> reacta
548562 for (IAtomContainer mol : products ) {
549563 for (IAtom atom : mol .atoms ()) {
550564 int mapidx = accessAtomMap (atom );
551- if (mapidx > 0 ) {
565+ if (mapidx > 0 && reactantMapIdxs . contains ( mapidx ) ) {
552566 colorMap .put (atom , mapToColor .get (mapidx ));
553567 }
554568 }
0 commit comments