Hi Christopher, On Fri, Jun 3, 2011 at 12:41 PM, Christopher Rogers <[email protected]> wrote: > I would like to use CDK (or CDK with JChemPaint) to render a molecule into > SVG programmatically.
Yes, that should be more or less possible. The 'possible' comes in as the code has probably not been so often used yet. > I have the contents of a MOL file in a byte[] I'll assume the V2000 version of the molfile format :) // byte[] yourdata = ...; MDLV2000Reader reader = new MDLV2000Reader( new ByteArrayInputStream(yourdata) ); > and I need SVG in a String or written to an OutputStream or a Writer. I have just uploaded example code: https://github.com/egonw/groovy-jcp Look for the svgMol.groovy script (see also below). > Can this be achieved using the pre-made jars downloadable from SourceForge? Yes, premade jars are available from the above groovy-jcp repository. The examples are written in Groovy, but very close in syntax to pure Java. > Is there a method to do this? If so, how do I call it? The new CDK-JChemPaint code refactored the original code to make the core functionality indepdent from the drawing toolkit. And we have two well-developed implementations, one for Swing/AWT (used by the JChemPaint applet), and one for SWT (used by Bioclipse). And there is one that generates SVG too, which is what is used in this svgMol.groovy script. Each of these implementations implement the IDrawVisitor interface. The key, therefore, is to switch the AWTDrawVisitor by the SVGGenerator: -renderer.paint(triazole, new AWTDrawVisitor(g2)); +svgGenerator = new SVGGenerator(); +renderer.paint(triazole, svgGenerator); (comparing the renderMol.groovy with svgMol.groovy) The SVGGenerator method returns the SVG as String with the getResult() method. Now, you will likely notice glitches. Comments, bug reports, and patches most welcome! Egon -- Dr E.L. Willighagen Postdoctoral Researcher Institutet för miljömedicin Karolinska Institutet (http://ki.se/imm) Homepage: http://egonw.github.com/ LinkedIn: http://se.linkedin.com/in/egonw Blog: http://chem-bla-ics.blogspot.com/ PubList: http://www.citeulike.org/user/egonw/tag/papers ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Cdk-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cdk-user

