Skip to main content

linkcell

linkcell

Periodic linked-cell k-nearest neighbour search for molecular simulations.

vesin builds cutoff pair lists. nanoflann builds Euclidean KD-trees without a minimum-image convention. This crate is the piece those two leave open: the linked-cell walk of Allen and Tildesley (Computer Simulation of Liquids), a k-heap per source, shells expanded until the k-th neighbour cannot sit outside the visited cube. The optional gpulite path runs that walk on a CUDA device (linkcell::gpu::Workspace); pair lists stay on the device.

It is a LODE library. The Rust crate is the implementation. The C ABI (lc_*) is the hourglass waist, the same shape as readcon-core. C++ is a RAII header over that ABI.

Install

Rust:

cargo add linkcell

C and C++ consumers take the staticlib (--features capi, on by default) plus include/linkcell.h or include/linkcell.hpp. Meson, CMake, and pkg-config all install that archive and those headers.

Python takes the same search through DLPack (dlpk). Any __dlpack__() object (numpy, torch, jax, cupy) is a valid xyz / cell, on any device. A CUDA xyz stays on device; a CUDA cell is inverted on device. torch.from_dlpack consumes (indices, dist2). Wheels: one CPython 3.12 limited-ABI (abi3) artifact per platform (GIL, 3.12+), and one abi3t artifact (CPython 3.15+ GIL and free-threaded).

pip install linkcell
import numpy as np
import linkcell

xyz = np.array([[0.2, 0.0, 0.0], [9.4, 0.0, 0.0]], dtype=np.float64)
cell = np.array([10.0, 10.0, 10.0], dtype=np.float64)
nn, d2 = linkcell.knearest(xyz, cell, 1)
nn = np.from_dlpack(nn)

Meson

meson setup build
meson compile -C build
meson install -C build

As a wrap, Meson exposes linkcell_dep:

[wrap-git]
url = https://github.com/d-SEAMS/linkcell.git
revision = v0.3.3
depth = 1

[provide]
linkcell = linkcell_dep
linkcell_dep = dependency('linkcell', fallback: ['linkcell', 'linkcell_dep'])

CMake

cmake -B build -DCMAKE_INSTALL_PREFIX=$PREFIX
cmake --build build
cmake --install build
find_package(linkcell 0.3 REQUIRED)
target_link_libraries(app PRIVATE linkcell::linkcell)

In the same build tree the target is linkcell::linkcell.

pkg-config

pkg-config --cflags --libs linkcell

Both Meson and CMake write linkcell.pc (Libs includes the Rust sysroot: pthread, dl, m on Linux).

Rust

use linkcell::{knearest, Cell};

let sim = Cell::ortho(10.0, 10.0, 10.0)?;
let sheared = Cell::from_vectors(
    [10.0, 0.0, 0.0],
    [5.0, 8.66, 0.0],
    [0.0, 0.0, 10.0],
    [0.0, 0.0, 0.0],
)?;
let xyz = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]];
let rows = knearest(&xyz, &sim, 1, None, None)?;
assert_eq!(rows[0].indices, vec![1]);

mask[i] == false removes a point as both a source and a candidate. cell_hint is the target cell edge; None uses 3.0 in the box units.

C

#include "linkcell.h"

double xyz[] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0};
lc_cell box = lc_cell_ortho(10.0, 10.0, 10.0);
int out[2];
if (lc_knearest(xyz, 2, &box, 1, NULL, 0.0, out) != 0) {
  return 1;
}

n and k are size_t. out has length n * k. Unused slots are -1. Neighbours of source i are out[i*k + 0 ..], nearest first.

C++

#include "linkcell.hpp"

const linkcell::Cell box = linkcell::Cell::ortho(10.0, 10.0, 10.0);
const double xyz[] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0};
const linkcell::Neighbours nn = linkcell::knearest(xyz, 2, box, 1);

nn owns the packed n * k buffer. Unused slots are -1. nn.neighbour(i, j) is the j-th neighbour of i. Failure throws linkcell::Error.

The optional device walk reads occupancy from the environment: LINKCELL_TPP (threads per particle) and LINKCELL_BLOCK (CUDA block size). Unset, the library picks a pair that maximises particles per block under the device thread and 48 KiB shared-memory limits. d-SEAMS writes the same keys from SEAMS_CONFIG / seams --tpp.

Docs

Quadrant Page
Tutorial Two points
How-to Embed from C, Embed from C++, pkg-config
Reference C ABI, Algorithm
Explanation MIC and cells

Rust API: docs.rs/linkcell. Map: docs/index.md.

Design

  • The cell is a general parallelepiped: three lattice vectors plus an origin. Orthorhombic boxes are Cell::ortho / lc_cell_ortho. Binning is in fractional space, so a sheared dump is not treated as orthogonal.
  • Points fold into the primary cell once. Each source then walks Chebyshev shells of neighbour cells. Pair distances are a Cartesian subtract plus that cell's lattice translation (dist2_shifted and lattice_shift), the vesin / LAMMPS ghost construction. Orthorhombic boxes use three independent wraps and skip the two Hinv matvecs.
  • One lattice shift per unique cell is wrong unless every wrap of that cell is visited. The walk visits integer cell offsets, so each wrap of a bin is a separate visit.
  • The search does not take a cutoff. A cell-size hint only sets the bin width. Shells grow until the k-heap is exact.
  • vesin remains the right library for a cutoff pair list.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkcell-0.3.3.tar.gz (188.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl (374.7 kB view details)

Uploaded CPython 3.15CPython 3.15+manylinux: glibc 2.28+ x86-64

linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl (361.0 kB view details)

Uploaded CPython 3.15CPython 3.15+manylinux: glibc 2.28+ ARM64

linkcell-0.3.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl (328.3 kB view details)

Uploaded CPython 3.15CPython 3.15+macOS 11.0+ ARM64

linkcell-0.3.3-cp312-abi3-manylinux_2_28_x86_64.whl (371.7 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

linkcell-0.3.3-cp312-abi3-manylinux_2_28_aarch64.whl (357.2 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

linkcell-0.3.3-cp312-abi3-macosx_11_0_arm64.whl (325.0 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file linkcell-0.3.3.tar.gz.

File metadata

  • Download URL: linkcell-0.3.3.tar.gz
  • Upload date:
  • Size: 188.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for linkcell-0.3.3.tar.gz
Algorithm Hash digest
SHA256 038176c506cc08ca043103f543b1b37cc416aa5041ca6fe2c221810437a5a380
MD5 5d87fe6b9cc16ab31323bd23b205feda
BLAKE2b-256 b3b0625aab663ca234f215ef0756b546225daf6f1a00b3b9225e7f86add1d409

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3.tar.gz:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d5c9f1bb988f318a213e4bcbdc7c5ac0040917bb74149f0f0825a04d3dc1aa0
MD5 a22d6619e262144b7125725c57dc5289
BLAKE2b-256 614a13764e75096ee475c8e722f799de73a8bcacab51aaf50e9da1a9c16bc758

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9013c413899a38aa07788d52220285768ebc531cad77141efd8875c74124915d
MD5 d8bba0dd7f0e7fe469972b649f8eea05
BLAKE2b-256 df8356466c00dafded4793b1afeee7de6f194d37e5c776af40e5b4610b4352d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60142680a6f2792bba82e192096a16f834593fc4d7403bf931ccc99cbb6f86dd
MD5 b21b3f3e823a2fbb2a230854d54e6128
BLAKE2b-256 4c60368b4cbd16e3eed690b6b2b51f1e2cdffa3945ae84cca87e190d53f8ca35

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ad7c3cbc9e75faad119297edc69d84215dedd035cc15c7545d1b6f0d352c843
MD5 e47f15b64b0a26b7d8c2724964aae1a9
BLAKE2b-256 b181034bda193f5a6a511e90f955a3b268205abe4900900b5e8e7fc573a78033

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp312-abi3-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0dbd6f24b5a1fe20b03731b7f68ffc5ff88ad418a81fda4b842f3bad4607aed6
MD5 096f14d40c88f0d5cdcff00e11b1ea35
BLAKE2b-256 79c76ae14447db1d2bbe65ed37c577c56f799922ff2be46063a0b83c9930212c

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp312-abi3-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkcell-0.3.3-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linkcell-0.3.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e68e5358c381c3e4ec1b4cd147d52ae582219d000f9f9eaf56fbdcf5d07219cb
MD5 0be5ebc13bdc07bc4ba23f4258f5dbf2
BLAKE2b-256 598134236196aa77b68ef5bb582f8cb6e85d6a1e8a20c2067ee64584e3f87a9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkcell-0.3.3-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on d-SEAMS/linkcell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page