Skip to content

Commit b7df135

Browse files
committed
Update customize inputs page of docs/howto
1 parent 1341c41 commit b7df135

File tree

3 files changed

+200
-33
lines changed

3 files changed

+200
-33
lines changed
Lines changed: 200 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,213 @@
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 by Nascimento *et al.*, [arXiv2504:03962](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-pwx-input-file)=
43+
## Customizing the pw.x input file
44+
45+
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.
46+
47+
![Scheme of a pw.x input file](../images/pw_input_scheme.png "Scheme of a pw.x input file")
48+
49+
For example, cutoff parameters can be adjusted by modifying the builder dictionary:
50+
51+
```python
52+
from aiida import orm
53+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
54+
55+
from ase.build import bulk
56+
57+
builder = PwBaseWorkChain.get_builder_from_protocol(
58+
code = orm.load_code('pw@localhost'),
59+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
60+
protocol='balanced'
61+
)
62+
63+
builder.pw.parameters["SYSTEM"]["ecutrho"] = 300.0
64+
builder.pw.parameters["SYSTEM"]["ecutwfc"] = 40.0
65+
```
66+
67+
### Inputs provided through AiiDA data types
68+
69+
**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).
70+
71+
**Pseudopotentials**
72+
73+
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.
74+
75+
- By default, AiiDA-QuantumESPRESSO workchains are using pseudopotentials from SSSP v1.3 Efficiency
76+
77+
- To use a different pseudopotential family installed via AiiDA-Pseudo, pass the required label to the overrides dictionary (see the [Overrides](#overrides) section):
78+
79+
- To directly specify the pseudopotentials from a certain AiiDA-Pseudo family one can use `get_pseudos()` method:
80+
81+
```python
82+
from aiida import orm
83+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
84+
85+
from ase.build import bulk
86+
87+
my_structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43))
88+
89+
builder = PwBaseWorkChain.get_builder_from_protocol(
90+
code = orm.load_code('pw@localhost'),
91+
structure = my_structure,
92+
protocol='balanced'
93+
)
94+
95+
family = orm.load_group("PseudoDojo/0.4/PBE/SR/standard/upf")
96+
builder.pw.pseudos = family.get_pseudos(structure=my_structure)
97+
```
98+
99+
**K-points**
100+
101+
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.
102+
103+
Refer to the [Builder structures](#builder-structures) section to see where to specify these inputs in the builder dictionary depending on the WorkChain you are using.
104+
105+
## Customizing the submission script
106+
107+
The submission script can also be customized mainly through `metadata.options` namespace of the builder.
108+
109+
![Scheme of a submission script](../images/aiidasubmit.png "Scheme of a submission script")
110+
111+
For example, when running `PwBaseWorkChain`
112+
113+
```python
114+
from aiida import orm
115+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
116+
117+
from ase.build import bulk
118+
119+
builder = PwBaseWorkChain.get_builder_from_protocol(
120+
code = orm.load_code('pw@localhost'),
121+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
122+
protocol='balanced'
123+
)
124+
125+
builder.metadata["options"]["queue_name"] = "normal" # to specify partition
126+
builder.metadata["options"]["resources"]["num_machines"] = 1
127+
builder.metadata["options"]["resources"]["tot_num_mpiprocs"] = 12
128+
```
129+
130+
Full list of metadata available can be found at [AiiDA documentation page](link to this section of the real-world tips and tricks)
131+
132+
(overrides)=
133+
## Overrides
134+
135+
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.
136+
It is necessary to arrange the custom parameters into a dictionary respecting the structure of the builder of the workchain.
137+
138+
```python
139+
from aiida import orm
140+
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
141+
142+
from ase.build import bulk
143+
144+
overrides = {
145+
"pseudo_family": "PseudoDojo/0.4/PBEsol/SR/standard/upf",
146+
"pw": {
147+
"parameters": {
148+
"SYSTEM": {
149+
"ecutrho": 300.0,
150+
"ecutwfc": 40.0
151+
}
43152
}
153+
},
154+
"metadata": {
155+
"options": {
156+
"queue_name": "normal",
157+
"resources": {
158+
"num_machines": 1,
159+
"tot_num_mpiprocs": 12
160+
}
161+
}
162+
}
44163
}
45-
results = engine.run(PwBaseWorkChain, **inputs)
164+
165+
builder = PwBaseWorkChain.get_builder_from_protocol(
166+
code = orm.load_code('pw@localhost'),
167+
structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43)),
168+
protocol='balanced'
169+
)
46170
```
171+
172+
## Accessing the simulation directory and all files
173+
174+
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>`:
175+
```
176+
verdi calcjob gotocomputer <pk>
177+
```
178+
In order to find the `<pk>` of the CalcJob, run
179+
```
180+
verdi process status <workchain pk>
181+
```
182+
providing the `<pk>` number of the submitted WorkChain to see which calculations were started by the workflow.
183+
184+
Another way is to dump all the files from the workchain to a folder using
185+
```
186+
verdi process dump <pk>
187+
```
188+
189+
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.
190+
191+
(builder-structures)=
192+
## Builder structures of AiiDA-QuantumESPRESSO workflows
193+
194+
In order to actually change the inputs you need to modify the relevant fields of the builder dictionary.
195+
196+
### Building blocks
197+
198+
**.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.
199+
200+
**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).
201+
202+
### Full builder structures
203+
204+
To see the full structures of the builders of the AiiDA-QuantumESPRESSO workflows, consult the respective reference pages:
205+
206+
- [**PwBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/base.html)
207+
- [**PwRelaxWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/relax.html)
208+
- [**PwBandsWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pw/bands.html)
209+
- [**PdosWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/pdos.html)
210+
- [**PhBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/ph.html)
211+
- [**MatdynBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/matdyn.html)
212+
- [**NebBaseWorkChain**](https://aiida-quantumespresso.readthedocs.io/en/latest/reference/workflows/neb.html)
213+
- [**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)