From 8a8336565fe93af8ebb84bf41c5abc58d9ae6743 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 9 Jan 2025 11:40:26 +0900 Subject: [PATCH 1/9] Update velph-ph_bands-generate --- src/phelel/velph/cli/ph_bands/generate.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/phelel/velph/cli/ph_bands/generate.py b/src/phelel/velph/cli/ph_bands/generate.py index d4ff92a..527eb5d 100644 --- a/src/phelel/velph/cli/ph_bands/generate.py +++ b/src/phelel/velph/cli/ph_bands/generate.py @@ -17,7 +17,10 @@ ) -def write_input_files(toml_filename: pathlib.Path) -> None: +def write_input_files( + toml_filename: pathlib.Path, + dir_name: str = "phelel", +) -> None: """Generate VASP inputs to generate phonon band structure.""" with open(toml_filename, "rb") as f: toml_dict = tomli.load(f) @@ -58,12 +61,12 @@ def write_input_files(toml_filename: pathlib.Path) -> None: ) # phelel_params.hdf5 - if pathlib.Path("supercell/phelel_params.hdf5").exists(): + if pathlib.Path(f"{dir_name}/phelel_params.hdf5").exists(): shutil.copy2( - "supercell/phelel_params.hdf5", "ph_bands/bands/phelel_params.hdf5" + f"{dir_name}/phelel_params.hdf5", "ph_bands/bands/phelel_params.hdf5" ) else: - click.echo('"supercell/bands/phelel_params.hdf5" not found.', err=True) + click.echo(f'"{dir_name}/bands/phelel_params.hdf5" not found.', err=True) return None # POTCAR From f1ba34a4648fb061d4742924c4ba0c3a57b5778a Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 9 Jan 2025 17:50:19 +0900 Subject: [PATCH 2/9] Update documentation --- doc/conf.py | 1 + doc/velph-subcommands.md | 223 +++++++++++++++++++++++++++++---------- 2 files changed, 170 insertions(+), 54 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 5943517..98a7321 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -21,6 +21,7 @@ "IPython.sphinxext.ipython_console_highlighting", "IPython.sphinxext.ipython_directive", "sphinx.ext.extlinks", + "sphinxcontrib.mermaid", ] myst_enable_extensions = ["linkify", "dollarmath", "amsmath"] diff --git a/doc/velph-subcommands.md b/doc/velph-subcommands.md index 416971f..d64ec54 100644 --- a/doc/velph-subcommands.md +++ b/doc/velph-subcommands.md @@ -9,6 +9,20 @@ The following subcommands must be executed in the directory containing the properly organized relative to the current directory where `velph.toml` is located. +A typical workflow of velph subcommands for transport property calculation is illustrated below. + +```{mermaid} +graph LR +A[velph-init] --> B[velph-relax] +B --> C[velph-init] +C --> D[velph-nac] +C --> E[velph-el_bands] +F[velph-phelel] +D --> F +E --> F +F --> G[velph-transport] +``` + In the following example, two `velph init` command operations generate two different directories. The first operation performs crystal structure relaxation in the `relax` directory. The second operation, using the relaxed crystal @@ -60,6 +74,105 @@ VASP input files will be generated by "velph phelel generate". ... ``` +## `velph init` + +See {ref}`velph_init`. + +## `velph hints` + +See {ref}`velph_hints`. + +## `velph relax` + +It is recommended to create a project directory secific for relaxation +calculation, e.g., as + +```bash +% ls +POSCAR-unitcell POTCAR velph-tmpl.toml +% velph init --template-toml velph-tmpl.toml POSCAR-unitcell relax +... +% cd relax +% ls +POTCAR velph.toml +% velph relax generate +... +``` +### `velph relax generate` + +This subcommand generates VASP input files and a job script for crystal +structure relaxation. Initially, these files are created in the `iter1` +directory. The process supports multiple relaxation steps, where the `CONTCAR` +file from the previous iteration is used as the `POSCAR` for the next step once +the preceding VASP calculation is complete. Each subsequent set of input files +is generated in directories named `iter2`, `iter3`, and so on. + +```bash +% ls +POTCAR velph.toml +% velph relax generate +VASP input files were made in "relax/iter1". +... +# Run VASP calculation in relax/iter1 +... +% ls +POTCAR relax/ velph.toml +% velph relax generate +"relax/iter1" exists. +"relax/iter1/CONTCAR" will be as new "POSCAR". +VASP input files were made in "relax/iter2". +... +``` + +(velph_nac_subcommand)= +## `velph nac` + +This subcommand is used to prepare VASP input files for calculating the +dielectric constant and Born effective charges. These quantities are required +for the non-analytical term correction in phonon calculations and for handling +the long-range terms in electron-phonon interaction calculations. + +### `velph nac generate` + +After the VASP calculation is complete, the dielectric constant and Born +effective charges are extracted from the `vasprun.xml` file during the execution +of `velph phelel init`, `velph phono3py init`, or `velph phonopy init`. The +extracted values are then written to `phelel_disp.yaml`, `phono3py_disp.yaml`, +or `phonopy_disp.yaml`, respectively. + +```bash +% velph nac generate +VASP input files were made in "nac". +``` + +## `velph el_bands` + +This subcommand is used to prepare VASP input files for electronic band +structure and density of states calculations, and to plot the resulting data. + +### `velph el_bands generate` + +The VASP input files have been prepared so that the calculation results will be +stored in `vaspout.h5`. + +```bash +% velph el_bands generate +VASP input files were made in "el_bands/bands". +VASP input files were made in "el_bands/dos". +``` + +### `velph el_bands plot` + +The electronic band structure and density of states are plotted and saved in the +`el_bands.pdf` file. The energy range must be specified using the `--windows` +option, with the first and second arguments representing the range below and +above the Fermi energy in eV, respectively. + +```bash +% velph el_bands plot --window -5 9 +Electronic band structure plot was saved in "el_bands/el_bands.pdf". +``` + ## `velph phelel` This subcommand calculates the derivatives of local potentials and PAW strengths @@ -121,6 +234,14 @@ Running finufft (eps=1.000e-06)... (velph_phelel_phonopy_subcommand)= ### `velph phelel phonopy` +```{note} +This subcommand is similar to `velph ph_bands`, but the phonon band structure is +calculated using the phonopy code. While the phonon calculation routines of VASP +and phonopy are expected to yield similar results, they are not entirely +equivalent. However, for electron-phonon calculations, the VASP routine is +utilized. +``` + `phonopy_params.yaml` that contains information necessary for phonon calculation by the phonopy code is generated from `phelel_disp.yaml` and the results of the VASP inputs generated by `velph phelel generate`. @@ -133,82 +254,76 @@ VASP inputs generated by `velph phelel generate`. ## `velph transport` +This subcommand is used to prepare VASP input files for calculating transport +properties based on electron-phonon interactions. + ### `velph transport generate` +The VASP input files are prepared for transport property calculations. Users +should review the generated `INCAR` tags and modify them as necessary for the +target material. If results from `el_bands/dos` calculations are available, the +maximum band index for the self-energy calculation is estimated and written into +the `INCAR` file. + +```bash +% velph transport generate +Found "el_bands/dos" directory. Estimate elph_selfen_band_stop. + "elph_selfen_band_stop=5" in INCAR is set. +VASP input files were generated in "transport". +``` + ### `velph transport plot` -## `velph relax` +The following command opens a graphical window that contains plots of transport +properties in `vaspout.h5`. -It is recommended to create a project directory secific for relaxation -calculation, e.g., as +```bash +% velph transport plot transport +``` + +The following command opens a graphical window that displays eigenvalues in the +Brillouin zone with non-zero and non-one occupations. The eigenvalues are +obtained from `vaspout.h5`, and their occupations are calculated based on the +temperature and Fermi level specified through the command options. ```bash -% ls -POSCAR-unitcell POTCAR velph-tmpl.toml -% velph init --template-toml velph-tmpl.toml POSCAR-unitcell relax -... -% cd relax -% ls -POTCAR velph.toml -% velph relax generate -... +% velph transport plot eigenvalues +mu: 4.837002 eV +temperature: 300.000000 K +No eigenvalues to plot. +% velph transport plot eigenvalues --mu 4 ``` -### `velph relax generate` -This subcommand generates VASP input files and a job script for crystal -structure relaxation. Initially, these files are created in the `iter1` -directory. The process supports multiple relaxation steps, where the `CONTCAR` -file from the previous iteration is used as the `POSCAR` for the next step once -the preceding VASP calculation is complete. Each subsequent set of input files -is generated in directories named `iter2`, `iter3`, and so on. +The following command opens a graphical window that displays Fan self-energies. ```bash -% ls -POTCAR velph.toml -% velph relax generate -VASP input files were made in "relax/iter1". -... -# Run VASP calculation in relax/iter1 -... -% ls -POTCAR relax/ velph.toml -% velph relax generate -"relax/iter1" exists. -"relax/iter1/CONTCAR" will be as new "POSCAR". -VASP input files were made in "relax/iter2". -... +% velph transport plot selfenergy ``` -(velph_nac_subcommand)= -## `velph nac` +## `velph ph_bands` -This subcommand is used to calculate dielectric constant and Born effective -charges that are used for non-analytical term correction of phonon calculation -and treatment of long range term of electron-phonon interaction calculation. +This subcommand is used to prepare VASP input files for phonon band structure +calculation using the supercell force constants stored in `phelel_params.hdf5`, +and to plot the resulting data. -### `velph nac generate` +### `velph ph_bands generate` -After the VASP calculation is complete, the dielectric constant and Born -effective charges are extracted from the `vasprun.xml` file during the execution -of `velph phelel init`, `velph phono3py init`, or `velph phonopy init`. The -extracted values are then written to `phelel_disp.yaml`, `phono3py_disp.yaml`, -or `phonopy_disp.yaml`, respectively. +The VASP input files including `QPOINTS` are prepared so that the +calculation results will be stored in `vaspout.h5`. ```bash -% velph nac generate -VASP input files were made in "nac". +% velph ph_bands generate +VASP input files were made in "ph_bands/bands". ``` -## `velph el_bands` - -### `velph el_bands generate` -### `velph el_bands plot` +### `velph ph_bands plot` -## `velph ph_bands` +The phonon band structure is plotted and saved in the `ph_bands.pdf` file. -### `velph ph_bands generate` - -### `velph ph_bands plot` +```bash +% velph ph_bands plot +Phonon band structure plot was saved in "ph_bands/ph_bands.pdf". +``` ## `velph phono3py` From 0ae132bb68485d3c4ff4f34b9adaef08514ae99b Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 9 Jan 2025 17:50:54 +0900 Subject: [PATCH 3/9] Update github workflow to publish documentation --- .github/workflows/publish-gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-gh-pages.yml b/.github/workflows/publish-gh-pages.yml index 506e42b..c6069b1 100644 --- a/.github/workflows/publish-gh-pages.yml +++ b/.github/workflows/publish-gh-pages.yml @@ -26,7 +26,7 @@ jobs: run: | conda activate test conda install --yes -c conda-forge python=${{ matrix.python-version }} - conda install --yes -c conda-forge sphinx-book-theme linkify-it-py myst-parser sphinxcontrib-bibtex ipython + conda install --yes -c conda-forge sphinx-book-theme linkify-it-py myst-parser sphinxcontrib-bibtex sphinxcontrib-mermaid ipython - name: Build run: | conda activate test From 536b75adad6dcefdf9b22fecbe8ee0de7f8aa911 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 9 Jan 2025 17:51:44 +0900 Subject: [PATCH 4/9] Fix velph-transport-plot --- src/phelel/velph/cli/selfenergy/generate.py | 2 +- src/phelel/velph/cli/transport/plot/__init__.py | 1 - .../velph/cli/transport/plot/plot_selfenergy.py | 11 +++++++---- src/phelel/velph/cli/transport/plot/plot_transport.py | 9 ++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/phelel/velph/cli/selfenergy/generate.py b/src/phelel/velph/cli/selfenergy/generate.py index ee7f53e..1005e48 100644 --- a/src/phelel/velph/cli/selfenergy/generate.py +++ b/src/phelel/velph/cli/selfenergy/generate.py @@ -173,7 +173,7 @@ def _estimate_elph_selfen_band_stop( is 0.5 eV. occupation_condition : float Condition to determine either if bands are occupied or not. This value - is used as occupation_number > occupation_condition. Default is 1e-5. + is used as occupation_number > occupation_condition. Default is 1e-10. Returns ------- diff --git a/src/phelel/velph/cli/transport/plot/__init__.py b/src/phelel/velph/cli/transport/plot/__init__.py index 56a4e4e..cbf97ab 100644 --- a/src/phelel/velph/cli/transport/plot/__init__.py +++ b/src/phelel/velph/cli/transport/plot/__init__.py @@ -138,7 +138,6 @@ def cmd_plot_eigenvalues( plot_eigenvalues( args[0], tid=tid, - nid=nid, temperature=temperature, cutoff_occupancy=cutoff_occupancy, mu=mu, diff --git a/src/phelel/velph/cli/transport/plot/plot_selfenergy.py b/src/phelel/velph/cli/transport/plot/plot_selfenergy.py index df86063..9ffa473 100644 --- a/src/phelel/velph/cli/transport/plot/plot_selfenergy.py +++ b/src/phelel/velph/cli/transport/plot/plot_selfenergy.py @@ -22,11 +22,14 @@ def plot_selfenergy(f_h5py: h5py.File, plot_filename: str, save_plot: bool = Fal import matplotlib.pyplot as plt selfens = {} - for key in f_h5py["results"]["electron_phonon"]["electrons"]: + f_elph = f_h5py["results/electron_phonon/electrons"] + for key in f_elph: if "self_energy_" in key: - selfens[int(key.split("_")[2])] = f_h5py["results"]["electron_phonon"][ - "electrons" - ][key] + index = key.split("_")[-1] + if index.isdigit(): + selfens[int(index)] = f_elph[key] + + assert len(selfens) == int(f_elph["self_energy_meta/ncalculators"][()]) if len(selfens) == 1: fig, axs = plt.subplots(1, 1, figsize=(4, 4)) diff --git a/src/phelel/velph/cli/transport/plot/plot_transport.py b/src/phelel/velph/cli/transport/plot/plot_transport.py index 07936b3..24ccb0d 100644 --- a/src/phelel/velph/cli/transport/plot/plot_transport.py +++ b/src/phelel/velph/cli/transport/plot/plot_transport.py @@ -35,13 +35,12 @@ def plot_transport(f_h5py: h5py.File, plot_filename: str, save_plot: bool = Fals "seebeck", ) + f_elph = f_h5py["results/electron_phonon/electrons"] + n_transport = len( - [ - key - for key in f_h5py["results/electron_phonon/electrons"] - if "transport_" in key - ] + [key for key in f_elph if "transport_" in key and key.split("_")[1].isdigit()] ) + assert n_transport == int(f_elph["transport_meta/ncalculators"][()]) transports = [ f_h5py[f"results/electron_phonon/electrons/transport_{n + 1}"] for n in range(n_transport) From d97ab1df634e302b66e93090755ecd8c6aaca30f Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 9 Jan 2025 18:11:56 +0900 Subject: [PATCH 5/9] Update documentation --- doc/velph-subcommands.md | 21 ++++++++++++++----- .../velph/cli/transport/plot/__init__.py | 8 ------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/velph-subcommands.md b/doc/velph-subcommands.md index d64ec54..8fce38b 100644 --- a/doc/velph-subcommands.md +++ b/doc/velph-subcommands.md @@ -9,7 +9,8 @@ The following subcommands must be executed in the directory containing the properly organized relative to the current directory where `velph.toml` is located. -A typical workflow of velph subcommands for transport property calculation is illustrated below. +A typical workflow of velph subcommands for transport property calculation is +illustrated below. ```{mermaid} graph LR @@ -274,6 +275,8 @@ VASP input files were generated in "transport". ### `velph transport plot` +#### `velph transport plot transport` + The following command opens a graphical window that contains plots of transport properties in `vaspout.h5`. @@ -281,10 +284,9 @@ properties in `vaspout.h5`. % velph transport plot transport ``` -The following command opens a graphical window that displays eigenvalues in the -Brillouin zone with non-zero and non-one occupations. The eigenvalues are -obtained from `vaspout.h5`, and their occupations are calculated based on the -temperature and Fermi level specified through the command options. +#### `velph transport plot eigenvalues` + +The following command opens a graphical window that displays eigenvalues in the Brillouin zone with non-zero and non-one occupations. These eigenvalues are obtained from `vaspout.h5`, and their occupations are computed based on the temperature and Fermi level specified through the command options. ```bash % velph transport plot eigenvalues @@ -294,6 +296,15 @@ No eigenvalues to plot. % velph transport plot eigenvalues --mu 4 ``` +This subcommand requires pre-calculated eigenvalues, Fermi levels, and input +parameters such as temperatures. However, electron-phonon calculation results +are not necessary. If the goal is to visualize Fermi surface pockets on a +k-point grid, it is recommended to run the electron-phonon calculation using +`ELPH_SCATTERING_APPROX=CRTA` to generate the required `vaspout.h5` file +efficiently. + +#### `velph transport plot selfenergy` + The following command opens a graphical window that displays Fan self-energies. ```bash diff --git a/src/phelel/velph/cli/transport/plot/__init__.py b/src/phelel/velph/cli/transport/plot/__init__.py index cbf97ab..9720018 100644 --- a/src/phelel/velph/cli/transport/plot/__init__.py +++ b/src/phelel/velph/cli/transport/plot/__init__.py @@ -114,13 +114,6 @@ def cmd_plot_transport(vaspout_filename: str, save_plot: bool): default=None, help=("Index of temperature. (tid: int, default=None)"), ) -@click.option( - "--nid", - nargs=1, - type=int, - default=None, - help=("Index of N. (nid: int, default=None)"), -) @click.help_option("-h", "--help") def cmd_plot_eigenvalues( vaspout_filename: str, @@ -128,7 +121,6 @@ def cmd_plot_eigenvalues( cutoff_occupancy: float, mu: Optional[float], tid: Optional[int], - nid: Optional[int], ): """Show eigenvalues in transports.""" args = _get_f_h5py_and_plot_filename( From 1f89249c4f8899df14dce3a01373e58b48c0113c Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 10 Jan 2025 10:50:22 +0900 Subject: [PATCH 6/9] Update documentation --- doc/velph-command.md | 66 ++++++++++++++++ doc/velph-subcommands.md | 157 +++++++++++++++++++++------------------ 2 files changed, 149 insertions(+), 74 deletions(-) diff --git a/doc/velph-command.md b/doc/velph-command.md index bea594b..d87fc75 100644 --- a/doc/velph-command.md +++ b/doc/velph-command.md @@ -20,6 +20,21 @@ and calculate derivatives of the local potential and PAW strengths with respect to atomic displacement, resulting in the `phelel_params.hdf5` file. Most of the `velph` subcommands are explained in {ref}`velph_subcommands`. +A typical workflow of velph subcommands for transport property calculation is +illustrated below. + +```{mermaid} +graph LR +A[velph-init] --> B[velph-relax] +B --> C[velph-init] +C --> D[velph-nac] +C --> E[velph-el_bands] +F[velph-phelel] +D --> F +E --> F +F --> G[velph-transport] +``` + A list of supported subcommands is displayed by typing: ```bash @@ -46,6 +61,57 @@ Commands: transport Choose transport options. ``` +In the following example, two `velph init` command operations generate two +different directories. The first operation performs crystal structure relaxation +in the `relax` directory. The second operation, using the relaxed crystal +structure, carries out additional calculations required for electron-phonon +interactions in the `calc` directory. Details about `velph-tmpl.toml` are +described in {ref}`velph_init_template`. + +```bash +% ls +POSCAR-unitcell POTCAR velph-tmpl.toml +% velph init --template-toml velph-tmpl.toml POSCAR-unitcell relax +... +% cd relax +% velph relax generate +... +# Run VASP relaxation calculation +... +% cd .. +% ls +POSCAR-unitcell POTCAR relax/ velph-tmpl.toml +% velph init --template-toml velph-tmpl.toml `ls relax/relax/iter*/CONTCAR|tail -n 1` calc +... +% cd calc +% ls +POTCAR velph.toml +% velph nac generate +VASP input files were made in "nac". +% ls +POTCAR nac/ velph.toml +... +# Run NAC calculation +... +% velph phelel init +Found "nac" directory. Read NAC params. +"phelel/phelel_disp.yaml" was generated. +VASP input files will be generated by "velph phelel generate". +% velph phelel generate +VASP input files were generated in "phelel/disp-000". +VASP input files were generated in "phelel/disp-001". +VASP input files were generated in "phelel/disp-002". +VASP input files were generated in "phelel/disp-003". +VASP input files were generated in "phelel/disp-004". +% ls +POTCAR nac/ phelel/ velph.toml +% velph phelel init +Found "nac" directory. Read NAC params. +"phelel/phelel_disp.yaml" was generated. +VASP input files will be generated by "velph phelel generate". +... +``` + (velph_hints)= ## `velph hints` diff --git a/doc/velph-subcommands.md b/doc/velph-subcommands.md index 8fce38b..ca7a0f6 100644 --- a/doc/velph-subcommands.md +++ b/doc/velph-subcommands.md @@ -9,80 +9,6 @@ The following subcommands must be executed in the directory containing the properly organized relative to the current directory where `velph.toml` is located. -A typical workflow of velph subcommands for transport property calculation is -illustrated below. - -```{mermaid} -graph LR -A[velph-init] --> B[velph-relax] -B --> C[velph-init] -C --> D[velph-nac] -C --> E[velph-el_bands] -F[velph-phelel] -D --> F -E --> F -F --> G[velph-transport] -``` - -In the following example, two `velph init` command operations generate two -different directories. The first operation performs crystal structure relaxation -in the `relax` directory. The second operation, using the relaxed crystal -structure, carries out additional calculations required for electron-phonon -interactions in the `calc` directory. Details about `velph-tmpl.toml` are -described in {ref}`velph_init_template`. - -```bash -% ls -POSCAR-unitcell POTCAR velph-tmpl.toml -% velph init --template-toml velph-tmpl.toml POSCAR-unitcell relax -... -% cd relax -% velph relax generate -... -# Run VASP relaxation calculation -... -% cd .. -% ls -POSCAR-unitcell POTCAR relax/ velph-tmpl.toml -% velph init --template-toml velph-tmpl.toml `ls relax/relax/iter*/CONTCAR|tail -n 1` calc -... -% cd calc -% ls -POTCAR velph.toml -% velph nac generate -VASP input files were made in "nac". -% ls -POTCAR nac/ velph.toml -... -# Run NAC calculation -... -% velph phelel init -Found "nac" directory. Read NAC params. -"phelel/phelel_disp.yaml" was generated. -VASP input files will be generated by "velph phelel generate". -% velph phelel generate -VASP input files were generated in "phelel/disp-000". -VASP input files were generated in "phelel/disp-001". -VASP input files were generated in "phelel/disp-002". -VASP input files were generated in "phelel/disp-003". -VASP input files were generated in "phelel/disp-004". -% ls -POTCAR nac/ phelel/ velph.toml -% velph phelel init -Found "nac" directory. Read NAC params. -"phelel/phelel_disp.yaml" was generated. -VASP input files will be generated by "velph phelel generate". -... -``` - -## `velph init` - -See {ref}`velph_init`. - -## `velph hints` - -See {ref}`velph_hints`. - ## `velph relax` It is recommended to create a project directory secific for relaxation @@ -338,12 +264,95 @@ Phonon band structure plot was saved in "ph_bands/ph_bands.pdf". ## `velph phono3py` +This subcommand facilitates lattice thermal conductivity calculations using the +phono3py code. To use this subcommand, the `velph.toml` file must include a +`[phono3py]` section configured as shown below: + +```toml +[phono3py] +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +``` + ### `velph phono3py init` +The `phono3py_disp.yaml` file, which contains displacement information, is +generated by this subcommand. It is recommended to use the `--rd` option with a +sufficiently large argument to create supercells with random directional +displacements. Note that it is not necessary to calculate forces for all +supercells to ultimately generate the `phono3py_params.yaml` file. + +```bash +% velph phono3py init --rd 2000 +Displacement distance: 0.03 +Number of displacements: 2000 +Found "nac" directory. Read NAC params. +"phono3py/phono3py_disp.yaml" was generated. +VASP input files will be generated by "velph phono3py generate". +``` + ### `velph phono3py generate` +VASP input files for supercell force calculations are generated, with each +directory corresponding to a specific supercell displacement configuration. The +perfect supercell (i.e., without displacements) is labeled as `disp-00000`. + +For example: + +```bash +% velph phono3py generate +VASP input files were generated in "phono3py/disp-0000". +VASP input files were generated in "phono3py/disp-0001". +... +``` + +After completing supercell force calculations using the VASP code, the +`phono3py_params.yaml` file can be created with the following command: + +```bash +% phono3py --cfz phono3py/disp-00000/vasprun.xml --cf3 phono3py/disp-{00001..00120}/vasprun.xml --sp +``` + +In this step, forces from 120 supercells are collected, and the corresponding +data are stored in the `phono3py_params.yaml` file. + ## `velph phonopy` +The purpose of this subcommand is nearly identical to that of `velph phono3py`. + +```toml +[phonopy] +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +``` + ### `velph phonopy init` +```bash +% velph phonopy init --rd 10 +Displacement distance: 0.03 +Number of displacements: 10 +Found "nac" directory. Read NAC params. +"phonopy/phonopy_disp.yaml" was generated. +VASP input files will be generated by "velph phonopy generate". +``` + ### `velph phonopy generate` + +```bash +% velph phonopy generate +VASP input files were generated in "phonopy/disp-000". +VASP input files were generated in "phonopy/disp-001". +... +``` + +After completing supercell force calculations using the VASP code, the +`phonopy_params.yaml` file can be created with the following command: + +```bash +% phonopy --fz phonopy/disp-{00000..00010}/vasprun.xml --sp +``` From 2d801effdeb6092e2c09be851ee67b2ee12ab4b8 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 10 Jan 2025 13:57:02 +0900 Subject: [PATCH 7/9] Update documentation --- doc/index.md | 1 + doc/velph-init-template.md | 115 ++++++--------------- doc/velph-subcommands.md | 36 +++++-- doc/velph-toml.md | 166 +++++++++++++++++++++++++++++++ test/velph/__init__.py | 1 - test/velph/utils/__init__.py | 1 - test/velph/workflows/__init__.py | 1 - 7 files changed, 229 insertions(+), 92 deletions(-) create mode 100644 doc/velph-toml.md delete mode 100644 test/velph/__init__.py delete mode 100644 test/velph/utils/__init__.py delete mode 100644 test/velph/workflows/__init__.py diff --git a/doc/index.md b/doc/index.md index 2c271c7..3c72584 100644 --- a/doc/index.md +++ b/doc/index.md @@ -31,6 +31,7 @@ install workflow phelel-command velph-command +velph-toml velph-init velph-init-template velph-subcommands diff --git a/doc/velph-init-template.md b/doc/velph-init-template.md index ea81b7a..83e3b85 100644 --- a/doc/velph-init-template.md +++ b/doc/velph-init-template.md @@ -1,19 +1,23 @@ (velph_init_template)= # `velph init` template -`velph init` is the command to prepare `velph.toml`. Without specifying a -velph-toml-template, the default template is used. Custom template can be -specified as follows: +The `velph init` command is used to prepare the `velph.toml` file. If no custom +template is specified, a default template is applied. To specify a custom +template, use the following command: +```bash +% velph init CELL_FILENAME PROJECT_FOLDER --template-toml velph-tmpl.toml [OPTIONS] ``` -% velph init [OPTIONS] CELL_FILENAME PROJECT_FOLDER --template-toml velph-tmpl.toml -``` -The `velph-tmpl.toml` (arbitrary file name) is almost like the `velph.toml` -file. It means that the `velph-tmpl.toml` may be created modifying -`velph.toml`. The sections that exist only in the `velph-tmpl.toml` but not in -`velph.toml` is `[init.options]`. This can be used as alternatives of command -options of `velph-init`, e.g., +The `velph-tmpl.toml` file (which can have any file name) is similar to the +`velph.toml` file. It can be created by modifying an existing `velph.toml`. +However, a key difference is that `velph-tmpl.toml` may include an +`[init.options]` section that is not present in `velph.toml`. This section +allows you to define default values as substitutes for command-line options used +with `velph init`, as described in the next section. + +(velph_init_template_init_options)= +## `[init.options]` ```toml [init.options] @@ -22,83 +26,30 @@ kspacing_dense = 0.1 max_num_atoms = 120 ``` -These `[init.options]` keywords can be found along with the list of the command -options by +The `[init.options]` keywords correspond to command-line options for `velph +init`. To view a complete list of available options, use: -``` +```bash % velph init --help ``` -## Settings in sections of `velph.toml` - -Note that the same can be applied to `velph-tmpl.toml`. - -### Default INCAR settings - -The default INCAR settins are written in `[vasp.incar]`. These settings are -overwritten by `[vasp.CALC_TYPE.incar]` (`CALC_TYPE` can be `phelel`, `relax`, -`nac`, `transport`, `phono3py`, `phono3py.phonon`, etc). - -### Scheduler settings +(velph_init_template_incar)= +## `[vasp.incar]` -The parameters used for generating the job submission script are specified as -strings in `[scheduler]`. If `[vasp.CALC_TYPE.scheduler]` is -specified, `[scheduler]` settings are overwritten by the settings for -`[vasp.CALC_TYPE]`. The content in this section operates through [Python string -formatting](https://docs.python.org/3/library/stdtypes.html#str.format), using -replacement fields named after keyword arguments. Each parameter line in the -`[scheduler]` section is treated as a keyword argument, which is then inserted -into the string format. - -In the `[scheduler]` section, the parameters `scheduler_name` and -`scheduler_template` have special roles: - -- `scheduler_name`: Specifies the template type, with options `slurm`, `sge`, or - `custom`. For `slurm` and `sge`, the template string (i.e., - `scheduler_template`) is - [hard-coded](https://github.com/phonopy/phelel/blob/develop/src/phelel/velph/utils/scheduler.py). - If `custom` is selected, the string provided by `scheduler_template` is used, - into which the parameters are inserted. -- `scheduler_template`: The string template where parameters defined in this - section are inserted. - -An example is shown below. +The base INCAR settings are defined in the `[vasp.incar]` section. These +settings can be overridden by the `[vasp.CALC_TYPE.incar]` section if existed, +where `CALC_TYPE` could be `phelel`, `relax`, `nac`, `transport`, `phono3py`, +`phono3py.phonon`, etc. For example, consider the following configuration: ```toml -[scheduler] -scheduler_name = "sge" -job_name = "PbTe" -mpirun_command = "mpirun" -vasp_binary = "/usr/local/cluster-1/bin/vasp_std" -pe = "vienna 32" -prepend_text = ''' -source /opt/intel/oneapi/setvars.sh --config="/home/togo/.oneapi-config" -''' - -... -[vasp.phelel.scheduler] -pe = "paris 24" - -... -[vasp.phonopy.scheduler] -scheduler_template = '''#!/bin/bash -#QSUB2 core 192 -#QSUB2 mpi 192 -#QSUB2 smp 1 -#QSUB2 wtime 48:00:00 -#PBS -N {job_name} -cd $PBS_O_WORKDIR - -{prepend_text} -{mpirun_command} {vasp_binary} | tee vasp_output -{append_text} -''' -job_name = "PbTe" -mpirun_command = "mpijob" -vasp_binary = "/usr/local/cluster-2/bin/vasp_std" -prepend_text = ''' -. /etc/profile.d/modules.sh -module load inteloneapi22u3 -''' -append_text = "" +[vasp.incar] +encut = 400 +ncore = 4 +gga = "PS" ``` + +In this case, the `[vasp.phelel.incar]` section in `velph.toml` is initially +populated with these base settings. And then, the default parameters specific to +the `phelel` calculation, as well as any settings defined in the +`[vasp.phelel.incar]` section of the template, will override these +configurations as needed. diff --git a/doc/velph-subcommands.md b/doc/velph-subcommands.md index ca7a0f6..3ed9433 100644 --- a/doc/velph-subcommands.md +++ b/doc/velph-subcommands.md @@ -100,6 +100,7 @@ above the Fermi energy in eV, respectively. Electronic band structure plot was saved in "el_bands/el_bands.pdf". ``` +(velph_phelel_subcommand)= ## `velph phelel` This subcommand calculates the derivatives of local potentials and PAW strengths @@ -113,6 +114,17 @@ The subcommands below should be executed in the following order: 3. {ref}`velph_phelel_differentiate_subcommand` 4. {ref}`velph_phelel_phonopy_subcommand` (optional) +Certain configurations for phelel can be specified directly in the +`velph.toml` file: + +```toml +[phelel] +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +``` + (velph_phelel_init_subcommand)= ### `velph phelel init` @@ -212,7 +224,10 @@ properties in `vaspout.h5`. #### `velph transport plot eigenvalues` -The following command opens a graphical window that displays eigenvalues in the Brillouin zone with non-zero and non-one occupations. These eigenvalues are obtained from `vaspout.h5`, and their occupations are computed based on the temperature and Fermi level specified through the command options. +The following command opens a graphical window that displays eigenvalues in the +Brillouin zone with non-zero and non-one occupations. These eigenvalues are +obtained from `vaspout.h5`, and their occupations are computed based on the +temperature and Fermi level specified through the command options. ```bash % velph transport plot eigenvalues @@ -262,11 +277,13 @@ The phonon band structure is plotted and saved in the `ph_bands.pdf` file. Phonon band structure plot was saved in "ph_bands/ph_bands.pdf". ``` +(velph_phono3py_subcommand)= ## `velph phono3py` -This subcommand facilitates lattice thermal conductivity calculations using the -phono3py code. To use this subcommand, the `velph.toml` file must include a -`[phono3py]` section configured as shown below: +This subcommand facilitates anharmonic phonon calculation including lattice +thermal conductivity calculation using the phono3py code. Certain configurations +for supercell and displacements can be specified directly in the `velph.toml` +file: ```toml [phono3py] @@ -312,15 +329,19 @@ After completing supercell force calculations using the VASP code, the `phono3py_params.yaml` file can be created with the following command: ```bash -% phono3py --cfz phono3py/disp-00000/vasprun.xml --cf3 phono3py/disp-{00001..00120}/vasprun.xml --sp +% cd phono3py +% phono3py --cfz disp-00000/vasprun.xml --cf3 disp-{00001..00120}/vasprun.xml --sp ``` In this step, forces from 120 supercells are collected, and the corresponding data are stored in the `phono3py_params.yaml` file. +(velph_phonopy_subcommand)= ## `velph phonopy` -The purpose of this subcommand is nearly identical to that of `velph phono3py`. +This subcommand facilitates phonon calculation using the phonopy code. Certain +configurations for supercell and displacements can be specified directly in the +`velph.toml` file: ```toml [phonopy] @@ -354,5 +375,6 @@ After completing supercell force calculations using the VASP code, the `phonopy_params.yaml` file can be created with the following command: ```bash -% phonopy --fz phonopy/disp-{00000..00010}/vasprun.xml --sp +% cd phonopy +% phonopy --fz disp-{00000..00010}/vasprun.xml --sp ``` diff --git a/doc/velph-toml.md b/doc/velph-toml.md new file mode 100644 index 0000000..cf616f2 --- /dev/null +++ b/doc/velph-toml.md @@ -0,0 +1,166 @@ +(velph_toml)= +# `velph.toml` file + +The `velph.toml` file contains the settings required to perform electron-phonon +interaction calculations using the phelel and VASP codes. Ideally, once created, +it should remain unchanged throughout the duration of a calculation project for +the reproducibility. + +There are several ways to create a `velph.toml` file: + +- Using the default template (see {ref}`velph_init` command) +- Using a user-defined template (`velph init --template-toml`), as explained in + {ref}`velph_init_template` +- Copying and modifying an existing `velph.toml` file + +Regardless of how it is created, the `velph.toml` file is used in conjunction +with the `velph` command to generate VASP input files and operate other tools, +based on the information it contains. This page provides guidance on how to +interpret and effectively use the contents of `velph.toml`. + +## `[phelel]` + +This section contains information specific to the phelel code and must be +included to execute the {ref}`velph_phelel_subcommand` subcommand. + +```toml +[phelel] +version = "0.6.5" +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +fft_mesh = [30, 30, 30] +``` + +## `[vasp]` + +There are sub-sections for respective specific calculations: + +- `[vasp.phelel]` +- `[vasp.relax]` +- `[vasp.nac]` +- `[vasp.el_bands]` +- `[vasp.ph_bands]` +- `[vasp.phono3py]` +- `[vasp.phonopy]` + +In each section, VASP calculation and job script settings can be written, e.g., + +```toml +[vasp.phelel.incar] +lwap = true +isym = 0 +kpar = 2 +ismear = 0 +sigma = 0.01 +ediff = 1e-08 +encut = 400 +prec = "accurate" +lreal = false +lwave = false +lcharg = false +ncore = 4 +gga = "PS" +[vasp.phelel.kpoints] +mesh = [4, 4, 4] +shift = [0.500000, 0.500000, 0.500000] +[vasp.phelel.scheduler] +pe = "mpi* 48" +``` + +When `velph.toml` is generated from a template using the `velph init +--template-toml` command, not all information needs to be explicitly specified. +Default settings for each calculation can automatically populate the relevant +sections, leveraging the VASP INCAR parameters defined in the {ref}`[vasp.incar] +` section of the template. + +## `[scheduler]` : Job script setting + +The parameters used for generating the job submission script are specified as +strings in `[scheduler]`. If `[vasp.CALC_TYPE.scheduler]` is +specified, `[scheduler]` settings are overwritten by the settings for +`[vasp.CALC_TYPE]`. The content in this section operates through [Python string +formatting](https://docs.python.org/3/library/stdtypes.html#str.format), using +replacement fields named after keyword arguments. Each parameter line in the +`[scheduler]` section is treated as a keyword argument, which is then inserted +into the string format. + +In the `[scheduler]` section, the parameters `scheduler_name` and +`scheduler_template` have special roles: + +- `scheduler_name`: Specifies the template type, with options `slurm`, `sge`, or + `custom`. For `slurm` and `sge`, the template string (i.e., + `scheduler_template`) is + [hard-coded](https://github.com/phonopy/phelel/blob/develop/src/phelel/velph/utils/scheduler.py). + If `custom` is selected, the string provided by `scheduler_template` is used, + into which the parameters are inserted. +- `scheduler_template`: The string template where parameters defined in this + section are inserted. + +An example is shown below. + +```toml +[scheduler] +scheduler_name = "sge" +job_name = "PbTe" +mpirun_command = "mpirun" +vasp_binary = "/usr/local/cluster-1/bin/vasp_std" +pe = "vienna 32" +prepend_text = ''' +source /opt/intel/oneapi/setvars.sh --config="/home/togo/.oneapi-config" +''' + +... +[vasp.phelel.scheduler] +scheduler_template = '''#!/bin/bash +#QSUB2 core 192 +#QSUB2 mpi 192 +#QSUB2 smp 1 +#QSUB2 wtime 48:00:00 +#PBS -N {job_name} +cd $PBS_O_WORKDIR + +{prepend_text} +{mpirun_command} {vasp_binary} | tee vasp_output +{append_text} +''' +job_name = "PbTe" +mpirun_command = "mpijob" +vasp_binary = "/usr/local/cluster-2/bin/vasp_std" +prepend_text = ''' +. /etc/profile.d/modules.sh +module load inteloneapi22u3 +''' +append_text = "" + +... +[vasp.phono3py.scheduler] +pe = "paris 24" +``` + +## `[phono3py]` + +This section contains information specific to the phono3py code and must be +included to execute the {ref}`velph_phono3py_subcommand` subcommand. + +```toml +[phono3py] +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +``` + +## `[phonopy]` + +This section contains information specific to the phono3py code and must be +included to execute the {ref}`velph_phonopy_subcommand` subcommand. + +```toml +[phonopy] +supercell_dimension = [2, 2, 2] +amplitude = 0.03 +diagonal = false +plusminus = true +``` diff --git a/test/velph/__init__.py b/test/velph/__init__.py deleted file mode 100644 index fa61198..0000000 --- a/test/velph/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""tests module.""" diff --git a/test/velph/utils/__init__.py b/test/velph/utils/__init__.py deleted file mode 100644 index ada8898..0000000 --- a/test/velph/utils/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""tests utils module.""" diff --git a/test/velph/workflows/__init__.py b/test/velph/workflows/__init__.py deleted file mode 100644 index 706c00d..0000000 --- a/test/velph/workflows/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""test workflows module.""" From c97d0ce98ad240f530eaf0cf992a7bb1cdd2e568 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 10 Jan 2025 15:06:42 +0900 Subject: [PATCH 8/9] Imporove velph-transport-plot interface --- doc/velph-subcommands.md | 17 ++-- .../velph/cli/transport/plot/__init__.py | 33 +++++--- .../cli/transport/plot/plot_eigenvalues.py | 11 +-- .../cli/transport/plot/plot_selfenergy.py | 68 ++++++++++------ .../cli/transport/plot/plot_transport.py | 78 ++++++++++++------- 5 files changed, 130 insertions(+), 77 deletions(-) diff --git a/doc/velph-subcommands.md b/doc/velph-subcommands.md index 3ed9433..8798a1b 100644 --- a/doc/velph-subcommands.md +++ b/doc/velph-subcommands.md @@ -216,7 +216,8 @@ VASP input files were generated in "transport". #### `velph transport plot transport` The following command opens a graphical window that contains plots of transport -properties in `vaspout.h5`. +properties. By default, it uses the `transport/vaspout.h5` file unless a +different file is specified as the first argument. ```bash % velph transport plot transport @@ -224,10 +225,12 @@ properties in `vaspout.h5`. #### `velph transport plot eigenvalues` -The following command opens a graphical window that displays eigenvalues in the -Brillouin zone with non-zero and non-one occupations. These eigenvalues are -obtained from `vaspout.h5`, and their occupations are computed based on the -temperature and Fermi level specified through the command options. +The following command opens a graphical window to display eigenvalues in the +Brillouin zone with occupations that are neither zero nor one. By default, these +eigenvalues are extracted from the `transport/vaspout.h5` file unless a +different file is specified as the first argument. Their occupations are +determined based on the temperature and Fermi level set through the command-line +options. ```bash % velph transport plot eigenvalues @@ -246,7 +249,9 @@ efficiently. #### `velph transport plot selfenergy` -The following command opens a graphical window that displays Fan self-energies. +The following command opens a graphical window to display Fan self-energies. By +default, it uses the `transport/vaspout.h5` file unless a different file is +specified as the first argument. ```bash % velph transport plot selfenergy diff --git a/src/phelel/velph/cli/transport/plot/__init__.py b/src/phelel/velph/cli/transport/plot/__init__.py index 9720018..92bc14b 100644 --- a/src/phelel/velph/cli/transport/plot/__init__.py +++ b/src/phelel/velph/cli/transport/plot/__init__.py @@ -126,14 +126,25 @@ def cmd_plot_eigenvalues( args = _get_f_h5py_and_plot_filename( "transport", vaspout_filename=pathlib.Path(vaspout_filename) ) - if args[0] is not None: - plot_eigenvalues( - args[0], - tid=tid, - temperature=temperature, - cutoff_occupancy=cutoff_occupancy, - mu=mu, - ) + if args[0] is None: + return + + retvals = plot_eigenvalues( + args[0], + tid=tid, + temperature=temperature, + cutoff_occupancy=cutoff_occupancy, + mu=mu, + ) + + if retvals is not None: + with open("transport/bz.dat", "w") as w: + for i, (e, wt, rk) in enumerate(zip(*retvals)): + print( + f"{i + 1} {e:.6f} {wt:.6f} [{rk[0]:.6f} {rk[1]:.6f} {rk[2]:.6f}]", + file=w, + ) + click.echo('"transport/bz.dat" file was created.') def _get_f_h5py_and_plot_filename( @@ -146,11 +157,13 @@ def _get_f_h5py_and_plot_filename( click.echo("Please specify vaspout.h5 file path.") return None, None + dir_name = vaspout_filename.parent + if plot_filename is None: - _plot_filename = vaspout_filename.parent / f"{property_name}.pdf" + _plot_filename = dir_name / f"{property_name}.pdf" else: _plot_filename = plot_filename f_h5py = h5py.File(vaspout_filename) - return f_h5py, _plot_filename + return f_h5py, _plot_filename, dir_name diff --git a/src/phelel/velph/cli/transport/plot/plot_eigenvalues.py b/src/phelel/velph/cli/transport/plot/plot_eigenvalues.py index 036445d..cbd3fac 100644 --- a/src/phelel/velph/cli/transport/plot/plot_eigenvalues.py +++ b/src/phelel/velph/cli/transport/plot/plot_eigenvalues.py @@ -36,7 +36,7 @@ def plot_eigenvalues( cutoff_occupancy: float = 1e-2, mu: Optional[float] = None, time_reversal: bool = True, -): +) -> Optional[tuple[np.ndarray, np.ndarray, np.ndarray]]: """Show eigenvalues, occupation, k-points and Fermi-Dirac distribution. Parameters @@ -114,13 +114,6 @@ def plot_eigenvalues( all_weights = np.array(all_weights) all_eigenvals = np.array(all_eigenvals) - with open("bz.dat", "w") as w: - for i, (e, wt, rk) in enumerate(zip(all_eigenvals, all_weights, all_kpoints)): - print( - f"{i + 1} {e:.6f} {wt:.6f} [{rk[0]:.6f} {rk[1]:.6f} {rk[2]:.6f}]", - file=w, - ) - _plot_eigenvalues_in_BZ( all_kpoints, all_weights, @@ -128,6 +121,8 @@ def plot_eigenvalues( title=f"mu={_mu:.6f} eV, temperature={_temperature:.1f} K", ) + return all_eigenvals, all_weights, all_kpoints + def _plot_eigenvalues_in_BZ( data: np.ndarray, diff --git a/src/phelel/velph/cli/transport/plot/plot_selfenergy.py b/src/phelel/velph/cli/transport/plot/plot_selfenergy.py index 9ffa473..03e723c 100644 --- a/src/phelel/velph/cli/transport/plot/plot_selfenergy.py +++ b/src/phelel/velph/cli/transport/plot/plot_selfenergy.py @@ -2,11 +2,18 @@ from __future__ import annotations +import pathlib + import click import h5py -def plot_selfenergy(f_h5py: h5py.File, plot_filename: str, save_plot: bool = False): +def plot_selfenergy( + f_h5py: h5py.File, + plot_filename: str, + dir_name: pathlib.Path, + save_plot: bool = False, +): """Plot imaginary part of self-energies. Number of "self_energy_*" is @@ -37,11 +44,18 @@ def plot_selfenergy(f_h5py: h5py.File, plot_filename: str, save_plot: bool = Fal nrows = len(selfens) // 2 fig, axs = plt.subplots(nrows, 2, figsize=(8, 4 * nrows), squeeze=True) + lines = [] for i in range(len(selfens)): selfen = selfens[i + 1] - _show(selfen, i + 1) + lines += _get_text_lines(selfen, i + 1) _plot(axs[i], selfen) + with open(dir_name / "selfenergy.txt", "w") as w: + print("\n".join(lines), file=w) + click.echo( + f'Summary of data structure was saved in "{dir_name / "selfenergy.txt"}".' + ) + plt.tight_layout() if save_plot: plt.rcParams["pdf.fonttype"] = 42 @@ -62,7 +76,7 @@ def _plot(ax, selfen): ) -def _show(selfen: h5py.Group, index: int): +def _get_text_lines(selfen: h5py.Group, index: int) -> list[str]: """Show self-energy properties. ['band_start', 'band_stop', 'bks_idx', 'carrier_per_cell', @@ -71,27 +85,31 @@ def _show(selfen: h5py.Group, index: int): 'selfen_dw', 'selfen_fan', 'static', 'tetrahedron'] """ - print(f"- parameters: # {index}") - print( - " scattering_approximation:", - selfen["scattering_approximation"][()].decode("utf-8"), - ) - print(f" static_approximation: {bool(selfen['static'][()])}") - print(f" use_tetrahedron_method: {bool(selfen['tetrahedron'][()])}") + lines = [ + f"- parameters: # {index}", + " scattering_approximation: {}".format( + selfen["scattering_approximation"][()].decode("utf-8") + ), + f" static_approximation: {bool(selfen['static'][()])}", + f" use_tetrahedron_method: {bool(selfen['tetrahedron'][()])}", + ] if not selfen["tetrahedron"][()]: - print(f" smearing_width: {selfen['delta'][()]}") - print( - f" band_start_stop: [{selfen['band_start'][()]}, {selfen['band_stop'][()]}]" - ) - print(f" nbands: {selfen['nbands'][()]}") - print(f" nbands_sum: {selfen['nbands_sum'][()]}") - print(f" nw: {selfen['nw'][()]}") - print(" temperatures:") + lines.append(f" smearing_width: {selfen['delta'][()]}") + lines += [ + f" band_start_stop: [{selfen['band_start'][()]}, {selfen['band_stop'][()]}]", + f" nbands: {selfen['nbands'][()]}", + f" nbands_sum: {selfen['nbands_sum'][()]}", + f" nw: {selfen['nw'][()]}", + " temperatures:", + ] for i, t in enumerate(selfen["temps"]): - print(f" - {t} # {i + 1}") - - print(" data_array_shapes:") - print(f" carrier_per_cell: {list(selfen['carrier_per_cell'].shape)}") - print(f" Fan_self_energy: {list(selfen['selfen_fan'].shape)}") - print(f" sampling_energy_points: {list(selfen['energies'].shape)}") - print(f" Fermi_energies: {list(selfen['efermi'].shape)}") + lines.append(f" - {t} # {i + 1}") + + lines += [ + " data_array_shapes:", + f" carrier_per_cell: {list(selfen['carrier_per_cell'].shape)}", + f" Fan_self_energy: {list(selfen['selfen_fan'].shape)}", + f" sampling_energy_points: {list(selfen['energies'].shape)}", + f" Fermi_energies: {list(selfen['efermi'].shape)}", + ] + return lines diff --git a/src/phelel/velph/cli/transport/plot/plot_transport.py b/src/phelel/velph/cli/transport/plot/plot_transport.py index 24ccb0d..a45071e 100644 --- a/src/phelel/velph/cli/transport/plot/plot_transport.py +++ b/src/phelel/velph/cli/transport/plot/plot_transport.py @@ -2,12 +2,19 @@ from __future__ import annotations +import pathlib + import click import h5py import numpy as np -def plot_transport(f_h5py: h5py.File, plot_filename: str, save_plot: bool = False): +def plot_transport( + f_h5py: h5py.File, + plot_filename: str, + dir_name: pathlib.Path, + save_plot: bool = False, +): """Plot transport properties. Number of "transport_*" is @@ -46,8 +53,14 @@ def plot_transport(f_h5py: h5py.File, plot_filename: str, save_plot: bool = Fals for n in range(n_transport) ] + lines = [] for i, transport in enumerate(transports): - _show(transport, i + 1) + lines += _show(transport, i + 1) + with open(dir_name / "transport.txt", "w") as w: + print("\n".join(lines), file=w) + click.echo( + f'Summary of data structure was saved in "{dir_name / "transport.txt"}".' + ) n_props = len(property_names) _, axs = plt.subplots( @@ -65,6 +78,7 @@ def plot_transport(f_h5py: h5py.File, plot_filename: str, save_plot: bool = Fals i, transport["id_idx"][:], last_transport_idx, + transport_dir_name=dir_name, ) plt.tight_layout() @@ -84,6 +98,7 @@ def _plot( index: int, transport_idx: np.ndarray, last_transport_idx: np.ndarray, + transport_dir_name: pathlib.Path = pathlib.Path("transport"), ): """Plot transport properties. @@ -93,7 +108,7 @@ def _plot( import matplotlib.ticker as ticker temps = transport["temps"][:] - dat_filename = f"transport-{index + 1}.dat" + dat_filename = transport_dir_name / f"transport-{index + 1}.dat" properties = [] label_property_names = [] @@ -109,20 +124,23 @@ def _plot( else: properties.append([np.trace(tensor) / 3 for tensor in transport[key][:]]) - with open(dat_filename, "w") as w: - print("# temperature", *label_property_names, file=w) - for temp, props in zip(temps, np.transpose(properties)): - print(temp, *props, file=w) - click.echo(f'Transport data {index + 1} was saved in "{dat_filename}".') - names = [name.decode("utf-8") for name in transport["id_name"][:]] labels = [] - click.echo([(name, int(i)) for name, i in zip(names, transport_idx)]) + click.echo( + f"{index + 1}. " + + " / ".join([f"{name} {int(i)}" for name, i in zip(names, transport_idx)]) + ) for i, name in enumerate(names): if last_transport_idx[i] > 1: if name == "selfen_approx": labels.append(transport["scattering_approximation"][()].decode("utf-8")) + with open(dat_filename, "w") as w: + print("# temperature", *label_property_names, file=w) + for temp, props in zip(temps, np.transpose(properties)): + print(temp, *props, file=w) + click.echo(f'Transport data {index + 1} was saved in "{dat_filename}".') + for i, label_property in enumerate(label_property_names): if label_property == "e_conductivity": axs[i].semilogy(temps, properties[i], ".-") @@ -143,7 +161,7 @@ def _plot( ax.set_yticklabels([]) -def _show(transport: h5py.Group, index: int): +def _show(transport: h5py.Group, index: int) -> list[str]: """Show transport properties. ['cell_volume', 'dfermi_tol', 'e_conductivity', 'e_t_conductivity', 'emax', @@ -152,13 +170,15 @@ def _show(transport: h5py.Group, index: int): 'tau_average', 'temperature', 'transport_function'] """ - print(f"- parameters: # {index}") + lines = [f"- parameters: # {index}"] for i, temp in enumerate(transport["temps"][:]): - print(f" - temperature: {temp}") - print( - " scattering_approximation:", - transport["scattering_approximation"][()].decode("utf-8"), - ) + lines += [ + f" - temperature: {temp}", + " scattering_approximation: {}".format( + transport["scattering_approximation"][()].decode("utf-8") + ), + ] + for key in ( "cell_volume", "dfermi_tol", @@ -166,12 +186,12 @@ def _show(transport: h5py.Group, index: int): "nedos", ): if isinstance(key, tuple): - print(f" {key[1]}: {transport[key[0]][()]}") + lines.append(f" {key[1]}: {transport[key[0]][()]}") else: - print(f" {key}: {transport[key][()]}") - print(f" static_approximation: {bool(transport['static'][()])}") + lines.append(f" {key}: {transport[key][()]}") + lines.append(f" static_approximation: {bool(transport['static'][()])}") - print(" data_scalar:") + lines.append(" data_scalar:") for key in ( ("emax", "emax_for_transport_function"), ("emin", "emin_for_transport_function"), @@ -182,11 +202,11 @@ def _show(transport: h5py.Group, index: int): "tau_average", ): if isinstance(key, tuple): - print(f" {key[1]}: {transport[key[0]][i]}") + lines.append(f" {key[1]}: {transport[key[0]][i]}") else: - print(f" {key}: {transport[key][i]}") + lines.append(f" {key}: {transport[key][i]}") - print(" data_array_diagonal:") + lines.append(" data_array_diagonal:") for key in ( "e_conductivity", "e_t_conductivity", @@ -195,18 +215,20 @@ def _show(transport: h5py.Group, index: int): "seebeck", ): v = transport[key][:].ravel() - print( + lines.append( 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:") + lines.append(" data_array_shapes:") for key in ( "energy", ("lab", "Onsager_coefficients"), "transport_function", ): if isinstance(key, tuple): - print(f" {key[1]}: {list(transport[key[0]][i].shape)}") + lines.append(f" {key[1]}: {list(transport[key[0]][i].shape)}") else: - print(f" {key}: {list(transport[key][i].shape)}") + lines.append(f" {key}: {list(transport[key][i].shape)}") + + return lines From 944b61a4196858c7c3ef10b6a80f8cbf77b3d059 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 10 Jan 2025 15:15:06 +0900 Subject: [PATCH 9/9] Set version 0.8.2 --- doc/changelog.md | 4 ++++ doc/conf.py | 2 +- src/phelel/version.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 0b7dee4..f48175b 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,10 @@ # Change Log +## Jan-10-2025: Version 0.8.2 + +- Collection of small updates of velph command + ## Jan-8-2025: Version 0.8.1 - Fix minor bugs in velph command diff --git a/doc/conf.py b/doc/conf.py index 98a7321..b602ac5 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,7 +11,7 @@ author = "Atsushi Togo" version = "0.8" -release = "0.8.1" +release = "0.8.2" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/src/phelel/version.py b/src/phelel/version.py index 2468b95..08a072b 100644 --- a/src/phelel/version.py +++ b/src/phelel/version.py @@ -1,3 +1,3 @@ """Version number.""" -__version__ = "0.8.1" +__version__ = "0.8.2"