Hi RDkitters,   I'm experimenting a bit with an application with some user 
interactivity. I get the SVG coordinates from the Mol SVG drawing from the user 
interaction and need to get back to the atom coordinates with the goal of 
identifying the atom nearest the selected coordinates (or is there a smarter 
way to achieve that goal?).
Is this possible from Python currently?
I see that there is a MolDraw2D::getAtomCoords function in the cpp code for 
MolDraw2D, but I can't see it from the Python side, and there don't seem to be 
a way to get the scaling from the MolDraw2DSVG object.

As I understand it, the coordinates from the molecule are offset and scaled 
(and flipped for y) to fit the drawing canvas of the specified size. To get 
back to the original atom coordinates I must somehow reverse the 
transformation. Here's some script snippets illustrating what I try to achieve.

#Get som SVG depiction of a mol
mol = Chem.MolFromSmiles('CCCC')
mc = Chem.Mol(mol.ToBinary())
rdDepictor.Compute2DCoords(mc)
drawer = rdMolDraw2D.MolDraw2DSVG(300,300)
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText().replace('svg:','')

#....#Visualization and User interaction code here gives SVG coordinates
#....
svg_x = 271.0svg_y = 237.0

#Is there a function to scale back the coordinates? alternatively get the 
scaling and the offset from drawer and handle it manually
atomcoords = drawer.getAtomCoords((svg_x, svg_y))
#But this function doesn't exist:-(
#...#Continue working with the rdkit mol

I would welcome some hints or suggestions.

Esben Jannik Bjerrum
cand.pharm, Ph.D
/Sent from my Ubuntu Touch Phone

Phone +45 2823 8009
http://dk.linkedin.com/in/esbenbjerrum
http://www.wildcardconsulting.dk
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to