Hi, Esben Jannik Bjerrum,
    I have studied how to do it, though it may not be the best way. In 
`rdMolDraw` there are `getAtomCoords` and `getDrawCoords` in C++ APIs    
     But these APIs are not wrapped for python.  So you may have to add the 
wrapper into the source and compile it manually.
Here are some codes I made in older version:### in 
`rdkit/Code/GraphMol/MolDraw2D/Wrap` ###namespace RDKit {....Point2D 
getDrawCoordsViaId(MolDraw2D &self,  int at_num) {

  return  self.getDrawCoords(at_num);


Point2D getAtomCoordsViaId(MolDraw2D &self, int at_num) {

  return self.getAtomCoords(at_num);


    .def ...)    .def("getDrawCoords", RDKit::getDrawCoordsViaId, "a")     
.def("getAtomCoords", RDKit::getAtomCoordsViaId,"b")


(I don't know why I added "a" and "b" and they may not necessary. I am not good 
at C++ and boost-python)        BTW, I wonder is it possible to open these APIs 
officially ?

Hongbin Yang 

 From: Esben Jannik Bjerrum via Rdkit-discussDate: 2017-06-21 22:38To: 
rdkit-discuss@lists.sourceforge.netSubject: [Rdkit-discuss] Reverse scale of 
svg coordinates to atom coordinates
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.

 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())
drawer = rdMolDraw2D.MolDraw2DSVG(300,300)
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
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

Reply via email to