density¶
(
- data_context,
- **kwargs
)
This class accesses various densities (charge, magnetization, …) of VASP.
The charge density is one key quantity optimized by VASP. With this class you can extract the final density and visualize it within the structure of the system. For collinear calculations, one can also consider the magnetization density. For noncollinear calculations, the magnetization density has three components. One may also be interested in the kinetic energy density for metaGGA calculations.
is_collinear
is_noncollinear
is_nonpolarized
path
plot
View
read
selections
dict
Returns possible densities VASP can produce along with all available components.
In the dictionary, the key density lists all different densities you can access from the VASP output provided you set the relevant INCAR tags. You can combine any of these with any possible choice from the key component to further specify the particular output you will receive. If you do not specify a density or a component the other routines will default to the electronic charge and the 0-th component.
To nest density and component, please use parentheses, e.g. charge(1, 2) or
3(kinetic_energy).
For convenience, py4vasp accepts the following aliases
- electronic charge density
- charge, n, charge_density, and electronic_charge_density
- kinetic energy density
- kinetic_energy, kinetic_energy, and kinetic_energy_density
- 0th component
- 0, unity, sigma_0, and, scalar
- 1st component
- 1, sigma_x, x, and, sigma_1
- 2nd component
- 2, sigma_y, y, and, sigma_2
- 3rd component
- 3, sigma_z, z, and, sigma_3
Returns
dict- Possible densities and components to pass as selection in other functions on density.
Notes
In the special case of collinear calculations, magnetization, mag, and m are another alias for the 3rd component of the charge density.
Examples
>>> calculation = py4vasp.Calculation.from_path(".")
>>> calculation.density.to_dict("n")
>>> calculation.density.plot("magnetization")
Using synonyms and nesting
>>> calculation.density.plot("n m(1,2) mag(sigma_z)")
to_contour
(
- selection:
str= None, - a:
float= None, - b:
float= None, - c:
float= None, - normal:
str | None= None, - supercell:
int | np.ndarray= None
) → Graph
Generate a contour plot of the selected component of the density.
You need to specify a plane defined by two of the lattice vectors by selecting a cut along the third one. You must only select a single cut and the value should correspond to the fractional length along this third lattice vector. py4vasp will then create a plane from the other two lattice vectors and generate a contour plot within this plane.
Usually, the first remaining lattice vector is aligned with the x-axis and the second one such that the angle between the vectors is preserved. You can overwrite this choice by defining a normal direction. Then py4vasp will rotate the normal vector of the plane to align with the specified direction. This is particularly useful if the lattice vector you cut is aligned with a Cartesian direction.
Parameters
- selection:
str= None - Select which component of the density you want to visualize. Please use the selections method to get all available choices.
- a:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- b:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- c:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- normal:
str | None= None - If not set, py4vasp will align the first remaining lattice vector with the x-axis and the second one such that the angle between the lattice vectors is preserved. You can set it to “x”, “y”, or “z”; then py4vasp will rotate the plane in such a way that the normal direction aligns with the specified Cartesian axis. This may look better if the normal direction is close to a Cartesian axis. You may also set it to “auto” so that py4vasp chooses a close Cartesian axis if it can find any.
- supercell:
int | np.ndarray= None - Replicate the contour plot periodically a given number of times. If you provide two different numbers, the resulting cell will be the two remaining lattice vectors multiplied by the specific number.
Returns
Graph- A contour plot in the plane spanned by the 2 remaining lattice vectors.
Examples
Cut a plane through the magnetization density at the origin of the third lattice vector.
>>> calculation.density.to_contour("3", c=0)
Replicate a plane in the middle of the second lattice vector 2 times in each direction.
>>> calculation.density.to_contour(b=0.5, supercell=2)
Take a slice of the kinetic energy density along the first lattice vector and rotate it such that the normal of the plane aligns with the x axis.
>>> calculation.density.to_contour("kinetic_energy", a=0.3, normal="x")
to_dict
str) → dict
Read the density into a dictionary.
Parameters
- selection:
str - VASP computes different densities depending on the INCAR settings. With this parameter, you can control which one of them is returned. Please use the selections routine to get a list of all possible choices.
Returns
dict- Contains the structure information as well as the density represented on a grid in the unit cell.
to_ngl
NGLWidget
to_numpy
np.ndarray
Convert the density to a numpy array.
The number of components is 1 for nonpolarized calculations, 2 for collinear calculations, and 4 for noncollinear calculations. Each component is 3 dimensional according to the grid VASP uses for the FFTs.
Returns
np.ndarray- All components of the selected density.
to_quiver
(
- a:
float= None, - b:
float= None, - c:
float= None, - normal:
str | None= None, - supercell:
int | np.ndarray= None
) → Graph
Generate a quiver plot of magnetization density.
You need to specify a plane defined by two of the lattice vectors by selecting a cut along the third one. You must only select a single cut and the value should correspond to the fractional length along this third lattice vector. py4vasp will then create a plane from the other two lattice vectors and generate a contour plot within this plane.
Usually, the first remaining lattice vector is aligned with the x-axis and the second one such that the angle between the vectors is preserved. You can overwrite this choice by defining a normal direction. Then py4vasp will rotate the normal vector of the plane to align with the specified direction. This is particularly useful if the lattice vector you cut is aligned with a Cartesian direction.
For a collinear calculation, the magnetization density will be aligned with the y axis of the plane. For noncollinear calculations, the magnetization density is projected into the plane.
Parameters
- a:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- b:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- c:
float= None - You must select exactly one of these to specify which of the three lattice vectors you want to remove to form a plane. The assigned value represents the fractional length along this lattice vector, so a = 0.3 will remove the first lattice vector and then take the grid points at 30% of the length of the first vector in the b-c plane. The fractional height uses periodic boundary conditions.
- normal:
str | None= None - If not set, py4vasp will align the first remaining lattice vector with the x-axis and the second one such that the angle between the lattice vectors is preserved. You can set it to “x”, “y”, or “z”; then py4vasp will rotate the plane in such a way that the normal direction aligns with the specified Cartesian axis. This may look better if the normal direction is close to a Cartesian axis. You may also set it to “auto” so that py4vasp chooses a close Cartesian axis if it can find any.
- supercell:
int | np.ndarray= None - Replicate the contour plot periodically a given number of times. If you provide two different numbers, the resulting cell will be the two remaining lattice vectors multiplied by the specific number.
Returns
Graph- A quiver plot in the plane spanned by the 2 remaining lattice vectors.
Examples
Cut a plane at the origin of the third lattice vector.
>>> calculation.density.to_quiver(c=0)
Replicate a plane in the middle of the second lattice vector 2 times in each direction.
>>> calculation.density.to_quiver(b=0.5, supercell=2)
Take a slice of the spin components of the kinetic energy density along the first lattice vector and rotate it such that the normal of the plane aligns with the x axis.
>>> calculation.density.to_quiver("kinetic_energy", a=0.3, normal="x")
to_vasp_viewer
VASPViewerWidget
Convert the view to a VASP Viewer widget.
This method wraps the to_view() method and converts the resulting View
to a VASP Viewer widget. The to_view() method documents all the possible
arguments of this function.
Returns
VASPViewerWidget- A widget to display the structure and other quantities in the unit cell.
to_view
(
- selection:
str= None, - supercell:
int | np.ndarray= None, - **user_options
) → View
Plot the selected density as a 3d isosurface within the structure.
Parameters
- selection:
str= None - Can be either charge or magnetization, depending on which quantity should be visualized. For a noncollinear calculation, the density has 4 components which can be represented in a 2x2 matrix. Specify the component of the density in terms of the Pauli matrices: sigma_1, sigma_2, sigma_3.
- supercell:
int | np.ndarray= None - If present the data is replicated the specified number of times along each direction.
- **user_options
- Further arguments with keyword that get directly passed on to the visualizer. Most importantly, you can set isolevel to adjust the value at which the isosurface is drawn.
Returns
View- Visualize an isosurface of the density within the 3d structure.
Examples
>>> calculation = py4vasp.Calculation.from_path(".")
Plot an isosurface of the electronic charge density
>>> calculation.density.plot()
Plot isosurfaces for positive (blue) and negative (red) magnetization of a spin-polarized calculation (ISPIN=2)
>>> calculation.density.plot("m")
Plot the isosurface for the third component of a noncollinear magnetization
>>> calculation.density.plot("m(3)")