Skip to content

Commit a69be2a

Browse files
committed
PwOutput: Add k-point outputs
Add three new Specs on `_PwMapping` exposing the k-points at which the Kohn-Sham states were computed, parsed from the XML output of `pw.x`: - `number_of_k_points` — direct read of `band_structure.nks`. - `k_points_weights` — weights of each k-point. Per QE convention they sum to 2 for `nspin=1` and to 1 for `nspin=2`. - `k_points_cartesian` — cartesian coordinates in 1/Å. QE reports k-points in units of `2π/alat`; the Spec reads `atomic_structure.@alat` alongside the `ks_energies` list and converts to 1/Å. The `_cartesian` suffix leaves room for a future `k_points_crystal` if a use case needs it.
1 parent ac8818e commit a69be2a

7 files changed

Lines changed: 194 additions & 0 deletions

File tree

src/qe_tools/outputs/pw.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Output of the Quantum ESPRESSO pw.x code."""
22

3+
import math
34
from pathlib import Path
45
from typing import TextIO
56

@@ -103,6 +104,37 @@ class _PwMapping:
103104
Only available when ``tot_magnetization`` is set in ``SYSTEM``.
104105
"""
105106

107+
number_of_k_points: int = Spec("xml.output.band_structure.nks")
108+
"""Number of k-points at which the Kohn-Sham states were computed."""
109+
110+
k_points_weights: list = Spec(
111+
(
112+
"xml.output.band_structure.ks_energies",
113+
[lambda ks: ks["k_point"]["@weight"]],
114+
)
115+
)
116+
"""Weights of the k-points at which the Kohn-Sham states were computed.
117+
118+
Dimensionless; per QE convention the weights sum to 2 for `nspin=1` and to 1 for `nspin=2`.
119+
"""
120+
121+
k_points_cartesian: list = Spec(
122+
(
123+
"xml.output",
124+
lambda output: [
125+
[
126+
kp
127+
* 2
128+
* math.pi
129+
/ (output["atomic_structure"]["@alat"] * CONSTANTS.bohr_to_ang)
130+
for kp in ks["k_point"]["$"]
131+
]
132+
for ks in output["band_structure"]["ks_energies"]
133+
],
134+
)
135+
)
136+
"""Cartesian coordinates of the k-points in 1/Å, shape `[n_kpoints][3]`."""
137+
106138
number_of_bands: int = Spec(
107139
Coalesce(
108140
"xml.output.band_structure.nbnd",

tests/outputs/test_pw_output/test_default_xml_211101_.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ base_outputs:
77
- - 0.0
88
- 0.0
99
- 0.1714861209572958
10+
k_points_cartesian:
11+
- - 0.0
12+
- 0.0
13+
- 0.0
14+
- - 0.81241615259136
15+
- 0.4690486843912825
16+
- 0.3316675054314128
17+
k_points_weights:
18+
- 1.0
19+
- 1.0
1020
number_of_bands: 8
21+
number_of_k_points: 2
1122
stress:
1223
- - 19.802407083925143
1324
- 3.18983295531761e-15

tests/outputs/test_pw_output/test_default_xml_220603_.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,26 @@ base_outputs:
77
- - 0.0
88
- -1.5988141933326028e-26
99
- 3.5990582562436014e-05
10+
k_points_cartesian:
11+
- - 0.0
12+
- 0.0
13+
- 0.0
14+
- - 0.0
15+
- 0.0
16+
- -0.995002516309094
17+
- - 0.0
18+
- -0.9380973687825651
19+
- 0.33166750544626855
20+
- - 0.0
21+
- -0.9380973687825651
22+
- -0.6633350108628259
23+
k_points_weights:
24+
- 0.25
25+
- 0.25
26+
- 0.75
27+
- 0.75
1028
number_of_bands: 8
29+
number_of_k_points: 4
1130
stress:
1231
- - 7.558511471674453
1332
- 2.3923747164882088e-15

tests/outputs/test_pw_output/test_default_xml_230310_.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,62 @@ base_outputs:
1313
- - 0.0
1414
- 9.008856055736822e-25
1515
- -3.12669022280311e-25
16+
k_points_cartesian:
17+
- - 0.0
18+
- 0.0
19+
- 0.0
20+
- - -0.5577989051433998
21+
- -0.3220453480444437
22+
- 0.11177179819501858
23+
- - 1.1155978102867996
24+
- 0.6440906960888875
25+
- -0.22354359639003715
26+
- - -0.5577989051433998
27+
- 0.3220453480444437
28+
- 0.2235435963969118
29+
- - 1.1155978102867996
30+
- 1.2881813921777754
31+
- -0.11177179818814392
32+
- - 0.5577989051433998
33+
- 0.9661360441333311
34+
- 6.8746528017552155e-12
35+
- - 1.1155978102867996
36+
- -0.6440906960888875
37+
- -0.44708719279382364
38+
- - 0.0
39+
- 0.0
40+
- 0.33531539459193044
41+
- - 1.6733967154301994
42+
- 0.9661360441333311
43+
- 6.8746528017552155e-12
44+
- - 1.1155978102867996
45+
- 0.6440906960888875
46+
- 0.11177179820189323
47+
- - 1.6733967154301994
48+
- -0.9661360441333311
49+
- -0.335315394598805
50+
- - 1.1155978102867996
51+
- -1.2881813921777754
52+
- -0.22354359640378646
53+
- - 0.0
54+
- 0.0
55+
- -0.6706307891838609
56+
k_points_weights:
57+
- 0.03125
58+
- 0.1875
59+
- 0.09375
60+
- 0.1875
61+
- 0.375
62+
- 0.1875
63+
- 0.09375
64+
- 0.0625
65+
- 0.1875
66+
- 0.1875
67+
- 0.1875
68+
- 0.1875
69+
- 0.03125
1670
number_of_bands: 16
71+
number_of_k_points: 13
1772
stress:
1873
- - -62.88281405555692
1974
- -2.551866364254089e-14

tests/outputs/test_pw_output/test_default_xml_240411_.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,62 @@ base_outputs:
77
- - -6.945510284945072e-25
88
- -2.665236731143183e-19
99
- 5.875314824057878e-06
10+
k_points_cartesian:
11+
- - 0.0
12+
- 0.0
13+
- 0.0
14+
- - -5.90640860423821e-20
15+
- -2.266496846931142e-14
16+
- 0.49963226034871844
17+
- - 1.181281720847642e-19
18+
- 4.532993693862284e-14
19+
- -0.9992645206974368
20+
- - -4.4951691091524867e-20
21+
- 0.471057718822376
22+
- -0.16654408678790097
23+
- - -1.0401577713390695e-19
24+
- 0.4710577188223534
25+
- 0.33308817356081744
26+
- - 7.317648099323935e-20
27+
- 0.47105771882242137
28+
- -1.1658086074853378
29+
- - 1.4112394950857237e-20
30+
- 0.4710577188223985
31+
- -0.6661763471366193
32+
- - 8.990338218304972e-20
33+
- -0.942115437644752
34+
- 0.33308817357580184
35+
- - 3.083929614066762e-20
36+
- -0.9421154376447746
37+
- 0.8327204339245202
38+
- - 2.0803155426781388e-19
39+
- -0.9421154376447066
40+
- -0.666176347121635
41+
- - 0.4079479511500927
42+
- -1.1776442970559284
43+
- 0.16654408679539323
44+
- - 0.4079479511500927
45+
- -1.1776442970559509
46+
- 0.6661763471441117
47+
- - 0.4079479511500927
48+
- -1.1776442970559053
49+
- -0.33308817355332515
50+
k_points_weights:
51+
- 0.03125
52+
- 0.0625
53+
- 0.03125
54+
- 0.1875
55+
- 0.1875
56+
- 0.1875
57+
- 0.1875
58+
- 0.09375
59+
- 0.1875
60+
- 0.09375
61+
- 0.375
62+
- 0.1875
63+
- 0.1875
1064
number_of_bands: 8
65+
number_of_k_points: 13
1166
stress:
1267
- - 0.00831212176267791
1368
- 5.84098538270437e-18

tests/outputs/test_pw_output/test_default_xml_250521_.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ base_outputs:
2525
- - 0.11819283971808975
2626
- -0.5120812364569893
2727
- 0.07225493313766373
28+
k_points_cartesian:
29+
- - 0.0
30+
- 0.0
31+
- 0.0
32+
- - -0.7795515303527284
33+
- 0.0
34+
- 0.0
35+
k_points_weights:
36+
- 1.0
37+
- 1.0
2838
number_of_bands: 24
39+
number_of_k_points: 2
2940
stress:
3041
- - 3.345625870189871
3142
- 0.6180019560502391

tests/outputs/test_pw_output/test_success_base_collinear_.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
base_outputs:
22
fermi_energy: 1.8452196496373638
3+
k_points_cartesian:
4+
- - 0.0
5+
- 0.0
6+
- 0.0
7+
- - -0.7795515303527284
8+
- 0.0
9+
- 0.0
10+
k_points_weights:
11+
- 0.5
12+
- 0.5
313
number_of_bands: 24
14+
number_of_k_points: 2
415
structure:
516
atomic_species:
617
- F

0 commit comments

Comments
 (0)