Documentation for Release 2024.2
PyChaste
The PyChaste project is a Python package which wraps a small amount of Chaste functionality. It provides common Chaste functionality to other projects with Python bindings, such as the Angiogenesis Project.
Installation
A conda Python package for Linux is currently under development. However, at the moment, the package needs to be built from source using the development version of Chaste and CMake.
First, Chaste dependencies need to be built from source following the Chaste Install Guide. In addition to the normal Chaste dependencies, this project also requires Boost Python and a Python shared library. These may already be on your system, in which case an attempt will be made to find them automatically. If not, Boost Python can be built by adding python
to the list of libraries when following the Boost build instructions here.
The project only supports the development version of Chaste. This can be obtained by doing:
using subversion. The project code itself can be obtained by doing:
The PyChaste project code needs to be included in the projects
folder of the main Chaste source. This can be done with a symbolic link:
or just by copying the project in. The project can then be configured in the typical way using CMake (see CMake build system guide for additional details). First, create a build directory outside the source tree and proceed as:
The Python package chaste
will be in $BUILD_DIR
under Chaste/projects/PyChaste/python
. For convenience, the directory $BUILD_DIR/Chaste/projects/PyChaste/python
should be added to your PYTHONPATH. A proper Python build script (i.e. setup.py
) is still under development.
Usage
The package can be imported in Python as normal. For example, in a Python session do:
Often it is neccessary to initialize MPI/PETSc when launching the C++ version of Chaste. This is the same for the Python version, with MPI initialization errors returned if you try to use functions which depend on it. To use MPI/PETSc functionality it is neccessary to install the petsc4py
Python interface to PETSc. This can be done using pip:
however care should be taken to ensure that the installed version of petsc4py
matches your PETSc version. To initialize MPI/PETSc with Chaste you can do:
User Projects
User projects, such as the Angiogenesis Project can have their own Python packages, which depend on PyChaste. They can be placed in the chaste/projects
module of PyChaste and can be loaded as follows:
Binding Regeneration (Developers Only)
PyChaste is a mix of manual and automatically generated bindings. Binding logic is in WrapPython.cmake
and dynamic\generate_X_bindings.py
. To regenerate the automatic binding code do: