4. Generating and managing inputs#

Learning Objectives

For larger and more complex projects it is beneficial to automate the generation of input nodes, rather than manually creating them. We would also like to be able to manage the inputs in a structured way, so that we can easily find them and change them.

In this section we will look at methods for generating input nodes in a more automated fashion, and how to manage them using groups and extras.

In the previous section, we generated the inputs for a calculation manually, by reading from a previously written input file.

For more complex calculations though, it is likely that we would like to automate the input generation process.

In this section, we will see the some methods for generating the inputs for a PwCalculation automatically.

Hide cell content
from local_module import load_temp_profile

data = load_temp_profile(name="input-gen", add_sssp=True, add_structure_si=True)
data
AiiDALoaded(profile=Profile<uuid='cde64d0a219549029207c2227fee5909' name='input-gen'>, computer=None, code=None, pseudos=SsspFamily<1>, structure=<StructureData: uuid: 012f0bef-d866-4fc6-bfc1-e58a8128c45e (pk: 86)>, cpu_count=1, workdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/aiida-qe-demo/checkouts/latest/tutorial/local_module/_aiida_workdir/input-gen'), pwx_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/aiida-qe-demo/conda/latest/bin/pw.x'))

4.1. Importing structures from external databases#

AiiDA ships with a number of plugins that allow you to import structures from external databases. These plugins are called importers and are available in the aiida.tools.dbimporters module.

As an example, let’s import a structure from the Crystallography Open Database (COD).

from aiida.tools.dbimporters.plugins.cod import CodEntry

entry = CodEntry("http://www.crystallography.net/cod/1526655.cif")
structure = entry.get_aiida_structure()
structure.get_pymatgen()
Structure Summary
Lattice
    abc : 5.381 5.381 5.381
 angles : 90.0 90.0 90.0
 volume : 155.80772134100002
      A : 5.381 0.0 3.294912213105954e-16
      B : -3.294912213105954e-16 5.381 3.294912213105954e-16
      C : 0.0 0.0 5.381
PeriodicSite: Si (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]
PeriodicSite: Si (1.3453, 1.3453, 1.3453) [0.2500, 0.2500, 0.2500]
PeriodicSite: Si (-0.0000, 2.6905, 2.6905) [0.0000, 0.5000, 0.5000]
PeriodicSite: Si (4.0358, 1.3453, 4.0358) [0.7500, 0.2500, 0.7500]
PeriodicSite: Si (2.6905, 0.0000, 2.6905) [0.5000, 0.0000, 0.5000]
PeriodicSite: Si (1.3452, 4.0358, 4.0358) [0.2500, 0.7500, 0.7500]
PeriodicSite: Si (2.6905, 2.6905, 0.0000) [0.5000, 0.5000, 0.0000]
PeriodicSite: Si (4.0358, 4.0358, 1.3453) [0.7500, 0.7500, 0.2500]

AiiDA also works closely with the Open Databases Integration for Materials Design (OPTIMADE) consortium, which provides a common REST API for querying a number of databases for structures.

optimade

from local_module.optimade import count_structures, get_providers, yield_structures

get_providers()[["name", "description"]]
name description
id
cod Crystallography Open Database Open-access collection of crystal structures o...
mc3d MC3D - Materials Cloud three-dimensional cryst... Curated set of relaxed three-dimensional cryst...
mp The Materials Project The Materials Project OPTIMADE endpoint
mpds Materials Platform for Data Science A highly curated Pauling File dataset based on...
nmd novel materials discovery (NOMAD) A FAIR data sharing platform for materials sci...
odbx odbx The Open Database of Xtals is run by the group...
omdb_production Open Materials Database (omdb) production data... This is the main production version of the Ope...
oqmd The OQMD The Open Quantum Materials Database endpoint
jarvis JARVIS-DFT JARVIS-DFT is a materials property repository ...
tcod Theoretical Crystallography Open Database Open-access collection of theoretically calcul...
twodmatpedia 2DMatpedia 2DMatpedia, an open computational database of ...

We can also use the OPTIMADE plugin to query the COD database for a structure.

count_structures("cod", 'chemical_formula_hill = "Si" AND nelements = 1')
25
# for structure in yield_structures("cod", 'chemical_formula_hill = "Si"', max_results=2):
#     print(structure)

4.2. Importing Pseudopotential families#

The aiida-pseudo package provides a number of pseudopotential families that are available for download. These install a full set of pseudopotentials for all elements into the AiiDA profile as a Group.

$ aiida-pseudo install sssp -x PBE -p efficiency -v 1.1

They can later be loaded:

from aiida import orm

family = orm.load_group(label="SSSP/1.1/PBE/efficiency")
family
SsspFamily<1>

4.3. Using Groups#

We can view all groups in our profile using the verdi group list command:

%verdi group list -a --all
  PK  Label                    Type string         User
----  -----------------------  ------------------  --------------
   1  SSSP/1.1/PBE/efficiency  pseudo.family.sssp  user@email.com

Groups are a powerful feature of AiiDA, allowing you to organize your data in a flexible way. They can be used to organize nodes into sets, or to assign nodes as members of subgroups. You can add any nodes to a group, and any node can be in multiple groups.

Lets create a new group

%verdi group create my_group
Success: Group created with PK = 2 and label 'my_group'.

Now we can add a set of structures to the group:

group = orm.load_group("my_group")

other_structure = data.structure.clone().store()

for structure in [data.structure, other_structure]:
    structure.store()
    group.add_nodes(structure)
%verdi group show my_group
-----------------  ----------------
Group label        my_group
Group type_string  core
Group description  <no description>
-----------------  ----------------
# Nodes:
  PK  Type           Created
----  -------------  ---------
  86  StructureData  1s ago
  87  StructureData  0s ago

4.4. Adding extras to nodes and querying for them#

We can add extra information to nodes using the extras dictionary. This is a flexible way to add additional information to nodes that is not part of the node’s provenance model, i.e. these can be modified after the node is stored (as opposed to other data).

group = orm.load_group("my_group")
node: orm.Node
for node in group.nodes:
    node.base.extras.set('structure', 'silicon')

AiiDA provides a powerful query system that allows you to search for nodes based on their properties, and location in the provenance graph.

We can gather all the structures we tagged as silicon using the QueryBuilder:

query = orm.QueryBuilder()
query.append(orm.Group, filters={"label": "my_group"}, tag="group")
query.append(
    orm.StructureData,
    with_group="group",
    tag="structure",
    filters={"extras.structure": "silicon"},
    project="*",
)
query.all(flat=True)
[<StructureData: uuid: 012f0bef-d866-4fc6-bfc1-e58a8128c45e (pk: 86)>,
 <StructureData: uuid: 60ee2a23-550b-4fa5-b49b-aebbd753175d (pk: 87)>]

See also

The Query Builder documentation provides more information on how to use the QueryBuilder, and the features available.