Skip to content

Commit

Permalink
Adjustment required to symbol visibility, otherwise carbons will be d…
Browse files Browse the repository at this point in the history
…isplayed as '>CH' in the delocalised rings.
  • Loading branch information
johnmay committed Dec 29, 2017
1 parent 2ffa3e1 commit 603bc2d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,23 @@ public boolean visible(IAtom atom, List<IBond> bonds, RendererModel model) {
private static boolean isFourValent(IAtom atom, List<IBond> bonds) {
Integer valence = atom.getImplicitHydrogenCount();
if (valence == null) return true;
for (final IBond bond : bonds) {
valence += bond.getOrder().numeric();
if (atom.isAromatic()) {
boolean hasUnsetArom = false;
for (final IBond bond : bonds) {
if (bond.getOrder() == IBond.Order.UNSET && bond.isAromatic()) {
hasUnsetArom = true;
valence++;
} else {
valence += bond.getOrder().numeric();
}
}
// valence nudge, we're only dealing with neutral carbons here
// and if
if (hasUnsetArom)
valence++;
} else {
for (final IBond bond : bonds)
valence += bond.getOrder().numeric();
}
return valence == 4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,26 @@ public void alwaysDisplayCharges() {
.visible(a1, Collections.singletonList(bond1), new RendererModel()));
}

@Test
public void delocalisedCarbons() {
IAtom a1 = new Atom("CH");
IAtom a2 = new Atom("CH");
IAtom a3 = new Atom("CH");

a1.setPoint2d(new Point2d(0, 0));
a2.setPoint2d(new Point2d(0.5, -0.5));
a3.setPoint2d(new Point2d(1, 0));

IBond bond1 = new Bond(a1, a2, IBond.Order.UNSET);
IBond bond2 = new Bond(a2, a3, IBond.Order.UNSET);
bond1.setIsAromatic(true);
bond2.setIsAromatic(true);
a1.setIsAromatic(true);
a2.setIsAromatic(true);
a3.setIsAromatic(true);

assertFalse(SymbolVisibility.iupacRecommendationsWithoutTerminalCarbon()
.visible(a2, Arrays.asList(bond1, bond2), new RendererModel()));
}

}

0 comments on commit 603bc2d

Please sign in to comment.