Skip to content

Commit 5bedfcf

Browse files
committed
Add CommonRelaxInputGenerator subclass for DFT based codes
1 parent f83cbba commit 5bedfcf

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

aiida_common_workflows/common/types.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Module with basic type definitions."""
33
from enum import Enum
44

5-
__all__ = ('ElectronicType', 'SpinType', 'RelaxType')
5+
__all__ = ('ElectronicType', 'SpinType', 'RelaxType', 'SmearingMethodType', 'XcFunctionalType')
66

77

88
class RelaxType(Enum):
@@ -33,3 +33,18 @@ class ElectronicType(Enum):
3333
AUTOMATIC = 'automatic'
3434
METAL = 'metal'
3535
INSULATOR = 'insulator'
36+
37+
38+
class SmearingMethodType(Enum):
39+
"""Enumeration of known smearing method types."""
40+
41+
GAUSSIAN = 'gaussian'
42+
FERMI_DIRAC = 'fermi-dirac'
43+
44+
45+
class XcFunctionalType(Enum):
46+
"""Enumeration of known exchange-correlation functional types."""
47+
48+
LDA = 'lda'
49+
PBE = 'pbe'
50+
PBESOL = 'pbesol'

aiida_common_workflows/workflows/relax/generator.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from aiida import orm
66
from aiida import plugins
77

8-
from aiida_common_workflows.common import ElectronicType, RelaxType, SpinType
8+
from aiida_common_workflows.common import ElectronicType, RelaxType, SpinType, SmearingMethodType, XcFunctionalType
99
from aiida_common_workflows.generators import ChoiceType, InputGenerator
1010

1111
__all__ = ('CommonRelaxInputGenerator',)
@@ -109,3 +109,65 @@ def define(cls, spec):
109109
required=False,
110110
help='Options for the geometry optimization calculation jobs.',
111111
)
112+
113+
114+
class CommonDftRelaxInputGenerator(CommonRelaxInputGenerator, metaclass=abc.ABCMeta):
115+
"""Input generator for the common relax workflow.
116+
117+
.. note:: This class is a subclass of the ``CommonRelaxInputGenerator`` but defines some additional inputs that are
118+
common to a number of implementations.
119+
120+
This class should be subclassed by implementations for specific quantum engines. After calling the super, they can
121+
modify the ports defined here in the base class as well as add additional custom ports.
122+
"""
123+
124+
@staticmethod
125+
def validate_kpoints_shift(value, _):
126+
"""Validate the ``kpoints_shift`` input."""
127+
if not isinstance(value, list) or len(value) != 3 or any(not isinstance(element, float) for element in value):
128+
return f'The `kpoints_shift` argument should be a list of three floats, but got: `{value}`.'
129+
130+
@classmethod
131+
def define(cls, spec):
132+
"""Define the specification of the input generator.
133+
134+
The ports defined on the specification are the inputs that will be accepted by the ``get_builder`` method.
135+
"""
136+
super().define(spec)
137+
spec.input(
138+
'kpoints_distance',
139+
valid_type=float,
140+
required=False,
141+
help='The desired minimum distance between k-points in reciprocal space in 1/Å. The implementation will'
142+
'guarantee that a k-point mesh is generated for which the distances between all adjacent k-points along '
143+
'each cell vector are at most this distance. It is therefore possible that the distance is smaller than '
144+
'requested along certain directions.',
145+
)
146+
spec.input(
147+
'kpoints_shift',
148+
valid_type=list,
149+
validator=cls.validate_kpoints_shift,
150+
required=False,
151+
help='Optional shift to apply to all k-points of the k-point mesh. Should be a list of three floats where '
152+
'each float is a number between 0 and 1.',
153+
)
154+
spec.input(
155+
'smearing_method',
156+
valid_type=SmearingMethodType,
157+
serializer=SmearingMethodType,
158+
default=SmearingMethodType.GAUSSIAN,
159+
help='The method to use for the smearing of the electronic occupations.',
160+
)
161+
spec.input(
162+
'smearing_broadening',
163+
valid_type=float,
164+
required=False,
165+
help='The broadening of the smearing in eV.',
166+
)
167+
spec.input(
168+
'functional',
169+
valid_type=XcFunctionalType,
170+
serializer=XcFunctionalType,
171+
default=XcFunctionalType.PBE,
172+
help='The functional for the exchange-correlation to be used.',
173+
)

aiida_common_workflows/workflows/relax/quantum_espresso/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from aiida_common_workflows.common import ElectronicType, RelaxType, SpinType
88
from aiida_common_workflows.generators import ChoiceType, CodeType
99

10-
from ..generator import CommonRelaxInputGenerator
10+
from ..generator import CommonDftRelaxInputGenerator
1111

1212
__all__ = ('QuantumEspressoCommonRelaxInputGenerator',)
1313

@@ -62,7 +62,7 @@ def create_magnetic_allotrope(structure, magnetization_per_site):
6262
return (allotrope, allotrope_magnetic_moments)
6363

6464

65-
class QuantumEspressoCommonRelaxInputGenerator(CommonRelaxInputGenerator):
65+
class QuantumEspressoCommonRelaxInputGenerator(CommonDftRelaxInputGenerator):
6666
"""Input generator for the common relax workflow implementation of Quantum ESPRESSO."""
6767

6868
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)