File tree Expand file tree Collapse file tree
main/org/openscience/cdk/io
test/org/openscience/cdk/io Expand file tree Collapse file tree Original file line number Diff line number Diff 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" );
Original file line number Diff line number Diff line change 3737import org .openscience .cdk .ChemObject ;
3838import org .openscience .cdk .DefaultChemObjectBuilder ;
3939import org .openscience .cdk .Molecule ;
40+ import org .openscience .cdk .exception .CDKException ;
4041import org .openscience .cdk .interfaces .IAtom ;
4142import org .openscience .cdk .interfaces .IAtomContainer ;
4243import 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments