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!
==== Calling the External Function ==== So, to start, let's look at the Python code that will call the C-function: <source lang="python"> # # -- in someCode.py # # Call funName. Pass it a list () of lists. (sel1 and sel2 are lists.) # Get the return value into rValFromC. # rValFromC = funName( (sel1, sel2) ); </source> where '''sel1''' and '''sel2''' could be any list of atom coordinates, say, from PyMOL. (See above.) Ok, this isn't hard. Now, we need to see what the code that receives this function call in C, looks like. Well, first we need to let C know we're integrating with Python. So, in your [http://docs.python.org/api/includes.html header file] of '''funName.h''' we put: <source lang="c"> // in funName.h #include <Python.h> </source> Next, by default your C-function's name is '''funName_funName''' (and that needs to be setup, I'll show how, later). So, let's define funName: <source lang="c"> static PyObject* funName_funName(PyObject* self, PyObject* args) { ...more code... </source> This is the generic call. '''funName''' is taking two pointers to [http://docs.python.org/api/common-structs.html PyObjects]. It also returns a PyObject. This is how you get the Python data into and out of C. It shows up in "[http://docs.python.org/api/arg-parsing.html args]" array of packaged Python objects and we then unpack it into C, using some [http://docs.python.org/api/arg-parsing.html helper methods]. Upon completion of unpacking, we perform our C/C++ procedure with the data, package up the results using the [http://docs.python.org/api/api.html Python API], and send the results back to Python/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