User c23c5e9da4
24-07-2007 19:22:51
How can I show atom maps when using MolPrinter? I tried using the setDispopts option but this causes the output to be in black and white without anti-aliasing.
import chemaxon.formats.MolImporter;
import chemaxon.marvin.MolPrinter;
import chemaxon.marvin.paint.DispOptConsts;
import chemaxon.struc.Molecule;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class MolPrinterTest {
static BufferedImage createTestImage() throws IOException {
// Create a molecule
Molecule mol = MolImporter.importMol("[CH35][NH24].[CH33][C2]([OH6])=[O1]>>[CH35][NH4][C2]([CH33])=[O1]");
// Create a writable image
BufferedImage im = new BufferedImage(400, 400,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = im.createGraphics();
// Clear background
g.setColor(Color.white);
g.fillRect(0, 0, im.getWidth(), im.getHeight());
// Draw the bounding rectangle
g.setColor(Color.red);
Rectangle r = new Rectangle(20, 20, 360, 200);
g.draw(r);
// Paint the molecule
MolPrinter p = new MolPrinter(mol);
p.setDispopts(DispOptConsts.ATMAP_FLAG);
p.setScale(p.maxScale(r)); // fit image in the rectangle
p.paint(g, r);
return im;
}
public static void main(String[] args) throws Exception {
BufferedImage im = createTestImage();
ImageIO.write(im, "png", new File("test.png"));
}
}
Thanks,
Trevor
import chemaxon.formats.MolImporter;
import chemaxon.marvin.MolPrinter;
import chemaxon.marvin.paint.DispOptConsts;
import chemaxon.struc.Molecule;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class MolPrinterTest {
static BufferedImage createTestImage() throws IOException {
// Create a molecule
Molecule mol = MolImporter.importMol("[CH35][NH24].[CH33][C2]([OH6])=[O1]>>[CH35][NH4][C2]([CH33])=[O1]");
// Create a writable image
BufferedImage im = new BufferedImage(400, 400,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = im.createGraphics();
// Clear background
g.setColor(Color.white);
g.fillRect(0, 0, im.getWidth(), im.getHeight());
// Draw the bounding rectangle
g.setColor(Color.red);
Rectangle r = new Rectangle(20, 20, 360, 200);
g.draw(r);
// Paint the molecule
MolPrinter p = new MolPrinter(mol);
p.setDispopts(DispOptConsts.ATMAP_FLAG);
p.setScale(p.maxScale(r)); // fit image in the rectangle
p.paint(g, r);
return im;
}
public static void main(String[] args) throws Exception {
BufferedImage im = createTestImage();
ImageIO.write(im, "png", new File("test.png"));
}
}
Thanks,
Trevor