use of org.openscience.cdk.renderer.visitor.AWTDrawVisitor in project Smiles2Monomers by yoann-dufresne.
the class AbstractPictureGenerator method createPNG.
/**
* Create a PNG picture of molecule with width and height sizes
* @param molecule Molecule to be print
* @param outfile Out file
*/
public void createPNG(IMolecule molecule, File outfile) {
/* Warning : This part of code change IAtoms coordinates
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setMolecule(molecule);
try {
sdg.generateCoordinates();
molecule = sdg.getMolecule();
} catch (CDKException e1) {
e1.printStackTrace();
}*/
// the draw area and the image should be the same size
Rectangle drawArea = new Rectangle(0, 0, SIZE, SIZE);
this.renderer.setup(molecule, drawArea);
Rectangle diagramBounds = this.renderer.calculateDiagramBounds(molecule);
int width = diagramBounds.width;
int height = diagramBounds.height;
int diff = Math.abs(width - height);
int max = width > height ? width : height;
int xshift = width > height ? 0 : diff / 2;
int yshift = width > height ? diff / 2 : 0;
// Recenter image
this.renderer.shiftDrawCenter(xshift - diagramBounds.x, yshift - diagramBounds.y);
Image image = new BufferedImage(max, max, BufferedImage.TYPE_INT_RGB);
// Drawing options
this.model.set(ColoredAtomGenerator.KekuleStructure.class, true);
this.model.set(ColoredAtomGenerator.ColorByType.class, true);
// paint the background
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, max, max);
// the paint method also needs a toolkit-specific renderer
this.renderer.paint(molecule, new AWTDrawVisitor(g2));
try {
ImageIO.write((RenderedImage) image, "PNG", outfile);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.openscience.cdk.renderer.visitor.AWTDrawVisitor in project Smiles2Monomers by yoann-dufresne.
the class PictureGenerator method createPNG.
/**
* Create a PNG picture of molecule with width and height sizes
* @param smiles SMILES of the molecule to be print
* @param outfile Out file
* @throws InvalidSmilesException
*/
public void createPNG(String smiles, File outfile) throws InvalidSmilesException {
IMolecule molecule = this.transform(smiles);
// the draw area and the image should be the same size
Rectangle drawArea = new Rectangle(0, 0, SIZE, SIZE);
this.renderer.setup(molecule, drawArea);
Rectangle diagramBounds = this.renderer.calculateDiagramBounds(molecule);
int width = diagramBounds.width;
int height = diagramBounds.height;
int diff = Math.abs(width - height);
int max = width > height ? width : height;
int xshift = width > height ? 0 : diff / 2;
int yshift = width > height ? diff / 2 : 0;
// Recenter image
this.renderer.shiftDrawCenter(xshift - diagramBounds.x, yshift - diagramBounds.y);
Image image = new BufferedImage(max, max, BufferedImage.TYPE_INT_RGB);
// Drawing options
this.model.set(BasicAtomGenerator.KekuleStructure.class, true);
this.model.set(BasicAtomGenerator.ColorByType.class, true);
// paint the background
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, max, max);
// the paint method also needs a toolkit-specific renderer
this.renderer.paint(molecule, new AWTDrawVisitor(g2));
try {
ImageIO.write((RenderedImage) image, "PNG", outfile);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations