pyrho.charge_density#

Chang Density Objects: Periodic Grid + Lattice / Atoms.

Module Contents#

Classes#

ChargeDensity

Charge density object.

class pyrho.charge_density.ChargeDensity[source]#

Bases: monty.json.MSONable

Charge density object.

Defines a charge density with a PGrid object along with the atomic structure.

pgrids[source]#

Dictionaries whose values are periodic PGrid objects representing some periodic scalar field (typically the keys are total and diff for spin-polarized charge densities.)

Type:

Dict[str, PGrid]

structure[source]#

The atomic structure for the electronic charge density.

Type:

Structure

normalization[source]#

The normalzation scheme (vasp or None)

Type:

str | None = “vasp”

property normalized_data: dict[str, numpy.typing.NDArray][source]#

Get the normalized data.

Since different codes use different normalization methods for volumetric data we should convert them to the same units (electrons / Angstrom^3)

Returns:

The normalized data in units of (electrons / Angstrom^3)

Return type:

dict[str, NDArray]

property grid_shape: tuple[int, int, int][source]#

Return the shape of the charge density.

property normalized_pgrids: dict[str, pyrho.pgrid.PGrid][source]#

Get the normalized pgrids.

Since different codes use different normalization methods for volumetric data we should convert them to the same units (electrons / Angstrom^3)

Returns:

The normalized pgrids in units of (electrons / Angstrom^3)

Return type:

dict[str, PGrid]

property lattice: numpy.typing.NDArray[source]#

Lattice represented as an NDArray.

__post_init__()[source]#

Post initialization.

Steps:
  • Make sure all the lattices are identical

classmethod from_pmg(vdata: pymatgen.io.vasp.VolumetricData, normalization: str = 'vasp') ChargeDensity[source]#

Get data from pymatgen object.

Read a single key from the data field of a VolumetricData object

Parameters:
  • vdata – The volumetric data object

  • normalization – The normalization scheme - ‘vasp’ sum of the data / number of grid points == number of electrons - None/”none” no normalization

Returns:

The charge density object

Return type:

ChargeDensity

reorient_axis() None[source]#

Rorient the lattices.

Change the orientation of the lattice vector so that: a points along the x-axis, b is in the xy-plane, c is in the positive-z halve of space

get_data_in_cube(s: float, ngrid: int, key: str = 'total') numpy.typing.NDArray[source]#

Return the charge density data sampled on a cube.

Obtain a cubic basic cubic crop of the normalized charge density data.

Parameters:
  • s – The side length of the cube

  • ngrid – Number of grid points in each direction

  • key – The key to read from self.normalized_data

Returns:

Regridded data in a ngrid x ngrid x ngrid array

Return type:

NDArray

get_transformed(sc_mat: numpy.typing.NDArray, grid_out: list[int] | int, origin: numpy.typing.ArrayLike = (0, 0, 0), up_sample: int = 1) ChargeDensity[source]#

Modify the structure and data and return a new object containing the reshaped data.

Parameters:
  • sc_mat – The transformation matrix to apply to the lattice vectors

  • grid_out – The dimensions of the transformed grid

  • origin – Origin of the new lattice in fractional coordinates of the input cell

  • up_sample – The factor to scale up the sampling of the grid data using Fourier interpolation

Returns:

The transformed ChargeDensity object

Return type:

ChargeDensity

to_Chgcar() pymatgen.io.vasp.Chgcar[source]#

Convert the charge density to a pymatgen.io.vasp.outputs.Chgcar object.

Scale and convert each key in the pgrids dictionary and create a Chgcar object

Returns:

The charge density object

Return type:

Chgcar

to_VolumetricData(cls=VolumetricData, normalization: str = 'vasp') pymatgen.io.vasp.VolumetricData[source]#

Convert the charge density to a pymatgen.io.vasp.outputs.VolumetricData object.

Scale and convert each key in the pgrids dictionary and create a VolumetricData object

Returns:

The charge density object

Return type:

VolumetricData

classmethod from_file(filename: str, pmg_obj: pymatgen.io.vasp.VolumetricData = Chgcar) ChargeDensity[source]#

Read a ChargeDensity object from a file.

Parameters:
  • filename – The filename of the ChargeDensity object

  • pmg_obj – The pymatgen object to read from the file (default: Chgcar). the from_file method from this class will be called to read the file.

Returns:

ChargeDensity: The ChargeDensity object

classmethod from_hdf5(filename: str, pmg_obj: pymatgen.io.vasp.VolumetricData = Chgcar) ChargeDensity[source]#

Read a ChargeDensity object from a hdf5 file.

Parameters:
  • filename – The filename of the ChargeDensity object

  • pmg_obj – The pymatgen object to read from the file (default: Chgcar). the from_file method from this class will be called to read the file.

Returns:

ChargeDensity: The ChargeDensity object