Skip to main content

Python bindings for Voro++ with 2D/3D Voronoi and power/Laguerre tessellations, periodic topology utilities, and inverse power fitting.

Project description

pyvoro2

CI Docs PyPI Python Versions License

Documentation: https://delonecommons.github.io/pyvoro2/


pyvoro2 is a Python interface to the C++ library Voro++ for computing 2D and 3D Voronoi-type tessellations around a set of points:

  • Voronoi tessellations (standard, unweighted)
  • power / Laguerre tessellations (weighted Voronoi, via per-site radii)
  • a dedicated planar namespace, pyvoro2.planar, for 2D rectangular domains

The focus is not only on computing cells, but on making the results usable in scientific and geometric settings that need periodic boundary conditions, explicit neighbor-image shifts, reproducible topology/normalization utilities, and a reusable mathematical interface to Voronoi and power tessellations.

pyvoro2 is designed to be honest and predictable:

  • it vendors and wraps an upstream Voro++ snapshot (with a small numeric robustness patch for power/Laguerre diagrams);
  • the 3D top-level API stays separate from the 2D pyvoro2.planar namespace;
  • the core tessellation modes are standard Voronoi and power/Laguerre.

License note: starting with 0.6.0, the pyvoro2-authored code is released under LGPLv3+. Versions before 0.6.0 were released under MIT. Vendored third-party code remains under its own licenses.

Quickstart

1) Standard Voronoi in a 3D bounding box

For 3D visualization, install the optional dependency: pip install "pyvoro2[viz]".

import numpy as np
import pyvoro2 as pv
from pyvoro2.viz3d import view_tessellation

points = np.random.default_rng(0).uniform(-1.5, 1.5, size=(10, 3))
box = pv.Box(((-2, 2), (-2, 2), (-2, 2)))
cells = pv.compute(points, domain=box, mode='standard')

view_tessellation(
    cells,
    domain=box,
    show_vertices=False,
)
Voronoi tessellation in a box

2) Planar periodic workflow

import numpy as np
import pyvoro2.planar as pv2

pts2 = np.array([
    [0.2, 0.2],
    [0.8, 0.25],
    [0.4, 0.8],
], dtype=float)

cell2 = pv2.RectangularCell(((0.0, 1.0), (0.0, 1.0)), periodic=(True, True))
result2 = pv2.compute(
    pts2,
    domain=cell2,
    return_diagnostics=True,
    normalize='topology',
)

diag2 = result2.require_tessellation_diagnostics()
topo2 = result2.require_normalized_topology()

3) Power/Laguerre tessellation (weighted Voronoi)

radii = np.full(len(points), 1.2)

cells = pv.compute(
    points,
    domain=box,
    mode='power',
    radii=radii,
    include_empty=True,  # power diagrams can have zero-volume cells
)

4) Periodic crystal cell with neighbor image shifts

cell = pv.PeriodicCell(
    vectors=(
        (10.0, 0.0, 0.0),
        (2.0,  9.0, 0.0),
        (1.0,  0.5, 8.0),
    )
)

cells = pv.compute(points, domain=cell, return_face_shifts=True)

# Each face can include:
#   adjacent_cell  (neighbor id)
#   adjacent_shift (which periodic image produced the face)

Numerical safety notes

Voro++ uses a few fixed absolute tolerances internally (most importantly a hard near-duplicate check around ~1e-5 in container distance units). For very small or very large coordinate systems, this can lead to hard process termination or loss of accuracy.

pyvoro2 does not silently rescale your coordinates. If you work in unusual units, rescale explicitly before calling into the C++ layer.

As an additional safety net, you can ask pyvoro2 to run a fast Python-side near-duplicate pre-check before entering the C++ layer:

cells = pv.compute(points, domain=cell, duplicate_check='raise')

For stricter post-hoc checks, see:

  • pyvoro2.validate_tessellation(..., level='strict')
  • pyvoro2.validate_normalized_topology(..., level='strict')
  • pyvoro2.planar.validate_tessellation(..., level='strict')
  • pyvoro2.planar.validate_normalized_topology(..., level='strict')

Note: pyvoro2 vendors a Voro++ snapshot that includes the upstream numeric robustness fix for power/Laguerre mode (radical pruning). This avoids rare cross-platform edge cases where fully periodic power tessellations could yield a non-reciprocal face/neighbor graph under aggressive floating-point codegen.

Why use pyvoro2

Voro++ is fast and feature-rich, but it is a C++ library with a low-level API. pyvoro2 aims to be a scientific interface that stays close to Voro++ while adding practical pieces that are easy to get wrong:

  • triclinic periodic cells (PeriodicCell) with robust coordinate mapping in 3D
  • partially periodic orthorhombic cells (OrthorhombicCell) for slabs and wires
  • dedicated planar 2D support in pyvoro2.planar for boxes and rectangular periodic cells
  • optional periodic image shifts (adjacent_shift) on faces/edges for building periodic graphs
  • diagnostics and normalization utilities for reproducible topology work
  • convenience operations beyond full tessellation:
    • locate(...) / pyvoro2.planar.locate(...) (owner lookup for arbitrary query points)
    • ghost_cells(...) / pyvoro2.planar.ghost_cells(...) (probe cell at a query point without inserting it)
    • power-fitting utilities for fitting power weights from desired pairwise separator locations in both 2D and 3D

Documentation overview

The documentation is written as a short scientific tutorial: it starts with the geometric ideas, then explains domains and operations, and only then dives into implementation-oriented details.

Section What it contains
Concepts What Voronoi and power/Laguerre tessellations are, and what you can expect from them.
Domains (3D) Which spatial containers exist (Box, OrthorhombicCell, PeriodicCell) and how to choose between them.
Planar (2D) The planar namespace, current 2D domain scope, wrapper-level diagnostics/normalization convenience, and plotting.
Operations How to compute tessellations, assign query points, and compute probe (ghost) cells in the 3D and planar namespaces.
Topology and graphs How to build periodic neighbor graphs and how normalization helps in both 2D and 3D.
Power fitting Fit power weights from pairwise bisector constraints, realized-boundary matching, and self-consistent active sets in 2D or 3D.
Visualization Optional py3Dmol / matplotlib helpers for debugging and exploratory analysis.
Examples (notebooks) End-to-end examples, including focused power-fitting notebooks for reports, infeasibility witnesses, and active-set path diagnostics.
API reference The full reference (docstrings) for both the spatial and planar APIs.

Installation

Most users should install a prebuilt wheel:

pip install pyvoro2

Optional extras:

  • pyvoro2[viz] for the 3D py3Dmol viewer (and 2D plotting too)
  • pyvoro2[viz2d] for 2D matplotlib plotting only
  • pyvoro2[all] to install the full optional stack used for local notebook, docs, lint, and publishability checks

To build from source (requires a C++ compiler and Python development headers):

pip install -e .

For contributor-style local validation, install the full optional stack:

pip install -e ".[all]"

Testing

pyvoro2 uses pytest. The default test suite is intended to be fast and deterministic:

pip install -e ".[test]"
pytest

Additional test groups are opt-in:

  • Fuzz/property tests (randomized):

    pytest -m fuzz --fuzz-n 100
    
  • Cross-check tests vs pyvoro (requires installing pyvoro first):

    pip install pyvoro
    pytest -m pyvoro --fuzz-n 100
    
  • Slow tests (if any are added in the future):

    pytest -m slow
    

Tip: you can combine markers, e.g. pytest -m "fuzz and pyvoro" --fuzz-n 100.

Release and publishability checks

For a one-shot local publishability pass (lint, notebook execution, exported notebook sync, README sync, tests, docs, build, metadata checks, and wheel smoke test):

python tools/release_check.py

Project status

pyvoro2 is currently in beta.

The core tessellation modes (standard and power/Laguerre) are stable, and the 0.6.0 release now includes a first-class planar namespace. A future 1.0 release is planned once the inverse-fitting workflow is more mature, its disconnected-graph / coverage diagnostics are stabilized, and the project has reassessed whether planar PeriodicCell support is actually needed.

AI-assisted development

Some parts of the implementation, tests, and documentation were developed with AI assistance (OpenAI ChatGPT). The maintainer reviews and integrates changes, and remains responsible for the resulting code and scientific claims.

Details are documented in the AI usage page.

License

  • Starting with 0.6.0, the pyvoro2-authored code is released under the GNU Lesser General Public License v3.0 or later (LGPLv3+).
  • Versions before 0.6.0 were released under the MIT License.
  • Voro++ is vendored and redistributed under its original upstream license.

This README is auto-generated from the MkDocs sources in docs/. To update it, edit the docs pages and re-run: python tools/gen_readme.py.

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

pyvoro2-0.6.1.tar.gz (762.0 kB view details)

Uploaded Source

Built Distributions

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

pyvoro2-0.6.1-cp313-cp313-win_amd64.whl (380.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pyvoro2-0.6.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (451.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyvoro2-0.6.1-cp313-cp313-macosx_11_0_arm64.whl (361.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyvoro2-0.6.1-cp312-cp312-win_amd64.whl (380.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pyvoro2-0.6.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (452.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyvoro2-0.6.1-cp312-cp312-macosx_11_0_arm64.whl (361.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyvoro2-0.6.1-cp311-cp311-win_amd64.whl (378.5 kB view details)

Uploaded CPython 3.11Windows x86-64

pyvoro2-0.6.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (452.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyvoro2-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (362.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyvoro2-0.6.1-cp310-cp310-win_amd64.whl (377.2 kB view details)

Uploaded CPython 3.10Windows x86-64

pyvoro2-0.6.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (449.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyvoro2-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (360.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyvoro2-0.6.1.tar.gz.

File metadata

  • Download URL: pyvoro2-0.6.1.tar.gz
  • Upload date:
  • Size: 762.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyvoro2-0.6.1.tar.gz
Algorithm Hash digest
SHA256 a00266cc4b5db58a5c37ebcad5f626043a5ed4fbd5a9b24ef82e3ff738beaa83
MD5 babe938b0ba8ad8bf790b7fc91a0cefa
BLAKE2b-256 5a067d182891286dbfc9ad1d07770efa28aeee4965991a1672d15c48d23c54e7

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyvoro2-0.6.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 380.2 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyvoro2-0.6.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6637dabc3f7a5691861f26c54618b4ec1c89b7abfb30d663c26832f5030f6db5
MD5 fa6b8758e27156c0478b6d35ec15ff39
BLAKE2b-256 0ed28cfa803b59f7a4ab3f900e2b1a7675d3ec5e9738f194d2291c491705d5b5

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 878720027cf11bfe28d33aa6ec49648552756872159821a04e30098d92b1352f
MD5 240c0a807158cf7a4cc8cc382b5fced1
BLAKE2b-256 dd4850df0f0e8b82be790cb3e435f26063a41872ecd57b9c040b146190819cd7

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f6f80af3b65720f5d96c9dcc89b828dcc3b27da31fab0c101124866527052fc
MD5 1e90562aa37ae39186ef8fb199edb43a
BLAKE2b-256 7bafade7be48594b32bc29844fbffa13ffd02a947034f4b03f9da581519ffdf6

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyvoro2-0.6.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 380.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyvoro2-0.6.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c644081e026627923834fd28f9c1424adca129cec1a6d07576b14cc7cbfe3fd0
MD5 0860f41b38d14c61f063aae6d136bcb7
BLAKE2b-256 330cfd1bc76fe5627edfaf2c96976d2f659a6d285bf2e737b9e522bc02025336

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bba96346cb53b56fc0793e57b1baf9e49c0eab56b7b89efe875693b5c5f89297
MD5 bcfa5d09b1b6ac90b6726690024c3ac3
BLAKE2b-256 4914ff1728e30a47402272560549feeb5a7a362355cc24a94e0be3a7a55e3294

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d298f3a3433a41ab797310d5bb1d33110809eef9146605092ac70a09400b6cbf
MD5 b8ba60c2579c3080e2db8fd728a315a6
BLAKE2b-256 95827c488396c590a6cde545f6ca47510e7333cd32e193a04778faa018510861

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyvoro2-0.6.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 378.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyvoro2-0.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4caaebaa4ab82c4962995fca68bb8b7965c13844799b0228dceb90e7b0bfe439
MD5 68aa0f981609e069ceb26b6f9bb759f0
BLAKE2b-256 0f571bee820dc62752248c2f1411eae05965a751b432b82b2cd86ff4b9b9da9d

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 09f6632c71f036dde460f25c8b0b4d903a27117440bdab8002aad073779527c2
MD5 0213b09a0b3d7892b8cbf0592728545f
BLAKE2b-256 8be502d7fbc21dc53e2c6b92af6661c4a954010a75c7df272523e56548cb92c5

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 140bee45869ca35e79d463ab6e4d07ea443e295afed0dd4c3c8ac1a709692236
MD5 48dd2a2ed43165b13ea8528f8171ad2a
BLAKE2b-256 dab5ae55b82d91c638f9b6779c9bd48550b2f2041c1957a8b7e2af40df61b224

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyvoro2-0.6.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 377.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyvoro2-0.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 888d6a9cf3249dcd82782ee1f000ba130271db4fef881476f9023ec365c7a733
MD5 efc987a49fdfbd08490ca54e136fdaee
BLAKE2b-256 a778e199c85af34cac620c966646fbf822daa07aa27fb904d8656569a753db80

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de5c5701fe8d3b8f8904c9487ed24b5f8a218281c5988b5c0f72005e9a96ed1f
MD5 6a599adc9a27c8ed64356bbdd82a19a5
BLAKE2b-256 66a3ba92a3b9999c1b761e5879c0fd4fa6f0418c38df8d66b1895bc36ad25865

See more details on using hashes here.

File details

Details for the file pyvoro2-0.6.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvoro2-0.6.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b615c46bbca6117a1269a9cb9ee7022a79ea8d0014d21e3cc7530b8562c21a08
MD5 bc2abc4547b8d78b0b35d5ee2a54ae57
BLAKE2b-256 67912727c4997ba972972418033e603df57e08b15745b785feadc65e68d68148

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