PythonInterpreterWrite Python scripts for BALLViewThe 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 informations 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.
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 scriptBALLView can load a Python script at startup. In this script the user can define
variables and methods to simplify usage of the Python interface.
The file, which is used as startup script is set in the Preferences:
An example for a startup script: mc = MainControl.getInstance(0) pm = mc.getPrimitiveManager() cm = mc.getCompositeManager() dp = DisplayProperties.getInstance(0) fd = MolecularFileDialog.getInstance(0) moc = MolecularControl.getInstance(0) def clearRepresentations(): nr = pm.getNumberOfRepresentations() rl = pm.getRepresentations() i = 0 while i < nr: mc.remove(rl[i]) i = i + 1 def createStickModel(): 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(): mc.clearSelection() if moc.applySelector("residue(HOH)") == 0: return moc.cut() Use self written scripts with hotkeysBALLView can bind any Python command to an hotkey for the F-keys. This is especially usefull with self defined methods. With the startup script above, the user could bind the three methods to different hotkeys (see below). Thereby he can e.g. remove all water molecules in the loaded Systems with one keypress. By using the Shift- and Control-modifier, BALLView can have up to 36 different hotkeys. This enables the user to accelerate repetitive tasks dramatically. |