Hi there,

I'm trying to wrap the very handy method getPositions from
rdkit/Code/GraphMol/Wrap/Conformer.cpp to return coordinates of a conformer
as a numpy array.

So far I was able to return a tuple of tuples, as below

  PyObject *convertPoint(RDGeom::Point3D &point){
    PyObject *res = PyTuple_New(3);
    PyTuple_SetItem(res,0,PyFloat_FromDouble(point.x));
    PyTuple_SetItem(res,1,PyFloat_FromDouble(point.y));
    PyTuple_SetItem(res,2,PyFloat_FromDouble(point.z));
    return res;
  }

  PyObject* GetPos(const Conformer *conf) {
    RDGeom::POINT3D_VECT pos=conf->getPositions();
    PyObject *res = PyTuple_New(pos.size());
    for(int idx=0;idx<pos.size();idx++){
          PyTuple_SetItem(res,idx,convertPoint(pos[idx]));
    }
    return res;
  }

Getting the PyArray_SimpleNew was a little tricky in my hands, but I assume
that's what I need to use somehow. Does anybody have any pointers?

Thanks,

- Jan
------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to