Skip to main content

Periodic atom-centered voxel grids for atomistic structures.

Project description

AtomVoxelizer

AtomVoxelizer builds periodic atom-centered voxel grids for atomistic structures. The core VoxelGrid class stores a 3D NumPy grid over a periodic cell and provides helpers for adding, setting, scaling, sampling, and plotting spherical regions.

Installation

Install the latest released package from PyPI:

pip install AtomVoxelizer

Install from the GitLab repository for development or unreleased changes:

git clone https://gitlab.com/tgmaxson/atomvoxelizer.git
cd atomvoxelizer
pip install -e ".[dev,examples]"

Install optional acceleration backends directly if you need them:

pip install numba
pip install taichi
# Choose the CuPy package matching your CUDA runtime, for example:
pip install cupy-cuda12x
pip install ".[analysis]"

VoxelGrid is always the NumPy backend. Optional acceleration backends are explicit: VoxelGridNumba, VoxelGridTaichi, and VoxelGridCuPy. VoxelGridAnalysis uses scikit-image for connected-volume and marching-cubes analysis when the analysis extra is installed. The examples extra installs ASE for CIF loading and Wulff construction examples.

Basic Usage

import numpy as np

from atomvoxelizer import VoxelGrid

cell = np.eye(3) * 10.0
grid = VoxelGrid(cell=cell, resolution=0.25)

grid.add_sphere(center=np.array([5.0, 5.0, 5.0]), radius=1.0, value=1.0)
grid.set_sphere(center=np.array([2.0, 2.0, 2.0]), radius=0.5, value=-1.0)
grid.clamp_grid(min_val=-1.0, max_val=1.0)

Sphere operations accept two masks. mask="constant" writes the supplied value or factor across the sphere. mask="distance" writes the real-space distance from the sphere center at each voxel. Combining a distance mask with min_spheres gives a nearest-atom distance field:

from atomvoxelizer import VoxelGridAnalysis

grid.grid.fill(np.inf)
grid.min_spheres(atom_positions, cutoff_radii, mask="distance")

analysis = VoxelGridAnalysis(grid)
vertices, faces = analysis.mesh_at_value(2.0, periodic=True)
surface_area = analysis.mesh_surface_area(vertices, faces)

Periodic scalar meshes are clipped at the primary cell boundary so triangles that cross a periodic boundary are cut at the cell edge.

Zeolite Example

The zeolite example and CIF files live in examples/zeolite/.

pip install -e ".[examples]"
python examples/zeolite/zeolite_voxel.py BEA

The script reads a framework CIF, builds voxel grids at several resolutions, plots middle XZ slices, benchmarks supercell scaling, and opens a 3D scatter plot.

The analysis example estimates geometric pore volume and geometric internal surface area:

pip install -e ".[examples,analysis]"
python examples/zeolite/zeolite_analysis.py BEA --resolution 0.25
python examples/zeolite/zeolite_analysis.py BEA --convergence 1.00 0.95 0.90 0.85 0.80 0.75 0.70 0.65 0.60 0.55 0.50 0.45 0.40 0.35 0.30 0.25 0.20 0.15 0.10 0.05 --plot bea_convergence.png

The analysis example reports geometric voxel estimates, not probe-accessible BET surface areas. It uses a fast voxel-face surface-area estimate by default. Use --surface-method marching-cubes for a smoother marching-cubes estimate on smaller grids.

Wulff Distance-Surface Example

The Wulff example builds a nanoparticle, voxelizes the nearest-atom distance field, and exports a marching-cubes mesh at a requested distance:

pip install -e ".[examples,analysis]"
python examples/wulff/distance_surface.py --symbol Pt --size 147 --distance 2.0 --output pt_surface.npz
python examples/wulff/distance_surface.py --symbol Pt --size 147 --distance 2.0 --plot pt_surface.png
python examples/wulff/distance_surface.py --symbol Pt --size 147 --distance 2.0 --show

Periodic Surface Example

The Pt(211) example traces a periodic nearest-atom distance surface for a stepped slab:

pip install -e ".[examples,analysis]"
python examples/surfaces/pt211_distance_surface.py --distance 1.8 --show

Tests and Benchmarks

Run the correctness tests with:

pytest

Run the backend benchmark with:

python benchmarks/benchmark_backends.py --backends numpy numba taichi cupy
python benchmarks/benchmark_backends.py --zeolite-scaling --framework BEA --resolution 0.5 --plot zeolite_scaling.png
python benchmarks/benchmark_backends.py --workload zeolite --backends taichi-gpu

Run the built-in structure benchmarks for a zeolite and a roughly 1000 atom Wulff construction with:

python benchmarks/benchmark_structures.py

Backends whose optional dependencies are not installed are reported as missing.

Documentation

Documentation is scaffolded with Sphinx for Read the Docs.

Build it locally with:

pip install -e ".[docs]"
sphinx-build -b html docs/source docs/build/html

Read the Docs can use .readthedocs.yaml directly.

Publishing

Build and check PyPI artifacts with:

pip install -e ".[publish]"
python -m build
twine check dist/*

Upload to TestPyPI first, then PyPI:

twine upload --repository testpypi dist/*
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atomvoxelizer-0.2.6.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atomvoxelizer-0.2.6-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file atomvoxelizer-0.2.6.tar.gz.

File metadata

  • Download URL: atomvoxelizer-0.2.6.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for atomvoxelizer-0.2.6.tar.gz
Algorithm Hash digest
SHA256 03038dd93b3b8dd845ccc31cecf20c01e1481baac725b38ad7ba8cdb1f0e3b68
MD5 c0eb87906d26577a89645bf666492948
BLAKE2b-256 eba68afc40ae5f19ea1e54b9812838756b809350038dd6a8cd6fccd36b957fa7

See more details on using hashes here.

File details

Details for the file atomvoxelizer-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: atomvoxelizer-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for atomvoxelizer-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e85c6f909b5a5321f059d83cbff2702c6b0e1238f34cf51218f2a92830a76e98
MD5 46359e6779b92be01a7d48f56e4d40c4
BLAKE2b-256 d79a25abbaaae1c57a110af452ffa0123cf44c0b552dfdec5196eac7e675c53d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page