Skip to content

Commit 42b64e1

Browse files
Stefan Kuhnrajarshi
authored andcommitted
I made sure the MDLV2000Reader considers 0,0,0 coordinates in files with a single atom as 2d and 3d coordinates. The MDLReader does not handle the 0,0,0 case explicitly, so I just added a test for 2d. It might be better to have uniforma handling, but I will file a bug report for that.
Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
1 parent 6ff55ba commit 42b64e1

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/main/org/openscience/cdk/io/MDLV2000Reader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,12 @@ private IMolecule readMolecule(IMolecule molecule) throws CDKException {
573573
// convert to 2D, if totalZ == 0
574574
if (totalX == 0.0 && totalY == 0.0 && totalZ == 0.0) {
575575
logger.info("All coordinates are 0.0");
576-
for (IAtom atomToUpdate : molecule.atoms()) {
577-
atomToUpdate.setPoint3d(null);
576+
if (molecule.getAtomCount()==1){
577+
molecule.getAtom(0).setPoint2d(new Point2d(x,y));
578+
}else{
579+
for (IAtom atomToUpdate : molecule.atoms()) {
580+
atomToUpdate.setPoint3d(null);
581+
}
578582
}
579583
} else if (totalZ == 0.0 && !forceReadAs3DCoords.isSet()) {
580584
logger.info("Total 3D Z is 0.0, interpreting it as a 2D structure");

src/test/org/openscience/cdk/io/MDLReaderTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.openscience.cdk.ChemObject;
3838
import org.openscience.cdk.DefaultChemObjectBuilder;
3939
import org.openscience.cdk.Molecule;
40+
import org.openscience.cdk.exception.CDKException;
4041
import org.openscience.cdk.interfaces.IAtom;
4142
import org.openscience.cdk.interfaces.IAtomContainer;
4243
import org.openscience.cdk.interfaces.IBond;
@@ -221,4 +222,14 @@ public class MDLReaderTest extends SimpleChemObjectReaderTest {
221222
Assert.assertEquals(15, ((Integer)mol.getAtom(1).getProperty(CDKConstants.ATOM_ATOM_MAPPING)).intValue());
222223
Assert.assertNull(mol.getAtom(2).getProperty(CDKConstants.ATOM_ATOM_MAPPING));
223224
}
225+
226+
@Test(expected=AssertionError.class)
227+
public void testHas2DCoordinates_With000() throws CDKException {
228+
String filenameMol = "data/mdl/with000coordinate.mol";
229+
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol);
230+
Molecule molOne=null;
231+
MDLReader reader = new MDLReader(ins, Mode.RELAXED);
232+
molOne = (Molecule)reader.read(new Molecule());
233+
Assert.assertNotNull(molOne.getAtom(0).getPoint2d());
234+
}
224235
}

src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,4 +784,16 @@ private void testShortLinesForMode (IChemObjectReader.Mode mode) throws Exceptio
784784
Assert.assertEquals(15, ((Integer)mol.getAtom(1).getProperty(CDKConstants.ATOM_ATOM_MAPPING)).intValue());
785785
Assert.assertNull(mol.getAtom(2).getProperty(CDKConstants.ATOM_ATOM_MAPPING));
786786
}
787+
788+
@Test public void testHas2DCoordinates_With000() throws CDKException {
789+
String filenameMol = "data/mdl/with000coordinate.mol";
790+
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol);
791+
Molecule molOne=null;
792+
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
793+
molOne = (Molecule)reader.read(new Molecule());
794+
System.out.println(molOne.getAtomCount());
795+
Assert.assertNotNull(molOne.getAtom(0).getPoint2d());
796+
Assert.assertNotNull(molOne.getAtom(0).getPoint3d());
797+
}
798+
787799
}

0 commit comments

Comments
 (0)