Skip to content
Daniel Stoeckel edited this page Feb 20, 2015 · 1 revision

Scripting Python within BALLView


'''WARNING: THIS ARTICLE IS NOT COMPLETE!

Introduction

Our ultimate - but unfortunately so far unresolved - goal is to have all of BALL's data structures and algorithms wrapped for usage in python scripting. At the time of writing most classes have been wrapped.

There are three ways how users can develop and run BALL python scripts:

  • pure BALL python e.g. interactive python shell
  • BALLView's integrated Scripting Mode
  • BALLView's integrated Instant Mode

If BALLView's integrated modes are used, a special script startup.py is run that defines helper methods for e.g. removeWater(), BALLView related methods e.g. showOnlyScene() and getDatasetControl(), showCartoonAndLigand(). Within BALLView python hotkey-mapping is support as well, e.g. predefined or user-written python scripts can be mapped to hot keys and entered to the main menu entry Users.

In the integrated modes access to BALLView's maincontrol and representation widget is provided as well. Please note, that theses methods are not available in pure BALL python.

If you are interested in pure BALL python shell scripting, please have a look at Scripting BALL with Python.

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.

Another important point to keep in mind is the very special python indentation. Take care that you remain consistent in your use of either tabs or plain spaces for python indentation. Python relies on the relative indentation of nested blocks to determine the grouping of statements correctly.

You also have to take care that your script ends with two empty lines. Python needs them to interprete the end of the script.

Example scripts can be found in

  • source/EXAMPLES/PYTHON/
  • source/EXAMPLES/PYTHON/howtos/
  • source/APPLICATIONS/UTILITIES/ (planned for BALL 1.4.1)

if the sources are available. Binary packages will install the examples in doc/EXAMPLES.

If BALLView's Instant Mode is used, you can get help by

  • instantiating a class and using the dir() command to get all available methods
  • using the autocompletion by pressing the 'right arrow key'

Advanced

If you plan to add some python bindings either of existing or new C++ BALL classes seek advice in Creating a Python binding

Clone this wiki locally