Skip to content

Commit

Permalink
Corner case - don't suppress hydrogen connected by a non-single bonds.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Feb 27, 2017
1 parent fa43771 commit 34a8908
Showing 1 changed file with 6 additions and 3 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

0 comments on commit 34a8908

Please sign in to comment.