Skip to content

Commit

Permalink
Update CdTe VASP file IO tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Oct 30, 2023
1 parent 6da3121 commit 103a00a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
46 changes: 25 additions & 21 deletions doped/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def __init__(
Creates attributes:
- `DefectRelaxSet.vasp_gam` -> `DefectDictSet` for Gamma-point only
relaxation. Not needed if ShakeNBreak structure searching has been
performed (recommended), unless only Γ-point _k_-point sampling is
relaxation. Usually not needed if ShakeNBreak structure searching has
been performed (recommended), unless only Γ-point _k_-point sampling is
required (converged) for your system, and no vasp_std calculations
with multiple _k_-points are required (determined from kpoints settings).
- `DefectRelaxSet.vasp_nkred_std` -> `DefectDictSet` for relaxation with a
Expand Down Expand Up @@ -538,11 +538,11 @@ def __init__(
Attributes:
vasp_gam (DefectDictSet):
DefectDictSet for Gamma-point only relaxation. Not needed if
ShakeNBreak structure searching has been performed (recommended),
unless only Γ-point _k_-point sampling is required (converged)
for your system, and no vasp_std calculations with multiple
_k_-points are required (determined from kpoints settings).
DefectDictSet for Gamma-point only relaxation. Usually not needed
if ShakeNBreak structure searching has been performed
(recommended), unless only Γ-point _k_-point sampling is required
(converged) for your system, and no vasp_std calculations with
multiple _k_-points are required (determined from kpoints settings).
vasp_nkred_std (DefectDictSet):
DefectDictSet for relaxation with a non-Γ-only kpoint mesh, using
`NKRED(X,Y,Z)` INCAR tag(s) to downsample kpoints for the HF exchange
Expand Down Expand Up @@ -1065,13 +1065,16 @@ def bulk_vasp_nkred_std(self) -> Optional[DefectDictSet]:
if nkred_defect_dict_set is None:
return None

user_incar_settings = copy.deepcopy(self.user_incar_settings)
if "KPAR" not in user_incar_settings:
user_incar_settings["KPAR"] = 2 # multiple k-points, likely quicker with this
user_incar_settings.update(singleshot_incar_settings)
user_incar_settings.update( # add NKRED settings
{k: v for k, v in nkred_defect_dict_set.incar.as_dict().items() if "NKRED" in k}
)
if nkred_defect_dict_set._check_user_potcars(unperturbed_poscar=True, snb=False):
user_incar_settings = copy.deepcopy(self.user_incar_settings)
if "KPAR" not in user_incar_settings:
user_incar_settings["KPAR"] = 2 # multiple k-points, likely quicker with this
user_incar_settings.update(singleshot_incar_settings)
user_incar_settings.update( # add NKRED settings
{k: v for k, v in nkred_defect_dict_set.incar.as_dict().items() if "NKRED" in k}
)
else:
user_incar_settings = {}

return DefectDictSet(
bulk_supercell,
Expand Down Expand Up @@ -1168,7 +1171,7 @@ def write_gam(
self,
defect_dir: Optional[str] = None,
subfolder: Optional[str] = "vasp_gam",
unperturbed_poscar: bool = True,
unperturbed_poscar: bool = False,
bulk: bool = False,
**kwargs,
):
Expand Down Expand Up @@ -1565,8 +1568,8 @@ def write_all(
If vasp_gam=True (not recommended) or self.vasp_std = None (i.e. Γ-only
_k_-point sampling converged for the kpoints settings used), then outputs:
- vasp_gam -> Γ-point only defect relaxation. Not needed if ShakeNBreak
structure searching has been performed (recommended).
- vasp_gam -> Γ-point only defect relaxation. Usually not needed if
ShakeNBreak structure searching has been performed (recommended).
By default, does not generate a `vasp_gam` folder unless `self.vasp_std`
is None (i.e. only Γ-point sampling required for this system), as
Expand Down Expand Up @@ -1681,6 +1684,7 @@ def write_all(
self.write_gam(
defect_dir=defect_dir,
bulk=any("vasp_gam" in vasp_type for vasp_type in bulk_vasp),
unperturbed_poscar=unperturbed_poscar,
**kwargs,
)

Expand Down Expand Up @@ -1727,8 +1731,8 @@ def __init__(
DefectRelaxSet has the attributes:
- `DefectRelaxSet.vasp_gam` -> `DefectDictSet` for Gamma-point only
relaxation. Not needed if ShakeNBreak structure searching has been
performed (recommended), unless only Γ-point _k_-point sampling is
relaxation. Usually not needed if ShakeNBreak structure searching has
been performed (recommended), unless only Γ-point _k_-point sampling is
required (converged) for your system, and no vasp_std calculations with
multiple _k_-points are required (determined from kpoints settings).
- `DefectRelaxSet.vasp_nkred_std` -> `DefectDictSet` for relaxation with a
Expand Down Expand Up @@ -1987,8 +1991,8 @@ def write_files(
If vasp_gam=True (not recommended) or self.vasp_std = None (i.e. Γ-only
_k_-point sampling converged for the kpoints settings used), then outputs:
- vasp_gam -> Γ-point only defect relaxation. Not needed if ShakeNBreak
structure searching has been performed (recommended).
- vasp_gam -> Γ-point only defect relaxation. Usually not needed if
ShakeNBreak structure searching has been performed (recommended).
By default, does not generate a `vasp_gam` folder unless
`DefectRelaxSet.vasp_std` is None (i.e. only Γ-point sampling required
Expand Down
22 changes: 15 additions & 7 deletions tests/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,12 @@ def test_cdte_files(self):
for folder in os.listdir("."):
if os.path.isdir(f"{folder}/vasp_std"):
assert filecmp.cmp(f"{folder}/vasp_nkred_std/KPOINTS", f"{folder}/vasp_std/KPOINTS")
# assert filecmp.cmp(f"{folder}/vasp_nkred_std/POTCAR", f"{folder}/vasp_std/POTCAR")
nkred_incar = Incar.from_file(f"{folder}/vasp_nkred_std/INCAR")
std_incar = Incar.from_file(f"{folder}/vasp_std/INCAR")
nkred_incar.pop("NKRED", None)
assert nkred_incar == std_incar
if _potcars_available():
assert filecmp.cmp(f"{folder}/vasp_nkred_std/POTCAR", f"{folder}/vasp_std/POTCAR")
nkred_incar = Incar.from_file(f"{folder}/vasp_nkred_std/INCAR")
std_incar = Incar.from_file(f"{folder}/vasp_std/INCAR")
nkred_incar.pop("NKRED", None)
assert nkred_incar == std_incar

print("Checking vasp_ncl files")
self.check_generated_vasp_inputs(vasp_type="vasp_ncl", check_poscar=False, bulk=True) # vasp_ncl
Expand Down Expand Up @@ -1032,9 +1033,16 @@ def test_cdte_files(self):
{k: v for k, v in self.cdte_defect_gen.items() if "v_Te" in k},
user_potcar_settings={"Cd": "Cd_sv_GW", "Te": "Te_GW"},
user_kpoints_settings={"reciprocal_density": 500},
user_potcar_functional=None, # TODO: don't think we need this now?
)
defects_set.write_files(potcar_spec=True, vasp_gam=True) # include vasp_gam to compare POTCAR.spec

if _potcars_available():
defects_set.write_files(potcar_spec=True, vasp_gam=True) # vasp_gam to test POTCAR.spec
else:
with self.assertRaises(ValueError):
defects_set.write_files(potcar_spec=True, vasp_gam=True) # INCAR ValueError for charged
# defects if POTCARs not available and unperturbed_poscar=False
defects_set.write_files(potcar_spec=True, vasp_gam=True, unperturbed_poscar=True)

for folder in os.listdir("."):
if os.path.isdir(f"{folder}/vasp_gam"):
with open(f"{folder}/vasp_gam/POTCAR.spec", encoding="utf-8") as file:
Expand Down

0 comments on commit 103a00a

Please sign in to comment.