Skip to content

Commit

Permalink
Add a update_incar option for VaspJob. Allows for updating of incar
Browse files Browse the repository at this point in the history
parameters from previous vasprun.xml.
  • Loading branch information
shyuep committed Oct 16, 2024
1 parent 649c402 commit c4357d3
Show file tree
Hide file tree
Showing 4 changed files with 682,714 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/custodian/vasp/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
gamma_vasp_cmd=None,
copy_magmom=False,
auto_continue=False,
update_incar=False,
) -> None:
"""
This constructor is necessarily complex due to the need for
Expand Down Expand Up @@ -136,6 +137,12 @@ def __init__(
if a STOPCAR is present. This is very useful if using the
wall-time handler which will write a read-only STOPCAR to
prevent VASP from deleting it once it finishes
update_incar (bool): Whether to update INCAR settings from updated settings
in vasprun.xml. This is particularly useful in certain calculatons where VASP
automatically sets certain parameters, e.g., NBANDS. Only parameters that are
already present in the INCAR will be updated, i.e., no new parameters will be
added even if they are in the final vasprun.xml. Note that settings_override take
precedence over updated params.
"""
self.vasp_cmd = tuple(vasp_cmd)
self.output_file = output_file
Expand All @@ -149,6 +156,7 @@ def __init__(
self.gamma_vasp_cmd = tuple(gamma_vasp_cmd) if gamma_vasp_cmd else None
self.copy_magmom = copy_magmom
self.auto_continue = auto_continue
self.update_incar = update_incar

if SENTRY_DSN:
# if using Sentry logging, add specific VASP executable to scope
Expand Down Expand Up @@ -228,6 +236,17 @@ def setup(self, directory="./") -> None:
actions = self.auto_continue
dumpfn({"actions": actions}, os.path.join(directory, "continue.json"))

if self.update_incar:
try:
vasprun = Vasprun(os.path.join(directory, "vasprun.xml"))
params = vasprun.parameters
incar = Incar.from_file(os.path.join(directory, "INCAR"))
for k, v in incar.items():
incar[k] = params.get(k, v)
incar.write_file(os.path.join(directory, "INCAR"))
except Exception as ex:
logger.error(f"Unable to update INCAR with params from vasprun.xml. {ex}")

if self.settings_override is not None:
VaspModder(directory=directory).apply_actions(self.settings_override)

Expand Down
21 changes: 21 additions & 0 deletions tests/files/update_incar/INCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ALGO = Exact
CSHIFT = 0.1
EDIFF = 1e-08
EDIFFG = -0.05
ENCUT = 520
IBRION = -1
ISIF = 3
ISMEAR = -5
ISPIN = 2
LASPH = True
LOPTICS = True
LORBIT = 11
LREAL = Auto
LWAVE = True
MAGMOM = 9*0.6
NBANDS = 200
NEDOS = 8000
NELM = 100
NSW = 0
PREC = Accurate
SIGMA = 0.05
Loading

0 comments on commit c4357d3

Please sign in to comment.