Skip to main content

No project description provided

Project description

pbc_distance_calculator

This Python package computes pairwise distances in a simulation box accounting for periodic boundary conditions.

The only inputs are the positions of each particle and the simulation supercell matrix.

To install:

pip install pbc_distance_calculator

Example usage:

from numpy.typing import NDArray
from pbc_distance_calculator import get_pairwise_distances

# array of shape (N, 3) where N is the number of particles
positions: NDArray = ...

# array of shape (3, 3)
cell_matrix: NDArray = ...

# array of shape (N, N)
# element (i, j) is minimum image distance between i and j
pairwise_distances: NDArray = get_pairwise_distances(positions, cell_matrix)

The above script performs the calculation in a vectorized form, computing every pairwise distance at once. To do it serially instead:

from numpy.typing import NDArray
from pbc_distance_calculator import get_pairwise_distance

# arrays of shape (1, 3) or (3, 1)
first_position: NDArray = ...
second_position: NDArray = ...

# array of shape (3, 3)
cell_matrix: NDArray = ...

# minimum image distance
pairwise_distances: float = get_pairwise_distance(first_position - second_position, cell_matrix)

Note that the cell matrix, is, in general:

$$ \begin{pmatrix} \mathbf{a} & \mathbf{b} & \mathbf{c} \end{pmatrix} $$

where $\mathbf{a}$, $\mathbf{b}$, and $\mathbf{c}$ are the lattice vectors of the supercell. Note that this definition works for any set of lattice parameters! So, no matter how weird your crystal, this package should work. If there are any issues, feel free to open an issue 🙂.

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

pbc_distance_calculator-1.1.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

pbc_distance_calculator-1.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file pbc_distance_calculator-1.1.0.tar.gz.

File metadata

File hashes

Hashes for pbc_distance_calculator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9acf0577953961ebcafec0a5393902cc744ff27f239015a6b02274ccadc61a60
MD5 a3e0d51d5f978f50e7a177dd7bbc437d
BLAKE2b-256 50dd03197a50893fcdd7ad4fc15d24d5f09b2e602a05c406f32a9571f88c90fd

See more details on using hashes here.

File details

Details for the file pbc_distance_calculator-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pbc_distance_calculator-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be5536353b27e5ce90e2cbd3962cb2c80698ae911388105be68bd66a6abe4266
MD5 7b96eb438eb68576be82b6d636fbeac6
BLAKE2b-256 b46a0f751deae4a3ed8e2255a2ff018cc125a4ada75d75178cd5a051d88f41ee

See more details on using hashes here.

Supported by

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