Tutorial¶
About Python Automation in Bluelake¶
The Bluelake software contains a built-in interpreter of the Python programming language. This interpreter allows users to automate experiments using Python scripts. This tutorial will help you to write your first automation script.
If you’re not familiar with Python, don’t worry, you can start by checking out the website Python For Beginners , which contains great resources for beginners. For the rest of this tutorial, we assume a basic knowledge of Python.
Running Your First Script¶
To run a Bluelake script, you’ll need to work on a C-Trap (or m-Trap) Controller PC that has Bluelake installed. On the Controller PC, open up a text editor, and create a new file with the following contents:
print('Hello from Bluelake')
Save the file as test.py
in any folder of your choice. When saving the file, make sure to add the .py
extension explicitly and save the file as type All files (*.*)
.
In Bluelake, you’ll see a Browse button in the Scripting panel. Click it, and navigate to the folder where you stored your test.py
script. Open the script, and then run it using the Start button in the Scripting panel. You should now see the text Hello from Bluelake
appearing in the Scripting panel’s output box.
What just happened? Bluelake opened the test.py
file, and fed its contents to its built-in Python interpreter. The single line in test.py
then calls Python’s print
function to show a line of text on the screen.
Some Basic Bluelake Automation¶
To automate your experiment, you’ll first need to import the Python module that contains Bluelake’s automation functions. Add the following line to the top of your script:
import bluelake as bl
The functions that are available in this module are documented in the API Reference. As an example, you could actuate the shutter of the first optical trap using:
bl.shutters.clear(1)
Here, shutters
represents the shutters of the system, featuring a function clear()
that we can call to clear the wanted shutters.
Another example would be a script that keeps moving Trap 1 to the right in half-micrometer steps, until the force on a captured particle exceeds 20 pN — basically a poor-man’s version of a force clamp:
import bluelake as bl
while bl.timeline["Force LF"]["Trap 1"].latest_value < 20:
bl.mirror1.move_by(dx=0.5, speed=1)
Try copying the above lines of code into a .py
file and running it from Bluelake, while you have a bead captured in the optical trap. The trap should keep moving to the right until the force exceeds 20 pN (something that you could also simulate by starting some liquid flow in the flowcell).
Further Resources¶
- Lumicks provides a GitHub repository with sample scripts. Here, you’ll find sample scripts that showcase specific C-Trap components, as well as complete workflow automation scripts.