4. The AiiDA python interface¶
AiiDA is written in python, and while the
verdi command line interface
provides handy shortcuts for everyday operations, AiiDA provides its
full power only via the python interface.
4.1. Using the python interface¶
There are three practical ways of using the python interface:
python scripts that
For this tutorial we recommend using the
verdi shell (explained below)
but if you’re already familiar with
Jupyter notebooks you may use those as well.
We will get back to option 1 (python scripts) towards the end of the tutorial.
4.1.1. The verdi shell¶
verdi shell is a customized ipython shell, where all the AiiDA classes,
methods and functions are already accessible. Type in the terminal
$ verdi shell
verdi shell is handy for everyday AiiDA-based operations, e.g. creating,
querying and using AiiDA objects.
You would typically use two terminals, one for the
verdi shell and one to execute bash commands.
Ctrl+Shift+Tin order to open a new terminal tab.Don’t forget to
workon aiidain the new tab before using the shell.
4.1.2. Jupyter notebooks¶
Start a jupyter notebook server:
$ jupyter notebook
In the new browser window, select
New -> Python 2 (top right corner).You are now inside a jupyter notebook, consisting of cells where you can type
portions of python code. The code will not be executed until you press
Shift+Enter from within a cell.
In order to load the same environment as in the
verdi shell, type
in the first cell and execute it.
verdi shelland the
jupyter notebookare completely equivalent. Use either according to your personal preference.
You will still need sometimes to type command-line instructions in
Either keep a terminal open on the side or use execute terminal commands
directly from the
verdi shell or
jupyter notebook by prefixing the
command by an exclamation mark:
!verdi profile list
4.2. Loading a node¶
Most AiiDA objects are represented by nodes, identified in the database by their PK number (an integer). You can access a node using the following command in the shell:
node = load_node(<PK>)
NoteIn the following, we’ll use a dark gray border to indicate python code and a light gray border to indicate the terminal.
Load one of the calculation nodes you played around with before. Then get the density computed with the command
You can also type
and then press
TAB to directly access the keys of the output dictionary.