Skip to content

Commit

Permalink
Patch for bug 2843445. Aims to fix generation of NaN coordinates by SDG
Browse files Browse the repository at this point in the history
  • Loading branch information
mark_rynbeek authored and egonw committed Oct 15, 2009
1 parent 6f6f41e commit d1397fe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/main/org/openscience/cdk/layout/OverlapResolver.java
Expand Up @@ -129,7 +129,13 @@ public double displace(IAtomContainer ac, Vector overlappingAtoms, Vector overla
v2 = new Vector2d(a2.getPoint2d());
v2.sub(v1);
v2.normalize();
v2.scale(bondLength / 20.0);

if(Double.isNaN(v2.x))
v2.x=0.01;
if(Double.isNaN(v2.y))
v2.y=0.01;

v2.scale(bondLength / 20.0);
logger.debug("Calculation translation vector " + v2);
choice = Math.random();
if (choice > 0.5)
Expand Down
@@ -1,6 +1,5 @@
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 2003-2007 Christoph Steinbeck <steinbeck@users.sf.net>
/* Copyright (C) 2003-2007 Christoph Steinbeck <steinbeck@users.sf.net>
* 2009 Mark Rijnbeek <markr@ebi.ac.uk>
*
* Contact: cdk-devel@lists.sourceforge.net
*
Expand Down Expand Up @@ -29,6 +28,7 @@
import javax.vecmath.Vector2d;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.Atom;
Expand All @@ -38,7 +38,9 @@
import org.openscience.cdk.Molecule;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.geometry.GeometryTools;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemModel;
Expand Down Expand Up @@ -843,5 +845,51 @@ public void testBug1784850InfiniteLoop() throws Exception {
// test completed, no timeout occured
}

/**
* For the SMILES compound below (the largest molecule in Chembl) a
* handful of atoms had invalid (NaN) Double coordinates.
*
* @cdk.bug 2843445
*/
@Test (timeout=5000)
public void testBug2843445NaNCoords() throws Exception {

SmilesParser sp =
new SmilesParser(NoNotificationChemObjectBuilder.getInstance());
String smiles =
"CCCC[C@H](NC(=O)[C@H](CCC(O)=O)NC(=O)[C@@H](NC(=O)[C@@H](CCCC)NC" +
"(=O)[C@H](CC(N)=O)NC(=O)[C@H](CCC\\N=C(\\N)N)NC(=O)[C@H](CC(C)C)NC" +
"(=O)[C@H](CC(C)C)NC(=O)[C@H](CC1=CNC=N1)NC(=O)[C@H](CC1=CC=CC=C1" +
")NC(=O)[C@@H](NC(=O)[C@H](CC(C)C)NC(=O)[C@H](CC(O)=O)NC(=O)[C@@H" +
"](NC(=O)[C@H](CO)NC(=O)[C@@H](NC(=O)[C@@H]1CCCN1C(=O)[C@@H]1CCCN" +
"1C(=O)[C@H](CC(O)=O)NC(=O)[C@H](CC(O)=O)NC(=O)[C@@H](N)CC(N)=O)[" +
"C@@H](C)CC)[C@@H](C)CC)[C@@H](C)O)[C@@H](C)CC)C(=O)N[C@@H](C)C(=" +
"O)N[C@@H](CCC\\N=C(\\N)N)C(=O)N[C@@H]([C@@H](C)CC)C(=O)N[C@@H](CCC" +
"(O)=O)C(=O)N[C@@H](CC(N)=O)C(=O)N[C@@H](CCC(=O)OC)C(=O)N[C@@H](C" +
"CC\\N=C(\\N)N)C(=O)N[C@@H](CCC(O)=O)C(=O)N[C@@H](CCC(O)=O)C(=O)N[C" +
"@@H](C)C(=O)NCC(=O)N[C@@H](CCCCN)C(=O)N[C@@H](CC(N)=O)C(=O)N[C@@" +
"H](CCC\\N=C(\\N)N)C(=O)N[C@@H](CCCCN)C(=O)N[C@@H](CC1=CC=C(O)C=C1)" +
"C(=O)N[C@@H](CC(C)C)C(=O)N[C@@H](CC(O)=O)C(=O)N[C@@H](CCC(O)=O)C" +
"(=O)N[C@@H](C(C)C)C(N)=O";
IMolecule mol = sp.parseSmiles(smiles);

StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setMolecule(mol);
sdg.generateCoordinates(new Vector2d(0, 1));
mol = sdg.getMolecule();

int invalidCoordCount=0;
for (IAtom atom: mol.atoms()) {
if (Double.isNaN(atom.getPoint2d().x) ||
Double.isNaN(atom.getPoint2d().y)) {
invalidCoordCount++;
}
}
Assert.assertEquals("No 2d coordinates should be NaN",
0, invalidCoordCount
);
}


}

0 comments on commit d1397fe

Please sign in to comment.