-
Notifications
You must be signed in to change notification settings - Fork 93
/
enums.py
95 lines (80 loc) · 2.33 KB
/
enums.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
"""
This module defines enumerators associated to important Abinit input variables
"""
from __future__ import annotations
import enum
class EnumMixin:
"""Mixin for enums provides extra capabilities."""
@classmethod
def validate(cls, value) -> None:
"""Validate value"""
values = [member.value for member in cls]
if value not in values:
raise ValueError(f"{value=} is not valid. Must be among: {values=}")
class StrEnum(str, enum.Enum): # StrEnum added in 3.11
def __new__(cls, *args):
for arg in args:
if not isinstance(arg, (str, enum.auto)):
raise TypeError(
"Values of StrEnums must be strings: {} is a {}".format(
repr(arg), type(arg)
)
)
return super().__new__(cls, *args)
def __str__(self):
return self.value
# The first argument to this function is documented to be the name of the
# enum member, not `self`:
# https://docs.python.org/3.6/library/enum.html#using-automatic-values
def _generate_next_value_(name, *_):
return name
class RUNL(EnumMixin, enum.IntEnum):
"""
Values of optdriver corresponding to the different run-levels. See defs_basis.F90
"""
GSTATE = 0
RESPFN = 1
SCREENING = 3
SIGMA = 4
NONLINEAR = 5
GWR = 6
EPH = 7
WFK = 8
RTTDDFT = 9
GWLS = 66
BSE = 99
LONGWAVE = 10
def __str__(self):
return str(self.value)
class WFK_TASK(EnumMixin, enum.IntEnum):
"""
Integer flags defining the task to be performed in wfk_analyze. See defs_basis.F90
"""
NONE = 0
FULLBZ = 1
CLASSIFY = 2
PAW_AEPSI = 3
EINTERP = 4
DDK = 5
DDK_DIAGO = 6
OPTICS_FULLBZ = 7
KPTS_ERANGE= 8
CHECK_SYMTAB = 9
def __str__(self):
return str(self.value)
class GWR_TASK(EnumMixin, StrEnum): # StrEnum added in 3.11
"""
String flags defining the task to be performed in the GWR code.
"""
HDIAGO = "HDIAGO"
HDIAGO_FULL = "HDIAGO_FULL"
CC4S = "CC4S"
CC4S_FULL = "CC4S_FULL"
G0W0 = "G0W0"
G0V = "G0V"
EGEW = "EGEW"
EGW0 = "EGW0"
G0EW = "G0EW"
RPA_ENERGY = "RPA_ENERGY"
GAMMA_GW = "GAMMA_GW"
CHI0 = "CHI0"