diff --git a/src/phelel/velph/cli/supercell/__init__.py b/src/phelel/velph/cli/supercell/__init__.py index ff5e5ea..078a002 100644 --- a/src/phelel/velph/cli/supercell/__init__.py +++ b/src/phelel/velph/cli/supercell/__init__.py @@ -1,6 +1,7 @@ """velph command line tool / velph-supercell.""" import pathlib +from typing import Optional import click import tomli @@ -12,6 +13,7 @@ from phelel.velph.cli.supercell.generate import write_supercell_input_files from phelel.velph.cli.supercell.init import run_init from phelel.velph.cli.supercell.phonopy import create_phonopy_yaml +from phelel.velph.utils.vasp import CutoffToFFTMesh @cmd_root.group("supercell") @@ -99,11 +101,19 @@ def cmd_generate(toml_filename: str, yaml_filename: str): type=click.Path(), default="supercell/phelel_params.hdf5", ) +@click.option( + "--encut", + nargs=1, + type=float, + default=None, + help=( + "Cutoff energy corresponding to FFT mesh of local potential grid. " + "(encut: float, default=None)" + ), +) @click.help_option("-h", "--help") def cmd_differentiate( - toml_filename: str, - yaml_filename: str, - hdf5_filename: str, + toml_filename: str, yaml_filename: str, hdf5_filename: str, encut: Optional[float] ) -> None: """Calculate derivatives and write phelel_params.hdf5.""" with open(toml_filename, "rb") as f: @@ -131,6 +141,24 @@ def cmd_differentiate( is_symmetry=is_symmetry, ) + if encut is not None: + try: + prec = toml_dict["vasp"]["selfenergy"]["incar"]["prec"] + except KeyError: + click.echo(f'[vasp.selfenergy.incar] not found in "{toml_filename}".') + click.echo('prec = "accurate" is assumed.') + prec = "accurate" + click.echo(f"FFT mesh is generated for encut={encut}.") + phe.fft_mesh = CutoffToFFTMesh.get_FFTMesh(encut, phe.primitive.cell, prec) + + if phe.fft_mesh is None: + click.echo("FFT mesh is not specified.", err=True) + else: + if encut is None: + click.echo(f"FFT mesh: {phe.fft_mesh}.") + else: + click.echo(f"FFT mesh: {phe.fft_mesh} (encut={encut}).") + run_derivatives(phe, hdf5_filename=hdf5_filename) diff --git a/src/phelel/velph/cli/supercell/differentiate.py b/src/phelel/velph/cli/supercell/differentiate.py index 8562eae..331272e 100644 --- a/src/phelel/velph/cli/supercell/differentiate.py +++ b/src/phelel/velph/cli/supercell/differentiate.py @@ -31,7 +31,11 @@ def run_derivatives( id_number = f"{i:0{nd}d}" filepath = pathlib.Path(f"{dir_name}/disp-{id_number}") if filepath.exists(): - dir_names.append(filepath) + if _check_files_exist(filepath): + dir_names.append(filepath) + else: + click.echo(f'Necessary file not found in "{filepath}".', err=True) + return None else: click.echo(f'"{filepath}" does not exist.', err=True) return None @@ -65,3 +69,53 @@ def run_derivatives( phe.save_hdf5(filename=hdf5_filename) click.echo(f'"{hdf5_filename}" has been made.') + + +def _check_files_exist(filepath: pathlib.Path) -> bool: + 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): + return True + else: + if (filepath / "vaspout.h5").exists(): + click.echo(f'Found "{filepath}/vaspout.h5".', err=True) + return True + else: + for filename in ( + "inwap.yaml", + "LOCAL-POTENTIAL.bin", + "PAW-STRENGTH.bin", + "PAW-OVERLAP.bin", + ): + 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: + for filename in ( + "inwap.yaml", + "LOCAL-POTENTIAL.bin", + "PAW-STRENGTH.bin", + "PAW-OVERLAP.bin", + ): + 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}*"))) diff --git a/src/phelel/velph/cli/transport/plot/plot_transport.py b/src/phelel/velph/cli/transport/plot/plot_transport.py index f788831..d1553c9 100644 --- a/src/phelel/velph/cli/transport/plot/plot_transport.py +++ b/src/phelel/velph/cli/transport/plot/plot_transport.py @@ -135,15 +135,25 @@ def _show(transport: h5py._hl.group.Group, index: int): print(f" {key[1]}: {transport[key[0]][()]}") else: print(f" {key}: {transport[key][()]}") - print(" data_array_shapes:") + + print(" data_array_diagonal:") for key in ( "e_conductivity", "e_t_conductivity", - "energy", - ("lab", "Onsager_coefficients"), "mobility", "peltier", "seebeck", + ): + v = transport[key][:].ravel() + print( + f" {key}: [{v[0]:.3e}, {v[4]:.3e}, {v[8]:.3e}, " + f"{v[5]:.3e}, {v[2]:.3e}, {v[1]:.3e}]" + ) + + print(" data_array_shapes:") + for key in ( + "energy", + ("lab", "Onsager_coefficients"), "transport_function", ): if isinstance(key, tuple): diff --git a/test/velph/cli/supercell/differentiate/test_differentiate.py b/test/velph/cli/supercell/differentiate/test_differentiate.py index 6976c82..c35307b 100644 --- a/test/velph/cli/supercell/differentiate/test_differentiate.py +++ b/test/velph/cli/supercell/differentiate/test_differentiate.py @@ -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()