Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help
Special pages
SBGrid Resources
SBGrid Consortium
SBGrid Data Bank
Software Webinars
PyMOL Webinar
PyMOL Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Advanced Scripting
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== More Complex Unpacking ==== If you're dealing with simple scalars, then you might be able to skip this portion. Now, we should have access to the data the user sent us, in '''listA''' and '''listB,''' and it should be there and be clean. But, not forgetting that '''listA''' and '''listB''' are list of 3D coordinates, let's unpack them further into sets of coordinates. Because we know the length of the lists, we can do something like the following: <source lang="c"> // make space for the current coords; pcePoint is just a float[3] pcePoint coords = (pcePoint) malloc(sizeof(cePoint)*length); // loop through the arguments, pulling out the // XYZ coordinates. int i; for ( i = 0; i < length; i++ ) { PyObject* curCoord = PyList_GetItem(listA,i); Py_INCREF(curCoord); PyObject* curVal = PyList_GetItem(curCoord,0); Py_INCREF(curVal); coords[i].x = PyFloat_AsDouble(curVal); Py_DECREF(curVal); curVal = PyList_GetItem(curCoord,1); Py_INCREF(curVal); coords[i].y = PyFloat_AsDouble(curVal); Py_DECREF(curVal); curVal = PyList_GetItem(curCoord,2); Py_INCREF(curVal); coords[i].z = PyFloat_AsDouble(curVal); Py_DECREF(curVal); Py_DECREF(curCoord); } ... more code ... </source> Where, '''pcePoint''' is just a float[3]. Line 2 just gets some memory ready for the 3xlenght list of coordinates. Then, for each item for 1..length, we unpack the list using '''[http://docs.python.org/api/listObjects.html PyList_GetItem]''', into '''curCoord'''. This then gets further unpacked into the float[3], '''coords'''. We now have the data in C++/C data structures that the user passed from PyMOL. Now, perform your task in C/C++ and then return the data to PyMOL.
Summary:
Please note that all contributions to PyMOL Wiki are considered to be released under the GNU Free Documentation License 1.2 (see
PyMOL Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Advanced Scripting
(section)
Add topic