-
Notifications
You must be signed in to change notification settings - Fork 41
/
bands.py
315 lines (281 loc) · 11.8 KB
/
bands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
"""
This module, 'bands.py', contains recipes for performing bands and fermi surface calculations using the
bands.x and fs.x binaries from Quantum ESPRESSO via the quacc library.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from ase.dft.kpoints import bandpath
from pymatgen.io.ase import AseAtomsAdaptor
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from quacc import flow, job
from quacc.calculators.espresso.espresso import EspressoTemplate
from quacc.recipes.espresso._base import run_and_summarize
from quacc.utils.kpts import convert_pmg_kpts
from quacc.wflow_tools.customizers import customize_funcs
if TYPE_CHECKING:
from typing import Any, Callable, TypedDict
from ase.atoms import Atoms
from quacc.schemas._aliases.ase import RunSchema
from quacc.utils.files import Filenames, SourceDirectory
class BandsSchema(TypedDict, total=False):
bands_pw: RunSchema
bands_pp: RunSchema
fermi_surface: RunSchema
@job
def bands_pw_job(
atoms: Atoms,
copy_files: (
SourceDirectory
| list[SourceDirectory]
| dict[SourceDirectory, Filenames]
| None
) = None,
prev_outdir: SourceDirectory | None = None,
make_bandpath: bool = True,
line_density: float = 20,
force_gamma: bool = True,
test_run: bool = False,
**calc_kwargs,
) -> RunSchema:
"""
Function to carry out a basic bands structure calculation with pw.x.
First perform a normal SCF calculation [quacc.recipes.espresso.core.static_job][];
then use this job if you are interested in calculating only the Kohn-Sham states
for the given set of k-points
Parameters
----------
atoms
The Atoms object.
copy_files
Source directory or directories to copy files from. If a `SourceDirectory` or a
list of `SourceDirectory` is provided, this interface will automatically guess
which files have to be copied over by looking at the binary and `input_data`.
If a dict is provided, the mode is manual, keys are source directories and values
are relative path to files or directories to copy. Glob patterns are supported.
prev_outdir
The output directory of a previous calculation. If provided, Quantum Espresso
will directly read the necessary files from this directory, eliminating the need
to manually copy files. The directory will be ungzipped if necessary.
make_bandpath
If True, it returns the primitive cell for your structure and generates
the high symmetry k-path using Latmer-Munro approach.
For more information look at
[pymatgen.symmetry.bandstructure.HighSymmKpath][]
line_density
Density of kpoints along the band path if make_bandpath is True
For more information [quacc.utils.kpts.convert_pmg_kpts][]
force_gamma
Forces gamma-centered k-points when using make_bandpath
For more information [quacc.utils.kpts.convert_pmg_kpts][]
test_run
If True, a test run is performed to check that the calculation input_data is correct or
to generate some files/info if needed.
**calc_kwargs
Additional keyword arguments to pass to the Espresso calculator. Set a value to
`quacc.Remove` to remove a pre-existing key entirely. See the docstring of
[quacc.calculators.espresso.espresso.Espresso][] for more information.
Returns
-------
RunSchema
Dictionary of results from [quacc.schemas.ase.summarize_run][].
See the type-hint for the data structure.
"""
calc_defaults = {
"input_data": {"control": {"calculation": "bands", "verbosity": "high"}}
}
if make_bandpath:
structure = AseAtomsAdaptor.get_structure(atoms)
primitive = SpacegroupAnalyzer(structure).get_primitive_standard_structure()
atoms = primitive.to_ase_atoms()
calc_defaults["kpts"] = bandpath(
convert_pmg_kpts(
{"line_density": line_density}, atoms, force_gamma=force_gamma
)[0],
cell=atoms.get_cell(),
)
return run_and_summarize(
atoms,
template=EspressoTemplate("pw", test_run=test_run, outdir=prev_outdir),
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
additional_fields={"name": "pw.x bands"},
copy_files=copy_files,
)
@job
def bands_pp_job(
copy_files: (
SourceDirectory
| list[SourceDirectory]
| dict[SourceDirectory, Filenames]
| None
) = None,
prev_outdir: SourceDirectory | None = None,
test_run: bool = False,
**calc_kwargs,
) -> RunSchema:
"""
Function to re-order bands and computes bands-related properties with bands.x.
This allows to get the bands structure in a more readable way. This requires a
previous [quacc.recipes.espresso.bands.bands_pw_job][] calculation.
Parameters
----------
copy_files
Source directory or directories to copy files from. If a `SourceDirectory` or a
list of `SourceDirectory` is provided, this interface will automatically guess
which files have to be copied over by looking at the binary and `input_data`.
If a dict is provided, the mode is manual, keys are source directories and values
are relative path to files or directories to copy. Glob patterns are supported.
prev_outdir
The output directory of a previous calculation. If provided, Quantum Espresso
will directly read the necessary files from this directory, eliminating the need
to manually copy files. The directory will be ungzipped if necessary.
test_run
If True, a test run is performed to check that the calculation input_data is correct or
to generate some files/info if needed.
**calc_kwargs
Additional keyword arguments to pass to the Espresso calculator. Set a value to
`quacc.Remove` to remove a pre-existing key entirely. See the docstring of
[quacc.calculators.espresso.espresso.Espresso][] for more information.
Returns
-------
RunSchema
Dictionary of results from [quacc.schemas.ase.summarize_run][].
See the type-hint for the data structure.
"""
return run_and_summarize(
template=EspressoTemplate("bands", test_run=test_run, outdir=prev_outdir),
calc_defaults={},
calc_swaps=calc_kwargs,
additional_fields={"name": "bands.x post-processing"},
copy_files=copy_files,
)
@job
def fermi_surface_job(
copy_files: (
SourceDirectory
| list[SourceDirectory]
| dict[SourceDirectory, Filenames]
| None
) = None,
prev_outdir: SourceDirectory | None = None,
test_run: bool = False,
**calc_kwargs,
) -> RunSchema:
"""
Function to retrieve the fermi surface with fs.x
It requires a previous uniform unshifted k-point grid bands calculation.
Parameters
----------
copy_files
Source directory or directories to copy files from. If a `SourceDirectory` or a
list of `SourceDirectory` is provided, this interface will automatically guess
which files have to be copied over by looking at the binary and `input_data`.
If a dict is provided, the mode is manual, keys are source directories and values
are relative path to files or directories to copy. Glob patterns are supported.
prev_outdir
The output directory of a previous calculation. If provided, Quantum Espresso
will directly read the necessary files from this directory, eliminating the need
to manually copy files. The directory will be ungzipped if necessary.
test_run
If True, a test run is performed to check that the calculation input_data is correct or
to generate some files/info if needed.
**calc_kwargs
Additional keyword arguments to pass to the Espresso calculator. Set a value to
`quacc.Remove` to remove a pre-existing key entirely. See the docstring of
[quacc.calculators.espresso.espresso.Espresso][] for more information.
Returns
-------
RunSchema
Dictionary of results from [quacc.schemas.ase.summarize_run][].
See the type-hint for the data structure.
"""
return run_and_summarize(
template=EspressoTemplate("fs", test_run=test_run, outdir=prev_outdir),
calc_defaults={},
calc_swaps=calc_kwargs,
additional_fields={"name": "fs.x fermi_surface"},
copy_files=copy_files,
)
@flow
def bands_flow(
atoms: Atoms,
copy_files: (
SourceDirectory | list[SourceDirectory] | dict[SourceDirectory, Filenames]
),
run_bands_pp: bool = True,
run_fermi_surface: bool = False,
make_bandpath: bool = True,
line_density: float = 20,
force_gamma: bool = True,
job_params: dict[str, Any] | None = None,
job_decorators: dict[str, Callable | None] | None = None,
) -> BandsSchema:
"""
Function to compute bands structure and fermi surface using pw.x, bands.x and fs.x.
Consists of the following steps:
1. A pw.x non-self consistent calculation
- name: "bands_pw_job"
- job : [quacc.recipes.espresso.bands.bands_pw_job][]
2. A bands.x post-processing calculation
- name: "bands_pp_job"
- job : [quacc.recipes.espresso.bands.bands_pp_job][]
3. A fs.x calculation to obtain the fermi surface
- name: "fermi_surface_job"
- job : [quacc.recipes.espresso.bands.fermi_surface_job][]
Parameters
----------
atoms
The Atoms object.
copy_files
Files to copy (and decompress) from source to the runtime directory.
run_bands_pp
If True, a bands.x post-processing calculation will be carried out.
This allows to re-order bands and computes band-related properties.
run_fermi_surface
If True, a fs.x calculation will be carried out.
This allows to generate the fermi surface of your structure.
It requires a uniform unshifted k-point grid bands calculation.
make_bandpath
If True, it returns the primitive cell for your structure and generates
the high symmetry k-path using Latmer-Munro approach.
For more information look at
[pymatgen.symmetry.bandstructure.HighSymmKpath][]
line_density
Density of kpoints along the band path if make_bandpath is True
For more information [quacc.utils.kpts.convert_pmg_kpts][]
force_gamma
Forces gamma-centered k-points when using make_bandpath
For more information [quacc.utils.kpts.convert_pmg_kpts][]
job_params
Custom parameters to pass to each Job in the Flow. This is a dictionary where
the keys are the names of the jobs and the values are dictionaries of parameters.
job_decorators
Custom decorators to apply to each Job in the Flow. This is a dictionary where
the keys are the names of the jobs and the values are decorators.
Returns
-------
BandsSchema
Dictionary of results from [quacc.schemas.ase.summarize_run][].
See the type-hint for the data structure.
"""
(bands_pw_job_, bands_pp_job_, fermi_surface_job_) = customize_funcs(
["bands_pw_job", "bands_pp_job", "fermi_surface_job"],
[bands_pw_job, bands_pp_job, fermi_surface_job],
param_swaps=job_params,
decorators=job_decorators,
)
bands_results = bands_pw_job_(
atoms,
copy_files,
make_bandpath=make_bandpath,
line_density=line_density,
force_gamma=force_gamma,
)
results = {"bands_pw": bands_results}
if run_bands_pp:
bands_pp_results = bands_pp_job_(prev_outdir=bands_results["dir_name"])
results["bands_pp"] = bands_pp_results
if run_fermi_surface:
fermi_results = fermi_surface_job_(prev_outdir=bands_results["dir_name"])
results["fermi_surface"] = fermi_results
return results