PackLab
PackLab computes structure in three-dimensional hard-sphere systems. Its primary analytical workflow evaluates the Percus–Yevick (PY) approximation for equilibrium mixtures. It also generates explicit random sequential adsorption (RSA) configurations and samples fixed-volume equilibrium configurations with Metropolis Monte Carlo (MC).
Badge |
Status |
|---|---|
Python versions |
|
Documentation |
|
Continuous integration |
|
Test coverage |
|
PyPI package |
|
PyPI downloads |
|
Anaconda package |
|
Anaconda downloads |
|
Latest Anaconda release |
|
Citation |
The workflows share physical inputs such as particle radii, number fractions, and volume fraction, but they answer different questions:
PY is a fast analytical equilibrium reference for pair correlations, structure factors, and structure-aware scattering calculations.
RSA creates an explicit, non-overlapping deposition configuration. It is irreversible and retains the history of accepted particles.
Metropolis MC moves particles in a valid configuration to sample an equilibrium hard-sphere system at fixed volume, particle count, and radii.
Installation
Install the core package from PyPI:
pip install packlab
For scattering calculations, install the optional PyMieSim integration:
pip install "packlab[scattering]"
Or install the Conda package:
conda install -c martinpdes packlab
Verify the compiled package with:
python -c "import PackLab; print(PackLab.__version__)"
1. Compute a Percus–Yevick equilibrium reference
Use PY when you need equilibrium mixture correlations without generating an explicit packing. PackLab computes the partial pair correlations \(g_{ij}(r)\) and reciprocal-space correlations on an automatically resolved wavenumber grid.
import numpy as np
from PackLab import analytical, ureg
radii = np.array([75, 140]) * ureg.nanometer
domain = analytical.PercusYevickDomain(
size=50 * ureg.micrometer,
radii=radii,
volume_fraction=0.25,
number_fractions=np.array([0.7, 0.3]),
)
distances = np.linspace(0.0, 1.5, 300) * ureg.micrometer
result = analytical.PercusYevickSolver(
densities=domain.particle_densities_per_radius,
radii=domain.radii,
wavenumber="auto",
).compute(distances)
g_12 = result.g[0, 1]
wavenumber = result.wavenumber
The automatic grid is a useful default. For a resolution study, use analytical.make_wavenumber_grid(...) and compare the resulting curves. PY is an analytical approximation to an equilibrium hard-sphere mixture; it does not create particle centres or reproduce the irreversible RSA process.
2. Generate an explicit RSA packing
RSA proposes particles one at a time and keeps only non-overlapping proposals. Accepted particles never move, so the final configuration is physically valid but history-dependent rather than an equilibrium sample.
from PackLab import monte_carlo, samplers, ureg
domain = monte_carlo.PackingDomain(
5 * ureg.micrometer,
5 * ureg.micrometer,
5 * ureg.micrometer,
use_periodic_boundaries=True,
)
sampler = samplers.UniformRadiusSampler(
90 * ureg.nanometer,
170 * ureg.nanometer,
bins=8,
)
options = monte_carlo.RSAOptions()
options.random_seed = 42
options.maximum_attempts = 40_000
options.target_packing_fraction = 0.12
rsa_result = monte_carlo.RSASimulator(domain, sampler, options).run()
print(rsa_result.statistics.packing_fraction_geometry)
figure = rsa_result.plot_slice_2d(show=False)
PackingResult provides accepted centres, sampled radii, packing statistics, pair-correlation estimators, and plotting helpers. Radius samplers support constant, uniform, normal, log-normal, and discrete distributions.
3. Equilibrate hard spheres with Metropolis MC
Use Metropolis MC when an equilibrium configuration is needed. It can start from the valid RSA configuration above, but then proposes particle displacements; particle count, radii, and class labels remain fixed.
options = monte_carlo.MetropolisOptions()
options.random_seed = 34
options.number_of_sweeps = 500
options.maximum_displacement = 50 * ureg.nanometer
simulator = monte_carlo.MetropolisSimulator(
domain,
rsa_result.sphere_configuration,
options,
)
mc_result = simulator.run()
print(simulator.statistics.acceptance_rate)
figure = mc_result.plot_slice_2d(show=False)
The number of sweeps alone does not establish equilibration. Discard an initial burn-in interval, assess autocorrelation for the quantity of interest, and compare larger systems when finite-size effects may matter.
Choosing the right workflow
Workflow |
Use it when you need |
Important limitation |
|---|---|---|
PY analytical |
Fast equilibrium pair correlations, structure factors, parameter sweeps, or scattering inputs. |
It is an equilibrium approximation, not an explicit packing. |
RSA |
Particle centres, radius-sampling effects, deposition history, or a finite non-overlapping configuration. |
It is irreversible and is not an equilibrium sampler. |
Metropolis MC |
An explicit equilibrium hard-sphere configuration at fixed volume and composition. |
Equilibration, autocorrelation, and finite-size effects require checks. |
Scattering
The optional PackLab.scattering workflow computes optical amplitudes with PyMieSim. Combine them with the PY correlation tensor when you need a structure-corrected mixture phase function. See the scattering examples for runnable single-particle and mixture calculations.
Documentation, validation, and citation
The online documentation contains theory, API reference, output conventions, assumptions, and executable galleries for PY, RSA, Metropolis MC, scattering, validation, and benchmarks.
For development:
git clone https://github.com/MartinPdeS/PackLab.git
cd PackLab
pip install -e ".[testing,documentation]"
pytest
If PackLab contributes to academic work, cite the archived Zenodo release you used. Release metadata is included in .zenodo.json.
Metadata
Release files for PackLab 0.6.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| packlab-0.6.10-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| packlab-0.6.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details |
| packlab-0.6.10-cp313-cp313-macosx_26_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 26.0+ ARM64 | Details |
| packlab-0.6.10-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| packlab-0.6.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| packlab-0.6.10-cp312-cp312-macosx_26_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 26.0+ ARM64 | Details |
| packlab-0.6.10-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| packlab-0.6.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| packlab-0.6.10-cp311-cp311-macosx_26_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 26.0+ ARM64 | Details |
Total release size: 28.1 MB
Release files / packlab-0.6.10-cp313-cp313-win_amd64.whl
| Download URL | packlab-0.6.10-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
52f8f5040552d220a07400d68c95eba203c0a52b228aae0dafff262c84e09d60
|
|
BLAKE2b-256 checksum How to use checksums |
47ae66b708acbaa8a2519ff3235d3fbebd4617f7a125947f059765b044f56d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | packlab-0.6.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
4c29f75e97f69aa22a83fa997c45f5ebcb2be36922d3077b0d6d1eab868799ae
|
|
BLAKE2b-256 checksum How to use checksums |
6a171bd2bdc7f0bd9ae597dc8c97c24c3380e0739e23b39e1918330c81043638
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp313-cp313-macosx_26_0_arm64.whl
| Download URL | packlab-0.6.10-cp313-cp313-macosx_26_0_arm64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.13 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4ed3a8d29f7be4db6430bf6ca1efffd065b80b55636d4852fb6c1ba532f27f89
|
|
BLAKE2b-256 checksum How to use checksums |
7d74c790f107946bffd9ea49f50e1fd82acf152b6c1a3376fb2cc67b8f5be151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp312-cp312-win_amd64.whl
| Download URL | packlab-0.6.10-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7b6a0cdf03df631ce341aaa19f05f2d90be6b8ffda69b5a603cc73e2f4d49445
|
|
BLAKE2b-256 checksum How to use checksums |
ca5e59fcf294ba6b9fc91e15a82fb41a87ad1f5f789b5c9ee33e3b2c196197dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | packlab-0.6.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
29f5f016139eae6bb9db3a0206bf2b8b8ec30cac995251c81ab9ee13a77c295a
|
|
BLAKE2b-256 checksum How to use checksums |
52f78364542921f9f8e16f85437048b9dd57e3c19539d0c88b426309ae8d292c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp312-cp312-macosx_26_0_arm64.whl
| Download URL | packlab-0.6.10-cp312-cp312-macosx_26_0_arm64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.12 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8814d831132913f2f9c976daca9fa9bfd73c46e8591d9366290a77be0024c0e0
|
|
BLAKE2b-256 checksum How to use checksums |
b279943773377ba2403dc04f113adc609ebdc085e81d8dce1e0e36e196a241b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp311-cp311-win_amd64.whl
| Download URL | packlab-0.6.10-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d00a2ecadd308cabf145de9751deb79d0522490798a91afdd6f7fbb0addf0a53
|
|
BLAKE2b-256 checksum How to use checksums |
5b02a1dc278d8c23ddf861e90a83225c948baf5e6a137dae70c7329098f14d6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | packlab-0.6.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
6b1f144aacf2f5375b8c99e343fdb129919f4ec67806d945734700a270828c64
|
|
BLAKE2b-256 checksum How to use checksums |
363184f2089be82ad8fa0799faa17d43e24f6cc2f019ad007ed4a29a0014080f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / packlab-0.6.10-cp311-cp311-macosx_26_0_arm64.whl
| Download URL | packlab-0.6.10-cp311-cp311-macosx_26_0_arm64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.11 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b0ca9d8f20357fcd80869fd711250331cd513349102f0370a82d6ea75b4322a9
|
|
BLAKE2b-256 checksum How to use checksums |
b979f7b4b1904071442cff1aea6e02d4fbf18a52fc4682cde44a2c2b10effad1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|