[cctbxbb] Passing array between python and C++

Zhenwei Luo tluozhenwei at gmail.com
Sat Dec 7 20:25:08 PST 2013

Hello Everyone,

	I am writing a refinement program using the cctbx. I have encountered with a problem when I wanted to pass an array between c++ and python. The type of array I used in my c++ source file is af::shared<af::shared<vec3> >, I would like to pass it into my python script, thus I could do some other operations to this array. 
I wrote a method in my class to return this array.

 af::shared<af::shared<vec3<double> > return_modes( ) { return modes; }  

I wrote another method in the *_ext file to wrap this method to make it callable from python.

.def("return_modes", &nm_init::return_modes)

But when I use it in python,
eigenvector = nm_init_manager.return_modes()

It gave me an error:

TypeError: No to_python (by-value) converter found for c++ type: scitbx::af::shared<scitbx::af::shared<scitbx::vec3<double> > >

What I want to realize is just creating an two dimensional array using vec3 as its element. I can also using the select method  in this array to select some elements from its column, just like in the af::shared<vec3<double> > array. Namely, the column of this array should have some same properties like af::shared<vec3<double> >. Can anyone help me figure out what I should do? 

Thank you very much! Any help will be greatly appreciated.

Zhenwei Luo
Rice University

More information about the cctbxbb mailing list