Skip to content

Commit

Permalink
Merge pull request #271 from cdk/patch/27Feb17
Browse files Browse the repository at this point in the history
Looks good.
  • Loading branch information
egonw authored Feb 27, 2017
2 parents f1e1e2c + c57989a commit 20c1122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ public static IAtomContainer suppressHydrogens(IAtomContainer org) {

// we need fast adjacency checks (to check for suppression and
// update hydrogen counts)
final int[][] graph = GraphUtil.toAdjList(org);
GraphUtil.EdgeToBondMap bondmap = GraphUtil.EdgeToBondMap.withSpaceFor(org);
final int[][] graph = GraphUtil.toAdjList(org, bondmap);

final int nOrgAtoms = org.getAtomCount();
final int nOrgBonds = org.getBondCount();
Expand All @@ -685,7 +686,7 @@ public static IAtomContainer suppressHydrogens(IAtomContainer org) {
// be suppressed
for (int v = 0; v < nOrgAtoms; v++) {
final IAtom atom = org.getAtom(v);
if (suppressibleHydrogen(org, graph, v)) {
if (suppressibleHydrogen(org, graph, bondmap, v)) {
hydrogens.add(atom);
incrementImplHydrogenCount(org.getAtom(graph[v][0]));
} else {
Expand Down Expand Up @@ -891,7 +892,7 @@ private static void incrementImplHydrogenCount(final IAtom atom) {
* @param v vertex (atom index)
* @return the atom is a hydrogen and it can be suppressed (implicit)
*/
private static boolean suppressibleHydrogen(final IAtomContainer container, final int[][] graph, final int v) {
private static boolean suppressibleHydrogen(final IAtomContainer container, final int[][] graph, final GraphUtil.EdgeToBondMap bondmap, final int v) {

IAtom atom = container.getAtom(v);

Expand All @@ -903,6 +904,8 @@ private static boolean suppressibleHydrogen(final IAtomContainer container, fina
if (atom.getMassNumber() != null && atom.getMassNumber() != 1) return false;
// hydrogen is either not attached to 0 or 2 neighbors
if (graph[v].length != 1) return false;
// non-single bond
if (bondmap.get(v, graph[v][0]).getOrder() != Order.SINGLE) return false;

// okay the hydrogen has one neighbor, if that neighbor is a
// hydrogen (i.e. molecular hydrogen) then we can not suppress it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ public boolean visible(IAtom atom, List<IBond> bonds, RendererModel model) {
if (mass != null && !isMajorIsotope(element.number(), mass)) return true;

// no kink between bonds to imply the presence of a carbon and it must
// be displayed
if (hasParallelBonds(atom, bonds)) {
// TODO only when both bonds are single?
return true;
// be displayed if the bonds have the same bond order
if (bonds.size() == 2 &&
bonds.get(0).getOrder() == bonds.get(1).getOrder()) {
IBond.Order bndord = bonds.get(0).getOrder();
if (bndord == IBond.Order.DOUBLE || hasParallelBonds(atom, bonds))
return true;
}

// special case ethane
Expand Down

0 comments on commit 20c1122

Please sign in to comment.