Skip to content

Commit

Permalink
Resolve NPE in circular fingerprint - SF bug:1357.
Browse files Browse the repository at this point in the history
Change-Id: I8848d47fccc4eac2378bf55d751827281a203724
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Feb 12, 2015
1 parent f698b3d commit 989fd7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,14 @@ private int[] rubricTetrahedral(int aidx) {
xp[n] = (float) (o3d.x - x0);
yp[n] = (float) (o3d.y - y0);
zp[n] = (float) (o3d.z - z0);
} else {
} else if (o2d != null) {
IBond.Stereo stereo = bond.getStereo();
xp[n] = (float) (o2d.x - x0);
yp[n] = (float) (o2d.y - y0);
zp[n] = other == bond.getAtom(0) ? 0 : stereo == IBond.Stereo.UP ? 1 : stereo == IBond.Stereo.DOWN ? -1
: 0;
} else {
return null; // no 2D coordinates on some atom
}

final float dx = xp[n] - x0, dy = yp[n] - y0, dz = zp[n] - z0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.vecmath.Point2d;

/**
* @cdk.module test-standard
*/
Expand Down Expand Up @@ -299,11 +301,39 @@ public void iminesDetectionDoesntCauseNPE() throws Exception {
assertNotNull(circ.getBitFingerprint(pyrazole));
}

/**
* @cdk.bug 1357
*/
@Test
public void partialCoordinatesDontCauseNPE() throws Exception {
IAtomContainer m = new AtomContainer();
m.addAtom(atom("C", 3, 0.000, 0.000));
m.addAtom(atom("C", 0, 1.299, -0.750));
m.addAtom(atom("H", 0, 0));
m.addAtom(atom("O", 0, 1));
m.addAtom(atom("C", 2, 2.598, -0.000));
m.addAtom(atom("C", 3, 3.897, -0.750));
m.addBond(0, 1, IBond.Order.SINGLE);
m.addBond(1, 2, IBond.Order.SINGLE);
m.addBond(1, 3, IBond.Order.SINGLE, IBond.Stereo.DOWN);
m.addBond(1, 4, IBond.Order.SINGLE);
m.addBond(4, 5, IBond.Order.SINGLE);
CircularFingerprinter circ = new CircularFingerprinter(CircularFingerprinter.CLASS_ECFP6);
assertNotNull(circ.getBitFingerprint(m));
}

static IAtom atom(String symbol, int q, int h) {
IAtom a = new Atom(symbol);
a.setFormalCharge(q);
a.setImplicitHydrogenCount(h);
return a;
}

static IAtom atom(String symbol, int h, double x, double y) {
IAtom a = new Atom(symbol);
a.setPoint2d(new Point2d(x,y));
a.setImplicitHydrogenCount(h);
return a;
}

}

0 comments on commit 989fd7d

Please sign in to comment.