Index     


PythonInterpreter

Write Python scripts for BALLView

The easiest way to access objects in BALLView is to use the interface to the ModularWidgets. Every major widget in BALLView, like the Scene or the MolecularControl is such a ModularWidget. To get the instance of a ModularWidget in a running BALLView session, call e.g.
MainControl.getInstance(0)
The MainControl manages almost all loaded objects, like Molecules or Representations. The documentation of the BALL library gives detailled information on the syntax of this class. Examples for Python script for usage with BALLView can be found in the folder BALL/source/EXAMPLES/PYTHON. See also below for an other code example.

Users can start scripts, which are stored as extern files, either by calling 'runScript("filename")'in the Python widget or by using the menu entry.

Caveat: Not all methods, which are defined in the C++ library are also exportet to the Python interface. If a method, which you want to use does not seem to work, have a look at the *.sip files in BALL/source/PYTHON/EXTENSIONS to make sure, this method is exported.


Setup a Python startup script

BALLView loads a standard Python script, every time it is started. This script is located in BALL/data/startup.py and defines some shortcuts for obtaining objectes and widgets at runtime. Furthermore a user can load an additional Python script at startup. In this script the user can define variables and methods to further simplify usage of the Python interface. The location of the additional startup script is set in the Preferences:

An example for a startup script:
def createStickModel():
  dp = DisplayProperties.getInstance(0)
  dp.setDrawingPrecision(DRAWING_PRECISION_HIGH)
  dp.selectMode(DRAWING_MODE_SOLID)
  dp.selectModel(MODEL_STICK)
  dp.selectColoringMethod(COLORING_ELEMENT)
  dp.setTransparency(0)
  dp.apply()

def removeWater():
  getMainControl().clearSelection()
  if getMolecularControlSelection().applySelector("residue(HOH)") == 0:
    return
  getMolecularControl().cut()

Python hotkeys

BALLView can bind any Python command to an hotkey for the F-keys. By using the Shift-modifier, BALLView can have up to 24 different hotkeys additional to the standard hotkeys for menu entries. This enables the user to accelerate repetitive tasks dramatically. The standard startup Python Scripts defines many different shortcuts, which can be mapped to any F-key. Thereby a user can e.g. remove all water molecules in the loaded Systems with one keypress. Of course, it is also possible to start methods defined in the user startup script or extern Python scripts with a hotkey: Just add an hotkey entry with runScript("filename").

Method Note
runScriptAgain() Runs last executed script in the python interpreter. If no script was executed earlier, the interpreter prints the message "Could not find file"
hideAllRepresentations() Disables all representations in the representations view
removeWater() Remove water molecules of all loaded systems. Remark: All selected molecular entities are deselected.
printAtomTypesForHighlighted() Print atoms with their type for all highlighted residues
printAtomTypesForLigands() Highlight existing ligands for one highlighted system and print all atoms of the ligands. See also highlightLigand()
highlightLigand() Highlight existing ligands for one highlighted system. If no system is highlighted the first one is taken. Remark: All water molecules are removed.
showCartoonAndLigand() Create a cartoon model with coloring by residue index for one highlighted system and a Van-Der-Waals model for its ligands. If no system is highlighted the first one is taken. Remark: All other representations are removed:
addOptimizedHydrogens() Add hydrogens to one highlighted system and select them to perform a energy minimization. If no system is highlighted the first one is taken.
relaxStructure() Add optimized hydrogens to one loaded system and perform a MD simulation for this system. Remark: Settings for MDS and mimization are take from the corresponding dialog.
quickSave() Save current BALLView session in a project file. Remark: The file is stored in the users home directory under the name "quick.bvp"
quickLoad() Load project file "quick.bvp" from the home directory. See also quickSave()
clearRepresentations() Remove all represenations in the representations view.
clearAll() Remove all loaded systems and all representations. Remark: The datasets are not removed


    Index