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
http://www.rdkit.org/docs/cppapi/classRDKit_1_1MolDraw2D.html#abd327050dfa838543103d1f2c5f28f23
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);
}
}...BOOST_PYTHON_MODULE(rdMolDraw2D)
{...python::class_<RDKit::MolDraw2D,boost::noncopyable>("MolDraw2D",docString.c_str(),python::no_init)
.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.
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