Hi Peleg,

On Sat, Aug 12, 2017 at 4:08 PM, Peleg Bar-Sapir <pel...@gmail.com> wrote:

>
> I'm trying to get the 2D coordinates and info of all the atoms and bonds,
> including hydrogens (i.e. atom type, bond type, etc.) of a molecule in a
> standard structural formula. To clarify: I'm not referring to
> Chem.MolToMolBlock(), but the coordinates used by the Draw class (e.g. in
> MolToFile()) to create standard representations.
>
> Any advice on how to extract those? Maybe one can reach them via one of
> the Draw member functions/variables?
>

The drawing code calls rdMolDraw2D.PrepareMolForDrawing() before actually
doing the drawing. This function, among other things, assigns coordinates.
Assuming that you're looking for the coordinates in the molecule's
coordinate space, you can get access to them by calling
PrepareMolForDrawing() and then either getting a mol block:

In [7]: m = Chem.AddHs(Chem.MolFromSmiles('CC#C'))

In [8]: nm = rdMolDraw2D.PrepareMolForDrawing(m)

In [9]: print(Chem.MolToMolBlock(nm))

     RDKit          2D

  7  6  0  0  0  0  0  0  0  0999 V2000
   -0.6887   -0.0795    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.8112   -0.0614    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.3111   -0.0433    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.4230   -1.3875    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.1044    0.4165    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.4461    1.4007    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.5400   -0.2455    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0
  2  3  3  0
  1  4  1  0
  1  5  1  0
  1  6  1  0
  3  7  1  0
M  END


Or by using the molecule's conformer object:

In [13]: conf = nm.GetConformer()

In [14]: for aidx in range(conf.GetNumAtoms()):
    ...:     pos = conf.GetAtomPosition(aidx)
    ...:     print(pos.x, pos.y, pos.z)
    ...:
-0.6887274130576998 -0.07950997820751476 0.0
0.8111632161215289 -0.0613964335423347 0.0
2.311053845300757 -0.04328288887715446 0.0
-1.4229859378146839 -1.387510138307542 0.0
-2.104358766425875 0.416461665499047 0.0
-0.4461124978218231 1.4007393261007453 0.0
1.5399675536977953 -0.24550155266524612 0.0


I'm not sure what kind of additional info you are looking for, but maybe
this much helps?

-greg
------------------------------------------------------------------------------
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