From 2c84432a3770fd4123bbdaf4468fb99d2eb32ab8 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Wed, 25 Sep 2024 13:40:11 +0900 Subject: [PATCH] Fix velph-selfenergy-generate (#28) --- src/phelel/velph/cli/hints/__init__.py | 34 ++++++------ src/phelel/velph/cli/selfenergy/__init__.py | 43 ++------------- src/phelel/velph/cli/selfenergy/generate.py | 50 ++++++++++-------- src/phelel/velph/cli/transport/__init__.py | 16 +----- src/phelel/velph/cli/transport/generate.py | 10 +--- .../disp-000/LOCAL-POTENTIAL.bin.xz | Bin .../disp-000/PAW-OVERLAP.bin | Bin .../disp-000/PAW-Rnij.bin | Bin .../disp-000/PAW-STRENGTH.bin | Bin .../{supercell => phelel}/disp-000/inwap.yaml | 0 .../disp-000/vasprun.xml.xz | Bin .../disp-001/LOCAL-POTENTIAL.bin.xz | Bin .../disp-001/PAW-OVERLAP.bin | Bin .../disp-001/PAW-Rnij.bin | Bin .../disp-001/PAW-STRENGTH.bin | Bin .../{supercell => phelel}/disp-001/inwap.yaml | 0 .../disp-001/vasprun.xml | 0 .../differentiate/test_differentiate.py | 6 +-- 18 files changed, 56 insertions(+), 103 deletions(-) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/LOCAL-POTENTIAL.bin.xz (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/PAW-OVERLAP.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/PAW-Rnij.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/PAW-STRENGTH.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/inwap.yaml (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-000/vasprun.xml.xz (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/LOCAL-POTENTIAL.bin.xz (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/PAW-OVERLAP.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/PAW-Rnij.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/PAW-STRENGTH.bin (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/inwap.yaml (100%) rename test/velph/cli/phelel/differentiate/C111/{supercell => phelel}/disp-001/vasprun.xml (100%) diff --git a/src/phelel/velph/cli/hints/__init__.py b/src/phelel/velph/cli/hints/__init__.py index d47262d..bed3d31 100644 --- a/src/phelel/velph/cli/hints/__init__.py +++ b/src/phelel/velph/cli/hints/__init__.py @@ -56,10 +56,10 @@ def _show_hints(toml_filename: str): click.echo("3. Run VASP.") click.echo() click.echo("# Supercell calculation") - click.echo(f'1. Modify [vasp.supercell] section in "{toml_filename}".') - click.echo('2. "velph supercell init": Prepare finite displacement calculation. ') + click.echo(f'1. Modify [vasp.phelel] section in "{toml_filename}".') + click.echo('2. "velph phelel init": Prepare finite displacement calculation. ') click.echo(" NAC parameters are read when NAC calculation is available.") - click.echo('3. "velph supercell generate": Generate input files.') + click.echo('3. "velph phelel generate": Generate input files.') click.echo("4. Run VASP.") click.echo() click.echo("# Phonon band structure calculation") @@ -72,9 +72,16 @@ def _show_hints(toml_filename: str): click.echo("3. Run VASP in ph_bands directories.") click.echo('4. "velph ph_bands plot" to plot the phonon bands') click.echo() - click.echo( - '# Electron self-energy calculation (optional, default for "velph selfenergy")' - ) + click.echo("# Electron transport calculation") + click.echo(f'1. Write [vasp.transport] section in "{toml_filename}".') + click.echo('2. (optioanl) "velph transport generate": ' "Dry-run to find FFT-mesh.") + click.echo("3. (optioanl) Run VASP.") + click.echo('4. (optioanl) "velph transport check-fft": Check FFT grid.') + click.echo('5. (optioanl) Modify "fft_mesh" in [phelel] section manually.') + click.echo('6. "velph supercell differentiate": Generate derivatives hdf5 file') + click.echo('7. "velph transport generate": Generate input files') + click.echo() + click.echo("# Electron self-energy calculation") click.echo(f'1. Modify [vasp.selfenergy] section in "{toml_filename}".') click.echo( '2. (optional) "velph selfenergy generate -d": ' "Dry-run to find FFT-mesh." @@ -82,21 +89,12 @@ def _show_hints(toml_filename: str): click.echo("3. (optional) Run VASP.") click.echo('4. (optioanl) "velph selfenergy check-fft": Check FFT grid.') click.echo('5. (optioanl) Modify "fft_mesh" in [phelel] section manually.') - click.echo('6. "velph supercell differentiate": Generate derivatives hdf5 file') + click.echo('6. "velph phelel differentiate": Generate derivatives hdf5 file') click.echo('7. "velph selfenergy generate": Generate input files') click.echo() - click.echo("# Other electron-phonon calculation, e.g., transport") - click.echo(f'1. Write [vasp.transport] section in "{toml_filename}".') - click.echo('2. (optioanl) "velph transport generate": ' "Dry-run to find FFT-mesh.") - click.echo("3. (optioanl) Run VASP.") - click.echo('4. (optioanl) "velph transport check-fft": Check FFT grid.') - click.echo('5. (optioanl) Modify "fft_mesh" in [phelel] section manually.') - click.echo('6. "velph supercell differentiate": Generate derivatives hdf5 file') - click.echo('7. "velph transport generate": Generate input files') - click.echo() click.echo("# Different supercell size for phonon") - click.echo('1. Write "phonon_supercell_dimension" in [phelel] section and') - click.echo("2. Write [vasp.supercell.phonon.*] entry.") + click.echo('1. Write "supercell_dimension" in [phonopy] section and') + click.echo("2. Write [vasp.phelel.phonon.*] entry.") click.echo( "------------------------------- velph hints -------------------------------" ) diff --git a/src/phelel/velph/cli/selfenergy/__init__.py b/src/phelel/velph/cli/selfenergy/__init__.py index 5aed1fb..a5e64e6 100644 --- a/src/phelel/velph/cli/selfenergy/__init__.py +++ b/src/phelel/velph/cli/selfenergy/__init__.py @@ -9,7 +9,7 @@ from phelel.velph.cli.utils import check_fft -@cmd_root.group("elph") +@cmd_root.group("selfenergy") @click.help_option("-h", "--help") def cmd_selfenergy(): """Choose selfenergy options.""" @@ -23,23 +23,6 @@ def cmd_selfenergy(): type=click.Path(), default="velph.toml", ) -@click.option( - "--hdf5-filename", - "hdf5_filename", - nargs=1, - type=click.Path(), - default="supercell/phelel_params.hdf5", - show_default=True, -) -@click.option( - "-c", - "--calculation", - "calculation_name", - nargs=1, - type=str, - default="selfenergy", - show_default=True, -) @click.option( "--dry-run/--no-dry-run", "-d", @@ -49,19 +32,12 @@ def cmd_selfenergy(): show_default=True, ) @click.help_option("-h", "--help") -def cmd_generate( - toml_filename: str, hdf5_filename: str, calculation_name: str, dry_run: bool -): +def cmd_generate(toml_filename: str, dry_run: bool): """Generate elph input files.""" if not pathlib.Path("POTCAR").exists(): click.echo('"POTCAR" not found in current directory.') - write_input_files( - pathlib.Path(toml_filename), - pathlib.Path(hdf5_filename), - calculation_name, - dry_run, - ) + write_input_files(pathlib.Path(toml_filename), dry_run) @cmd_selfenergy.command("check-fft") @@ -71,16 +47,7 @@ def cmd_generate( type=click.Path(), default="velph.toml", ) -@click.option( - "-c", - "--calculation", - "calculation_name", - nargs=1, - type=click.Path(), - default="selfenergy", - show_default=True, -) @click.help_option("-h", "--help") -def cmd_check_fft(toml_filename: str, calculation_name: str): +def cmd_check_fft(toml_filename: str): """Show [NGX, NGY, NGZ] in vasprun.xml.""" - check_fft(toml_filename, calculation_name) + check_fft(toml_filename, "selfenergy") diff --git a/src/phelel/velph/cli/selfenergy/generate.py b/src/phelel/velph/cli/selfenergy/generate.py index 52201b3..e0c508a 100644 --- a/src/phelel/velph/cli/selfenergy/generate.py +++ b/src/phelel/velph/cli/selfenergy/generate.py @@ -20,24 +20,15 @@ ) -def write_input_files( - toml_filepath: pathlib.Path, - hdf5_filepath: pathlib.Path, - calculation_name: str, - dry_run: bool, -): +def write_input_files(toml_filepath: pathlib.Path, dry_run: bool): """Generate el-ph input files.""" - write_selfenergy_input_files( - toml_filepath, hdf5_filepath, calculation_name, dry_run - ) + write_selfenergy_input_files(toml_filepath, dry_run, calc_type="selfenergy") def write_selfenergy_input_files( toml_filepath: pathlib.Path, - hdf5_filepath: pathlib.Path, - calculation_name: str, dry_run: bool, - calc_type: Optional[Literal["transport"]] = None, + calc_type: Optional[Literal["transport", "selfenergy"]] = None, current_directory: pathlib.Path = pathlib.Path(""), energy_threshold: float = 0.5, ) -> None: @@ -50,14 +41,29 @@ def write_selfenergy_input_files( calc_type="transport". """ - directory_path = pathlib.Path(calculation_name) + directory_path = pathlib.Path(calc_type) with open(toml_filepath, "rb") as f: toml_dict = tomli.load(f) - if calculation_name not in toml_dict["vasp"]: + if "vasp" not in toml_dict: + click.echo(f"[vasp] section not found in {toml_filepath}.", err=True) + return None + + if "phelel" in toml_dict["vasp"]: + hdf5_filepath = pathlib.Path("phelel/phelel_params.hdf5") + elif "supercell" in toml_dict["vasp"]: + hdf5_filepath = pathlib.Path("supercell/phelel_params.hdf5") + else: + click.echo( + f'[vasp.phelel] section not found in "{toml_filepath}".', + err=True, + ) + return None + + if calc_type not in toml_dict["vasp"]: click.echo( - f'[vasp.{calculation_name}.*] section not found in "{toml_filepath}".', + f'[vasp.{calc_type}] section not found in "{toml_filepath}".', err=True, ) return None @@ -65,14 +71,14 @@ def write_selfenergy_input_files( # Check phelel_params.hdf5 if not dry_run and not hdf5_filepath.exists(): click.echo(f'"{hdf5_filepath}" not found.', err=True) - click.echo('Run "velph supercell differentiate" if necessary.') + click.echo('Run "velph phelel differentiate" if necessary.', err=True) return None # mkdir, e.g., selfenergy directory_path.mkdir(parents=True, exist_ok=True) # Dry run - toml_incar_dict = toml_dict["vasp"][calculation_name]["incar"] + toml_incar_dict = toml_dict["vasp"][calc_type]["incar"] if dry_run: toml_incar_dict["nelm"] = 0 toml_incar_dict["elph_run"] = False @@ -93,22 +99,22 @@ def write_selfenergy_input_files( write_incar(toml_incar_dict, directory_path, cell=primitive) # KPOINTS - kpoints_dict = toml_dict["vasp"][calculation_name]["kpoints"] + kpoints_dict = toml_dict["vasp"][calc_type]["kpoints"] assert_kpoints_mesh_symmetry(toml_dict, kpoints_dict, primitive) write_kpoints_mesh_mode( toml_incar_dict, directory_path, - f"vasp.{calculation_name}.kpoints", + f"vasp.{calc_type}.kpoints", kpoints_dict, ) # KPOINTS_DENSE - kpoints_dense_dict = toml_dict["vasp"][calculation_name]["kpoints_dense"] + kpoints_dense_dict = toml_dict["vasp"][calc_type]["kpoints_dense"] assert_kpoints_mesh_symmetry(toml_dict, kpoints_dense_dict, primitive) write_kpoints_mesh_mode( toml_incar_dict, directory_path, - f"vasp.{calculation_name}.kpoints_dense", + f"vasp.{calc_type}.kpoints_dense", kpoints_dense_dict, kpoints_filename="KPOINTS_DENSE", kspacing_name="elph_kspacing", @@ -125,7 +131,7 @@ def write_selfenergy_input_files( # Scheduler launch script if "scheduler" in toml_dict: - scheduler_dict = get_scheduler_dict(toml_dict, calculation_name) + scheduler_dict = get_scheduler_dict(toml_dict, calc_type) write_launch_script(scheduler_dict, directory_path) click.echo(f'VASP input files were generated in "{directory_path}".') diff --git a/src/phelel/velph/cli/transport/__init__.py b/src/phelel/velph/cli/transport/__init__.py index 475d538..434facb 100644 --- a/src/phelel/velph/cli/transport/__init__.py +++ b/src/phelel/velph/cli/transport/__init__.py @@ -23,14 +23,6 @@ def cmd_transport(): type=click.Path(), default="velph.toml", ) -@click.option( - "--hdf5-filename", - "hdf5_filename", - nargs=1, - type=click.Path(), - default="supercell/phelel_params.hdf5", - show_default=True, -) @click.option( "--dry-run/--no-dry-run", "-d", @@ -40,16 +32,12 @@ def cmd_transport(): show_default=True, ) @click.help_option("-h", "--help") -def cmd_generate(toml_filename: str, hdf5_filename: str, dry_run: bool): +def cmd_generate(toml_filename: str, dry_run: bool): """Generate transport input files.""" if not pathlib.Path("POTCAR").exists(): click.echo('"POTCAR" not found in current directory.') - write_input_files( - pathlib.Path(toml_filename), - pathlib.Path(hdf5_filename), - dry_run, - ) + write_input_files(pathlib.Path(toml_filename), dry_run) @cmd_transport.command("check-fft") diff --git a/src/phelel/velph/cli/transport/generate.py b/src/phelel/velph/cli/transport/generate.py index 2ae4c42..eea47f0 100644 --- a/src/phelel/velph/cli/transport/generate.py +++ b/src/phelel/velph/cli/transport/generate.py @@ -5,12 +5,6 @@ from phelel.velph.cli.selfenergy.generate import write_selfenergy_input_files -def write_input_files( - toml_filepath: pathlib.Path, - hdf5_filepath: pathlib.Path, - dry_run: bool, -): +def write_input_files(toml_filepath: pathlib.Path, dry_run: bool): """Generate transport input files.""" - write_selfenergy_input_files( - toml_filepath, hdf5_filepath, "transport", dry_run, calc_type="transport" - ) + write_selfenergy_input_files(toml_filepath, dry_run, calc_type="transport") diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/LOCAL-POTENTIAL.bin.xz b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/LOCAL-POTENTIAL.bin.xz similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/LOCAL-POTENTIAL.bin.xz rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/LOCAL-POTENTIAL.bin.xz diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-OVERLAP.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-OVERLAP.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-OVERLAP.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-OVERLAP.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-Rnij.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-Rnij.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-Rnij.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-Rnij.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-STRENGTH.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-STRENGTH.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/PAW-STRENGTH.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/PAW-STRENGTH.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/inwap.yaml b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/inwap.yaml similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/inwap.yaml rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/inwap.yaml diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-000/vasprun.xml.xz b/test/velph/cli/phelel/differentiate/C111/phelel/disp-000/vasprun.xml.xz similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-000/vasprun.xml.xz rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-000/vasprun.xml.xz diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/LOCAL-POTENTIAL.bin.xz b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/LOCAL-POTENTIAL.bin.xz similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/LOCAL-POTENTIAL.bin.xz rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/LOCAL-POTENTIAL.bin.xz diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-OVERLAP.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-OVERLAP.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-OVERLAP.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-OVERLAP.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-Rnij.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-Rnij.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-Rnij.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-Rnij.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-STRENGTH.bin b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-STRENGTH.bin similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/PAW-STRENGTH.bin rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/PAW-STRENGTH.bin diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/inwap.yaml b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/inwap.yaml similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/inwap.yaml rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/inwap.yaml diff --git a/test/velph/cli/phelel/differentiate/C111/supercell/disp-001/vasprun.xml b/test/velph/cli/phelel/differentiate/C111/phelel/disp-001/vasprun.xml similarity index 100% rename from test/velph/cli/phelel/differentiate/C111/supercell/disp-001/vasprun.xml rename to test/velph/cli/phelel/differentiate/C111/phelel/disp-001/vasprun.xml diff --git a/test/velph/cli/phelel/differentiate/test_differentiate.py b/test/velph/cli/phelel/differentiate/test_differentiate.py index e64929e..848d380 100644 --- a/test/velph/cli/phelel/differentiate/test_differentiate.py +++ b/test/velph/cli/phelel/differentiate/test_differentiate.py @@ -18,7 +18,7 @@ def test_run_derivatives(): """ phe = phelel.load(cwd / "C111" / "phelel_disp_C111.yaml", fft_mesh=[9, 9, 9]) - assert run_derivatives(phe, dir_name=cwd / "C111" / "supercell") + assert run_derivatives(phe, dir_name=cwd / "C111" / "phelel") def test_run_derivatives_with_wrong_supercell_matrix(): @@ -30,7 +30,7 @@ def test_run_derivatives_with_wrong_supercell_matrix(): """ phe = phelel.load(cwd / "phelel_disp_C222.yaml", fft_mesh=[9, 9, 9]) with pytest.raises(ValueError): - run_derivatives(phe, dir_name=cwd / "C111/supercell") + run_derivatives(phe, dir_name=cwd / "C111" / "phelel") def test_run_derivatives_with_wrong_phonon_supercell_matrix(): @@ -40,4 +40,4 @@ def test_run_derivatives_with_wrong_phonon_supercell_matrix(): """ phe = phelel.load(cwd / "phelel_disp_C111-222.yaml", fft_mesh=[9, 9, 9]) - assert not run_derivatives(phe, dir_name=cwd / "C111/supercell") + assert not run_derivatives(phe, dir_name=cwd / "C111" / "phelel")