Skip to main content

mp-pyrho

📄 Full Documentation

Installation

pip install mp-pyrho

Tools for re-griding volumetric quantum chemistry data for machine-learning purposes.

.github/workflows/testing.yml codecov DOI

If you use this package in your research, please cite the following:

Shen, J.-X., Munro, J. M., Horton, M. K., Huck, P., Dwaraknath, S., & Persson, K. A. (2022). 
A representation-independent electronic charge density database for crystalline materials. 
Sci Data, 9(661), 1–7. doi: 10.1038/s41597-022-01746-z

Regridding data using PyRho

The PGrid Class

The PGrid object is defined by an N-dimensional numpy array grid_data and a N lattice vector given as a matrix lattice. The input array is a scalar field that is defined on a regularly spaced set of grid points starting at the origin. For example, you can construct a periodic field as follows:

import numpy as np
from pyrho.pgrid import PGrid
from pyrho.vis.scatter import get_scatter_plot


def func(X, Y):
    return np.sin(X) * np.cos(2 * Y)


a = np.linspace(0, np.pi, 27, endpoint=False)
b = np.linspace(0, np.pi, 28, endpoint=False)
X, Y = np.meshgrid(a, b, indexing="ij")
data = func(X, Y)
pg2d = PGrid(grid_data=data, lattice=[[np.pi, 0], [0, np.pi]])

The data can be examined using the helper plotting function which supports up to 3-D.

import matplotlib as mpl

mpl.rc("image", cmap="viridis")
get_scatter_plot(pg2d.grid_data, pg2d.lattice, marker_size=40)

The period data in the PGrid object must be fixed-scaled so if you half the number of points in the domain, the range of the data will stay the same. This is different from how the charge density is stored in codes like VASP where the values at each point change based on the number of grid points used to store the data.

The regridding capabilities allow the user to obtain the data in any arbitrary representation. For example, if we want to shift to the middle of the unit-cell and create a ((1,1), (1,-1)) super-cell, with a 30 by 32 grid, we can run:

pg_2x = pg2d.get_transformed([[1, 1], [1, -1]], origin=[0.5, 0.5], grid_out=[30, 32])
get_scatter_plot(pg_2x.grid_data, pg_2x.lattice, skips=1, opacity=1, marker_size=10)

png

Up-sampling with Fourier interpolation

The up-sampling capabilities allow the user to exploit the periodicity of the data to obtain a higher-resolution grid. As an example, we can take a sparsely sampled periodic data in 1-D:

def func1(X):
    return np.sin(6 * X)


a = np.linspace(0, np.pi, 10, endpoint=False)
data = func1(a)

pg1d = PGrid(grid_data=data, lattice=[[np.pi]])
get_scatter_plot(pg1d.grid_data, pg1d.lattice, marker_size=50)

png

This does not really resemble the np.sin(6*X) function we used to generate the data. However, if we use an up-sample factor of 8, we can obtain a more dense representation:

pg1d_fine = pg1d.get_transformed(
    sc_mat=[[2]],
    grid_out=[
        200,
    ],
    up_sample=8,
)
get_scatter_plot(pg1d_fine.grid_data, pg1d_fine.lattice, marker_size=10)

png

The ChargeDensity class

The ChargeDensity object can use the from_file construction method from pymatgen.io.vasp.outputs.Chgcar as shown below.

from pymatgen.io.vasp import Chgcar
from pyrho.charge_density import ChargeDensity

cden_uc = ChargeDensity.from_file(
    "../test_files/CHGCAR.uc.vasp"
)
cden_sc = ChargeDensity.from_file(
    "../test_files/CHGCAR.sc1.vasp"
)
chgcar_sc = Chgcar.from_file(
    "../test_files/CHGCAR.sc1.vasp"
)
cden_transformed = cden_uc.get_transformed(
    [[1, 1, 0], [1, -1, 0], [0, 0, 1]],
    grid_out=cden_sc.grid_shape,
    up_sample=2,
)

The normalized_data property contains a dictionary keyed with the same keys as Chgcar.data (typically "total" and "diff" for spin charge densities). This quantity is the fixed scalar field that should remain fixed after the transformation.

data = cden_uc.normalized_data["total"]
print(
    f"The normalized charge density data is has a range of {data.min():0.3f} --> {data.max():0.3f} e-/Ang^3"
)
The normalized charge density data is has a range of -0.188 --> 0.572 e-/Ang^3

Note that the PAW transformation sometimes results in negative charge densities.

trans_data = cden_transformed.normalized_data["total"]
print(
    f"The transformed normalized charge density data is has a range of {trans_data.min():0.3f} --> {trans_data.max():0.3f} e-/Ang^3"
)
The transformed normalized charge density data is has a range of -0.188 --> 0.572 e-/Ang^3
sc_data = cden_sc.normalized_data["total"]
print(
    f"The reference normalized charge density data is has a range of {sc_data.min():0.3f} --> {sc_data.max():0.3f} e-/Ang^3"
)
The reference normalized charge density data is has a range of -0.188 --> 0.570 e-/Ang^3

Credits

Jimmy-Xuan Shen: Project lead

Wennie Wang: For naming the package

Metadata

Release files for mp-pyrho 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mp-pyrho 0.5.1
File Size Uploaded
mp_pyrho-0.5.1.tar.gz 2.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for mp-pyrho 0.5.1
File Interpreter ABI Platform
mp_pyrho-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.4 MB

Release files / mp_pyrho-0.5.1.tar.gz

Download URL mp_pyrho-0.5.1.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
f77fd7383d08f07c94896885fb6183413a8ff0befa3dca9791db0bdf4dd02d58
BLAKE2b-256 checksum
How to use checksums
e471fe2a483fdb5e25f91aa65b06b8e799be06ea1ffd38799e9c0a3b6652ec4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / mp_pyrho-0.5.1-py3-none-any.whl

Download URL mp_pyrho-0.5.1-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
934d90c6be35eeccc6b0d550771410b0801dbf4488aca96517f958b5045dd161
BLAKE2b-256 checksum
How to use checksums
51267461a015cf35925e193f4afbe5b066a5fdb5eb76e87e80c63f50f614c3f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page