Skip to content

BALLPythonScripting

Thomas Kemmer edited this page Jul 31, 2017 · 7 revisions

Scripting in Python

Important pages

Introduction

Most of the BALL and VIEW functionalities are available through the BALLCore and VIEW Python modules, respectively. Additionally, the BALLView application allows to run Python code from the Python widget (until version 1.4) or the Jupyter plugin (since version 1.5), offering access to currently loaded systems and representations.

Installation

BALL binary distributions

The BALLCore and VIEW Python modules are already included in all binary distributions and installed automatically.

BALL source distributions using CMake (BALL 1.3 and later)

With CMake, the Python bindings will be created automatically. The modules can also be built manually using the BALLCoremodule and VIEWmodule targets, respectively:

make BALLCoremodule VIEWmodule

On Windows, the modules can be built using the BALLPython.sln solution file instead.

BALL source distributions using autoconf (until BALL 1.4)

When using autoconf, the Python bindings need to be compiled manually.

 cd source/EXTENSIONS/
 make sip && make && make install

Setting up the environment:

In order to use BALL Python support you need to set the following variables:

# Linux/Mac
export PYTHONPATH=<PATH to BALL libs>:<PATH to sip libs>:${PYTHONPATH}
export LD_LIBRARY_PATH=<PATH to BALL libs>:<PATH to QT libs>:<PATH to sip libs>:${LD_LIBRARY_PATH}

# Windows
set PYTHONPATH=<PATH to BALL libs>;<PATH to sip libs>;%PYTHONPATH%
set PATH=<PATH to BALL libs>;<PATH to QT libs>;<PATH to sip libs>;%PATH%

Scripting with Python

Depending on your needs, you can include the BALLCore module and, optionally, the View module into your script

import BALLCore
import VIEW

or

from BALLCore import *
from VIEW import *

You can find some example Python code snippets and scripts in the CodeLibrary.

Documentation

As a rule of thumb all BALL classes are equally named in C++ and Python. Thus beeing aware of the special Python syntax the BALL web documentation can be used for Python as well.

Example code can be found in the Code Library and in the doc/examples/PYTHON (BALL 1.5 and later) or source/EXAMPLES/PYTHON (before BALL 1.5) directories, respectively.

Clone this wiki locally