The Flare Python Cookbook provides a fast-track and user-friendly path for novice and non-expert Python users to familiarize themselves with writing scripts, and take advantage of extended Flare functionality.
The Cookbook includes ready-to-use Python recipes (‘snippets’) which perform a specific task are included. Use these simple, but fully functional, recipes as building blocks for creating more advance customized workflows.
Although the Flare Python Cookbook is designed to support novice and non-expert Python users, more experienced users might also benefit from it as it provides friendly first contact with the Flare Python API style and functionalities.
New recipes featuring additional functionality will be available in future releases of the Flare Python Cookbook. In the meantime, if you would like a new recipe please contact Cresset support.
The Flare Python Cookbook uses the Flare Python API which extends Flare functionality by enabling medicinal and computational chemists to automate tasks, customize their workflows or develop new science.
How to run the snippets from the Flare GUI
The Flare Python Interpreter and Python Console windows in the Flare GUI, and the Python Notebook extension, are user-friendly and versatile environments for running Python interactively and from scripts from the Flare GUI.
Using the Flare Python Notebook extension
The easiest way to run a Flare Python Cookbook recipe is to:
- Download the ‘Flare Python Cookbook.ipynb’ file from GitLab
- Load the Cookbook into the Python Notebook in Flare
- Then ‘Run’ the cell containing the recipe to be executed
Instructions for setting input and output directories are provided at the beginning of the Flare Python Cookbook. Run the first snippet in the Flare Python Cookbook to test it has been set correctly.
Run the Flare Python Cookbook from the Python Interpreter and Python Console windows
Recipes in the Flare Python Cookbook can also be run from the GUI using the Flare Python Console and Python Interpreter windows.
The Python Console executes lines of code as you type them. If you’re a novice user, it’s worth familiarizing yourself with Python commands by executing a few lines of code.
Use the Python Interpreter window to write, load, run, save and re-use Python scripts and snippets copied from the Cookbook:
- Execute the code from the Python Interpreter window by pressing the ‘Run’ button
- Save changes made to the snippet into a new Python script (‘Save As’)
- Saved snippets can be reused at a later stage by loading them into the Python Interpreter (‘Load’)
Run snippets from the command line
Confident Python users might prefer to run Flare experiments behind the scenes and call the Flare Python API from the command line. In these instances you can export the snippet code from the Flare Python Cookbook into a Python script, for example, using the Python Interpreter extension as described above and run it with the pyflare command line binary.
Most snippets will run from an open Flare project within the GUI and from the command line. However, some snippets require user intervention and will only work when running an open Flare project in the GUI. For each snippet, this is indicated in the Cookbook in the ‘Platform’ section.