Skip to content

Commit

Permalink
Imporove velph-transport-plot interface
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Jan 10, 2025
1 parent 2d801ef commit c97d0ce
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 77 deletions.
17 changes: 11 additions & 6 deletions doc/velph-subcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,21 @@ 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
```

#### `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
Expand All @@ -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
Expand Down
33 changes: 23 additions & 10 deletions src/phelel/velph/cli/transport/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
11 changes: 3 additions & 8 deletions src/phelel/velph/cli/transport/plot/plot_eigenvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,20 +114,15 @@ 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,
np.linalg.inv(cell.cell),
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,
Expand Down
68 changes: 43 additions & 25 deletions src/phelel/velph/cli/transport/plot/plot_selfenergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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
Loading

0 comments on commit c97d0ce

Please sign in to comment.