minushalf.utils package¶
Submodules¶
minushalf.utils.atomic_potential module¶
Correct crystal potential to fractional occupations
- class minushalf.utils.atomic_potential.AtomicPotential(vtotal: Vtotal, vtotal_occupied: Vtotal, potential_file: PotentialFile)¶
Bases:
object
Correct atomic potential fourier tranform for fractional occupations in valence or conduction bands
- correct_file(potential: list, cut: float, amplitude: float, is_conduction: bool = False) None ¶
Create the potential file corrected
- Args:
potential (list): List of corrected potentials fourier transform
cut (float): Cutting parameter to cancel the potential
amplitude (float): Multiplicative factor of the potential function
- correct_potential(cut: float, amplitude: float, is_conduction: bool = False) list ¶
Correct fourier transform of the potential (V(k)) present in POTCAR file.
- Args:
cut (float): Cutting parameter to cancel the potential
amplitude (float): Multiplicative factor of the potential function
is_conduction (bool): Indicates whether the potential correction will be made in the valence or in the conduction
- Returns:
List of corrected potentials fourier transform
- get_corrected_file_lines(potential: list) list ¶
Create the potential file corrected
- Args:
potential (list): List of corrected potentials fourier transform
- Returns:
potential_lines(list): A List of potcar lines
- occupy_potential(cut: float, amplitude) list ¶
- Parameters:
cut (float) – Cutting parameter to cancel the potential
amplitude (float) – Multiplicative factor of the potential function
- Returns:
A list that contains the potentials of fractional electron occupation at the exact level to be corrected.
minushalf.utils.band_structure module¶
Band structure informations
- class minushalf.utils.band_structure.BandStructure(eigenvalues: dict, fermi_energy: float, atoms_map: dict, num_bands: int, band_projection: BandProjectionFile)¶
Bases:
object
Extact band structure insights from VASP classes
- band_gap() dict ¶
Find VBM and CBM, then returns band gap :returns: VBM index and its eigenvalue, CBM index and its eigenvalue and band gap
- band_projection(kpoint: int, band: int) -> defaultdict(<class 'list'>, {})¶
- Find the projection of each atom for a specific band.
- Args:
kpoint (int): Number of kpoints band_number (int): Number of the band
- Returns:
band_projection (defaultdict(list)): Contains the projection of each orbital of each atom in the respective band
- cbm_index() tuple ¶
Find the kpoint and the band for cbm
- Returns:
vbm_index (tuple): Contains the kpoint number and the band number of th vbm
- cbm_projection() -> defaultdict(<class 'list'>, {})¶
Find the projection of each atom for valence band minimum.
- Returns:
vbm_projection (defaultdict(list)): Contains the projection of each orbital of each atom in the respective band
- static create(software_module: SoftwaresAbstractFactory, base_path: str = '.')¶
Create band structure class from ab inition results
Args:
software_module (SoftwaresAbstractFactory): Holds the results of first principles output calculations base_path (str): Path to first principles output files
Returns:
band_strucure (BandStructure): Class with band structure informations
- is_metal(tolerance: float = 0.0001) bool ¶
Check if the band structure indicates a metal by looking if the fermi level crosses a band.
- Returns:
True if a metal, False if not
- vbm_index() tuple ¶
Find the kpoint and the band for vbm
- Returns:
vbm_index (tuple): Contains the kpoint number and the band number of th vbm
- vbm_projection() -> defaultdict(<class 'list'>, {})¶
Find the projection of each atom for valence band maximum.
- Returns:
vbm_projection (defaultdict(list)): Contains the projection of each orbital of each atom in the respective band
minushalf.utils.check_file_exists module¶
Function to check if a file exists
- minushalf.utils.check_file_exists.check_eigenval_exists(func)¶
Function decrator to check if a file exists
- minushalf.utils.check_file_exists.check_outcar_exists(func)¶
Function decrator to check if a file exists
- minushalf.utils.check_file_exists.check_potcar_exists(func)¶
Function decrator to check if a file exists
- minushalf.utils.check_file_exists.check_procar_exists(func)¶
Function decrator to check if a file exists
- minushalf.utils.check_file_exists.check_vasprun_exists(func)¶
Function decrator to check if a file exists
minushalf.utils.cli_messages module¶
Default cli messages
- minushalf.utils.cli_messages.end_message() None ¶
Print end message
- minushalf.utils.cli_messages.welcome_message(text: str) None ¶
Print welcome message
minushalf.utils.correct_potential_fourier_transform module¶
Fourier Transform
- minushalf.utils.correct_potential_fourier_transform.correct_potential_fourier_transform(coefficient: array, k: array, rays: array, occupation_potential: array, cut: float) array ¶
The pseudopotential is given in terms of the radial distance, and is only defined for r >= 0, as expected. Since it is only evaluated inside an integral from 0 to infinity, it does not matter what values it assumes for r < 0. A natural choice is to define the function to be zero for negative values, but a more convenient choice is to choose v(-r)=-v(r) and n(-r)=-n(r), since purely real and odd functions have purely imaginary Fourier transforms. Let v’ and n’ be the odd extensions of the potential and the number density, respectively.
\[E_{v} = \int_{0}^{\infty}v(r)n(r)dr = \int_{0}^{\infty}v'(r)n'(r)dr = \frac{1}{2}\cdot\int_{-\infty}^{\infty}v'(r)n'(r)dr = -\frac{1}{2}\cdot\int_{-\infty}^{\infty}V(k)N(k)dk\]On the third equalitty, we used the fact that the product of two odd functions is even, and in the last step we have applied Parseval’s theorem, considering that the Fourier transforms are purely imaginary. Even though the function may not pass through the origin, we can still make an odd extension, by making it discontinuous.
The data stored on POTCAR corresponds to the Fourier transform of the odd extension of v. It can be approximated by the summation on the right, where the prefactors were ommited.
\[V(k) = i\cdot \sqrt{\frac{2}{\pi}}\cdot\int_{0}^{\infty}v(r)sin(b\cdot k\cdot r)dr \Rightarrow V(k)\sim \sum^{N_{r}}_{i=1} \frac{(v[i]\cdot sin(b\cdot k\cdot r[i])+v[i-1]\cdot sin(b\cdot k\cdot r[i-1]))}{2\cdot (r[i]-r[i-1])}\]Computes the opposite of the imaginary part of the j-th fourier transform coefficient through numerical integrationIndex zero stands for the r=DeltaR, and the function is assumed to be zero at the origin. Thus, the first trapezium of the numerical integration is degenerated to a triangulum, and its area must be calculated as so.
- Args:
coefficient (np.array): Fourier transform of the potential for the atom in its ground state
k (np.array): The wave vector in reciprocal space
rays(np.array): List of rays on which pseudopotential calculations were made
occupation_potential (np.arraygit): Potential of fractional electron occupation at the exact level to be corrected
cut(float): Cutting parameter to cancel the potential
- Returns:
Fourier transform of the potential for the state with fractional occupation of the crystal
minushalf.utils.cut_initial_guess module¶
Gives cut initial guess
- class minushalf.utils.cut_initial_guess.CutInitialGuess¶
Bases:
object
Estimate cut inital guess from the nearest neighbor distance.
- guess(distance: float, method: str) float ¶
Given the nearest neighbor distance and the method, it returns the initial guess.
- Args:
method (str): method of gessing distance (float): nearest neighbor distance
- Returns:
cut_guess (float): An initial guess to cut.
minushalf.utils.drop_comments module¶
Function to check if the line a commentarie or not
- minushalf.utils.drop_comments.drop_comments(lines: list) list ¶
Function to remove comments from lines in a file
- Args:
lines(list): list of file lines
- Returns:
lines_without_comments (list): lines of the file without comments
minushalf.utils.fractionary_correction_indexes module¶
Get atoms to be corrected for simple valence correction and simple condunction correction
- minushalf.utils.fractionary_correction_indexes.get_fractionary_correction_indexes(band_projection: DataFrame, treshold: int = 5) dict ¶
Get dataframe index of the orbitals which contributes more than 5 percent to (VBM|CBM)
Returns:
- correction_indexes (dict):A dict wherw the keys are the atoms
symbols and the value is a list with the orbitals type to be corrected. Ex: { ‘Ga’: [‘p’,’s’], ‘N’ : [‘d’,’f’], }
minushalf.utils.get_correction_params module¶
Extract the parameters for the correction
- minushalf.utils.get_correction_params.get_conduction_correction_params(minushalf_yaml: MinushalfYaml, software_factory: SoftwaresAbstractFactory, **kwargs)¶
Returns the parameters for the conduction correction
- minushalf.utils.get_correction_params.get_valence_correction_params(minushalf_yaml: MinushalfYaml, software_factory: SoftwaresAbstractFactory, **kwargs)¶
Returns the parameters for the valence correction
minushalf.utils.negative_band_gap module¶
Returns band-gap with the sinal changed, so one can use minimization algorithms to find the cut value that results in the maximum band_gap
- minushalf.utils.negative_band_gap.find_negative_band_gap(cuts: list, *args: tuple) float ¶
Run vasp and return the gap value multiplied by -1
- Parameters:
cuts (float) – List of cuts
args (tuple) – tuple containning a dictionary with the fields base_path (str): Path to mkpotcar{symbol}_{orbital} symbol (str): Atom symbol default_potential_filename (str): The default potential filename for each software potfiles_folder (str): Folder containing unmodified potfiles amplitude (float): scale factor to trimming function runner (Runner): runner for the software software_factory(SoftwaresAbstractFactory): Factory for each software atom_potential(AtomicPotential): Holds fourier transforms of the potential software_files (list): Aditional files besides potential file to make ab initio calculations
- Returns:
band gap multiplied for -1
- Return type:
negative_gap (float)
minushalf.utils.parse_cut module¶
Parse cut string used in correct potential file
- minushalf.utils.parse_cut.parse_cut(cut: str) list ¶
Parse cut in a list of numbers.
- Parameters:
cut (str) –
Cut energy to be used in the program, it can be passed in two ways:
unique value : float or integer range: begin(float|integer):pass(float|integer):end(float|integer)
- Returns:
Permited values of cut.
- Return type:
cut_numbers (list)
minushalf.utils.parse_valence_orbital_line module¶
Parse valence orbital line in INP file.
- minushalf.utils.parse_valence_orbital_line.parse_valence_orbitals(line: str) dict ¶
Parse valence orbital line in principal quantum number, angular momentum quantum number and eletronic occupation
- Args:
line (str): line of imp file that represents a valence orbital
- Returns:
A dictionary with fields n, l and eletronic occupation
minushalf.utils.projection_to_df module¶
Transform informations about band_project generated by cbm_character, vbm_character or band_character in a normalized datafame Grouped by orbital types
- minushalf.utils.projection_to_df.projection_to_df(projection: defaultdict(<class 'list'>, {})) DataFrame ¶
Transform received dictionaries into information with a higher degree of readability.
- Args:
projection (defaultdict(list)): A dictionary containing the projections of each atom per orbital
- Returns:
prolection_df (pd.DataFrame): A dataframe containing the projections per orbital type and normalized between 0 - 100
minushalf.utils.simple_correction_indexes module¶
Get atoms to be corrected for simple valence correction and simple condunction correction
- minushalf.utils.simple_correction_indexes.get_simple_correction_indexes(band_projection: DataFrame) dict ¶
Get dataframe index of the orbital which contributes more to (VBM|CBM)
Returns:
- correction_indexes (dict):A dict wherw the keys are the atoms
symbols and the value is a list with the orbitals type to be corrected. Ex: { ‘Ga’: [‘p’,’s’], ‘N’ : [‘d’,’f’], }
minushalf.utils.trimming_function module¶
Trimming function
- minushalf.utils.trimming_function.trimming_function(radius: array, ion_potential: array, atom_potential: array, cut: float, amplitude: float) array ¶
Function that generate the potential for fractional occupation. The potential is cuted by a a function theta(r) to avoid divergence in calculations. The function of potential is defined as follows:
\[V_{1/2} = (V_{atom}- V_{ion})\cdot \theta (r)\]where theta is:
\[\theta (r)=A\cdot (1-(\frac{r}{CUT})^{n})^{3},r\leq CUT\]\[\theta (r) = 0, r > CUT\]—
- Args:
cut (float): cutting parameter to cancel the potential
amplitude (float): multiplicative factor of the potential function
radius (np.array): rays in which the potential was calculated
ion_potential (np.array): Atom pseudopotential with fractional occupation
atom_potential (np.array): Atom pseudopotential with all electrons
- Returns:
potential of fractional electron occupation at the exact level to be corrected
Module contents¶
Init file for utils module