-
Notifications
You must be signed in to change notification settings - Fork 80
/
mp.py
188 lines (158 loc) · 5.01 KB
/
mp.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
"""
Module defining Materials Project input set generators.
Reference: https://doi.org/10.1103/PhysRevMaterials.6.013801
In case of questions, consult @Andrew-S-Rosen, @esoteric-ephemera or @janosh.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from importlib.resources import files as get_mod_path
from typing import TYPE_CHECKING
from monty.serialization import loadfn
from atomate2.vasp.sets.core import RelaxSetGenerator, StaticSetGenerator
if TYPE_CHECKING:
from pymatgen.core import Structure
from pymatgen.io.vasp import Outcar, Vasprun
_BASE_MP_GGA_RELAX_SET = loadfn(
get_mod_path("atomate2.vasp.sets") / "BaseMPGGASet.yaml"
)
_BASE_MP_R2SCAN_RELAX_SET = loadfn(
get_mod_path("atomate2.vasp.sets") / "BaseMPR2SCANRelaxSet.yaml"
)
@dataclass
class MPGGARelaxSetGenerator(RelaxSetGenerator):
"""Class to generate MP-compatible VASP GGA relaxation input sets."""
config_dict: dict = field(default_factory=lambda: _BASE_MP_GGA_RELAX_SET)
auto_ismear: bool = False
auto_kspacing: bool = True
inherit_incar: bool | None = False
@dataclass
class MPGGAStaticSetGenerator(StaticSetGenerator):
"""Class to generate MP-compatible VASP GGA static input sets."""
config_dict: dict = field(default_factory=lambda: _BASE_MP_GGA_RELAX_SET)
auto_ismear: bool = False
auto_kspacing: bool = True
inherit_incar: bool | None = False
def get_incar_updates(
self,
structure: Structure,
prev_incar: dict = None,
bandgap: float = None,
vasprun: Vasprun = None,
outcar: Outcar = None,
) -> dict:
"""
Get updates to the INCAR for this calculation type.
Parameters
----------
structure
A structure.
prev_incar
An incar from a previous calculation.
bandgap
The band gap.
vasprun
A vasprun from a previous calculation.
outcar
An outcar from a previous calculation.
Returns
-------
dict
A dictionary of updates to apply.
"""
return {
"ALGO": "FAST",
"NSW": 0,
"LCHARG": True,
"LWAVE": False,
"LREAL": False,
"ISMEAR": -5,
}
@dataclass
class MPMetaGGAStaticSetGenerator(StaticSetGenerator):
"""Class to generate MP-compatible VASP GGA static input sets."""
config_dict: dict = field(default_factory=lambda: _BASE_MP_R2SCAN_RELAX_SET)
auto_ismear: bool = False
auto_kspacing: bool = True
bandgap_tol: float = 1e-4
inherit_incar: bool | None = False
def get_incar_updates(
self,
structure: Structure,
prev_incar: dict = None,
bandgap: float = None,
vasprun: Vasprun = None,
outcar: Outcar = None,
) -> dict:
"""
Get updates to the INCAR for this calculation type.
Parameters
----------
structure
A structure.
prev_incar
An incar from a previous calculation.
bandgap
The band gap.
vasprun
A vasprun from a previous calculation.
outcar
An outcar from a previous calculation.
Returns
-------
dict
A dictionary of updates to apply.
"""
return {
"ALGO": "FAST",
"GGA": None, # unset GGA, shouldn't be set anyway but best be sure
"NSW": 0,
"LCHARG": True,
"LWAVE": False,
"LREAL": False,
"ISMEAR": -5,
}
@dataclass
class MPMetaGGARelaxSetGenerator(RelaxSetGenerator):
"""Class to generate MP-compatible VASP metaGGA relaxation input sets.
Parameters
----------
config_dict: dict
The config dict.
bandgap_tol: float
Tolerance for metallic bandgap. If bandgap < bandgap_tol, KSPACING will be 0.22,
otherwise it will increase with bandgap up to a max of 0.44.
"""
config_dict: dict = field(default_factory=lambda: _BASE_MP_R2SCAN_RELAX_SET)
bandgap_tol: float = 1e-4
auto_ismear: bool = False
auto_kspacing: bool = True
inherit_incar: bool | None = False
def get_incar_updates(
self,
structure: Structure,
prev_incar: dict = None,
bandgap: float = None,
vasprun: Vasprun = None,
outcar: Outcar = None,
) -> dict:
"""
Get updates to the INCAR for this calculation type.
Parameters
----------
structure
A structure.
prev_incar
An incar from a previous calculation.
bandgap
The band gap.
vasprun
A vasprun from a previous calculation.
outcar
An outcar from a previous calculation.
Returns
-------
dict
A dictionary of updates to apply.
"""
# unset GGA, shouldn't be set anyway but doesn't hurt to be sure
return {"LCHARG": True, "LWAVE": True, "GGA": None}