Skip to content

Commit

Permalink
Fix phonon output file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Mar 3, 2025
1 parent 9b154b8 commit 26d651b
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_phonons_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def test_hdf5(tmp_path):
file_prefix = tmp_path / "test" / "NaCl"
phonon_results = tmp_path / "test" / "NaCl-phonopy.yml"
hdf5_results = tmp_path / "test" / "NaCl-force_constants.hdf5"
summary_path = tmp_path / "test" / "NaCl-phonons-summary.yml"
log_path = tmp_path / "test" / "NaCl-phonons-log.yml"

result = runner.invoke(
app,
Expand All @@ -171,11 +173,33 @@ def test_hdf5(tmp_path):
assert phonon_results.exists()
assert hdf5_results.exists()

# Read phonons summary file
with open(summary_path, encoding="utf8") as file:
phonon_summary = yaml.safe_load(file)

output_files = {
"params": phonon_results,
"force_constants": hdf5_results,
"bands": None,
"bands_plot": None,
"dos": None,
"dos_plot": None,
"band_dos_plot": None,
"pdos": None,
"pdos_plot": None,
"thermal": None,
"minimized_initial_structure": None,
"log": log_path,
"summary": summary_path,
}
check_output_files(summary=phonon_summary, output_files=output_files)


def test_thermal_props(tmp_path):
"""Test calculating thermal properties."""
file_prefix = tmp_path / "test" / "NaCl"
thermal_results = tmp_path / "test" / "NaCl-thermal.yml"
summary_path = tmp_path / "test" / "NaCl-phonons-summary.yml"

result = runner.invoke(
app,
Expand All @@ -192,6 +216,15 @@ def test_thermal_props(tmp_path):
assert result.exit_code == 0
assert thermal_results.exists()

# Read phonons summary file
with open(summary_path, encoding="utf8") as file:
phonon_summary = yaml.safe_load(file)

output_files = {
"thermal": thermal_results,
}
check_output_files(summary=phonon_summary, output_files=output_files)


def test_dos(tmp_path):
"""Test calculating the DOS."""
Expand Down Expand Up @@ -249,10 +282,13 @@ def test_pdos(tmp_path):
def test_plot(tmp_path):
"""Test for plotting routines."""
file_prefix = tmp_path / "NaCl"
phonon_results = tmp_path / "NaCl-phonopy.yml"
bands_path = tmp_path / "NaCl-auto_bands.yml.xz"
pdos_results = tmp_path / "NaCl-pdos.dat"
dos_results = tmp_path / "NaCl-dos.dat"
autoband_results = tmp_path / "NaCl-auto_bands.yml.xz"
summary_path = tmp_path / "NaCl-phonons-summary.yml"
log_path = tmp_path / "NaCl-phonons-log.yml"
svgs = [
tmp_path / "NaCl-dos.svg",
tmp_path / "NaCl-pdos.svg",
Expand Down Expand Up @@ -294,6 +330,27 @@ def test_plot(tmp_path):
assert phonon_summary["inputs"]["calcs"][1] == "dos"
assert phonon_summary["inputs"]["calcs"][2] == "pdos"

# Read phonons summary file
with open(summary_path, encoding="utf8") as file:
phonon_summary = yaml.safe_load(file)

output_files = {
"params": phonon_results,
"force_constants": None,
"bands": bands_path,
"bands_plot": svgs[3],
"dos": dos_results,
"dos_plot": svgs[0],
"band_dos_plot": [svgs[2]],
"pdos": pdos_results,
"pdos_plot": svgs[1],
"thermal": None,
"minimized_initial_structure": None,
"log": log_path,
"summary": summary_path,
}
check_output_files(summary=phonon_summary, output_files=output_files)


test_data = [
("1", [[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
Expand Down Expand Up @@ -390,6 +447,7 @@ def test_minimize_filename(tmp_path):
"""Test minimize filename overwrites default."""
file_prefix = tmp_path / "test" / "test"
opt_path = tmp_path / "test" / "geomopt-opt.extxyz"
summary_path = tmp_path / "test" / "test-phonons-summary.yml"

# write_results should be set automatically
minimize_kwargs = f"{{'write_kwargs': {{'filename': '{str(opt_path)}'}}}}"
Expand All @@ -411,6 +469,15 @@ def test_minimize_filename(tmp_path):
assert result.exit_code == 0
assert opt_path.exists()

# Read phonons summary file
with open(summary_path, encoding="utf8") as file:
phonon_summary = yaml.safe_load(file)

output_files = {
"minimized_initial_structure": opt_path,
}
check_output_files(summary=phonon_summary, output_files=output_files)


@pytest.mark.parametrize("read_kwargs", ["{'index': 0}", "{}"])
def test_valid_traj_input(read_kwargs, tmp_path):
Expand Down

0 comments on commit 26d651b

Please sign in to comment.