Skip to content

Commit

Permalink
Minor test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Apr 5, 2024
1 parent eeb390e commit a68ecfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions doped/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def __init__(
"""
_ignore_pmg_warnings()
self.charge_state = charge_state
self.potcars = self._check_user_potcars(unperturbed_poscar=True, snb=False)
self.poscar_comment = (
poscar_comment
or f"{structure.formula} {'+' if self.charge_state > 0 else ''}{self.charge_state}"
Expand Down Expand Up @@ -520,10 +519,8 @@ def write_input(
if potcar_spec:
potcars = True

elif not unperturbed_poscar and snb: # otherwise already called with these settings
potcars = self._check_user_potcars(unperturbed_poscar=unperturbed_poscar, snb=snb)
else:
potcars = self.potcars
potcars = self._check_user_potcars(unperturbed_poscar=unperturbed_poscar, snb=snb)

if unperturbed_poscar and potcars: # write everything, use DictSet.write_input()
try:
Expand All @@ -535,12 +532,14 @@ def write_input(
zip_output=zip_output,
)
except ValueError as e:
if str(e).startswith("NELECT") and potcar_spec:
with zopen(os.path.join(output_path, "POTCAR.spec"), "wt") as pot_spec_file:
pot_spec_file.write("\n".join(self.potcar_symbols))
if not str(e).startswith("NELECT") or not potcar_spec:
raise e

with zopen(os.path.join(output_path, "POTCAR.spec"), "wt") as pot_spec_file:
pot_spec_file.write("\n".join(self.potcar_symbols))

self.kpoints.write_file(f"{output_path}/KPOINTS")
self.poscar.write_file(f"{output_path}/POSCAR")
self.kpoints.write_file(f"{output_path}/KPOINTS")
self.poscar.write_file(f"{output_path}/POSCAR")

else: # use `write_file()`s rather than `write_input()` to avoid writing POSCARs/POTCARs
os.makedirs(output_path, exist_ok=True)
Expand Down Expand Up @@ -1185,7 +1184,7 @@ def bulk_vasp_nkred_std(self) -> Optional[DefectDictSet]:
if nkred_defect_dict_set is None:
return None

if nkred_defect_dict_set.potcars:
if any("VASP_PSP_DIR" in i for i in SETTINGS): # POTCARs available
user_incar_settings = copy.deepcopy(self.user_incar_settings)
user_incar_settings.update(singleshot_incar_settings)
user_incar_settings.update( # add NKRED settings
Expand Down
10 changes: 5 additions & 5 deletions tests/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def _general_defect_dict_set_check(self, dds, struct, incar_check=True, **dds_kw
potcar_settings[el_symbol] for el_symbol in dds.structure.symbol_set
}
else:
assert not dds.potcars
with pytest.raises(ValueError) as e:
_test_pop = dds.potcar
assert _check_no_potcar_available_warning_error(dds.potcar_symbols[0], e.value)
Expand Down Expand Up @@ -192,6 +191,7 @@ def _general_defect_dict_set_check(self, dds, struct, incar_check=True, **dds_kw
)

def _check_potcar_nupdown_dds_warnings(self, w, dds):
print("Testing:", [str(warning.message) for warning in w]) # for debugging
assert any(_check_potcar_dir_not_setup_warning_error(dds, warning.message) for warning in w)
assert any(_check_nupdown_neutral_cell_warning(warning.message) for warning in w)
assert any(
Expand Down Expand Up @@ -289,7 +289,9 @@ def _check_dds(self, dds, struct, **kwargs):
)

def _generate_and_check_dds(self, struct, incar_check=True, **dds_kwargs):
dds = DefectDictSet(struct, **dds_kwargs) # fine for bulk prim input as well
with warnings.catch_warnings(record=True) as w:
dds = DefectDictSet(struct, **dds_kwargs) # fine for bulk prim input as well
print([str(warning.message) for warning in w]) # for debugging
self._check_dds(dds, struct, incar_check=incar_check, **dds_kwargs)
return dds

Expand All @@ -301,8 +303,6 @@ def kpts_nelect_nupdown_check(self, dds, kpt, nelect, nupdown):
if _potcars_available():
assert dds.incar["NELECT"] == nelect
assert dds.incar["NUPDOWN"] == nupdown
else:
assert not dds.potcars

def test_neutral_defect_dict_set(self):
dds = self._generate_and_check_dds(self.prim_cdte.copy()) # fine for bulk prim input as well
Expand Down Expand Up @@ -593,7 +593,7 @@ def tearDown(self):
if_present_rm("CdTe_bulk")

for i in os.listdir():
if os.path.isdir(i) and any(j in i for j in ["Mg_", "O_", "v_", "MgO"]):
if os.path.isdir(i) and ("MgO" in i or any("vasp" in j for j in os.listdir(i))):
if_present_rm(i)

if_present_rm("MgO_defects_generator.json")
Expand Down

0 comments on commit a68ecfa

Please sign in to comment.