PubChemPy icon indicating copy to clipboard operation
PubChemPy copied to clipboard

Getting 3D coordinates

Open kumrud opened this issue 7 years ago • 1 comments

Hello, I'm trying to get xyz coordinates from Compound class. In _setup_atoms function (line 689) it looks like you are assigning the coordinates to _atoms dict with set_coordinates function. Where is this set_coordinates? There is one in Atom class sure but it's not in Compound class. I get no coordinates when I run this:

import pubchempy as pcp
cid = pcp.get_cids('methane', 'name')[0]
m = pcp.Compound.from_cid(cid, record_type='3d')
m._atom

Am I doing something wrong?

kumrud avatar Feb 05 '18 23:02 kumrud

>>> compounds = pcp.get_compounds('methane', 'name', record_type='3d')
>>> m = compounds[0]
>>> m
Compound(297)
>>> m.atoms
[Atom(1, C), Atom(2, H), Atom(3, H), Atom(4, H), Atom(5, H)]
>>> m.atoms[2].x
0.6833
>>> m.atoms[2].y
-0.8134
>>> m.atoms[2].z
-0.2536
>>> coords = [(a.x, a.y, a.z) for a in m.atoms]
>>> coords
[(0, 0, 0), (0.5541, 0.7996, 0.4965), (0.6833, -0.8134, -0.2536), (-0.7782, -0.3735, 0.6692), (-0.4593, 0.3874, -0.9121)]

Hope this helps!

mcs07 avatar Feb 06 '18 11:02 mcs07