Skip to content

Duplicate check

pyvoro2.duplicates

Duplicate / near-duplicate point detection.

Voro++ contains an internal "duplicate" safeguard that can terminate the process (via exit(1)) if it detects two points closer than an absolute threshold (~1e-5 in container distance units).

This module provides a fast Python-side pre-check to detect such cases before calling into the C++ library.

The check is intentionally simple
  • spatial hashing on an integer grid with cell size == threshold
  • compare each point only to points in its own grid cell and neighboring 26 cells

Expected complexity is O(n) for typical inputs.

DuplicateError

Bases: ValueError

Raised when near-duplicate points are detected.

duplicate_check(points, *, threshold=1e-05, domain=None, wrap=True, mode='raise', max_pairs=10)

Detect point pairs closer than an absolute threshold.

Parameters:

Name Type Description Default
points Any

Array-like of shape (n, 3).

required
threshold float

Absolute distance threshold. The default (1e-5) matches the effective Voro++ duplicate check (distance < 1e-5).

1e-05
domain Domain | None

Optional domain. If provided and wrap=True, points are first remapped into the primary periodic domain for periodic domains, matching what Voro++ will do internally.

None
wrap bool

Whether to remap points into the primary domain when domain has periodicity.

True
mode Literal['raise', 'warn', 'return']

Behavior when duplicates are found: - 'raise' (default): raise :class:DuplicateError - 'warn': emit a RuntimeWarning and return the pairs - 'return': return the pairs without warnings

'raise'
max_pairs int

Maximum number of pairs to include in the report.

10

Returns:

Type Description
tuple[DuplicatePair, ...]

Tuple of DuplicatePair records (possibly empty).

:::