From: SourceForge.net <no...@so...> - 2003-11-04 13:12:10
|
Bugs item #833535, was opened at 2003-10-31 08:30 Message generated for change (Comment added) made by egonw You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=120024&aid=833535&group_id=20024 Category: cdk-standard module Group: None Status: Closed Resolution: Accepted Priority: 5 Submitted By: Chris Pudney (cpudney) Assigned to: Egon Willighagen (egonw) Summary: NullPointerException in getBondCoordinates() Initial Comment: G'day, I've just migrated to cdk-20031017 and can no longer (2D) render some sturctures. A NullPointerException is raised in org.openscience.cdk.geometry.GeometryTools.getBondCoordinates(GeometryTools.java:382) (details below): The offending line is: 382: int beginX = (int)bond.getAtomAt(0).getPoint2D().x; The problem is that Atom.point2D == null (not properly initialized?) The attached example program illustrates the problem when run with the following input: ----- Rxxxxxx OMFMANAGER09140105503D 0.0000024924 43 44 0 0 0 0 0 0 0 0 1 V2000 -1.1103 -0.8724 0.0000 N 0 0 3 0 0 0 -1.8862 -0.4241 0.0000 C 0 0 0 0 0 0 -0.3448 -0.3724 0.0000 C 0 0 0 0 0 0 -0.8172 -1.7828 0.0000 C 0 0 0 0 0 0 -1.8862 0.4655 0.0000 C 0 0 0 0 0 0 -2.6621 -0.8724 0.0000 C 0 0 0 0 0 0 0.4379 -0.8724 0.0000 C 0 0 3 0 0 0 -0.3379 0.4793 0.0000 O 0 0 0 0 0 0 0.1448 -1.7828 0.0000 C 0 0 0 0 0 0 -2.6621 0.9172 0.0000 C 0 0 0 0 0 0 -3.4379 -0.4241 0.0000 C 0 0 0 0 0 0 1.2138 -0.4241 0.0000 O 0 0 0 0 0 0 -3.4379 0.4655 0.0000 C 0 0 0 0 0 0 -2.6621 1.8276 0.0000 Cl 0 0 0 0 0 0 -4.2241 -0.8828 0.0000 Cl 0 0 0 0 0 0 1.9897 -0.8724 0.0000 C 0 0 0 0 0 0 -4.2276 0.9241 0.0000 F 0 0 0 0 0 0 2.7621 -0.4241 0.0000 N 0 0 3 0 0 0 1.9897 -1.7690 0.0000 O 0 0 0 0 0 0 3.5379 -0.8724 0.0000 C 0 0 3 0 0 0 2.7621 0.4897 0.0000 C 0 0 0 0 0 0 4.3138 -0.4241 0.0000 C 0 0 0 0 0 0 3.5379 -1.7690 0.0000 C 0 0 0 0 0 0 4.3448 -1.2966 0.0000 C 0 0 0 0 0 0 -1.1843 -2.2866 -0.8820 H 0 0 0 0 0 0 -1.1843 -2.2866 0.8820 H 0 0 0 0 0 0 -0.9499 1.0038 0.0000 H 0 0 0 0 0 0 -2.6621 -1.9524 0.0000 H 0 0 0 0 0 0 0.4379 -0.8724 1.0800 H 0 0 0 0 0 0 0.5119 -2.2866 -0.8820 H 0 0 0 0 0 0 0.5119 -2.2866 0.8820 H 0 0 0 0 0 0 2.7621 0.8502 1.0181 H 0 0 0 0 0 0 1.8804 0.8502 -0.5090 H 0 0 0 0 0 0 3.6438 0.8502 -0.5090 H 0 0 0 0 0 0 4.6260 -0.2437 -1.0181 H 0 0 0 0 0 0 5.0670 -1.0071 0.5090 H 0 0 0 0 0 0 4.1849 0.5197 0.5090 H 0 0 0 0 0 0 3.5379 -2.1295 -1.0181 H 0 0 0 0 0 0 2.6562 -2.1295 0.5090 H 0 0 0 0 0 0 4.4196 -2.1295 0.5090 H 0 0 0 0 0 0 4.6639 -1.4644 -1.0181 H 0 0 0 0 0 0 4.2536 -2.2447 0.5090 H 0 0 0 0 0 0 5.0742 -0.6840 0.5090 H 0 0 0 0 0 0 1 2 1 0 0 0 0 1 3 1 0 0 0 0 1 4 1 0 0 0 0 2 5 2 0 0 0 0 2 6 1 0 0 0 0 3 7 1 0 0 0 0 3 8 2 0 0 0 0 4 9 1 0 0 0 0 5 10 1 0 0 0 0 6 11 2 0 0 0 0 7 12 1 0 0 0 0 10 13 2 0 0 0 0 10 14 1 0 0 0 0 11 15 1 0 0 0 0 12 16 1 0 0 0 0 13 17 1 0 0 0 0 16 18 1 0 0 0 0 16 19 2 0 0 0 0 18 20 1 0 0 0 0 18 21 1 0 0 0 0 20 22 1 0 0 0 0 20 23 1 0 0 0 0 20 24 1 0 0 0 0 7 9 1 0 0 0 0 11 13 1 0 0 0 0 4 25 1 0 0 0 0 4 26 1 0 0 0 0 5 27 1 0 0 0 0 6 28 1 0 0 0 0 7 29 1 0 0 0 0 9 30 1 0 0 0 0 9 31 1 0 0 0 0 21 32 1 0 0 0 0 21 33 1 0 0 0 0 21 34 1 0 0 0 0 22 35 1 0 0 0 0 22 36 1 0 0 0 0 22 37 1 0 0 0 0 23 38 1 0 0 0 0 23 39 1 0 0 0 0 23 40 1 0 0 0 0 24 41 1 0 0 0 0 24 42 1 0 0 0 0 24 43 1 0 0 0 0 M END $$$$ ----- The full exception is: /usr/java/j2sdk1.4.2/bin/java -classpath /home/chris/IdeaProjects/CDKMoleculeViewer2D/classes:/usr/java/j2sdk1.4.2/jre/lib/sunrsasign.jar:/usr/java/j2sdk1.4.2/jre/lib/jce.jar:/usr/java/j2sdk1.4.2/jre/lib/jsse.jar:/usr/java/j2sdk1.4.2/jre/lib/charsets.jar:/usr/java/j2sdk1.4.2/jre/lib/plugin.jar:/usr/java/j2sdk1.4.2/jre/lib/rt.jar:/usr/java/j2sdk1.4.2/jre/lib/ext/sunjce_provider.jar:/usr/java/j2sdk1.4.2/jre/lib/ext/dnsns.jar:/usr/java/j2sdk1.4.2/jre/lib/ext/ldapsec.jar:/usr/java/j2sdk1.4.2/jre/lib/ext/localedata.jar:/home/chris/Syngenta/cdk-source-20031017/jar/gnujaxp.jar:/home/chris/Syngenta/cdk-source-20031017/jar/vecmath1.2-1.14.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-apps.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-core.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-experimental.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-extra.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-io.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-libio.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-render.jar:/home/chris/Syngenta/cdk-source-20031017/dist/jar/cdk-standard.jar MoleculeViewer /home/chris/test.sdf java.lang.NullPointerException at org.openscience.cdk.geometry.GeometryTools.getBondCoordinates(GeometryTools.java:382) at org.openscience.cdk.renderer.Renderer2D.paintInnerBond(Renderer2D.java:938) at org.openscience.cdk.renderer.Renderer2D.paintRingBond(Renderer2D.java:834) at org.openscience.cdk.renderer.Renderer2D.paintBonds(Renderer2D.java:756) at org.openscience.cdk.renderer.Renderer2D.paintMolecule(Renderer2D.java:260) at org.openscience.cdk.renderer.MoleculeViewer2D.paint(MoleculeViewer2D.java:219) at javax.swing.JComponent.paintChildren(JComponent.java:647) at javax.swing.JComponent.paint(JComponent.java:817) at javax.swing.JComponent.paintChildren(JComponent.java:647) at javax.swing.JComponent.paint(JComponent.java:817) at javax.swing.JLayeredPane.paint(JLayeredPane.java:557) at javax.swing.JComponent.paintChildren(JComponent.java:647) at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4802) at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4748) at javax.swing.JComponent.paint(JComponent.java:798) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97) at java.awt.Container.paint(Container.java:1312) at sun.awt.RepaintArea.paint(RepaintArea.java:177) at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:405) at java.awt.Component.dispatchEventImpl(Component.java:3678) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) java.lang.NullPointerException at org.openscience.cdk.geometry.GeometryTools.getBondCoordinates(GeometryTools.java:382) at org.openscience.cdk.renderer.Renderer2D.paintInnerBond(Renderer2D.java:938) at org.openscience.cdk.renderer.Renderer2D.paintRingBond(Renderer2D.java:834) at org.openscience.cdk.renderer.Renderer2D.paintBonds(Renderer2D.java:756) at org.openscience.cdk.renderer.Renderer2D.paintMolecule(Renderer2D.java:260) at org.openscience.cdk.renderer.MoleculeViewer2D.paint(MoleculeViewer2D.java:219) at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4795) at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4748) at javax.swing.JComponent._paintImmediately(JComponent.java:4692) at javax.swing.JComponent.paintImmediately(JComponent.java:4495) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410) at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178) at java.awt.EventQueue.dispatchEvent(EventQueue.java:454) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) ----- Regards, Chris. ---------------------------------------------------------------------- >Comment By: Egon Willighagen (egonw) Date: 2003-11-04 14:12 Message: Logged In: YES user_id=25678 Chris, you could try using the cdk.tools.ConnectivityChecker.partitionIntoMolecules(m)... ---------------------------------------------------------------------- Comment By: Chris Pudney (cpudney) Date: 2003-11-04 08:51 Message: Logged In: YES user_id=624072 G'day, > about the convert3DTo2D() method... there used to be such > method... The name is not very intuitively, but see > cdk.tools.Projector... OK - I can use this instead. > about has2DCoordinates()... I think that this method tests that > *all* atoms have 2D coordinates... it only returns true if all > atoms have 2D coordinates... You're absolutely correct - my mistake. > BTW, a good alternative to create 2D coordinates (maybe even > better than projection in the XY plane) is to use the > cdk.layout.StructureDIagramGenerator... It does a pretty good > job... So it does - thanks. > Does this help? Very much. I now have: // Generate 2D coordinates? if (!GeometryTools.has2DCoordinates(m)) { if (conn_checker.isConnected(m)) // can't use SDG on disconnected structures. { sdg.setMolecule(m); try { // Generate 2D structure diagram. sdg.generateCoordinates(); m = sdg.getMolecule(); } catch (Exception e) { logger.warn("Failed to generate 2D structure for " + title + " - using projection"); Projector.project2D(m); } } else { logger.info("Diconnected structure for " + title + " - using projection"); Projector.project2D(m); } } // Store 2D coordinates (assuming above worked). if (GeometryTools.has2DCoordinates(m)) { hash.put(key, m); // store 2D structure. } ---------------------------------------------------------------------- Comment By: Egon Willighagen (egonw) Date: 2003-11-03 08:39 Message: Logged In: YES user_id=25678 Hi Chris, about the convert3DTo2D() method... there used to be such method... The name is not very intuitively, but see cdk.tools.Projector... about has2DCoordinates()... I think that this method tests that *all* atoms have 2D coordinates... it only returns true if all atoms have 2D coordinates... about Renderer2DModel.HandleMissing2DCoordinates... we try to keep algorithms separated... in this case rendering is standalone... so I do not really like having coordinate creation in the Renderer2D... it would suggest people to use the methods defined in the Renderer2D, and not others... BTW, a good alternative to create 2D coordinates (maybe even better than projection in the XY plane) is to use the cdk.layout.StructureDIagramGenerator... It does a pretty good job... Does this help? Egon ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2003-11-03 08:18 Message: Logged In: NO G'day, > I've modified the GeometryTools method to make > some noise to the logger and fail silently with a zero element > array. This behaviour might not be desirable in certain circumstances - it certainly isn't in our case. We have SDFs containing 3D coordinates that we want to render in 2D. Therefore, would it be possible to include the following method in GeometryTools: /** * Convert the 3D coordinates of an AtomContainer's Atoms from to 2D. * * @param container the AtomContainer to convert. */ public static void convert3DTo2D(AtomContainer container) { // Convert Atoms. Atom[] atoms = container.getAtoms(); final int length = atoms.length; for (int i = 0; i < length; i++) { final Atom atom = atoms[i]; Point3d pt = atom.getPoint3D(); atom.setPoint2D(new Point2d(pt.x, pt.y)); } } That way I (and others) can at least derive a set of 2D coordinates for use by the Renderer2D. E.g. // Make sure molecule has 2D coordinates. if (!GeometryTools.has2DCoordinates(m)) { GeometryTools.convert3DTo2D(m); } I realise this is not foolproof as has2DCoordinates() only indicates the presence of 2D coordinates not that _all_ Atoms have 2D coordinates. A more robust approach would be to provide a property on the Renderer2DModel that determines how to handle the case of missing 2D coordinates, e.g. Renderer2DModel.HandleMissing2DCoordinates that can take on the following values: Renderer2DModel.IGNORE Renderer2DModel.EXCEPTION Renderer2DModel.LOG Renderer2DModel.USE3DXY with the obvious semantics. I'm assuming that similar functionality doesn't already exist in CDK. If there is some other means of dealing with this problem then please let me know. Thanks, Chris. ---------------------------------------------------------------------- Comment By: Egon Willighagen (egonw) Date: 2003-11-01 15:26 Message: Logged In: YES user_id=25678 Recently, the MDLReader was changed to detect the kind of coordinates in the file. It used to store all coordinates as both 2D and 3D, which is wrong. The given MOL file only contains 3D coordinates. The Renderer2D does not, however, check each time wether the Molecule to be drawn has 2D coordinates (too inefficient). I've modified the GeometryTools method to make some noise to the logger and fail silently with a zero element array. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=120024&aid=833535&group_id=20024 |