tbplas.Visualizer
- class tbplas.Visualizer(enable_mpi: bool = False, echo_details: bool = False)
Class for quick data visualization.
Notes
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__(enable_mpi: bool = False, echo_details: bool = False) None
- Parameters:
enable_mpi – whether to enable mpi parallelism
echo_details – whether to output parallelization details
Methods
__init__
([enable_mpi, echo_details])- param enable_mpi:
whether to enable mpi parallelism
all_average
(data_local)Average results over random samples broadcast to all process.
all_reduce
(data_local)Reduce local data and broadcast to all processes.
average
(data_local)Average results over random samples and store results to master process.
barrier
()Wrapper for self.comm.Barrier.
bcast
(data_local)Broadcast data from master to other processes.
dist_bound
(n_max)Same as dist_range, but returns the lower and upper bounds.
dist_list
(raw_list[, algorithm])Distribute a list over processes.
dist_range
(n_max)Distribute range(n_max) over processes.
log
([event, fmt])Log the date and time of event.
plot_bands
(k_len, bands, k_idx, k_label[, ...])Plot band structure.
plot_dos
(energies, dos[, x_label, y_label])Plot density of states.
plot_phases
(kb_array, phases[, fig_name, ...])- param kb_array:
(num_kb,) float64 array
plot_scalar
(x, y, z[, fig_name, fig_size, ...])Plot 2d scalar field z = f(x, y).
plot_vector
(x, y, u, v[, fig_name, ...])Plot 2d vector field [u(x, y), v(x, y)].
plot_wfc
(model, wfc[, with_model])Plot wave function in real space.
plot_wfc3d
(model, wfc, quantum_numbers[, ...])Plot wave function to cube file.
plot_xy
(x, y[, fig_name, fig_size, fig_dpi, ...])Plot y as function of x.
print
([text])Print text on master process.
reduce
(data_local)Reduce local data to master process.
Attributes
Determine whether this is the master process.
Determine whether MPI is enabled.
Interface for the '__rank' attribute.
Interface for the '__size' attribute.
- __init__(enable_mpi: bool = False, echo_details: bool = False) None
- Parameters:
enable_mpi – whether to enable mpi parallelism
echo_details – whether to output parallelization details
- all_average(data_local: ndarray) ndarray
Average results over random samples broadcast to all process.
- Parameters:
data_local – local results on each process
- Returns:
averaged data from data_local
- all_reduce(data_local: ndarray) ndarray
Reduce local data and broadcast to all processes.
- Parameters:
data_local – local results on each process
- Returns:
summed data from data_local
- average(data_local: ndarray) ndarray
Average results over random samples and store results to master process.
- Parameters:
data_local – local results on each process
- Returns:
averaged data from data_local
- barrier() None
Wrapper for self.comm.Barrier.
- bcast(data_local: ndarray) None
Broadcast data from master to other processes.
- Parameters:
data_local – local results on each process
- Returns:
None
- dist_bound(n_max: int) Tuple[int, int]
Same as dist_range, but returns the lower and upper bounds. Both of the bounds are close, i.e. [i_min, i_max].
- Parameters:
n_max – upper bound of range
- Returns:
lower and upper bounds of subrange assigned to this process
- dist_list(raw_list: List[Any], algorithm: str = 'range') List[Any]
Distribute a list over processes.
- Parameters:
raw_list – raw list to distribute
algorithm – distribution algorithm, should be either “remainder” or “range”
- Returns:
sublist assigned to this process
- dist_range(n_max: int) range
Distribute range(n_max) over processes.
- Parameters:
n_max – upper bound of the range
- Returns:
subrange assigned to this process
- log(event: str = '', fmt: str = '%x %X') None
Log the date and time of event.
- Parameters:
event – notice of the event
fmt – date and time format
- Returns:
None.
- 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.
- Parameters:
k_len – (num_kpt,) float64 array distance of k-path in reciprocal space
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.
- Parameters:
energies – (num_eng,) float64 array energy grids
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
- Parameters:
kb_array – (num_kb,) float64 array FRACTIONAL coordinates of the loop along b-axis
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: Union[PrimitiveCell, Sample] = None, model_style: Dict[str, Any] = None, scatter: bool = False, site_size: Union[int, ndarray] = 5, site_color: Union[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).
- Parameters:
x – (num_data,) float64 array x-component of Cartesian coordinates of data points
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_vector(x: ndarray, y: ndarray, u: ndarray, v: ndarray, fig_name: str = None, fig_size: Tuple[float, float] = None, fig_dpi: int = 300, model: Union[PrimitiveCell, Sample] = None, model_style: Dict[str, Any] = None, arrow_color: Union[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)].
- Parameters:
x – (num_data,) float64 array x-component of Cartesian coordinates of data points
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: Union[PrimitiveCell, Sample], wfc: ndarray, with_model: bool = True, **kwargs) None
Plot wave function in real space.
- Parameters:
model – model to which the wave function belongs
with_model – whether to plot model along with the wave function
wfc – (num_orb,) float64 array projection of wave function on all the sites
kwargs – arguments for ‘plot_scalar’
- Returns:
None
- plot_wfc3d(model: Union[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.
- Parameters:
model – model to which the wave function belongs
wfc – (num_orb,) float64 array projection of wave function on all the sites
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.
- Parameters:
x – (num_data,) float64 array data x for plot
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
- print(text: str = '') None
Print text on master process.
NOTE: flush=True is essential for some MPI implementations, e.g. MPICH3.
- Parameters:
text – text to print
- Returns:
None
- reduce(data_local: ndarray) ndarray
Reduce local data to master process.
- Parameters:
data_local – local results on each process
- Returns:
summed data from data_local
- __weakref__
list of weak references to the object (if defined)
- property is_master: bool
Determine whether this is the master process.
- property mpi_enabled: bool
Determine whether MPI is enabled.
- property rank: int
Interface for the ‘__rank’ attribute.
- Returns:
rank of this MPI process
- property size: int
Interface for the ‘__size’ attribute.
- Returns:
number of MPI processes