Skip to content

Commit 23d9ba0

Browse files
committed
outputs: Annotate fields with Unit markers
`dough` 0.4 introduced the `Unit(...)` annotation on `Annotated[T, Spec(...), Unit(...)]` to label a field's physical unit, and a matching `to="pint"` target on `BaseOutput.get_output` / `get_output_dict` that wraps marked numeric outputs into `pint.Quantity`. Annotate the existing `_PwMapping`, `_PwParametersMapping`, and `_DosMapping` fields with their physical unit so users can opt in to `pint`-based conversion (`pw_out.get_output("total_energy", to="pint")`). Units annotated: - `_PwMapping`: `forces` (eV/Å), `stress` (GPa), `fermi_energy`/`fermi_energy_up`/ `fermi_energy_down`/`total_energy` (eV), `k_points_cartesian` (1/Å). - `_PwParametersMapping`: `ecutwfc`, `ecutrho`, `degauss` (eV). - `_DosMapping`: `energy`, `fermi_energy` (eV); `dos`, `dos_up`, `dos_down` (1/eV). Fields without a meaningful physical unit (`integrated_dos` is a count of states, `k_points_weights` are dimensionless QE-convention weights) deliberately stay unmarked — `to="pint"` passes those through unchanged. Also fix the `_DosMapping.integrated_dos` docstring to clarify the unit (number of states, not eV).
1 parent 7a0c952 commit 23d9ba0

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
'packaging',
3131
'xmlschema',
3232
'glom~=24.11',
33-
'dough==0.3.0',
33+
'dough==0.4.0',
3434
]
3535

3636
[project.urls]
@@ -40,14 +40,16 @@ Source = 'https://github.com/aiidateam/qe-tools'
4040
[project.optional-dependencies]
4141
ase = [
4242
"ase",
43-
"pint"
4443
]
4544
pymatgen = [
4645
"pymatgen"
4746
]
4847
aiida = [
4948
"aiida-core"
5049
]
50+
pint = [
51+
"dough[pint]",
52+
]
5153
docs = [
5254
"mkdocs",
5355
"mkdocs-material"

src/qe_tools/outputs/dos.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from glom import Spec
88

9+
from dough import Unit
910
from dough.converters import BaseConverter
1011
from dough.outputs import BaseOutput, output_mapping
1112

@@ -32,23 +33,23 @@ def _determine_spin_type(spin: dict) -> str:
3233
class _DosMapping:
3334
"""Typed outputs of a dos.x calculation."""
3435

35-
energy: Annotated[list, Spec("dos.energy")]
36+
energy: Annotated[list, Spec("dos.energy"), Unit("eV")]
3637
"""Energy grid in eV."""
3738

38-
dos: Annotated[list, Spec("dos.dos")]
39+
dos: Annotated[list, Spec("dos.dos"), Unit("1/eV")]
3940
"""Total density of states (states/eV). Not available for spin-polarised calculations."""
4041

41-
dos_up: Annotated[list, Spec("dos.dos_up")]
42+
dos_up: Annotated[list, Spec("dos.dos_up"), Unit("1/eV")]
4243
"""Spin-up DOS (states/eV). Not available for non-spin-polarised calculations."""
4344

44-
dos_down: Annotated[list, Spec("dos.dos_down")]
45+
dos_down: Annotated[list, Spec("dos.dos_down"), Unit("1/eV")]
4546
"""Spin-down DOS (states/eV). Not available for non-spin-polarised calculations."""
4647

47-
fermi_energy: Annotated[float, Spec("dos.fermi_energy")]
48+
fermi_energy: Annotated[float, Spec("dos.fermi_energy"), Unit("eV")]
4849
"""Fermi energy in eV."""
4950

5051
integrated_dos: Annotated[list, Spec("dos.integrated_dos")]
51-
"""Integrated DOS."""
52+
"""Integrated DOS (# of states)."""
5253

5354
full_dos: Annotated[dict, Spec("dos")]
5455
"""Full parsed DOS dictionary."""

src/qe_tools/outputs/pw.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from glom import Coalesce, Spec
99

10+
from dough import Unit
1011
from dough.converters import BaseConverter
1112
from dough.outputs import BaseOutput, output_mapping
1213

@@ -35,6 +36,7 @@ class _PwParametersMapping:
3536
lambda ecut: ecut * CONSTANTS.hartree_to_ev,
3637
)
3738
),
39+
Unit("eV"),
3840
]
3941
"""Kinetic-energy cutoff for wavefunctions in eV."""
4042

@@ -46,6 +48,7 @@ class _PwParametersMapping:
4648
lambda ecut: ecut * CONSTANTS.hartree_to_ev,
4749
)
4850
),
51+
Unit("eV"),
4952
]
5053
"""Kinetic-energy cutoff for the charge density and potential in eV."""
5154

@@ -107,6 +110,7 @@ class _PwParametersMapping:
107110
lambda d: d * CONSTANTS.hartree_to_ev,
108111
)
109112
),
113+
Unit("eV"),
110114
]
111115
"""Smearing width in eV."""
112116

@@ -185,6 +189,7 @@ class _PwMapping:
185189
],
186190
)
187191
),
192+
Unit("eV/angstrom"),
188193
]
189194
"""Forces on atoms in eV/Å, shape [n_atoms][3]."""
190195

@@ -202,6 +207,7 @@ class _PwMapping:
202207
],
203208
)
204209
),
210+
Unit("GPa"),
205211
]
206212
"""Stress tensor in GPa, shape [3][3]."""
207213

@@ -213,6 +219,7 @@ class _PwMapping:
213219
lambda energy: energy * CONSTANTS.hartree_to_ev,
214220
)
215221
),
222+
Unit("eV"),
216223
]
217224
"""Fermi energy in eV."""
218225

@@ -224,6 +231,7 @@ class _PwMapping:
224231
lambda energies: energies[0] * CONSTANTS.hartree_to_ev,
225232
)
226233
),
234+
Unit("eV"),
227235
]
228236
"""Fermi energy of spin-up channel in eV.
229237
@@ -238,6 +246,7 @@ class _PwMapping:
238246
lambda energies: energies[1] * CONSTANTS.hartree_to_ev,
239247
)
240248
),
249+
Unit("eV"),
241250
]
242251
"""Fermi energy of spin-down channel in eV.
243252
@@ -278,6 +287,7 @@ class _PwMapping:
278287
],
279288
)
280289
),
290+
Unit("1/angstrom"),
281291
]
282292
"""Cartesian coordinates of the k-points in 1/Å, shape `[n_kpoints][3]`."""
283293

@@ -300,6 +310,7 @@ class _PwMapping:
300310
lambda energy: energy * CONSTANTS.hartree_to_ev,
301311
)
302312
),
313+
Unit("eV"),
303314
]
304315
"""Total energy in eV."""
305316

0 commit comments

Comments
 (0)