Converting atom coordinates to/from image coordinates

User 6ef33138f9

14-12-2006 16:50:32

We'd like to be able to convert atom coordinates to and from image coordinates. For example, we'd like to display a molecule image rendered by Marvin, with our own additional information drawn over the image, based on the locations of certain atoms.





When Marvin renders a 2D image for a molecule, the scaling factor (between atomic coordinates and image coordinates) can be obtained by calling Molecule.getImageSize. If there are no labels on the atoms (hydrogens, charges, valences, etc.), then the scale is enough to determine the coordinate transformation accurately. But if there's extra text next to any of the atoms (the most common case is hydrogens on terminal atoms that appear on the edges of the molecule image), we don't know exactly how much to translate the coordinates before or after scaling.





Currently we're estimating this by doing our own approximate calculations: we look for heteroatoms that appear at the edges of the image that also have hydrogen counts, and estimate the width of the text given the scaling factor. Sometimes this works pretty well and sometimes it's off by quite a bit. Also, the results vary between different versions of Marvin.





Is there a more direct or reliable way to determine the coordinate transformations?





Thanks,


Chris

ChemAxon 7c2d26e5cf

15-12-2006 20:41:36

I suggest to convert the molecule also in SVG. It is a vector graphical image format. The SVG output is an XML. You can retrieve the labels' coordinates from the XML.


Before Marvin displays a label, draws a background colored rectangle where the font will be placed. These rectangles indicate the borders of the labels. (Superscripts and subscripts have got own rectangles.)


In the SVG file, you will find these background colored rectangles. With the help of them, you can calculate the exact size of the labels (in pixels).

User 6ef33138f9

18-12-2006 15:15:55

Thanks, Tamas -- that's a good idea! We'll give it a try.





Chris