Projector¶
- class py4vasp.data.Projector(data_context, **kwargs)¶
Bases:
Refinery
The projectors used for atom and orbital resolved quantities.
This is a common class used by all quantities that contains some projected quantity, e.g., the electronic band structure and the DOS. It provides utility functionality to access specific indices of the projected arrays based on a simple mini language specifying the atom or orbital names.
Attributes Summary
Returns the path from which the output is obtained.
Methods Summary
from_data
(raw_data)Create the instance directly from the raw data.
from_file
(file)Read the quantities from the given file.
from_path
([path])Read the quantities from the given path.
parse_selection
([selection])Generate all possible indices where the projected information is stored.
print
()Print a string representation of this instance.
read
(*args, **kwargs)Convenient wrapper around to_dict.
select
([atom, orbital, spin])Map selection strings onto corresponding Selection objects.
to_dict
([selection, projections])Read the selected data from an array and store it in a dictionary.
Attributes Documentation
- path¶
Returns the path from which the output is obtained.
Methods Documentation
- classmethod from_data(raw_data)¶
Create the instance directly from the raw data.
Use this approach when the data is put into the correct format by other means than reading from the VASP output files. A typical use case is to read the data with from_path and then act on it with some postprocessing and pass the results to this method.
- Parameters:
raw_data – The raw data required to produce this Refinery.
- Return type:
A Refinery instance to handle the passed data.
- classmethod from_file(file)¶
Read the quantities from the given file.
You want to use this method if you want to avoid using the Calculation wrapper, for example because you renamed the output of the VASP calculation.
- Parameters:
file (str or io.BufferedReader) – Filename from which the data is extracted. Alternatively, you can open the file yourself and pass the Reader object. In that case, you need to take care the file is properly closed again and be aware the generated instance of this class becomes unusable after the file is closed.
- Returns:
The returned instance handles opening and closing the file for every function called on it, unless a Reader object is passed in which case this is left to the user.
- Return type:
Refinery
Notes
VASP produces multiple output files whereas this routine will only link to the single specified file. Prefer from_path routine over this method unless you renamed the VASP output files, because from_path can collate results from multiple files.
- classmethod from_path(path=None)¶
Read the quantities from the given path.
The VASP schema determines the particular files accessed. The files will only be accessed when the data is required for a particular postprocessing call.
- Parameters:
path (str or pathlib.Path) – Path to the directory with the outputs of the VASP calculation. If not set explicitly the current directory will be used.
- Returns:
The returned instance handles opening and closing the files for every function called on it.
- Return type:
Refinery
- parse_selection(selection='__all__')¶
Generate all possible indices where the projected information is stored.
Given a string specifying which atoms, orbitals, and spin should be selected an iterable object is created that contains the indices compatible with the select.
- Parameters:
selection (str) –
A string specifying the projection of the orbitals. There are four distinct possibilities:
To specify the atom, you can either use its element name (Si, Al, …) or its index as given in the input file (1, 2, …). For the latter option it is also possible to specify ranges (e.g. 1:4).
To select a particular orbital you can give a string (s, px, dxz, …) or select multiple orbitals by their angular momentum (s, p, d, f).
For the spin, you have the options up, down, or total.
If you used a different k-point mesh choose “kpoints_opt” or “kpoints_wan” to select them instead of the default mesh specified in the KPOINTS file.
You separate multiple selections by commas or whitespace and can nest them using parenthesis, e.g. Sr(s, p) or s(up), p(down). The order of the selections does not matter, but it is case sensitive to distinguish p (angular momentum l = 1) from P (phosphorus).
- Yields:
Iterable[Index] – Indices of the atom, the orbital and the spin compatible with a specific selection.
- print()¶
Print a string representation of this instance.
- read(*args, **kwargs)¶
Convenient wrapper around to_dict. Check that function for examples and optional arguments.
- select(atom='__all__', orbital='__all__', spin='__all__')¶
Map selection strings onto corresponding Selection objects.
With the selection strings, you specify which atom, orbital, and spin component you are interested in.
- Parameters:
atom (str) – Element name or index of the atom in the input file of Vasp. If a range is specified (e.g. 1:3) a pointer to multiple indices will be created.
orbital (str) – Character identifying the angular momentum of the orbital. You may select a specific one (e.g. px) or all of the same character (e.g. d).
spin (str) – Select “up” or “down” for a specific spin component or “total” for the sum of both.
- Returns:
Indices to access the selected projection from an array and an associated label.
- Return type:
Index
- to_dict(selection=None, projections=None)¶
Read the selected data from an array and store it in a dictionary.
- Parameters:
selection (str) –
A string specifying the projection of the orbitals. There are four distinct possibilities:
To specify the atom, you can either use its element name (Si, Al, …) or its index as given in the input file (1, 2, …). For the latter option it is also possible to specify ranges (e.g. 1:4).
To select a particular orbital you can give a string (s, px, dxz, …) or select multiple orbitals by their angular momentum (s, p, d, f).
For the spin, you have the options up, down, or total.
If you used a different k-point mesh choose “kpoints_opt” or “kpoints_wan” to select them instead of the default mesh specified in the KPOINTS file.
You separate multiple selections by commas or whitespace and can nest them using parenthesis, e.g. Sr(s, p) or s(up), p(down). The order of the selections does not matter, but it is case sensitive to distinguish p (angular momentum l = 1) from P (phosphorus).
projections (np.ndarray or None) – Array containing projected data.
- Returns:
Dictionary where the label of the selection is linked to a particular column of the array. If a particular selection includes multiple indices these elements are added. If the projections are not present, the relevant indices are returned.
- Return type:
dict