htesp.plot_bandproj

Script to process projection data

Functions

find_all_indices(lst, element)

Find all indices of a specific element in a list.

main()

Main function to execute the program

parse_proj_sizes(lines[, legacy_index])

Locate the natomwfc nkstot nbnd line of a projwfc.x output.

Classes

DataProcessor([structure_file, proj_file])

A class to process projection data in "proj.out*" format from QE calculations.

PROCARProcessor(procar_file, band_file)

A class to process PROCAR file and extract band information.

class htesp.plot_bandproj.PROCARProcessor(procar_file, band_file)[source]

A class to process PROCAR file and extract band information.

Parameters:

  • procar_file (str): Path to the PROCAR file.

  • band_file (str): Path to the band file.

Attributes: - nkpoint (int): Number of k-points. - nband (int): Number of bands. - nion (int): Number of ions. - ncol (int): Number of columns in the PROCAR data. - col (list): List of column labels. - data (numpy.ndarray): Processed PROCAR data. - nspin (int): Number of spin channels. - elements (list): List of elements parsed from structure file. - nkpoint_extra (int): Additional k-points in PROCAR file not in band file.

Methods:

  • write_band_orbital(orb): Writes band orbital data to the specified file.

  • write_band_element(elm): Writes band element data to the specified file.

  • extract_data(elm, orb): Extracts data for a specific element and orbital.

  • extract_data_2(elm, orb): Extracts data for a specific element and orbital, summing over suborbitals.

  • print_info(): Prints available options for elements and orbitals.

  • clean(): Cleans up temporary files created during processing.

Example:

>>> procar_processor = PROCARProcessor("PROCAR", "BANDS")
>>> procar_processor.print_info()              # elements and orbitals
>>> procar_processor.extract_data('Fe', 's')
>>> procar_processor.write_band_orbital('s')
>>> procar_processor.write_band_element('Fe')
>>> procar_processor.clean()                   # temporary files
print_info()[source]

Print available options for elements and orbitals.

clean()[source]

Clean up temporary files created during processing.

extract_data(elm, orb)[source]

Extract data for a specific element and orbital.

Parameters: - elm (str): Element symbol. - orb (str): Orbital type.

extract_data_2(elm, orb)[source]

Extract data for a specific element and orbital, summing over suborbitals.

Parameters: - elm (str): Element symbol. - orb (str): Orbital type.

write_band_orbital(orb)[source]

Write orbital data to the specified file.

Parameters: - output_file (str): Path to the output file.

write_band_element(elm)[source]

Write element data to the specified file.

Parameters: - output_file (str): Path to the output file.

htesp.plot_bandproj.parse_proj_sizes(lines, legacy_index=12)[source]

Locate the natomwfc nkstot nbnd line of a projwfc.x output.

FIX(24): the caller used to read lines[12] outright. That position depends on the number of species and atoms in the header, so it broke for anything but the cell the code was written against - and it silently gave the wrong numbers rather than failing.

Parameters:
  • lines (list of str) – The whole projection file.

  • legacy_index (int) – Line used as a last resort (the old hard-coded 12).

Returns:

(natomwfc, nkstot, nbnd, lsda) - the first three as ints, lsda as a bool (True for a spin-polarised run).

Return type:

tuple

htesp.plot_bandproj.find_all_indices(lst, element)[source]

Find all indices of a specific element in a list.

Parameters: - lst (list): List to search. - element (str): Element to find.

Returns: - indices (list): List of indices where the element is found.

class htesp.plot_bandproj.DataProcessor(structure_file='scf.in', proj_file='proj.out*')[source]

A class to process projection data in “proj.out*” format from QE calculations.

projdata

The projection data.

Type:

str

nkpoint

The number of k-points.

Type:

int

nband

The number of bands.

Type:

int

nrow

The number of rows in the data.

Type:

int

dict_

A dictionary for storing projection data.

Type:

dict

dict_2

Another dictionary for storing data with keys as elements and values as list storing orbital info.

Type:

dict

dict_1

Similar to dict_1, but only with useful orbital info.

Type:

dict

ref_data

Reference data to initialize numpy array.

Type:

str

proj_dict

Dictionary for projection data.

Type:

dict

final_dict

Dictionary for final data for unique element-orbital combination.

Type:

dict

In a compound like A2B3, when combining orbital contributions for elements A and B,
we need to consider the stoichiometry.
For example, if we're summing contributions from the pz orbital
- For element A, the contribution from the pz orbital should be summed 2 times

(since there are 2 A atoms).

- For element B, the contribution from the pz orbital should be summed 3 times

(since there are 3 B atoms).

This ensures that the overall contribution is correctly weighted by the number
of atoms of each element in the compound.

Example: >>> processor = DataProcessor(structure_file=”scf.in”, proj_file=”proj.out*”)

convert_gnu(filename)[source]

Convert data file to GNU plot format.

Parameters:

filename (str) – The filename of the data file to be converted.

clean(delete_file)[source]

Delete a file produced during processing.

Parameters:

delete_file (str) – Path of the file to remove.

write_proj_elm_orbi()[source]

Write projection data for each element/orbital combination.

print_info()[source]

Printing available options

extract_data(elm, name)[source]

Extract projection data for a specific element and orbital and save it to a file.

Parameters:
  • elm (str) – Element for which projection data is extracted.

  • name (str) – Name of the orbital for which projection data is extracted.

extract_data_2(elm, name)[source]

Extract projection data for a specific element and orbital and save it to a file, while summing contributions from multiple suborbitals if applicable. Here, orbitals are “p”, “d” instead of suborbitals “px”, “py”, “pz”, etc.

Parameters:
  • elm (str) – Element for which projection data is extracted.

  • name (str) – Name of the orbital or orbital type for which projection data is extracted.

combine_element(elm)[source]

Combine projection data for a specific element and save it to a file.

Parameters:

elm (str) – Element for which projection data is combined.

combine_orbital(orb, key=None, if_gnu=False)[source]

Combine projection data for one orbital and save it to a file.

FIX(2): this method used to be defined twice with different signatures - combine_orbital(self, key, orb, if_gnu=False) earlier in the class (unreachable, shadowed by the later definition) and combine_orbital(self, orb) here. The two are merged: key=None keeps the behaviour of the definition that actually ran (sum the same orbital across all elements into <orb>.dat), while passing key restores the element-scoped variant (sum the sub-orbitals of one element into <key>-<orb>.dat). The only caller, dp.combine_orbital(orb) in main(), is unchanged.

Parameters:
  • orb (str) – Orbital type for which projection data is combined.

  • key (str, optional) – Element to scope the combination to. None (default) combines across every element.

  • if_gnu (bool) – Only used with key - also write a .gnu file for each per-orbital file before combining. Default False.

Returns:

Name of the combined .dat file that was written.

Return type:

str

convert_to_numpy(input_data)[source]

Convert input data to a NumPy array.

Parameters:

input_data (list) – List of strings representing data.

Returns:

NumPy array containing the converted data.

Return type:

numpy.ndarray

htesp.plot_bandproj.main()[source]

Main function to execute the program