Skip to content

Commit abaaf0a

Browse files
committed
Update customize inputs page of docs/howto
1 parent 946f9ca commit abaaf0a

File tree

3 files changed

+197
-33
lines changed

3 files changed

+197
-33
lines changed
Lines changed: 197 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,210 @@
1-
# Customize inputs
1+
# Customizing the inputs of an aiida-quantumespresso workchain
22

3-
## Starting from scratch
3+
## Interacting with the workchain builder
44

5-
The protocols make it easier to get a starting set of inputs.
6-
However, you can also start from an empty `builder`:
5+
Workchain builder is a dictionary that specifies all the inputs of the workflow and all called calculations. It is the main object to interact with in order to change the default settings/parameters. Every workchain class includes `get_builder()` method to initialize an empty builder with the correct namespaces as well as `get_builder_from_protocol()` method returning a builder, prepopulated with default parameters defined in the simulation protocols ('fast', 'balanced' or 'stringent' as defined in https://arxiv.org/pdf/2504.03962).
6+
7+
To check the builder structure in the interactive shell use the following commands for the relevant WorkChain:
78

89
```python
9-
pseudo_family = orm.load_group('SSSP/1.3/PBEsol/efficiency')
10+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
1011

1112
builder = PwBaseWorkChain.get_builder()
12-
builder.kpoints_distance = 0.3
13-
builder.pw.code = orm.load_code('pw@localhost')
14-
builder.pw.structure = structure
15-
builder.pw.pseudos = pseudo_family.get_pseudos(structure=structure)
16-
builder.pw.parameters = {
17-
'SYSTEM': {
18-
'nbnd': 10
19-
},
20-
'CONTROL': {
21-
'calculation': 'scf'
22-
}
23-
}
24-
results = engine.run(builder)
13+
builder
14+
# -> builder inputs
15+
```
16+
or
17+
```python
18+
from aiida import orm
19+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
20+
21+
from ase.build import bulk
22+
23+
builder = PwBaseWorkChain.get_builder_from_protocol(
24+
code = orm.load_code('pw@localhost'),
25+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
26+
protocol='balanced'
27+
)
28+
builder
29+
# -> builder inputs
2530
```
31+
Note that `get_builder_from_protocol()` requires structure and code arguments.
2632

27-
You can also directly pass your inputs to the engine by preparing all of them in an `inputs` dictionary:
33+
After providing the necessary information (see explanations below), the builder object is passed to `run()` or `submit()` methods of `aiida.engine` in order to perform the calculation.
2834

2935
```python
30-
pseudo_family = orm.load_group('SSSP/1.3/PBEsol/efficiency')
31-
32-
inputs = {
33-
'kpoints_distance': 0.3,
34-
'pw': {
35-
'code': orm.load_code('pw@localhost'),
36-
'structure': structure,
37-
'pseudos': pseudo_family.get_pseudos(structure=structure),
38-
'parameters': {
39-
'CONTROL': {
40-
'calculation': 'scf'
41-
}
42-
}
36+
from aiida.engine import submit
37+
38+
wkchain = submit(builder)
39+
print(f"Submitted workchain with pk {wkchain.pk}!")
40+
```
41+
42+
## Customizing the pw.x input file
43+
44+
Most of the input parameters can be customized directly through the builder. However, some inputs such as structure, pseudopotentials and k-points have to be provided using AiiDA-specific data types (see more detailed explanation below). Moreover, a few parameters such as the directory names for output and pseudopotentials as well as prefix are set by AiiDA and can not be modified.
45+
46+
![Scheme of a pw.x input file](../images/pw_input_scheme.png "Scheme of a pw.x input file")
47+
48+
For example, cutoff parameters can be adjusted by modifying the builder dictionary:
49+
50+
```python
51+
from aiida import orm
52+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
53+
54+
from ase.build import bulk
55+
56+
builder = PwBaseWorkChain.get_builder_from_protocol(
57+
code = orm.load_code('pw@localhost'),
58+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
59+
protocol='balanced'
60+
)
61+
62+
builder.pw.parameters["SYSTEM"]["ecutrho"] = 300.0
63+
builder.pw.parameters["SYSTEM"]["ecutwfc"] = 40.0
64+
```
65+
66+
### Inputs provided through AiiDA data types
67+
68+
**Crystal structure** needs to be provided using AiiDA StructureData. More information on the relevant [documentation page](https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/data_types.html#topics-data-types-materials-structure).
69+
70+
**Pseudopotentials**
71+
72+
Pseudopotentials are provided as [UpfData](https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/data_types.html#upfdata) data type. Usually they would be installed as part of the pseudopotential family via [aiida-pseudo](https://github.com/aiidateam/aiida-pseudo) package. As explained in [the package documentation](https://aiida-pseudo.readthedocs.io/en/latest/), pseudopotential families can be installed via a command line interface, either from the provided libraries ([SSSP](https://www.materialscloud.org/discover/sssp/table/efficiency) and [PseudoDojo](http://www.pseudo-dojo.org/)) or by importing from a custom archive or folder.
73+
74+
- By default, AiiDA-QuantumESPRESSO workchains are using pseudopotentials from SSSP v1.3 Efficiency
75+
76+
- To use a different pseudopotential family installed via AiiDA-Pseudo, pass the required label to the overrides dictionary (see the [**Overrides**](#overrides) section):
77+
78+
- To directly specify the pseudopotentials from a certain AiiDA-Pseudo family one can use `get_pseudos()` method:
79+
80+
```python
81+
from aiida import orm
82+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
83+
84+
from ase.build import bulk
85+
86+
my_structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43))
87+
88+
builder = PwBaseWorkChain.get_builder_from_protocol(
89+
code = orm.load_code('pw@localhost'),
90+
structure = my_structure,
91+
protocol='balanced'
92+
)
93+
94+
family = orm.load_group("PseudoDojo/0.4/PBE/SR/standard/upf")
95+
builder.pw.pseudos = family.get_pseudos(structure=my_structure)
96+
```
97+
98+
**K-points**
99+
100+
K-points are specified through [KpointsData](https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/data_types.html#kpointsdata) that supports k-point meshes as well as custom k-point lists, and also features symmetry-based automatic calculation of k-point paths for electronic band structure calculation.
101+
102+
Refer to the [**Builder structures**](#builder-structures-of-aiida-quantumespresso-workflows) section to see where to specify these inputs in the builder dictionary depending on the WorkChain you are using.
103+
104+
## Customizing the submission script
105+
106+
The submission script can also be customized mainly through `metadata.options` namespace of the builder.
107+
108+
![Scheme of a submission script](../images/aiidasubmit.png "Scheme of a submission script")
109+
110+
For example, when running `PwBaseWorkChain`
111+
112+
```python
113+
from aiida import orm
114+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
115+
116+
from ase.build import bulk
117+
118+
builder = PwBaseWorkChain.get_builder_from_protocol(
119+
code = orm.load_code('pw@localhost'),
120+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
121+
protocol='balanced'
122+
)
123+
124+
builder.metadata["options"]["queue_name"] = "normal" # to specify partition
125+
builder.metadata["options"]["resources"]["num_machines"] = 1
126+
builder.metadata["options"]["resources"]["tot_num_mpiprocs"] = 12
127+
```
128+
129+
Full list of metadata available can be found at [AiiDA documentation page](link to this section of the real-world tips and tricks)
130+
131+
## Overrides
132+
133+
If many default inputs need to be overwritten, it is convenient to use the `overrides` keyword, provided by `get_builder_from_protocol()` function of the required workchain.
134+
It is necessary to arrange the custom parameters into a dictionary respecting the structure of the builder of the workchain.
135+
136+
```python
137+
from aiida import orm
138+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
139+
140+
from ase.build import bulk
141+
142+
overrides = {
143+
"pseudo_family": "PseudoDojo/0.4/PBEsol/SR/standard/upf",
144+
"pw": {
145+
"parameters": {
146+
"SYSTEM": {
147+
"ecutrho": 300.0,
148+
"ecutwfc": 40.0
149+
}
43150
}
151+
},
152+
"metadata": {
153+
"options": {
154+
"queue_name": "normal",
155+
"resources": {
156+
"num_machines": 1,
157+
"tot_num_mpiprocs": 12
158+
}
159+
}
160+
}
44161
}
45-
results = engine.run(PwBaseWorkChain, **inputs)
162+
163+
builder = PwBaseWorkChain.get_builder_from_protocol(
164+
code = orm.load_code('pw@localhost'),
165+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
166+
protocol='balanced'
167+
)
46168
```
169+
170+
## Accessing the simulation directory and all files
171+
172+
In order to go to the calculation folder and see all the files you can use the following command for a given calculation with pk `<pk>`:
173+
```
174+
verdi calcjob gotocomputer <pk>
175+
```
176+
In order to find the `<pk>` of the CalcJob, run
177+
```
178+
verdi process status <workchain pk>
179+
```
180+
providing the `<pk>` number of the submitted WorkChain to see which calculations were started by the workflow.
181+
182+
Another way is to dump all the files from the workchain to a folder using
183+
```
184+
verdi process dump <pk>
185+
```
186+
187+
That will create a folder in your current directory, and it will contain all the retrieved files of the calculation (including the inputs). This is particularly useful if you want to inspect the retrieved files of a failed calculation, or if you want to re-run the calculation locally or somewhere else for debugging.
188+
189+
## Builder structures of AiiDA-QuantumESPRESSO workflows
190+
191+
In order to actually change the inputs you need to modify the relevant fields of the builder dictionary.
192+
193+
### Building blocks
194+
195+
**.pw** namespace of the builder contains the pw.x related inputs. The "parameters" field allows to directly customize pw.x input file where it can be manually changed by the user (green box on the figure in [**Customizing the pw.x input file**](#customizing-the-pwx-input-file) section). The full structure of the inputs is available at [**PwCalculation**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/calculations/pw.html) reference page.
196+
197+
**metadata** field allows to customize the submission parameters such as parallelization, HPC account, queue, etc. and its full structure is available on the reference pages of the respective calculations and workflows (see the links below).
198+
199+
### Full builder structures
200+
201+
To see the full structures of the builders of the AiiDA-QuantumESPRESSO workflows, consult the respective reference pages:
202+
203+
- [**PwBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/base.html)
204+
- [**PwRelaxWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/relax.html)
205+
- [**PwBandsWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/bands.html)
206+
- [**PdosWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pdos.html)
207+
- [**PhBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/ph.html)
208+
- [**MatdynBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/matdyn.html)
209+
- [**NebBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/neb.html)
210+
- [**Q2rBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/q2r.html)

docs/source/images/aiidasubmit.png

111 KB
Loading
145 KB
Loading

0 commit comments

Comments
 (0)