Skip to content

Commit b1e7049

Browse files
committed
Improved AAM highlight for reactions, if the bond type changes don't color it.
1 parent 2d466b3 commit b1e7049

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

app/depict/src/main/java/org/openscience/cdk/depict/DepictionGenerator.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.HashMap;
5959
import java.util.List;
6060
import java.util.Map;
61+
import java.util.TreeMap;
6162

6263
/**
6364
* A high-level API for depicting molecules and reactions.
@@ -511,8 +512,10 @@ public Depiction depict(IReaction rxn) throws CDKException {
511512
*/
512513
private Map<IChemObject, Color> makeHighlightAtomMap(List<IAtomContainer> reactants,
513514
List<IAtomContainer> products) {
515+
514516
Map<IChemObject, Color> colorMap = new HashMap<>();
515517
Map<Integer, Color> mapToColor = new HashMap<>();
518+
Map<Integer, IAtom> amap = new TreeMap<>();
516519
int colorIdx = -1;
517520
for (IAtomContainer mol : reactants) {
518521
int prevPalletIdx = colorIdx;
@@ -527,6 +530,7 @@ private Map<IChemObject, Color> makeHighlightAtomMap(List<IAtomContainer> reacta
527530
Color color = atomMapColors[colorIdx];
528531
colorMap.put(atom, color);
529532
mapToColor.put(mapidx, color);
533+
amap.put(mapidx, atom);
530534
}
531535
}
532536
if (colorIdx > prevPalletIdx) {
@@ -548,13 +552,25 @@ private Map<IChemObject, Color> makeHighlightAtomMap(List<IAtomContainer> reacta
548552
colorMap.put(atom, mapToColor.get(mapidx));
549553
}
550554
}
551-
for (IBond bond : mol.bonds()) {
552-
IAtom a1 = bond.getBegin();
553-
IAtom a2 = bond.getEnd();
554-
Color c1 = colorMap.get(a1);
555-
Color c2 = colorMap.get(a2);
556-
if (c1 != null && c1 == c2)
557-
colorMap.put(bond, c1);
555+
for (IBond pBnd : mol.bonds()) {
556+
IAtom pBeg = pBnd.getBegin();
557+
IAtom pEnd = pBnd.getEnd();
558+
Color c1 = colorMap.get(pBeg);
559+
Color c2 = colorMap.get(pEnd);
560+
if (c1 != null && c1 == c2) {
561+
IAtom rBeg = amap.get(accessAtomMap(pBeg));
562+
IAtom rEnd = amap.get(accessAtomMap(pEnd));
563+
if (rBeg != null && rEnd != null) {
564+
IBond rBnd = rBeg.getBond(rEnd);
565+
if (rBnd != null &&
566+
((pBnd.isAromatic() && rBnd.isAromatic()) ||
567+
rBnd.getOrder() == pBnd.getOrder())) {
568+
colorMap.put(pBnd, c1);
569+
} else {
570+
colorMap.remove(rBnd);
571+
}
572+
}
573+
}
558574
}
559575
}
560576

0 commit comments

Comments
 (0)