tbplas.Visualizer

class tbplas.Visualizer(echo_details: bool = False)

Class for quick data visualization.

_mpi_env

mpi parallel environment

Type:

‘MPIEnv’ instance

Notes

  1. Order of arguments

The arguments should follow:

data (x, y, z, u, v, …), figure settings (fig_name, fig_size, fig_dpi) model [optional], model settings [optional], axis settings (x_label, y_label, x_lim, y_lim) beautifier, arguments for low level matplotlib functions

__init__(echo_details: bool = False) None
Parameters:

echo_details – whether to output parallelization details

Methods

__init__([echo_details])

plot_bands(k_len, bands, k_idx, k_label[, ...])

Plot band structure. :param k_len: (num_kpt,) float64 array distance of k-path in reciprocal space :param bands: (num_kpt, num_band) float64 array energies corresponding to k_len :param k_idx: (num_hsk,) int32 array indices of highly-symmetric k-points in k_len :param k_label: (num_hsk,) labels of highly-symmetric k-points :param fig_name: file name of figure to save :param fig_size: width and height of the figure :param fig_dpi: resolution of figure :param x_label: label of x-axis :param y_label: label of y-axis :param beautifier: function for improving the plot :param color: line color :param linewidth: line width :param kwargs: parameters for plt.plot() :return: None.

plot_dos(energies, dos[, x_label, y_label])

Plot density of states. :param energies: (num_eng,) float64 array energy grids :param dos: (num_eng,) float64 array density of states :param x_label: label for x-axis :param y_label: label for y-axis :param kwargs: arguments for 'plot_xy' :return: None.

plot_phases(kb_array, phases[, fig_name, ...])

Plot evolution of Wannier function centers as function of kb. :param kb_array: (num_kb,) float64 array FRACTIONAL coordinates of the loop along b-axis :param phases: (num_kpt, num_occ) float64 array phases of WF centers :param fig_name: file name of figure :param fig_size: width and height of the figure :param fig_dpi: dpi of output figure :param scatter: whether to do scatter plot instead of line plot :param polar: whether to plot in polar coordinate system :param x_label: label for x-axis :param y_label: label for y-axis :param beautifier: function for improving the plot :param color: line color :param linewidth: line width :param kwargs: parameters for plt.plot() and plt.scatter() :return: None.

plot_scalar(x, y, z[, fig_name, fig_size, ...])

Plot 2d scalar field z = f(x, y). :param x: (num_data,) float64 array x-component of Cartesian coordinates of data points :param y: (num_data,) float64 array y-component of Cartesian coordinates of data points :param z: (num_data,) float64 array z-value of data points :param fig_name: image file name :param fig_size: width and height of the figure :param fig_dpi: dpi of output figure :param model: model with which the data will be plotted :param model_style: style of the model :param scatter: whether to plot the wave function as scatter :param site_size: size of the sites for scatter plot :param site_color: color of the sites, use colormap from z-value if set to camp, otherwise monochromatic :param num_grid: (nx, ny) number of grid-points for interpolation along x and y directions when plotting the wave function :param cmap: color map for plotting the wave function :param with_colorbar: whether to add colorbar to figure :param beautifier: function for improving the plot :param kwargs: parameters for plt.scatter() and plt.imshow() :return: None.

plot_tbpm_bands(energy, bands, k_len, k_idx, ...)

Plot band structure from TBPM calculation. :param energy: (num_eng,) float64 array energies of dos for each k-point in eV :param bands: (num_kpt, num_eng) float64 array k-dependent dos in 1/eV :param k_len: (num_kpt,) float64 array length of k-path in 1/nm :param k_idx: (num_hsk,) int32 array indices of highly-symmetric k-points in k_len :param k_label: (num_hsk,) labels of highly-symmetric k-points :param fig_name: file name of figure :param fig_size: width and height of the figure :param fig_dpi: dpi of output figure :param e_min: lower bound of energy in plot in eV :param e_max: upper bound of energy in plot in eV :param num_grid: (nx, ny) number of grid-points for interpolation along x and y directions when plotting the wave function :param cmap: color map for plotting the wave function :param kwargs: parameters for plt.scatter() and plt.imshow() :return: None.

plot_vector(x, y, u, v[, fig_name, ...])

Plot 2d vector field [u(x, y), v(x, y)]. :param x: (num_data,) float64 array x-component of Cartesian coordinates of data points :param y: (num_data,) float64 array y-component of Cartesian coordinates of data points :param u: (num_data,) float64 array x component of arrow directions :param v: (num_data,) float64 array y component of arrow directions :param fig_name: image file name :param fig_size: width and height of the figure :param fig_dpi: dpi of output figure :param model: model with which the data will be plotted :param model_style: style of the model :param arrow_color: color for the arrows :param cmap: color map for plotting the arrows :param with_colorbar: whether to add colorbar to figure :param beautifier: function for improving the plot :param kwargs: keyword arguments for quiver function :return: None.

plot_wfc(model, wfc[, with_model])

Plot wave function in real space. :param model: model to which the wave function belongs :param with_model: whether to plot model along with the wave function :param wfc: (num_orb,) float64 array projection of wave function on all the sites :param kwargs: arguments for 'plot_scalar' :return: None.

plot_wfc3d(model, wfc, quantum_numbers[, ...])

Plot wave function to cube file. :param model: model to which the wave function belongs :param wfc: (num_orb,) float64 array projection of wave function on all the sites :param quantum_numbers: (num_orb, 4) int32 array z, n, l, m of each orbital :param convention: convention of Hamiltonian from which the wave function is obtained :param k_point: (3, ) float64 array fractional coordinate of the k-point :param rn_max: (3, ) int64 array range of rn to evaluate the Bloch function, the actual range is [-rn_max[i], rn_max[i]] along 3 directions :param cube_name: name of output cube file :param cube_origin: (3, ) float64 array Cartesian coordinate of origin of plotting range in nm :param cube_size: (3, ) float64 array size of plotting range in nm :param resolution: resolution of plotting range in nm :param kind: data to plot, should be real, imag or abs2 :return: None.

plot_xy(x, y[, fig_name, fig_size, fig_dpi, ...])

Plot y as function of x. :param x: (num_data,) float64 array data x for plot :param y: (num_data,) float64 array data y for plot :param fig_name: file name of figure to save :param fig_size: width and height of the figure :param fig_dpi: resolution of figure :param x_label: label for x-axis :param y_label: label for y-axis :param x_lim: (x_min, x_max) range of x :param y_lim: (y_min, y_max) range of y :param beautifier: function for improving the plot :param color: line color :param linewidth: line width :param kwargs: parameters for plt.plot() :return: None.

Attributes

is_master

Wrapper for determine the master process for compatibility.

__init__(echo_details: bool = False) None
Parameters:

echo_details – whether to output parallelization details

plot_bands(k_len: ndarray, bands: ndarray, k_idx: ndarray, k_label: List[str], fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, x_label: str = 'k (1/nm)', y_label: str = 'Energy (eV)', beautifier: Callable = None, color: str = 'r', linewidth: float = 1.2, **kwargs) None

Plot band structure. :param k_len: (num_kpt,) float64 array

distance of k-path in reciprocal space

Parameters:
  • bands – (num_kpt, num_band) float64 array energies corresponding to k_len

  • k_idx – (num_hsk,) int32 array indices of highly-symmetric k-points in k_len

  • k_label – (num_hsk,) labels of highly-symmetric k-points

  • fig_name – file name of figure to save

  • fig_size – width and height of the figure

  • fig_dpi – resolution of figure

  • x_label – label of x-axis

  • y_label – label of y-axis

  • beautifier – function for improving the plot

  • color – line color

  • linewidth – line width

  • kwargs – parameters for plt.plot()

Returns:

None

plot_dos(energies: ndarray, dos: ndarray, x_label: str = 'Energy (eV)', y_label: str = 'DOS (1/eV)', **kwargs) None

Plot density of states. :param energies: (num_eng,) float64 array

energy grids

Parameters:
  • dos – (num_eng,) float64 array density of states

  • x_label – label for x-axis

  • y_label – label for y-axis

  • kwargs – arguments for ‘plot_xy’

Returns:

None

plot_phases(kb_array: ndarray, phases: ndarray, fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, scatter: bool = True, polar: bool = False, x_label: str = '$k_b (G_b)$', y_label: str = '$\\theta$', beautifier: Callable = None, color: str = 'r', linewidth: float = 1.2, **kwargs) None

Plot evolution of Wannier function centers as function of kb. :param kb_array: (num_kb,) float64 array

FRACTIONAL coordinates of the loop along b-axis

Parameters:
  • phases – (num_kpt, num_occ) float64 array phases of WF centers

  • fig_name – file name of figure

  • fig_size – width and height of the figure

  • fig_dpi – dpi of output figure

  • scatter – whether to do scatter plot instead of line plot

  • polar – whether to plot in polar coordinate system

  • x_label – label for x-axis

  • y_label – label for y-axis

  • beautifier – function for improving the plot

  • color – line color

  • linewidth – line width

  • kwargs – parameters for plt.plot() and plt.scatter()

Returns:

None

plot_scalar(x: ndarray, y: ndarray, z: ndarray, fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, model: PrimitiveCell | Sample = None, model_style: Dict[str, Any] = None, scatter: bool = False, site_size: int | ndarray = 5, site_color: str | List[str] = 'cmap', num_grid: Tuple[int, int] = (200, 200), cmap: str = 'viridis', with_colorbar: bool = False, beautifier: Callable = None, **kwargs) None

Plot 2d scalar field z = f(x, y). :param x: (num_data,) float64 array

x-component of Cartesian coordinates of data points

Parameters:
  • y – (num_data,) float64 array y-component of Cartesian coordinates of data points

  • z – (num_data,) float64 array z-value of data points

  • fig_name – image file name

  • fig_size – width and height of the figure

  • fig_dpi – dpi of output figure

  • model – model with which the data will be plotted

  • model_style – style of the model

  • scatter – whether to plot the wave function as scatter

  • site_size – size of the sites for scatter plot

  • site_color – color of the sites, use colormap from z-value if set to camp, otherwise monochromatic

  • num_grid – (nx, ny) number of grid-points for interpolation along x and y directions when plotting the wave function

  • cmap – color map for plotting the wave function

  • with_colorbar – whether to add colorbar to figure

  • beautifier – function for improving the plot

  • kwargs – parameters for plt.scatter() and plt.imshow()

Returns:

None

plot_tbpm_bands(energy: ndarray, bands: ndarray, k_len: ndarray, k_idx: ndarray, k_label: List[str], fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, e_min: float = -1.0, e_max: float = 1.0, num_grid: Tuple[int, int] = (200, 200), cmap: str = 'viridis', **kwargs) None

Plot band structure from TBPM calculation. :param energy: (num_eng,) float64 array

energies of dos for each k-point in eV

Parameters:
  • bands – (num_kpt, num_eng) float64 array k-dependent dos in 1/eV

  • k_len – (num_kpt,) float64 array length of k-path in 1/nm

  • k_idx – (num_hsk,) int32 array indices of highly-symmetric k-points in k_len

  • k_label – (num_hsk,) labels of highly-symmetric k-points

  • fig_name – file name of figure

  • fig_size – width and height of the figure

  • fig_dpi – dpi of output figure

  • e_min – lower bound of energy in plot in eV

  • e_max – upper bound of energy in plot in eV

  • num_grid – (nx, ny) number of grid-points for interpolation along x and y directions when plotting the wave function

  • cmap – color map for plotting the wave function

  • kwargs – parameters for plt.scatter() and plt.imshow()

Returns:

None

plot_vector(x: ndarray, y: ndarray, u: ndarray, v: ndarray, fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, model: PrimitiveCell | Sample = None, model_style: Dict[str, Any] = None, arrow_color: str | List[str] = 'cmap', cmap: str = 'viridis', with_colorbar: bool = False, beautifier: Callable = None, **kwargs) None

Plot 2d vector field [u(x, y), v(x, y)]. :param x: (num_data,) float64 array

x-component of Cartesian coordinates of data points

Parameters:
  • y – (num_data,) float64 array y-component of Cartesian coordinates of data points

  • u – (num_data,) float64 array x component of arrow directions

  • v – (num_data,) float64 array y component of arrow directions

  • fig_name – image file name

  • fig_size – width and height of the figure

  • fig_dpi – dpi of output figure

  • model – model with which the data will be plotted

  • model_style – style of the model

  • arrow_color – color for the arrows

  • cmap – color map for plotting the arrows

  • with_colorbar – whether to add colorbar to figure

  • beautifier – function for improving the plot

  • kwargs – keyword arguments for quiver function

Returns:

None

plot_wfc(model: PrimitiveCell | Sample, wfc: ndarray, with_model: bool = True, **kwargs) None

Plot wave function in real space. :param model: model to which the wave function belongs :param with_model: whether to plot model along with the wave function :param wfc: (num_orb,) float64 array

projection of wave function on all the sites

Parameters:

kwargs – arguments for ‘plot_scalar’

Returns:

None

plot_wfc3d(model: PrimitiveCell | Sample, wfc: ndarray, quantum_numbers: ndarray, convention: int = 1, k_point: ndarray = None, rn_max: ndarray = None, cube_name: str = 'wfc.cube', cube_origin: ndarray = None, cube_size: ndarray = None, resolution: float = 0.005, kind: str = 'real') None

Plot wave function to cube file. :param model: model to which the wave function belongs :param wfc: (num_orb,) float64 array

projection of wave function on all the sites

Parameters:
  • quantum_numbers – (num_orb, 4) int32 array z, n, l, m of each orbital

  • convention – convention of Hamiltonian from which the wave function is obtained

  • k_point – (3, ) float64 array fractional coordinate of the k-point

  • rn_max – (3, ) int64 array range of rn to evaluate the Bloch function, the actual range is [-rn_max[i], rn_max[i]] along 3 directions

  • cube_name – name of output cube file

  • cube_origin – (3, ) float64 array Cartesian coordinate of origin of plotting range in nm

  • cube_size – (3, ) float64 array size of plotting range in nm

  • resolution – resolution of plotting range in nm

  • kind – data to plot, should be real, imag or abs2

Returns:

None

plot_xy(x: ndarray, y: ndarray, fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, x_label: str = None, y_label: str = None, x_lim: Tuple[float, float] = None, y_lim: Tuple[float, float] = None, beautifier: Callable = None, color: str = 'r', linewidth: float = 1.2, **kwargs) None

Plot y as function of x. :param x: (num_data,) float64 array

data x for plot

Parameters:
  • y – (num_data,) float64 array data y for plot

  • fig_name – file name of figure to save

  • fig_size – width and height of the figure

  • fig_dpi – resolution of figure

  • x_label – label for x-axis

  • y_label – label for y-axis

  • x_lim – (x_min, x_max) range of x

  • y_lim – (y_min, y_max) range of y

  • beautifier – function for improving the plot

  • color – line color

  • linewidth – line width

  • kwargs – parameters for plt.plot()

Returns:

None

__weakref__

list of weak references to the object

property is_master: bool

Wrapper for determine the master process for compatibility.