Post-processing tools#

A module for post-processing utilities to perform averages and constractions in real space, compute single-point invariants from local topological markers, plot markers in real space and more.

lattice_contraction

Defines which atomic sites must be contracted on one site, for each site of the lattice.

pbc_lattice_contraction

Defines which atomic sites must be contracted on one site, for each site of the lattice within periodic boundary conditions (minimum image convention).

average_over_radius

Average of values in real space according to a certain cutoff.

get_pbc_distance_pairs

trace_marker

Trace a topological marker over the whole supercell to get the single-point invariant.

plot_marker

Plot the local topological marker in real space.

save_marker

Save marker data to a compressed .npz file.

load_marker

Load marker data from a compressed .npz file.

correlation

Calculate the spatial correlation function of local markers over disorder realizations.

Real-space operations#

strawberrypy.postprocessing.lattice_contraction(model, cutoff)[source]#

Defines which atomic sites must be contracted on one site, for each site of the lattice.

Parameters:
  • model (Model) – The model for which to compute the lattice contraction.

  • cutoff (float) – Real-space cutoff for the contraction window.

Returns:

contraction – List of the indices of the atoms that are within cutoff from each other, per atom.

Return type:

list

strawberrypy.postprocessing.pbc_lattice_contraction(model, cutoff, distance_pairs=None)[source]#

Defines which atomic sites must be contracted on one site, for each site of the lattice within periodic boundary conditions (minimum image convention).

Parameters:
  • model (Model) – The model for which to compute the lattice contraction.

  • cutoff (float) – Real-space cutoff for the contraction window.

  • distance_pairs (np.ndarray, optional) – Precomputed pair distances for the model. If not provided, it will be computed using the get_pbc_distance_pairs() function. This can be useful if the pair distances have already been computed for other purposes, to avoid redundant calculations.

Returns:

contraction – List of the indices of the atoms that are within cutoff from each other, per atom.

Return type:

list

strawberrypy.postprocessing.average_over_radius(model, vals, cutoff, contraction=None)[source]#

Average of values in real space according to a certain cutoff.

Parameters:
  • model (Model) – The model for which to compute the average.

  • vals (array-like) – Values that have to be averaged.

  • cutoff (float) – Real space cutoff for the real space average.

  • contraction (list, optional) – List of atoms that have to be considered in the macroscopic average, per atom. Default is None, which means it is computed from the positions of the atoms in the lattice assuming open boundary conditions.

Returns:

return_vals – List of averaged values per lattice site within a cutoff.

Return type:

np.ndarray

strawberrypy.postprocessing.get_pbc_distance_pairs(model)[source]#
Parameters:

model (Model)

Return type:

ndarray

Trace marker#

strawberrypy.postprocessing.trace_marker(model, marker, invariant='chern', bare_marker=False, macroscopic_average=False, cutoff=0.8, boundary_conditions='pbc')[source]#

Trace a topological marker over the whole supercell to get the single-point invariant. This function is intended for periodic boundary conditions (PBC) only since within open boundary conditions the trace over the whole sample vanishes by construction.

Parameters:
  • model (Model) – The model for which to compute the topological invariant.

  • marker (np.ndarray) – The PBC local topological marker to be traced.

  • invariant (str) – The type of topological marker computed. Allowed values are 'chern' when passing the PBC local Chern marker, and 'z2' when passing the PBC local spin-Chern marker or the local \(\mathbb{Z}_{2}\) marker using time reversal symmetry.

  • bare_marker (bool) – If the local marker passed is the bare marker. Default is False.

  • macroscopic_average (bool) – If True, performs a real space average of the local marker over a radius equal to cutoff, and then trace over the whole sample. marker is expected to be the bare marker in this case and bare_marker should be set to True. Default is False.

  • cutoff (float) – Cutoff set for the calculation of the macroscopic average in real space.

  • boundary_conditions (str) – If macroscopic_average == True, the boundary conditions to be used when computing the macroscopic average in real space. Default is pbc.

Returns:

sp_inv – Topological invariant computed as the trace over the whole supercell of the local topological marker.

Return type:

float

Plotting#

strawberrypy.postprocessing.plot_marker(model, marker, savefig=False, filename='marker.pdf', **kwargs)[source]#

Plot the local topological marker in real space. This function is intended for periodic boundary conditions (PBC) only since within open boundary conditions the trace over the whole sample vanishes by construction.

Parameters:
  • model (Model) – The model for which to plot the topological marker.

  • marker (np.ndarray) – The PBC local topological marker to be plotted.

  • title (str) – Title of the plot. Default is 'Local Chern marker'.

  • savefig (bool) – If True, saves the figure in a file with name given by filename. Default is False.

  • filename (str) – Name of the file where to save the figure if savefig == True. Default is 'local_marker.pdf'.

  • **kwargs – Additional keyword arguments to pass to the scatter plot.

Returns:

  • fig (plt.Figure) – The figure object.

  • ax (plt.Axes) – The axes object.

Return type:

tuple[Figure, Axes]

Marker I/O#

strawberrypy.postprocessing.save_marker(directory, filename, marker, header={})[source]#

Save marker data to a compressed .npz file. The marker data is saved along with an optional header containing metadata. The header is stored as a dictionary, and the marker data is stored as a NumPy array.

Parameters:
  • directory (str) – The directory where the marker data will be saved. If the directory does not exist, it will be created.

  • filename (str) – The name of the file (without extension) to save the marker data.

  • marker (np.ndarray) – The marker data to be saved.

  • header (dict, optional) – A dictionary containing header information to be saved with the marker data.

Return type:

None

strawberrypy.postprocessing.load_marker(directory, filename)[source]#

Load marker data from a compressed .npz file. The function returns a tuple containing the loaded header (dict) and marker data (np.ndarray).

Parameters:
  • directory (str) – The directory where the marker data is saved.

  • filename (str) – The name of the file (without extension) containing the marker data.

Returns:

A tuple containing the loaded header (dict) and marker data (np.ndarray).

Return type:

tuple[dict, np.ndarray]

Correlation functions#

strawberrypy.postprocessing.correlation(sup_model, directory=None, filenames=None, is_bare_marker=False, cutoff=0.5, spinful=False, to_normalize=True)[source]#

Calculate the spatial correlation function of local markers over disorder realizations.

This function computes the mean correlation over multiple disorder realizations (seeds). It averages the markers over a specified cutoff radius and calculates the normalized or unnormalized correlation function versus distance.

Parameters:
  • sup_model (Model) – The supercell model on which the markers were computed.

  • directory (str) – Directory containing the marker data files.

  • filenames (list of str or str) – Base filenames (prefix, without extension) of the data files.

  • is_bare_marker (bool, optional) – Whether the marker data files contain the bare marker values (True) or if they contain the marker values already averaged over the cutoff radius (False). Default is False.

  • cutoff (float, optional) – Radius to consider for the local averaging (contraction) around each orbital if is_bare_marker == True. Default is 0.5.

  • spinful (bool, optional) – Whether the model and markers are spinful. If True, computes the marker properly from spin-down and spin-up data columns. Default is False.

  • to_normalize (bool, optional) – Whether to normalize the correlation function by the variance. Default is True.

Returns:

  • unique_dist (np.ndarray) – 1D array of unique distances.

  • corr_r (np.ndarray) – 1D array containing the mean correlation value for each corresponding distance.

Return type:

tuple[ndarray, ndarray]