Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encut option to velph supercell differentiate #4

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix velph supercell differentiate for compressed (xz etc) files
atztogo committed Jul 19, 2024
commit 449036b9939287e3086f29df382691545bb876be
30 changes: 19 additions & 11 deletions src/phelel/velph/cli/supercell/differentiate.py
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ def run_derivatives(


def _check_files_exist(filepath: pathlib.Path) -> bool:
if not (filepath / "vasprun.xml").exists():
if not _check_file_exists(filepath, "vasprun.xml"):
click.echo(f'"{filepath}/vasprun.xml" not found.', err=True)
return False
if _check_four_files_exist(filepath):
@@ -88,26 +88,34 @@ def _check_files_exist(filepath: pathlib.Path) -> bool:
"PAW-STRENGTH.bin",
"PAW-OVERLAP.bin",
):
if not (filepath / filename).exists():
if not _check_file_exists(filepath, filename):
click.echo(f'"{filepath}/{filename}" not found.', err=True)
return False


def _check_four_files_exist(filepath: pathlib.Path) -> bool:
"""Check if the necessary files exist.

inwap.yaml
LOCAL-POTENTIAL.bin
PAW-STRENGTH.bin
PAW-OVERLAP.bin

"""
for filename in (
"inwap.yaml",
"LOCAL-POTENTIAL.bin",
"PAW-STRENGTH.bin",
"PAW-OVERLAP.bin",
):
if not (filepath / filename).exists():
if not _check_file_exists(filepath, filename):
return False
return True


def _check_file_exists(filepath: pathlib.Path, filename: str) -> bool:
"""Check if the necessary file exists.

The file can be compressed with xz, etc.

The file names that can be checked are:
inwap.yaml
LOCAL-POTENTIAL.bin
PAW-STRENGTH.bin
PAW-OVERLAP.bin
vasprun.xml

"""
return bool(list(pathlib.Path(filepath).glob(f"{filename}*")))
5 changes: 4 additions & 1 deletion test/velph/cli/supercell/differentiate/test_differentiate.py
Original file line number Diff line number Diff line change
@@ -18,8 +18,11 @@ def test_run_derivatives():
"""
phe = phelel.load(cwd / "C111" / "phelel_disp_C111.yaml", fft_mesh=[9, 9, 9])
hdf5_filename = "phelel_params_test_run_derivatives.hdf5"
run_derivatives(phe, hdf5_filename=hdf5_filename, dir_name=cwd / "C111/supercell")
run_derivatives(
phe, hdf5_filename=hdf5_filename, dir_name=cwd / "C111" / "supercell"
)
file_path = pathlib.Path(cwd_called / hdf5_filename)
print(file_path)
assert file_path.exists()
file_path.unlink()