-
Notifications
You must be signed in to change notification settings - Fork 41
/
mp.py
392 lines (334 loc) · 12.2 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
"""
Materials Project-compatible recipes.
!!! Important
Make sure that you use the Materials Project-compatible pseudpotential
versions. The GGA workflows use the old (no version) PAW PBE potentials.
The meta-GGA workflows currently use the v.54 PAW PBE potentials.
"""
from __future__ import annotations
from importlib.util import find_spec
from typing import TYPE_CHECKING
from monty.dev import requires
from quacc import change_settings, flow, job
from quacc.calculators.vasp.params import MPtoASEConverter
from quacc.recipes.vasp._base import run_and_summarize
from quacc.wflow_tools.customizers import customize_funcs
has_atomate2 = bool(find_spec("atomate2"))
if has_atomate2:
from atomate2.vasp.jobs.mp import (
MPGGARelaxMaker,
MPGGAStaticMaker,
MPMetaGGARelaxMaker,
MPMetaGGAStaticMaker,
MPPreRelaxMaker,
)
if TYPE_CHECKING:
from typing import Any, Callable
from ase.atoms import Atoms
from quacc.schemas._aliases.vasp import (
MPGGARelaxFlowSchema,
MPMetaGGARelaxFlowSchema,
VaspSchema,
)
from quacc.utils.files import SourceDirectory
_MP_SETTINGS = {"VASP_INCAR_COPILOT": "off", "VASP_USE_CUSTODIAN": True}
@job
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_gga_relax_job(
atoms: Atoms, prev_dir: SourceDirectory | None = None, **calc_kwargs
) -> VaspSchema:
"""
Function to relax a structure with the original Materials Project GGA(+U) settings.
Parameters
----------
atoms
Atoms object
prev_dir
A previous directory for a prior step in the workflow.
**calc_kwargs
Custom kwargs for the Vasp calculator. Set a value to
`None` to remove a pre-existing key entirely. For a list of available
keys, refer to [quacc.calculators.vasp.vasp.Vasp][].
Returns
-------
VaspSchema
Dictionary of results.
"""
calc_defaults = MPtoASEConverter(atoms=atoms, prev_dir=prev_dir).convert_vasp_maker(
MPGGARelaxMaker
)
with change_settings(_MP_SETTINGS):
return run_and_summarize(
atoms,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
report_mp_corrections=True,
additional_fields={"name": "MP GGA Relax"},
copy_files={prev_dir: ["CHGCAR*", "WAVECAR*"]},
)
@job
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_gga_static_job(
atoms: Atoms, prev_dir: SourceDirectory | None = None, **calc_kwargs
) -> VaspSchema:
"""
Function to run a static calculation on a structure with the original Materials Project GGA(+U) settings.
Parameters
----------
atoms
Atoms object
prev_dir
A previous directory for a prior step in the workflow.
**calc_kwargs
Custom kwargs for the Vasp calculator. Set a value to
`None` to remove a pre-existing key entirely. For a list of available
keys, refer to [quacc.calculators.vasp.vasp.Vasp][].
Returns
-------
VaspSchema
Dictionary of results from [quacc.schemas.vasp.vasp_summarize_run][].
"""
calc_defaults = MPtoASEConverter(atoms=atoms, prev_dir=prev_dir).convert_vasp_maker(
MPGGAStaticMaker
)
with change_settings(_MP_SETTINGS):
return run_and_summarize(
atoms,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
report_mp_corrections=True,
additional_fields={"name": "MP GGA Static"},
copy_files={prev_dir: ["CHGCAR*", "WAVECAR*"]},
)
@job
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_metagga_prerelax_job(
atoms: Atoms, prev_dir: SourceDirectory | None = None, **calc_kwargs
) -> VaspSchema:
"""
Function to pre-relax a structure with Materials Project r2SCAN workflow settings. By default, this
uses a PBEsol pre-relax step.
Reference: https://doi.org/10.1103/PhysRevMaterials.6.013801
Parameters
----------
atoms
Atoms object
prev_dir
A previous directory for a prior step in the workflow.
**calc_kwargs
Custom kwargs for the Vasp calculator. Set a value to
`None` to remove a pre-existing key entirely. For a list of available
keys, refer to [quacc.calculators.vasp.vasp.Vasp][].
Returns
-------
VaspSchema
Dictionary of results from [quacc.schemas.vasp.vasp_summarize_run][].
See the type-hint for the data structure.
"""
calc_defaults = MPtoASEConverter(atoms=atoms, prev_dir=prev_dir).convert_vasp_maker(
MPPreRelaxMaker
)
with change_settings(_MP_SETTINGS):
return run_and_summarize(
atoms,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
report_mp_corrections=True,
additional_fields={"name": "MP Meta-GGA Pre-Relax"},
copy_files={prev_dir: ["CHGCAR*", "WAVECAR*"]},
)
@job
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_metagga_relax_job(
atoms: Atoms, prev_dir: SourceDirectory | None = None, **calc_kwargs
) -> VaspSchema:
"""
Function to relax a structure with Materials Project r2SCAN workflow settings. By default, this uses
an r2SCAN relax step.
Reference: https://doi.org/10.1103/PhysRevMaterials.6.013801
Parameters
----------
atoms
Atoms object
prev_dir
A previous directory for a prior step in the workflow.
**calc_kwargs
Dictionary of custom kwargs for the Vasp calculator. Set a value to
`None` to remove a pre-existing key entirely. For a list of available
keys, refer to [quacc.calculators.vasp.vasp.Vasp][].
Returns
-------
VaspSchema
Dictionary of results.
"""
calc_defaults = MPtoASEConverter(atoms=atoms, prev_dir=prev_dir).convert_vasp_maker(
MPMetaGGARelaxMaker
)
with change_settings(_MP_SETTINGS):
return run_and_summarize(
atoms,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
report_mp_corrections=True,
additional_fields={"name": "MP Meta-GGA Relax"},
copy_files={prev_dir: ["CHGCAR*", "WAVECAR*"]},
)
@job
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_metagga_static_job(
atoms: Atoms, prev_dir: SourceDirectory | None = None, **calc_kwargs
) -> VaspSchema:
"""
Function to run a static calculation on a structure with r2SCAN workflow Materials Project settings.
By default, this uses an r2SCAN static step.
Parameters
----------
atoms
Atoms object
prev_dir
A previous directory for a prior step in the workflow.
**calc_kwargs
Dictionary of custom kwargs for the Vasp calculator. Set a value to
`None` to remove a pre-existing key entirely. For a list of available
keys, refer to `ase.calculators.vasp.vasp.Vasp`.
Returns
-------
VaspSchema
Dictionary of results from [quacc.schemas.vasp.vasp_summarize_run][].
See the type-hint for the data structure.
"""
calc_defaults = MPtoASEConverter(atoms=atoms, prev_dir=prev_dir).convert_vasp_maker(
MPMetaGGAStaticMaker
)
with change_settings(_MP_SETTINGS):
return run_and_summarize(
atoms,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
report_mp_corrections=True,
additional_fields={"name": "MP Meta-GGA Static"},
copy_files={prev_dir: ["CHGCAR*", "WAVECAR*"]},
)
@flow
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_gga_relax_flow(
atoms: Atoms,
job_params: dict[str, dict[str, Any]] | None = None,
job_decorators: dict[str, Callable | None] | None = None,
) -> MPGGARelaxFlowSchema:
"""
Materials Project GGA workflow consisting of:
1. MP-compatible relax
- name: "mp_gga_relax_job"
- job: [quacc.recipes.vasp.mp.mp_gga_relax_job][]
2. MP-compatible (second) relax
- name: "mp_gga_relax_job"
- job: [quacc.recipes.vasp.mp.mp_gga_relax_job][]
3. MP-compatible static
- name: "mp_gga_static_job"
- job: [quacc.recipes.vasp.mp.mp_gga_static_job][]
Parameters
----------
atoms
Atoms object for the structure.
job_params
Custom parameters to pass to each Job in the Flow. This is a dictinoary where
the keys are the names of the jobs and the values are dictionaries of parameters.
job_decorators
Custom decorators to apply to each Job in the Flow. This is a dictionary where
the keys are the names of the jobs and the values are decorators.
Returns
-------
MPGGARelaxFlowSchema
Dictionary of results. See the type-hint for the data structure.
"""
(mp_gga_relax_job_, mp_gga_static_job_) = customize_funcs(
["mp_gga_relax_job", "mp_gga_static_job"],
[mp_gga_relax_job, mp_gga_static_job],
param_swaps=job_params,
decorators=job_decorators,
)
# Run the relax
relax_results = mp_gga_relax_job_(atoms)
# Run the second relax
double_relax_results = mp_gga_relax_job_(
relax_results["atoms"], prev_dir=relax_results["dir_name"]
)
# Run the static
static_results = mp_gga_static_job_(
double_relax_results["atoms"], prev_dir=double_relax_results["dir_name"]
)
return {
"relax1": relax_results,
"relax2": double_relax_results,
"static": static_results,
}
@flow
@requires(has_atomate2, "atomate2 is not installed. Run `pip install quacc[mp]`")
def mp_metagga_relax_flow(
atoms: Atoms,
job_params: dict[str, dict[str, Any]] | None = None,
job_decorators: dict[str, Callable | None] | None = None,
) -> MPMetaGGARelaxFlowSchema:
"""
Materials Project r2SCAN workflow consisting of:
1. MP-compatible pre-relax
- name: "mp_metagga_prerelax_job"
- job: [quacc.recipes.vasp.mp.mp_metagga_prerelax_job][]
2. MP-compatible relax
- name: "mp_metagga_relax_job"
- job: [quacc.recipes.vasp.mp.mp_metagga_relax_job][]
3. MP-compatible (second) relax
- name: "mp_metagga_relax_job"
- job: [quacc.recipes.vasp.mp.mp_metagga_relax_job][]
4. MP-compatible static
- name: "mp_metagga_static_job"
- job: [quacc.recipes.vasp.mp.mp_metagga_static_job][]
Reference: https://doi.org/10.1103/PhysRevMaterials.6.013801
Parameters
----------
atoms
Atoms object for the structure.
job_params
Custom parameters to pass to each Job in the Flow. This is a dictinoary where
the keys are the names of the jobs and the values are dictionaries of parameters.
job_decorators
Custom decorators to apply to each Job in the Flow. This is a dictionary where
the keys are the names of the jobs and the values are decorators.
Returns
-------
MPMetaGGARelaxFlowSchema
Dictionary of results. See the type-hint for the data structure.
"""
(mp_metagga_prerelax_job_, mp_metagga_relax_job_, mp_metagga_static_job_) = (
customize_funcs(
[
"mp_metagga_prerelax_job",
"mp_metagga_relax_job",
"mp_metagga_static_job",
],
[mp_metagga_prerelax_job, mp_metagga_relax_job, mp_metagga_static_job],
param_swaps=job_params,
decorators=job_decorators,
)
)
# Run the prerelax
prerelax_results = mp_metagga_prerelax_job_(atoms)
# Run the relax
relax_results = mp_metagga_relax_job_(
prerelax_results["atoms"], prev_dir=prerelax_results["dir_name"]
)
# Run the second relax
double_relax_results = mp_metagga_relax_job_(
relax_results["atoms"], prev_dir=relax_results["dir_name"]
)
# Run the static
static_results = mp_metagga_static_job_(
double_relax_results["atoms"], prev_dir=double_relax_results["dir_name"]
)
return {
"prerelax": prerelax_results,
"relax1": relax_results,
"relax2": double_relax_results,
"static": static_results,
}