density

py4vasp.calculation.density
class py4vasp.calculation._density.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()

Returns whether the density has a collinear magnetization.

is_noncollinear()

Returns whether the density has a noncollinear magnetization.

is_nonpolarized()

Returns whether the density is not spin polarized.

plot(selection='0', **user_options)

Plot the selected density as a 3d isosurface within the structure.

Parameters:
  • selection (str) – 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.

  • 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:

Visualize an isosurface of the density within the 3d structure.

Return type:

Viewer3d

Examples

>>> calc = py4vasp.Calculation.from_path(".")
Plot an isosurface of the electronic charge density
>>> calc.density.plot()
Plot isosurfaces for positive (blue) and negative (red) magnetization
of a spin-polarized calculation (ISPIN=2)
>>> calc.density.plot("m")
Plot the isosurface for the third component of a noncollinear magnetization
>>> calc.density.plot("m(3)")
print()

Print a string representation of this instance.

read(*args, **kwargs)

Convenient wrapper around to_dict. Check that function for examples and optional arguments.

selections()

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(tau).

For convenience, py4vasp accepts the following aliases

electronic charge density

charge, n, charge_density, and electronic_charge_density

kinetic energy density

tau, 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:

Possible densities and components to pass as selection in other functions on density.

Return type:

dict

Notes

In the special case of collinear calculations, magnetization, mag, and m are another alias for the 3rd component of the charge density.

Examples

>>> calc = py4vasp.Calculation.from_path(".")
>>> calc.density.to_dict("n")
>>> calc.density.plot("magnetization")
Using synonyms and nesting
>>> calc.density.plot("n m(1,2) mag(sigma_z)")
to_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:

Contains the structure information as well as the density represented on a grid in the unit cell.

Return type:

dict

to_numpy()

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:

All components of the selected density.

Return type:

np.ndarray