1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BALLView Documentation: PythonInterpreter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align=center>
<table width="700" cellpadding="0" border=0>
<tr>
<td align="center">
<h2 align="center">
<a href="datasetControl.html"><img src="images/left.png" width="58" height="28" border=0 align="Middle"></a>
<a href="index.html">Index</a>
<a href="displayProperties.html"><img src="images/right.png" width="58" height="28" border=0 border="0" align="Middle"></a> </h2>
<hr width=700>
<h2>PythonInterpreter</h2>
<a name="python_scripts"></a><h2>Write Python scripts for BALLView</h2>
<div align="justify">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.<br>
</div>
<pre>MainControl.getInstance(0)</pre>
<div align="justify">The MainControl manages almost all loaded objects, like Molecules or Representations.
The documentation of the BALL library gives detailed 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.<br>
<br>
Users can start scripts, which are stored as external files, either by calling 'runScript("filename")'in the Python widget or by
using the menu entry.
<p>
<b>Caveat:</b> Not all methods, which are defined in the C++ library are also exported 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.<br>
</div>
<br>
<a name="startup_script"></a>
<h2 align=center>Completion and context sensitive help</h2>
<div align=justify>
<a name="completion"></a>
To ease and accelerate the development with Python we implemented a command completion, such that
a combobox pops up with all possible completions.
This can e.g. be used to show all members of a BALL class.
To use this feature in the "Instant Mode", press the right cursor key at the end of
the edit line. In the "Scripting Mode", press the right cursor key together with the Shift key:
</div>
<table border=0>
<tr><td align=left>
<pre>
a = AtomCon[Shift + Key_Right]
</pre>
</td></tr></table>
<div align="justify">
<br><br>
To get context sensitive help for the current line, write your line of code and
press "Enter" (from the numlock block) or
"Shift-F1" after the name of the method (like above).
This pops up a window with the BALL documentation for the class and member.
</div>
<a name="startup_script"></a>
<h2>Setup a Python startup script</h2>
<div align="justify">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
objects 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:
</div>
<div align="center">
<br>
<img src="images/startup_script1.png">
<br>
</div>
<div align = left>
<br>
An example for a startup script:<br>
<br>
</div>
<div align="center">
<table border=0>
<tr><td align=left>
<pre align=left>
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()
</pre>
</td></tr></table>
</div>
<h2>Python hotkeys</h2>
<p align="justify"><a name="create_hotkeys"></a>
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.
Furthermore all Python Hotkeys are show as entries in the "User" menu.
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 key press.
Of course, it is also possible to start methods defined in the user startup script or external Python scripts with a hotkey:
Just add an hotkey entry with <i>runScript("filename")</i>.
</p>
<p><img src="images/hotkeys.png"></p>
<br><br><br>
<table width="700" border="1" cellpadding="5">
<tr>
<td><b>Method</b></td>
<td><b>Note</b></td>
</tr>
<tr>
<td>runScriptAgain()</td>
<td>Runs last executed script in the python interpreter. If no script was executed earlier, the interpreter prints the message "Could not find file"</td>
</tr>
<tr>
<td>hideAllRepresentations()</td>
<td>Disables all representations in the representations view</td>
</tr>
<tr>
<td>removeWater()</td>
<td>Remove water molecules of all loaded systems. Remark: All selected molecular entities are deselected.</td>
</tr>
<tr>
<td>printAtomTypesForHighlighted()</td>
<td>Print atoms with their type for all highlighted residues</td>
</tr>
<tr>
<td>printAtomTypesForLigands()</td>
<td>Highlight existing ligands for one highlighted system and print all atoms of the ligands. See also highlightLigand()</td>
</tr>
<tr>
<td>highlightLigand()</td>
<td>Highlight existing ligands for one highlighted system. If no system is highlighted the first one is taken. Remark: All water molecules are removed. </td>
</tr>
<tr>
<td>showCartoonAndLigand()</td>
<td>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:</td>
</tr>
<tr>
<td>addOptimizedHydrogens()</td>
<td>Add hydrogens to one highlighted system and select them to perform a energy minimization. If no system is highlighted the first one is taken.</td>
</tr>
<tr>
<td>relaxStructure()</td>
<td>Add optimized hydrogens to one loaded system and perform a MD simulation for this system. Remark: Settings for MDS and minimization are
take from the corresponding dialog.</td>
</tr>
<tr>
<td>quickSave()</td>
<td>Save current BALLView session in a project file. Remark: The file is stored in the users home directory under the name "quick.bvp"</td>
</tr>
<tr>
<td>quickLoad()</td>
<td>Load project file "quick.bvp" from the home directory. See also quickSave()</td>
</tr>
<tr>
<td>clearRepresentations()</td>
<td>Remove all representations in the representations view.</td>
</tr>
<tr>
<td>clearAll()</td>
<td>Remove all loaded systems and all representations. Remark: The datasets are not removed</td>
</tr>
</table>
-->
<hr width=700>
<h2 align="center">
<a href="datasetControl.html"><img src="images/left.png" width="58" height="28" border=0 align="Middle"></a>
<a href="index.html">Index</a>
<a href="displayProperties.html"><img src="images/right.png" width="58" height="28" border=0 align="Middle"></a>
</h2>
</td></tr></table>
</div>
</body>
</html>
|