Utils#

This section describes the different utility funtions.

kpoints#

Functions for processing kpoints.

aiida_wannier90_workflows.utils.kpoints.cartesian_product(*arrays: ndarray) ndarray[source]#

Cartesian product.

Returns:

_description_

Return type:

np.ndarray

aiida_wannier90_workflows.utils.kpoints.create_kpoints_from_distance(structure: StructureData, distance: float | Float, force_parity: bool | Bool = False) KpointsData[source]#

Create KpointsData from a given distance.

Different from aiida_quantumespresso.calculations.functions.create_kpoints_from_distance, this is not a calcfunction, so the AiiDA database is unchanged.

Parameters:
  • structure ([type]) – [description]

  • distance ([type]) – [description]

  • force_parity (bool, aiida.orm.Bool) – whether the generated mesh is even or odd.

Returns:

[description]

Return type:

[type]

aiida_wannier90_workflows.utils.kpoints.create_kpoints_from_mesh(structure: StructureData, mesh: List[int]) KpointsData[source]#

Create KpointsData from a given distance.

Parameters:
  • structure ([type]) – [description]

  • mesh ([type]) – [description]

Returns:

[description]

Return type:

[type]

aiida_wannier90_workflows.utils.kpoints.get_explicit_kpoints(kmesh: KpointsData) KpointsData[source]#

Work just like kmesh.pl of Wannier90.

Parameters:

kmesh (aiida.orm.KpointsData) – contains a N1 * N2 * N3 mesh

Raises:

AttributeError – if kmesh does not contains a mesh

Returns:

an explicit list of kpoints

Return type:

aiida.orm.KpointsData

aiida_wannier90_workflows.utils.kpoints.get_explicit_kpoints_from_distance(structure: StructureData, distance: float | Float) KpointsData[source]#

Create an explicit list of kpoints with a given distance.

Parameters:
  • structure ([type]) – [description]

  • distance ([type]) – [description]

Returns:

[description]

Return type:

[type]

aiida_wannier90_workflows.utils.kpoints.get_explicit_kpoints_from_mesh(structure: StructureData, mesh: List[int]) KpointsData[source]#

Create an explicit list of kpoints with a given distance.

Parameters:
  • structure ([type]) – [description]

  • mesh ([type]) – [description]

Returns:

[description]

Return type:

[type]

aiida_wannier90_workflows.utils.kpoints.get_kpoints_from_bands(bands: BandsData) KpointsData[source]#

Create a KpointsData from a BandsData.

Parameters:

bands (aiida.orm.BandsData) – the input BandsData object .

Returns:

the returned KpointsData must contain labels.

Return type:

aiida.orm.KpointsData

aiida_wannier90_workflows.utils.kpoints.get_mesh_from_kpoints(kpoints: KpointsData) List[source]#

From .

Parameters:

kpoints (aiida.orm.KpointsData) – contains a N1 * N2 * N3 mesh

Raises:

AttributeError – if kmesh does not contains a mesh

Returns:

an explicit list of kpoints

Return type:

aiida.orm.KpointsData

aiida_wannier90_workflows.utils.kpoints.get_path_from_kpoints(kpoints: KpointsData) Dict[source]#

Translate bands kpoints path objects.

From the input bands_kpoints (a KpointsData object) of PwBandsWorkChain, to the input kpoint_path (a Dict object) of Wannier90Calculation.

Parameters:

kpoints (orm.KpointsData) – the input KpointsData must contain labels.

Returns:

the returned Dict object contains two keys: path and point_coords.

Return type:

orm.Dict

scdm#

Functions for SCDM fitting.

aiida_wannier90_workflows.utils.scdm.erfc_scdm(x, mu, sigma)[source]#

Error function.

aiida_wannier90_workflows.utils.scdm.fit_scdm_mu_sigma(bands: BandsData, projections: ProjectionData, sigma_factor: Float, return_data: bool = False) Tuple[float, float] | Tuple[float, float, array][source]#

Fit scdm_mu & scdm_sigma based on projectability.

This is the AiiDA wrapper of fit_scdm_mu_sigma_raw.

Parameters:
  • pw2wan_parameters (orm.Dict) – pw2wannier90 input parameters (the one to update with this calcfunction)

  • bands (orm.BandsData) – band structure of the projwfc output

  • projections (orm.ProjectionData) – projectability of the projwfc output

  • sigma_factor (orm.Float) – sigma_factor of SCDM

aiida_wannier90_workflows.utils.scdm.fit_scdm_mu_sigma_raw(bands: array, projections: array, sigma_factor: float = 3.0, return_data: bool = False) Tuple[float, float] | Tuple[float, float, array][source]#

Fit mu parameter for the SCDM-k method.

The projectability of all orbitals is fitted using an erfc(x) function. Mu and sigma are extracted from the fitted distribution, with mu = mu_fit - k * sigma, sigma = sigma_fit and k a parameter with default k = 3.

This function accepts numpy array inputs, the function fit_scdm_mu_sigma is the AiiDA wrapper which accepts AiiDA type as input parameters.

Parameters:
  • bands – output of projwfc, it was computed in the nscf calc

  • projections – output of projwfc

  • sigma_factor – scdm_mu will be set to:: scdm_mu = E(projectability==max_projectability) - sigma_factor * scdm_sigma Pass sigma_factor = 0 if you do not want to shift

Returns:

scdm_mu, scdm_sigma, optional data (shape 2 * N, 0th row energy, 1st row projectability)

aiida_wannier90_workflows.utils.scdm.get_energy_of_projectability(bands: BandsData, projections: ProjectionData, thresholds: float = 0.9)[source]#

Return energy corresponds to projectability = thresholds.

Parameters:
  • bands (orm.BandsData) – [description]

  • projections (orm.ProjectionData) – [description]

  • thresholds (float) – [description]

parser#

pseudo#

Utility functions for pseudo potential family.

aiida_wannier90_workflows.utils.pseudo.get_number_of_electrons(structure: StructureData, pseudos: Mapping[str, UpfData]) float[source]#

Get number of electrons for the structure based on pseudopotentials.

Usage:

nprojs = get_number_of_electrons(struct_MgO, {‘Mg’:UpfData_Mg, ‘O’:UpfData_O})

Parameters:
Returns:

number of electrons

Return type:

float

aiida_wannier90_workflows.utils.pseudo.get_number_of_projections(structure: StructureData, pseudos: Mapping[str, UpfData], spin_orbit_coupling: bool | None = None) int[source]#

Get number of projections for the structure with the given pseudopotential files.

Usage:

nprojs = get_number_of_projections(struct_MgO, {‘Mg’:UpfData_Mg, ‘O’:UpfData_O})

Parameters:
Returns:

number of projections

Return type:

int

aiida_wannier90_workflows.utils.pseudo.get_projections(structure: StructureData, pseudos: Mapping[str, UpfData])[source]#

Get wannier90 projection block for the structure with a given pseudopotential files.

Usage:

projs = get_projections(struct_MgO, {‘Mg’:UpfData_Mg, ‘O’:UpfData_O})

Parameters:
Returns:

wannier90 projection block

Return type:

list

aiida_wannier90_workflows.utils.pseudo.get_pseudo_and_cutoff(pseudo_family: str, structure: StructureData) Tuple[Mapping[str, PseudoPotentialData], float, float][source]#

Get pseudo potential and cutoffs of a given pseudo family and structure.

Parameters:
  • pseudo_family (str) – [description]

  • structure (orm.StructureData) – [description]

Raises:
Returns:

[description]

Return type:

ty.Tuple[ty.Mapping[str, PseudoPotentialData], float, float]

aiida_wannier90_workflows.utils.pseudo.get_pseudo_orbitals(pseudos: Mapping[str, PseudoPotentialData]) dict[source]#

Get the pseudo wavefunctions contained in the pseudopotential.

Currently only support the following pseudopotentials installed by aiida-pseudo:
  1. SSSP/1.1/PBE/efficiency

  2. SSSP/1.1/PBEsol/efficiency

aiida_wannier90_workflows.utils.pseudo.get_semicore_list(structure: StructureData, pseudo_orbitals: dict) list[source]#

Get semicore states (a subset of pseudo wavefunctions) in the pseudopotential.

Parameters:
  • structure (orm.StructureData) – [description]

  • pseudo_orbitals (dict) – [description]

Returns:

[description]

Return type:

list

aiida_wannier90_workflows.utils.pseudo.get_wannier_number_of_bands(structure, pseudos, factor=1.2, only_valence=False, spin_polarized=False, spin_orbit_coupling: bool = False)[source]#

Estimate number of bands for a Wannier90 calculation.

Parameters:
  • structure (aiida.orm.StructureData) – crystal structure

  • pseudos (dict of aiida.orm.UpfData) – dictionary of pseudopotentials

  • only_valence (bool) – return only occupied number of badns

  • spin_polarized (bool) – magnetic calculation?

  • spin_orbit_coupling (bool) – spin orbit coupling calculation?

Returns:

number of bands for Wannier90 SCDM

Return type:

int

workflows#

Utility functions for manipulating nodes.

aiida_wannier90_workflows.utils.workflows.get_last_calcjob(workchain: WorkChainNode) CalcJobNode[source]#

Return the last CalcJob of a WorkChain.

bands#

Utility functions for band structure.

aiida_wannier90_workflows.utils.bands.get_homo_lumo(bands: array, fermi_energy: float) Tuple[float, float][source]#

Find highest occupied bands and lowest unoccupied bands around Fermi energy.

Parameters:
  • bands (np.array) – num_kpoints * num_bands

  • fermi_energy (float) – [description]

Returns:

[description]

Return type:

ty.Tuple[float, float]

aiida_wannier90_workflows.utils.bands.remove_exclude_bands(bands: array, exclude_bands: list) array[source]#

Remove bands according the index specified by exclude_bands.

Parameters:
  • bands (np.array) – num_kpoints x num_bands

  • exclude_bands (list) – the index of the to-be-excluded bands, 0-based indexing

Returns:

the bands with exclude_bands removed

Return type:

np.array