On Friday 21 November 2008 18:38, Egon Willighagen wrote: > On Fri, Nov 21, 2008 at 5:51 PM, Adel Golovin <[EMAIL PROTECTED]> wrote: > > With this code I try to zero coordinates so, the generator will be forced > > to produce them. > > Well, you can better make them 'null', and, you should at least change > the 2D coordinates: > > for (IAtom atom : mol.atoms()) atom.setPoint2d(null); > > Egon Thanks, Now it generates the 2D coordinates but still the image I get back is black square.
The code is as follows: // read molecule from MDL file org.openscience.cdk.io.MDLReader cdkMDL = new org.openscience.cdk.io.MDLReader(mdl); org.openscience.cdk.Molecule mol = new org.openscience.cdk.Molecule(); cdkMDL.read(mol); // null the coordinates Iterator<org.openscience.cdk.interfaces.IAtom> itatoms = mol.atoms(); while (itatoms.hasNext()) { org.openscience.cdk.interfaces.IAtom atom = itatoms.next(); atom.setPoint2d(null); atom.setPoint3d(null); } // generate coordinates org.openscience.cdk.layout.StructureDiagramGenerator sdg = new org.openscience.cdk.layout.StructureDiagramGenerator(); sdg.setMolecule(mol); sdg.generateCoordinates(); org.openscience.cdk.interfaces.IMolecule layedOutMol = sdg.getMolecule(); // render org.openscience.cdk.renderer.SimpleRenderer2D renderer = new org.openscience.cdk.renderer.SimpleRenderer2D(); org.openscience.cdk.renderer.Renderer2DModel r2dm = new org.openscience.cdk.renderer.Renderer2DModel(); r2dm.setDrawNumbers(false); r2dm.setUseAntiAliasing(true); r2dm.setColorAtomsByType(true); r2dm.setShowImplicitHydrogens(true); r2dm.setShowAromaticity(true); r2dm.setShowReactionBoxes(false); r2dm.setKekuleStructure(false); renderer.setRenderer2DModel(r2dm); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = bufferedImage.createGraphics(); Rectangle2D bounds = new Rectangle2D.Double(0, 0, width, height); renderer.paintMolecule(layedOutMol, graphics, bounds); // write the image javax.imageio.ImageIO.write(bufferedImage, "png", out); -- Adel ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user