G'day, I'm migrating code from CDK 1.2 to 1.4. The code I wrote (several years ago now) for structure diagram generation still compiles and runs against CDK 1.4 but I'm wondering whether there are better techniques available now.
The code I use is in a utility class (of static methods): private static final StructureDiagramGenerator SDG = new StructureDiagramGenerator(); /** * Layout molecule structure diagram. * * @param mol the molecule to layout. * @return Laid out molecule. */ public static IAtomContainer layoutMolecule(final IAtomContainer mol) { // Layout structure. final IAtomContainer ac = makeHydrogensImplicit(mol); // Aromaticity. try { CDKHueckelAromaticityDetector.detectAromaticity(ac); } catch (final CDKException e) { LOG.log(Level.WARNING, "Failed to calculate aromaticity", e); } ac.setProperties(mol.getProperties()); return layout2D(ac); } /** * Lays out a 2D structure diagram. * * @param ac the molecule to layout. * @return A new molecule laid out in 2D. If the molecule already has 2D * coordinates then it is returned unchanged. If layout fails then null is * returned. */ public static IAtomContainer layout2D(final IAtomContainer ac) { LOG.fine("Layout structure"); // Generate 2D coordinates? if (GeometryTools.has2DCoordinates(ac)) { return ac; } else { // Generate 2D structure diagram (for each connected component). final IAtomContainer ac2d = new AtomContainer(); final IMoleculeSet som = ConnectivityChecker.partitionIntoMolecules(ac); for (int n = 0; n < som.getMoleculeCount(); n++) { synchronized (SDG) { IMolecule mol = som.getMolecule(n); SDG.setMolecule(mol, true); try { // Generate 2D coordinates for this molecule. SDG.generateCoordinates(); mol = SDG.getMolecule(); } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to generate 2D structure for " + ac.getID() + " (" + n + ") - using projection", e); Projector.project2D(mol); } ac2d.add(mol); // add 2D molecule. } } return GeometryTools.has2DCoordinates(ac2d) ? ac2d : null; } } I'm also interested in checking the currency of makeHydrogensImplicit() but I'll ask about that in a separate message. Thanks, Chris. Syngenta Limited, Registered in England No 2710846 Registered Office : Syngenta Limited, European Regional Centre, Priestley Road, Surrey Research Park, Guildford, Surrey, GU2 7YH, United Kingdom message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user