Metadata-Version: 2.2
Name: pyvoro2
Version: 0.6.3
Summary: Python bindings for Voro++ with 2D/3D Voronoi and power/Laguerre tessellations, periodic topology utilities, and inverse power fitting.
Author-Email: "Ivan Yu. Chernyshov" <ivan.chernyshoff@gmail.com>
License:                    GNU LESSER GENERAL PUBLIC LICENSE
                                Version 3, 29 June 2007
         
          Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
          Everyone is permitted to copy and distribute verbatim copies
          of this license document, but changing it is not allowed.
         
         
           This version of the GNU Lesser General Public License incorporates
         the terms and conditions of version 3 of the GNU General Public
         License, supplemented by the additional permissions listed below.
         
           0. Additional Definitions.
         
           As used herein, "this License" refers to version 3 of the GNU Lesser
         General Public License, and the "GNU GPL" refers to version 3 of the GNU
         General Public License.
         
           "The Library" refers to a covered work governed by this License,
         other than an Application or a Combined Work as defined below.
         
           An "Application" is any work that makes use of an interface provided
         by the Library, but which is not otherwise based on the Library.
         Defining a subclass of a class defined by the Library is deemed a mode
         of using an interface provided by the Library.
         
           A "Combined Work" is a work produced by combining or linking an
         Application with the Library.  The particular version of the Library
         with which the Combined Work was made is also called the "Linked
         Version".
         
           The "Minimal Corresponding Source" for a Combined Work means the
         Corresponding Source for the Combined Work, excluding any source code
         for portions of the Combined Work that, considered in isolation, are
         based on the Application, and not on the Linked Version.
         
           The "Corresponding Application Code" for a Combined Work means the
         object code and/or source code for the Application, including any data
         and utility programs needed for reproducing the Combined Work from the
         Application, but excluding the System Libraries of the Combined Work.
         
           1. Exception to Section 3 of the GNU GPL.
         
           You may convey a covered work under sections 3 and 4 of this License
         without being bound by section 3 of the GNU GPL.
         
           2. Conveying Modified Versions.
         
           If you modify a copy of the Library, and, in your modifications, a
         facility refers to a function or data to be supplied by an Application
         that uses the facility (other than as an argument passed when the
         facility is invoked), then you may convey a copy of the modified
         version:
         
            a) under this License, provided that you make a good faith effort to
            ensure that, in the event an Application does not supply the
            function or data, the facility still operates, and performs
            whatever part of its purpose remains meaningful, or
         
            b) under the GNU GPL, with none of the additional permissions of
            this License applicable to that copy.
         
           3. Object Code Incorporating Material from Library Header Files.
         
           The object code form of an Application may incorporate material from
         a header file that is part of the Library.  You may convey such object
         code under terms of your choice, provided that, if the incorporated
         material is not limited to numerical parameters, data structure
         layouts and accessors, or small macros, inline functions and templates
         (ten or fewer lines in length), you do both of the following:
         
            a) Give prominent notice with each copy of the object code that the
            Library is used in it and that the Library and its use are
            covered by this License.
         
            b) Accompany the object code with a copy of the GNU GPL and this license
            document.
         
           4. Combined Works.
         
           You may convey a Combined Work under terms of your choice that,
         taken together, effectively do not restrict modification of the
         portions of the Library contained in the Combined Work and reverse
         engineering for debugging such modifications, if you also do each of
         the following:
         
            a) Give prominent notice with each copy of the Combined Work that
            the Library is used in it and that the Library and its use are
            covered by this License.
         
            b) Accompany the Combined Work with a copy of the GNU GPL and this license
            document.
         
            c) For a Combined Work that displays copyright notices during
            execution, include the copyright notice for the Library among
            these notices, as well as a reference directing the user to the
            copies of the GNU GPL and this license document.
         
            d) Do one of the following:
         
                0) Convey the Minimal Corresponding Source under the terms of this
                License, and the Corresponding Application Code in a form
                suitable for, and under terms that permit, the user to
                recombine or relink the Application with a modified version of
                the Linked Version to produce a modified Combined Work, in the
                manner specified by section 6 of the GNU GPL for conveying
                Corresponding Source.
         
                1) Use a suitable shared library mechanism for linking with the
                Library.  A suitable mechanism is one that (a) uses at run time
                a copy of the Library already present on the user's computer
                system, and (b) will operate properly with a modified version
                of the Library that is interface-compatible with the Linked
                Version.
         
            e) Provide Installation Information, but only if you would otherwise
            be required to provide such information under section 6 of the
            GNU GPL, and only to the extent that such information is
            necessary to install and execute a modified version of the
            Combined Work produced by recombining or relinking the
            Application with a modified version of the Linked Version. (If
            you use option 4d0, the Installation Information must accompany
            the Minimal Corresponding Source and Corresponding Application
            Code. If you use option 4d1, you must provide the Installation
            Information in the manner specified by section 6 of the GNU GPL
            for conveying Corresponding Source.)
         
           5. Combined Libraries.
         
           You may place library facilities that are a work based on the
         Library side by side in a single library together with other library
         facilities that are not Applications and are not covered by this
         License, and convey such a combined library under terms of your
         choice, if you do both of the following:
         
            a) Accompany the combined library with a copy of the same work based
            on the Library, uncombined with any other library facilities,
            conveyed under the terms of this License.
         
            b) Give prominent notice with the combined library that part of it
            is a work based on the Library, and explaining where to find the
            accompanying uncombined form of the same work.
         
           6. Revised Versions of the GNU Lesser General Public License.
         
           The Free Software Foundation may publish revised and/or new versions
         of the GNU Lesser General Public License from time to time. Such new
         versions will be similar in spirit to the present version, but may
         differ in detail to address new problems or concerns.
         
           Each version is given a distinguishing version number. If the
         Library as you received it specifies that a certain numbered version
         of the GNU Lesser General Public License "or any later version"
         applies to it, you have the option of following the terms and
         conditions either of that published version or of any later version
         published by the Free Software Foundation. If the Library as you
         received it does not specify a version number of the GNU Lesser
         General Public License, you may choose any version of the GNU Lesser
         General Public License ever published by the Free Software Foundation.
         
           If the Library as you received it specifies that a proxy can decide
         whether future versions of the GNU Lesser General Public License shall
         apply, that proxy's public statement of acceptance of any version is
         permanent authorization for you to choose that version for the
         Library.
         
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: C++
Project-URL: Homepage, https://github.com/DeloneCommons/pyvoro2
Project-URL: Documentation, https://delonecommons.github.io/pyvoro2/
Project-URL: Repository, https://github.com/DeloneCommons/pyvoro2
Project-URL: Issues, https://github.com/DeloneCommons/pyvoro2/issues
Requires-Python: >=3.10
Requires-Dist: numpy<2,>=1.23; python_version < "3.11"
Requires-Dist: numpy<3,>=1.23; python_version >= "3.11"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.6; extra == "docs"
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.27; extra == "docs"
Requires-Dist: pymdown-extensions>=10.0; extra == "docs"
Requires-Dist: mkdocs-section-index>=0.3.9; extra == "docs"
Provides-Extra: viz2d
Requires-Dist: matplotlib; extra == "viz2d"
Provides-Extra: viz
Requires-Dist: matplotlib; extra == "viz"
Requires-Dist: py3Dmol; extra == "viz"
Provides-Extra: all
Requires-Dist: pytest; extra == "all"
Requires-Dist: flake8; extra == "all"
Requires-Dist: build; extra == "all"
Requires-Dist: twine; extra == "all"
Requires-Dist: mkdocs>=1.6; extra == "all"
Requires-Dist: mkdocs-material>=9.5; extra == "all"
Requires-Dist: mkdocstrings[python]>=0.27; extra == "all"
Requires-Dist: pymdown-extensions>=10.0; extra == "all"
Requires-Dist: mkdocs-section-index>=0.3.9; extra == "all"
Requires-Dist: matplotlib; extra == "all"
Requires-Dist: py3Dmol; extra == "all"
Requires-Dist: tomli; python_version < "3.11" and extra == "all"
Description-Content-Type: text/markdown

# pyvoro2

[![CI](https://github.com/DeloneCommons/pyvoro2/actions/workflows/ci.yml/badge.svg)](https://github.com/DeloneCommons/pyvoro2/actions/workflows/ci.yml) [![Docs](https://github.com/DeloneCommons/pyvoro2/actions/workflows/docs.yml/badge.svg)](https://github.com/DeloneCommons/pyvoro2/actions/workflows/docs.yml) [![PyPI](https://img.shields.io/pypi/v/pyvoro2.svg)](https://pypi.org/project/pyvoro2/) [![Python Versions](https://img.shields.io/pypi/pyversions/pyvoro2.svg)](https://pypi.org/project/pyvoro2/) [![License](https://img.shields.io/pypi/l/pyvoro2.svg)](https://github.com/DeloneCommons/pyvoro2/blob/main/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]"`.

```python
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,
)
```

<img src="https://raw.githubusercontent.com/DeloneCommons/pyvoro2/main/docs/assets/quickstart_box.png" width="50%" alt="Voronoi tessellation in a box" />

### 2) Planar periodic workflow

```python
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)

```python
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

```python
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:

```python
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](https://delonecommons.github.io/pyvoro2/guide/concepts/) | What Voronoi and power/Laguerre tessellations are, and what you can expect from them. |
| [Domains (3D)](https://delonecommons.github.io/pyvoro2/guide/domains/) | Which spatial containers exist (`Box`, `OrthorhombicCell`, `PeriodicCell`) and how to choose between them. |
| [Planar (2D)](https://delonecommons.github.io/pyvoro2/guide/planar/) | The planar namespace, current 2D domain scope, wrapper-level diagnostics/normalization convenience, and plotting. |
| [Operations](https://delonecommons.github.io/pyvoro2/guide/operations/) | How to compute tessellations, assign query points, and compute probe (ghost) cells in the 3D and planar namespaces. |
| [Topology and graphs](https://delonecommons.github.io/pyvoro2/guide/topology/) | How to build periodic neighbor graphs and how normalization helps in both 2D and 3D. |
| [Power fitting](https://delonecommons.github.io/pyvoro2/guide/powerfit/) | Fit power weights from pairwise bisector constraints, realized-boundary matching, and self-consistent active sets in 2D or 3D. |
| [Visualization](https://delonecommons.github.io/pyvoro2/guide/visualization/) | Optional `py3Dmol` / `matplotlib` helpers for debugging and exploratory analysis. |
| [Examples (notebooks)](https://delonecommons.github.io/pyvoro2/guide/notebooks/) | End-to-end examples, including focused power-fitting notebooks for reports, infeasibility witnesses, and active-set path diagnostics. |
| [API reference](https://delonecommons.github.io/pyvoro2/reference/planar/) | The full reference (docstrings) for both the spatial and planar APIs. |

## Installation

Most users should install a prebuilt wheel:

```bash
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):

```bash
pip install -e .
```

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

```bash
pip install -e ".[all]"
```

## Testing

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

```bash
pip install -e ".[test]"
pytest
```

Additional test groups are **opt-in**:

- **Fuzz/property tests** (randomized):

  ```bash
  pytest -m fuzz --fuzz-n 100
  ```

- **Cross-check tests vs `pyvoro`** (requires installing `pyvoro` first):

  ```bash
  pip install pyvoro
  pytest -m pyvoro --fuzz-n 100
  ```

- **Slow tests** (if any are added in the future):

  ```bash
  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):

```bash
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](https://delonecommons.github.io/pyvoro2/project/ai/) 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`.

