<jupyter_start><jupyter_text>*You can execute the active code cell's by pressing Ctrl+Enter*<jupyter_code># Load your aiida profile
from aiida import load_profile

load_profile();<jupyter_output><empty_output><jupyter_text>Introduction to AiiDA **Note**: All commands starting with a `!` are bash commands. Python notebooks provide this handy way of running shell/bash commands inside a python environment. *Also read through the comments*<jupyter_code># example
!ls<jupyter_output><empty_output><jupyter_text>Verdi Commands In this part of the tutorial, you will learn some basics about the AiiDA framework. Get familiar with some useful `verdi` commands.The command-line utility `verdi` is one of the most common ways to interact with AiiDA. Verdi with its subcommands enables a variety of operations such as inspecting the status of ongoing or terminated calculations, showing the details of calculations, computers, codes, or data structures, access the input and the output of a calculation, etc. Similar to the bash shell, verdi command support Tab completion. Try right now to type verdi in a terminal of the AiiDA container and tap Tab twice to have a list of subcommands. **Whenever you need the explanation of a command type verdi help or add `-h` flag if you are using any of the verdi subcommands**.<jupyter_code># Check if everything needed for AiiDA is available and running
!verdi status
# The daemon details
!verdi daemon status<jupyter_output><empty_output><jupyter_text>Looking for calculations We have prepared some data in the database for this part. In the later tutorials, you will learn to create such data using AiiDA-fleur.<jupyter_code># List all calculations currently running
!verdi process list<jupyter_output><empty_output><jupyter_text>Since you do not have any running processes, the previous command should yield an old calculation. To see all the calculations in the database use the following.<jupyter_code># List all calculations in the Postgres database
!verdi process list -a<jupyter_output><empty_output><jupyter_text>You must have noticed a column named `PK`. This is the **Primary Key** by which a particular node is referenced. There is also a `UUID` associated with each node, since these are very long and not so user-friendly `PK` is used. Look at a FINISHED inpgen calculation in more detail with `PK = 79`, what nodes went in? what output nodes were produced?<jupyter_code>!verdi process show 79<jupyter_output><empty_output><jupyter_text>The input file for inpgen for this calculation (with default parameters)<jupyter_code>!verdi calcjob inputcat 79<jupyter_output><empty_output><jupyter_text>Find the `PK` of a `FleurCalculation` node and check the convergence using the following command<jupyter_code># grep for the distance of that calculation in the out.xml file
!verdi calcjob outputcat <pk> | grep distance<jupyter_output><empty_output><jupyter_text>Look at the files retrieved from the remote computer/cluster, we store the last charge density (cdn1) too, this way any calculation can be continued from what we have 'locally' in the repository<jupyter_code>!verdi calcjob outputls <pk><jupyter_output><empty_output><jupyter_text>Codes and computers A code represents (in the database) the actual executable used to run the calculation. The command prints information on the plugin used to interface the code to AiiDA, the remote machine on which the code is executed, the path of its executable, etc. To have a list of all available codes type<jupyter_code>!verdi code list<jupyter_output><empty_output><jupyter_text>Find the `pk` of such a node in the graph and type<jupyter_code>!verdi code show 7<jupyter_output><empty_output><jupyter_text>Similarly, the list of computers on which AiiDA can submit calculations is accessible by means of the command<jupyter_code>!verdi computer list -a<jupyter_output><empty_output><jupyter_text>`-a` shows all computers, also the one imported in your database but that you did not configure, i.e., to which youdon’t have access). Details about each computer can be obtained by the comma<jupyter_code>!verdi computer show localhost<jupyter_output><empty_output><jupyter_text>For a list of all the `verdi` commands check the [AiiDA documentation](https://aiida-core.readthedocs.io/en/latest/working_with_aiida/index.html)  AiiDA data typesThere are a number of data types distributed with AiiDA. We summarize here the most common, and some useful features/functionalities to work with them.  Most common datatypesHere follows a short summary of common datatypes already provided with AiiDA. This list is notcomplete, see also inside the module `aiida.orm.nodes.data` for the list of all available plugins. **NOTE**: To inspect, create and manage data nodes use the `verdi` command `verdi data`  Base typesIn addition to the base datatypes such as `Int`, `Float`, `Str`, etc,. AiiDA also provides datatypes such as `Dict`, `StructureData`, `RemoteData`, etc. Uses and examples of these datatypes are illustrated in this notebook.**The different datatypes can be accessed through the `DataFactory()` function by passing an entry point to it as an argument** (you will see them in the examples used in this notebook).A list of all the data entry points can be obtain running the command ``verdi plugin list aiida.data``.  Dict`Dict` type is used to store a dictionary of python base types in the database.It can store any dictionary where elements can be a base python type (strings, floats,integers, booleans, None type,datetime objects, etc.) and lists or dictionaries of them, atany depth level (e.g. a dictionary where a value is a list of dictionaries ofstrings and floats).<jupyter_code>from aiida.orm import Dict

options=Dict(dict={
    'resources'  : {"num_machines": 1},
    'max_wallclock_seconds':  60*60,
})<jupyter_output><empty_output><jupyter_text>You can access all the methods associated with the options object using the `dot` operator (`options.`).you can also read the documentation associated with any object using `?`. Run the following cell to see it in action<jupyter_code>options.get_dict?
print options.get_dict()<jupyter_output><empty_output><jupyter_text>Aiida created a database storable dictionary for us. It is not stored in the database yet, for that we use the following method.<jupyter_code>options.store()<jupyter_output><empty_output><jupyter_text>This object is stored in the database and we can use `PK` to refer to this object from now on.<jupyter_code>!verdi data dict show <pk><jupyter_output><empty_output><jupyter_text>StructureDataTo store a crystal structure to be used by atomistic codes<jupyter_code>from aiida.plugins import DataFactory

StructureData = DataFactory('structure')

alat = 5.4 #angstrom
cell = [[alat/2, alat/2, 0.],
        [alat/2, 0., alat/2],
        [0., alat/2, alat/2],
       ]

s = StructureData(cell=cell)
s.append_atom(position=(0.,0.,0.), symbols='Si')
s.append_atom(position=(alat/4.,alat/4.,alat/4.),symbols="Si")<jupyter_output><empty_output><jupyter_text>You can access and inspect the structure sites with the command<jupyter_code>s.sites<jupyter_output><empty_output><jupyter_text>If you make a mistake, start over from `structure = StructureData(cell=the_cell)`, or equivalently use`s.clear_kinds()` to remove all kinds (atomic species) and sites. Once you are done with it store the StructureData to the database.<jupyter_code>s.store()<jupyter_output><empty_output><jupyter_text>Use the `pk` method to see the `PK` of this StructureData<jupyter_code>s.pk<jupyter_output><empty_output><jupyter_text>Alternatively, AiiDA structures can also be converted directly from ASE structures using<jupyter_code>from ase.spacegroup import crystal

ase_structure = crystal('Si', 
                        [(0,0,0)], 
                        spacegroup=227,
                        cellpar=[alat, alat, alat, 90, 90, 90],
                        primitive_cell=True,
                       )
structure=StructureData(ase=ase_structure)
structure.store()<jupyter_output><empty_output><jupyter_text>A structure can also be read from a cif file<jupyter_code>#replace the '/path/to/cif_file'

!verdi data cif import "/path/to/cif_file"<jupyter_output><empty_output><jupyter_text>FolderDataTo store a set of files/folders (with possibly a folder/subfolder structure)  RemoteDataThis basically represents a "symbolic link" to a specific folder on  a remote computer.  Its main use is to allow users to persist the provenance when e.g. a calculation  produces data in a raw/scratch folder, and the whole folder needs to be provided  to restart/continue. Note: There are many more derived datatypes available in AiiDA, for a full list see the [AiiDA Documentation](https://aiida-core.readthedocs.io/en/latest/datatypes/index.html)  CodeA code represents (in the database) the actual executable used to run the calculation. Note that in AiiDA the object `Code` in the database is meant to represent a specific executable, i.e. a given compiled version of a code. Every calculation in AiiDA is linked to a code, installed on a specific computer. This means that if you install `fleur` and `inpgen` on two computers A and B, you will need to have two different `codes` in the database (although the source of the code is the same, the binary file is different). Modify the following code cell using the information gathered in the Codes and computers section<jupyter_code>codename = 'somecode@somecomputer'
from aiida.orm import Code
code = Code.get_from_string(codename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0716455431025453, 'fraction_numerical': 0.0043992877343668165, 'mean_word_length': 5.425302826379542, 'pattern_counts': {'":': 1, '<': 100, '<?xml version=': 0, '>': 100, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '251773', 'license': 'MIT', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2675, 'n_words': 1167, 'path': 'tutorials/aiida_fleur_workshop_2019/1_AiiDA_data_types_and_verdi_commands.ipynb', 'repo_name': 'd-wortmann/judft_tutorials', 'size': '9547'}