Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Sep 8, 2023
1 parent b9329db commit 9ed5d1c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
90 changes: 58 additions & 32 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

file_path = os.path.dirname(__file__)


def _potcars_available() -> bool:
"""
Check if the POTCARs are available for the tests (i.e. testing locally).
Expand All @@ -41,6 +42,7 @@ def _potcars_available() -> bool:
except ValueError:
return False


def if_present_rm(path):
if os.path.exists(path):
if os.path.isfile(path):
Expand Down Expand Up @@ -286,7 +288,9 @@ def test_snb_generate(self):
# check if correct files were created:
V_Cd_Bond_Distortion_folder = f"{defect_name}_0/Bond_Distortion_-50.0%"
self.assertTrue(os.path.exists(V_Cd_Bond_Distortion_folder))
V_Cd_minus0pt5_rattled_POSCAR = Poscar.from_file(f"{V_Cd_Bond_Distortion_folder}/POSCAR")
V_Cd_minus0pt5_rattled_POSCAR = Poscar.from_file(
f"{V_Cd_Bond_Distortion_folder}/POSCAR"
)
self.assertEqual(
V_Cd_minus0pt5_rattled_POSCAR.comment,
"-50.0% N(Distort)=2 ~[0.0,0.0,0.0]",
Expand All @@ -300,7 +304,9 @@ def test_snb_generate(self):
self.assertEqual(kpoints.kpts, [[1, 1, 1]])

if _potcars_available():
assert filecmp.cmp(f"{V_Cd_Bond_Distortion_folder}/INCAR", self.V_Cd_INCAR_file)
assert filecmp.cmp(
f"{V_Cd_Bond_Distortion_folder}/INCAR", self.V_Cd_INCAR_file
)

# check if POTCARs have been written:
potcar = Potcar.from_file(f"{V_Cd_Bond_Distortion_folder}/POTCAR")
Expand Down Expand Up @@ -899,13 +905,14 @@ def test_snb_generate_config(self):
self.assertEqual(kpoints.kpts, [[1, 1, 1]])

if _potcars_available():
assert filecmp.cmp(f"{defect_name}_0/Bond_Distortion_-50.0%/INCAR", self.V_Cd_INCAR_file)
assert filecmp.cmp(
f"{defect_name}_0/Bond_Distortion_-50.0%/INCAR", self.V_Cd_INCAR_file
)

# check if POTCARs have been written:
potcar = Potcar.from_file(f"{defect_name}_0/Bond_Distortion_-50.0%/POTCAR")
assert set(potcar.as_dict()["symbols"]) == {"Cd", "Te_GW"}


test_yml = """
oxidation_states:
Cd: 3
Expand Down Expand Up @@ -1325,7 +1332,11 @@ def test_snb_generate_all(self):
1,
] + list(range(-1, 2)):
for dist in ["Unperturbed", "Bond_Distortion_30.0%"]:
self.assertTrue(os.path.exists(f"{defect_name}_{'+' if charge > 0 else ''}{charge}/{dist}/POSCAR"))
self.assertTrue(
os.path.exists(
f"{defect_name}_{'+' if charge > 0 else ''}{charge}/{dist}/POSCAR"
)
)
for dist in ["Unperturbed", "Rattled"]:
# -2 has 0 electron change -> only Unperturbed & rattled folders
self.assertTrue(os.path.exists(f"{defect_name}_-2/{dist}/POSCAR"))
Expand All @@ -1338,7 +1349,9 @@ def test_snb_generate_all(self):
self.assertEqual(kpoints.kpts, [[1, 1, 1]])

if _potcars_available():
assert not filecmp.cmp(f"{defect_name}_0/Bond_Distortion_30.0%/INCAR", self.V_Cd_INCAR_file)
assert not filecmp.cmp(
f"{defect_name}_0/Bond_Distortion_30.0%/INCAR", self.V_Cd_INCAR_file
)
# NELECT has changed due to POTCARs

v_Cd_INCAR = Incar.from_file(f"{defect_name}_0/Bond_Distortion_30.0%/INCAR")
Expand Down Expand Up @@ -2067,11 +2080,11 @@ def _test_OUTCAR_error(error_string):
self.assertNotIn("Unperturbed fully relaxed", out)
self.assertIn(
"Previous run for Unperturbed did not yield more than one ionic step, and multiple OUTCARs with <=1 ionic",
out
out,
)
self.assertIn(
"steps present, suggesting poor convergence. Recommended to manually check the VASP output files for this!",
out
out,
)
self.assertIn("Running job for Unperturbed", out)
self.assertIn("this vac_1_Ti_0_10.0% job_file", out) # job submit command
Expand Down Expand Up @@ -2168,7 +2181,10 @@ def _test_OUTCAR_error(error_string):

# test changing no message with poor electronic convergence when ALGO already = All
with open("Bond_Distortion_10.0%/OUTCAR", "w") as fp:
fp.write(poor_electronic_convergence_outcar_string + "\nIALGO = 58 # i.e. ALGO = All")
fp.write(
poor_electronic_convergence_outcar_string
+ "\nIALGO = 58 # i.e. ALGO = All"
)

proc = subprocess.Popen(
["snb-run", "-v", "-s echo", "-n this", "-j job_file"],
Expand Down Expand Up @@ -2505,9 +2521,9 @@ def test_parse(self):
self.assertTrue(any([warning.category == UserWarning for warning in w]))
self.assertTrue(
any(
str(warning.message)
== "Defect folder 'defect' not found in '.'. Please check these folders and paths."
for warning in w
str(warning.message)
== "Defect folder 'defect' not found in '.'. Please check these folders and paths."
for warning in w
)
)
self.assertFalse(
Expand Down Expand Up @@ -3309,14 +3325,10 @@ def test_plot(self):
)
)
self.assertTrue(
os.path.exists(
os.path.join(self.EXAMPLE_RESULTS, "v_Cd_0/v_Cd_0.png")
)
os.path.exists(os.path.join(self.EXAMPLE_RESULTS, "v_Cd_0/v_Cd_0.png"))
)
self.assertTrue(
os.path.exists(
os.path.join(self.EXAMPLE_RESULTS, "v_Cd_-1/v_Cd_-1.png")
)
os.path.exists(os.path.join(self.EXAMPLE_RESULTS, "v_Cd_-1/v_Cd_-1.png"))
)
if w:
[
Expand Down Expand Up @@ -3512,14 +3524,10 @@ def test_plot(self):
os.path.exists(os.path.join(self.EXAMPLE_RESULTS, f"{defect}/{defect}.png"))
)
self.assertFalse( # energy diff of 0.75 eV less than min_energy
os.path.exists(
os.path.join(self.EXAMPLE_RESULTS, "v_Cd_0/v_Cd_0.png")
)
os.path.exists(os.path.join(self.EXAMPLE_RESULTS, "v_Cd_0/v_Cd_0.png"))
)
self.assertFalse( # energy diff of 0.9 eV less than min_energy
os.path.exists(
os.path.join(self.EXAMPLE_RESULTS, "v_Cd_-s0_1/v_Cd_-1.png")
)
os.path.exists(os.path.join(self.EXAMPLE_RESULTS, "v_Cd_-s0_1/v_Cd_-1.png"))
)
[
os.remove(os.path.join(self.EXAMPLE_RESULTS, defect, file))
Expand All @@ -3542,9 +3550,18 @@ def test_regenerate(self):
catch_exceptions=False,
)
defect = "v_Cd" # in example results
non_ignored_warnings = [warning for warning in w if "Subfolders with" not in str(warning.message)]
non_ignored_warnings = [
warning for warning in w if "Subfolders with" not in str(warning.message)
]
self.assertEqual(
len([warning for warning in non_ignored_warnings if warning.category == UserWarning]), 0
len(
[
warning
for warning in non_ignored_warnings
if warning.category == UserWarning
]
),
0,
)

self.assertIn(
Expand Down Expand Up @@ -3626,9 +3643,18 @@ def test_regenerate(self):
],
catch_exceptions=False,
)
non_ignored_warnings = [warning for warning in w if "Subfolders with" not in str(warning.message)]
non_ignored_warnings = [
warning for warning in w if "Subfolders with" not in str(warning.message)
]
self.assertEqual(
len([warning for warning in non_ignored_warnings if warning.category == UserWarning]), 0
len(
[
warning
for warning in non_ignored_warnings
if warning.category == UserWarning
]
),
0,
)
assert any(
f"Subfolders with VASP input files (['INCAR', 'KPOINTS', 'POTCAR'] not found in "
Expand Down Expand Up @@ -3917,16 +3943,16 @@ def test_groundstate(self):
],
catch_exceptions=False,
)
self.assertTrue(
os.path.exists(f"{defect}/Groundstate/POSCAR")
)
self.assertTrue(os.path.exists(f"{defect}/Groundstate/POSCAR"))
self.assertIn(
f"{defect}: Ground state structure (found with -0.4 distortion) saved to "
f"./{defect}/Groundstate/POSCAR",
result.output,
)
gs_structure = Structure.from_file(f"{defect}/Groundstate/POSCAR")
V_Ti_minus0pt4_structure = Structure.from_file(f"{defect}/Bond_Distortion_-40.0%/CONTCAR")
V_Ti_minus0pt4_structure = Structure.from_file(
f"{defect}/Bond_Distortion_-40.0%/CONTCAR"
)
self.assertEqual(gs_structure, V_Ti_minus0pt4_structure)
if_present_rm(f"{defect}/Groundstate")
self.tearDown() # return to test file directory
Expand Down
3 changes: 1 addition & 2 deletions tests/test_energy_lowering_distortions.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,7 @@ def test_get_energy_lowering_distortions_rattle_too_large(self):
)
self.assertTrue(
any(
str(warning.message) == warning_message
for warning in user_warnings
str(warning.message) == warning_message for warning in user_warnings
)
)

Expand Down

0 comments on commit 9ed5d1c

Please sign in to comment.