Scaling using MolPrinter

User d7cf0350f9

17-07-2009 23:54:00

Hi,


I'm not sure if this is the right area to post, but here we go...


I'm writing a script in Java to read an SDF file and export the structure as a PNG file.  I'm using the MolPrinter example in the Java API as a base for exporting the image.  My goal is to highlight atoms and export the new image using a property listing on the SDF file.


However, the image of the molecule is scaled to fit the BufferedImage.  After a little debugging, I find that the original default scale is -1.54 using MolPrinter.getScale(), and after scaling to 250x250, the new scale is set to 35.499.  What does -1.54 mean?  Is there a way to determine the coordinate of each atom in terms of pixels by using their coordinates from the SDF file?  Or for that matter, from the coordinates using MolAtom.getLocation()?


Thanks,


Eric

ChemAxon 909aee4527

20-07-2009 10:06:46

Hi Eric,


you can use the code below to prevent overscaling of smaller molecules:


        double scale = printer.maxScale(getSize());
        if( scale > SketchPanel.DEFAULT_SCALE ) {
            scale = SketchPanel.DEFAULT_SCALE;
        }
        printer.setScale(scale);
The scale value means the number of pixels a Carbon-Carbon single bond will be painted with.
The default value (zoomed to 100%) that SketchPanel.DEFAULT_SCALE represents is 28.


The scale value has to be set to MolPrinter before displaying the molecule, otherwise the molecule is not displayed. The default value (-1.54) has no sense in this situation, don't bother with it.


I suppose the question relating atom pixel coordinates is not relevant after using the code sample. If it still is, please tell us what you need, and we might help you more specifically.


Kind regards,
Judit

User d7cf0350f9

20-07-2009 18:11:11

Thanks for the response, Judit.


Sorry, I seems I didn't give enough details on what needs to be done.


I'm actually just using MolPrinter as a way to read a 2D molecule from an sdf file and render it into an image.  Once the image is rendered, I'll be using RadialGradientPaint to draw a gradient circle around the atom, thus "highlighting" the atom. 


To do this, I need the location of the atoms in pixels, but the atom location is defined in arbitrary units in the SDF file, so its hard to determine how the coordinates scale out.


The SDF file will have the atom index numbers and colors listed as a property.  The script will run in the command line, read the file and output an image with the atoms highlighted.


Is there a way I could find the location of the atom on the image based on the x and y coordinates on the SDF file?


 


Thanks,


Eric

ChemAxon 909aee4527

22-07-2009 07:58:59

Dear Eric,


I've asked my colleage to answer, he is examining the possibilities and will reply soon.


Kind regards,
Judit

ChemAxon 7c2d26e5cf

27-07-2009 16:11:56

I recommend to see the following topic: MolPrinter, Graphics2D, transposing Angstrom to pixel coords

User d7cf0350f9

27-07-2009 17:57:25

This is great!  Thanks for your help!