Skip to content

Commit

Permalink
improve den-/tet error handling in case of not using kspacing
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 10, 2023
1 parent c11ab49 commit 283fe9d
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import datetime
import logging
import multiprocessing
import operator
import os
import re
import shutil
import time
import warnings
from collections import Counter
from functools import reduce
from math import prod

import numpy as np
from monty.os.path import zpath
Expand Down Expand Up @@ -178,16 +177,27 @@ def correct(self):
vi = VaspInput.from_directory(".")

if self.errors.intersection(["tet", "dentet"]):
if vi["INCAR"].get("KSPACING"):
# decrease KSPACING by 20% in each direction (approximately double no. of kpoints)
actions.append(
{
"dict": "INCAR",
"action": {"_set": {"KSPACING": vi["INCAR"].get("KSPACING") * 0.8}},
}
)
# follow advice in this thread
# https://vasp.at/forum/viewtopic.php?f=3&t=416&p=4047&hilit=dentet#p4047
err_type = "tet" if "tet" in self.errors else "dentet"
if self.error_count[err_type] == 0:
if vi["INCAR"].get("KSPACING"):
# decrease KSPACING by 20% in each direction (approximately double no. of kpoints)
action = {"_set": {"KSPACING": vi["INCAR"].get("KSPACING") * 0.8}}
actions.append({"dict": "INCAR", "action": action})
elif vi["KPOINTS"] and vi["KPOINTS"].num_kpts < 1:
# increase KPOINTS by 20% in each direction (approximately double no. of kpoints)
new_kpts = tuple(int(round(num * 1.2, 0)) for num in vi["KPOINTS"].kpts)
actions.append({"dict": "KPOINTS", "action": {"_set": {"kpoints": (new_kpts,)}}})
elif vi["KPOINTS"] and vi["KPOINTS"].num_kpts >= 1:
n_kpts = vi["KPOINTS"].num_kpts * 1.2
new_kpts = tuple([int(round(n_kpts**1 / 3, 0))] * 3)
actions.append(
{"dict": "KPOINTS", "action": {"_set": {"generation_style": "Gamma", "kpoints": (new_kpts,)}}}
)
else:
actions.append({"dict": "INCAR", "action": {"_set": {"ISMEAR": 0, "SIGMA": 0.05}}})
self.error_count[err_type] += 1

if "inv_rot_mat" in self.errors and vi["INCAR"].get("SYMPREC", 1e-5) > 1e-8:
actions.append({"dict": "INCAR", "action": {"_set": {"SYMPREC": 1e-8}}})
Expand Down Expand Up @@ -342,12 +352,8 @@ def correct(self):

if "rot_matrix" in self.errors:
if vi["KPOINTS"] and vi["KPOINTS"].style == Kpoints.supported_modes.Monkhorst:
actions.append(
{
"dict": "KPOINTS",
"action": {"_set": {"generation_style": "Gamma"}},
}
)
action = {"_set": {"generation_style": "Gamma"}}
actions.append({"dict": "KPOINTS", "action": action})
elif vi["INCAR"].get("ISYM", 2) > 0:
actions.append({"dict": "INCAR", "action": {"_set": {"ISYM": 0}}})

Expand Down Expand Up @@ -478,6 +484,7 @@ def correct(self):
if vi["INCAR"].get("ICHARG", 0) < 10:
actions.append({"file": "CHGCAR", "action": {"_file_delete": {"mode": "actual"}}})
actions.append({"file": "WAVECAR", "action": {"_file_delete": {"mode": "actual"}}})
self.error_count["eddrmm"] += 1

if "edddav" in self.errors:
# Copy CONTCAR to POSCAR if CONTCAR has already been populated.
Expand Down Expand Up @@ -754,7 +761,7 @@ def correct(self):
vi = VaspInput.from_directory(".")

if "kpoints_trans" in self.errors and self.error_count["kpoints_trans"] == 0:
m = reduce(operator.mul, vi["KPOINTS"].kpts[0])
m = prod(vi["KPOINTS"].kpts[0])
m = max(int(round(m ** (1 / 3))), 1)
if vi["KPOINTS"] and vi["KPOINTS"].style.name.lower().startswith("m"):
m += m % 2
Expand Down Expand Up @@ -1008,7 +1015,7 @@ def correct(self):
"""Perform corrections."""
backup(VASP_BACKUP_FILES | {self.output_filename})
vi = VaspInput.from_directory(".")
m = reduce(operator.mul, vi["KPOINTS"].kpts[0])
m = prod(vi["KPOINTS"].kpts[0])
m = max(int(round(m ** (1 / 3))), 1)
if vi["KPOINTS"] and vi["KPOINTS"].style.name.lower().startswith("m"):
m += m % 2
Expand Down

0 comments on commit 283fe9d

Please sign in to comment.