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_distance: float = get_pairwise_distance(
first_position - second_position,
cell_matrix
)
In both functions, you can also specify different engines to compute the distances. This is especially advantageous for large systems, where you can specify jax.numpy or torch as an engine. For example:
import torch
from pbc_distance_calculator import get_pairwise_distances
...
torch.set_default_device("cuda")
pairwise_distances = get_pairwise_distances(
positions,
cell_matrix,
engine=torch
)
which will calculate the pairwise distances using the CUDA-backend of PyTorch. Note that the only engine installed by default is numpy, so make sure to separately install jax or torch if you want to use these modules.
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 problems, feel free to open an issue 🙂.
Metadata
Release files for pbc-distance-calculator 1.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pbc_distance_calculator-1.3.3.tar.gz | 5.4 kB | Without provenance | Details for pbc_distance_calculator-1.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pbc_distance_calculator-1.3.3-py3-none-any.whl | Python 3 | none | any | Details for pbc_distance_calculator-1.3.3-py3-none-any.whl |
Total release size: 11.7 kB
Release files / pbc_distance_calculator-1.3.3.tar.gz
| Download URL | pbc_distance_calculator-1.3.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b775f59f7bed402b7e3a27c9d7bc66eeeccceb569649714b394f260d0632fb1
|
|
BLAKE2b-256 checksum How to use checksums |
172b49a5b8213bcf17a79522dee097d09c7fb2e34ca23b4ec6f40a77d6fd332f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / pbc_distance_calculator-1.3.3-py3-none-any.whl
| Download URL | pbc_distance_calculator-1.3.3-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c33465428c3c6002b9e58494e6d7e8a0e8f4096203819abfc42d7cde40d0c637
|
|
BLAKE2b-256 checksum How to use checksums |
ecac0ccb946d8c3f4f2145826168bedced78342246ff3d59925901a64eae2bfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for pbc-distance-calculator 1.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.