mp-pyrho: Quantum Chemistry Data Regridding

0.5.1 · active · verified Fri Apr 17

mp-pyrho is a Python library providing tools for re-gridding periodic volumetric quantum chemistry data (e.g., charge densities, COHP, ELFCAR) into a consistent, resolution-agnostic representation suitable for machine learning applications. It is currently at version 0.5.1 and is actively maintained with a regular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `RhoGrid` object with a `pymatgen.core.Structure` and dummy 3D volumetric data. It then shows how to use the `regrid` method to standardize the resolution and the `featurize` method to generate a machine-learning-ready representation, either as a 1D vector or a 3D grid.

from pymatgen.core import Structure
from mp_pyrho.grid import RhoGrid
import numpy as np

# Create a dummy structure (e.g., a simple cubic perovskite)
structure = Structure.from_spacegroup("Pm-3m", [3.8], ["Fe", "O"], [[0, 0, 0], [0.5, 0.5, 0.5]])

# Create dummy 3D volumetric data (e.g., 20x20x20 points)
# In a real scenario, this would be loaded from a CHGCAR, LOCPOT, or similar file
dummy_grid_data = np.random.rand(20, 20, 20)

# Initialize RhoGrid object with the structure and volumetric data
rho_grid = RhoGrid(structure=structure, grid_data=dummy_grid_data)

# Regrid the data to a new target resolution (e.g., 0.1 Å)
# The output is a 3D NumPy array
regridded_data = rho_grid.regrid(target_resolution=0.1)
print(f"Original grid shape: {rho_grid.grid_data.shape}")
print(f"Shape of regridded data: {regridded_data.shape}")

# Featurize the regridded data
# For mp-pyrho >= 0.5.0, `vectorize_grid` defaults to True and `center_method` to 'mass'
features_vectorized = rho_grid.featurize(target_resolution=0.1)
print(f"Shape of features (vectorized): {features_vectorized.shape}")

# If you need the 3D grid output from featurize, set vectorize_grid=False
features_3d_grid = rho_grid.featurize(target_resolution=0.1, vectorize_grid=False)
print(f"Shape of features (3D grid): {features_3d_grid.shape}")

view raw JSON →