Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #350 from cdk/patch/symbol_vis
Fix symbol visibility such that carbons with a charge are always shown.
  • Loading branch information
egonw committed Jul 26, 2017
2 parents 5851070 + 5513e39 commit e8d1777
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -123,6 +123,10 @@ public boolean visible(IAtom atom, List<IBond> bonds, RendererModel model) {
// abnormal valence, could be due to charge or unpaired electrons
if (!isFourValent(atom, bonds)) return true;

// charge, normally caught by previous rule but can have bad input: C=[CH-]C
if (atom.getFormalCharge() != null &&
atom.getFormalCharge() != 0) return true;

// carbon isotopes are displayed
Integer mass = atom.getMassNumber();
if (mass != null && !isMajorIsotope(element.number(), mass)) return true;
Expand Down
Expand Up @@ -212,4 +212,21 @@ public void ethaneNonTerminal() {
.visible(a1, Collections.singletonList(bond1), new RendererModel()));
}

@Test
public void alwaysDisplayCharges() {
IAtom a1 = new Atom("CH-");
IAtom a2 = new Atom("CH2");
IAtom a3 = new Atom("CH3");

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

IBond bond1 = new Bond(a1, a2, IBond.Order.DOUBLE);
IBond bond2 = new Bond(a2, a3, IBond.Order.SINGLE);

assertTrue(SymbolVisibility.iupacRecommendationsWithoutTerminalCarbon()
.visible(a1, Arrays.asList(bond1, bond2), new RendererModel()));
}

}

0 comments on commit e8d1777

Please sign in to comment.