Skip to main content

Generate neighbor list for the particles in a periodic boundary cell.

Project description

pairlist

Generates the pair list of atoms that are closer to each other than the given threshold under the periodic boundary conditions.

version 0.5.1.1

Usage

See pairlist.h for the function definition and pairlist-test.c for usage.

Python API is served in pairlist.py. The API document is here.

To find the neighbors in a face-centered cubic lattice of size 10x10x10 on a MacBook Air 2021 (Apple Silicon),

$ python benchmark.py
INFO crude: Neighboring pair list by a crude double loop.
INFO crude: 18024 ms
INFO crude: end.
24000 pairs
INFO numpyish: Neighboring pair list by numpy fancy array.
INFO numpyish: 741 ms
INFO numpyish: end.
24000.0 pairs
INFO pairlist_py: Neighboring pair list by pairlist in pure python.
INFO pairlist_py: 125 ms
INFO pairlist_py: end.
24000 pairs
INFO pairlist_c: Neighboring pair list by pairlist in c.
INFO pairlist_c: end.
INFO pairlist_c: 16 ms
24000 pairs
import pairlist as pl
from fcc import FaceCenteredCubic
from logging import getLogger, basicConfig, INFO, DEBUG
from decorator import timeit, banner
import numpy as np
from pairlist import pairs_py, pairs2_py


basicConfig(level=INFO, format="%(levelname)s %(message)s")
logger = getLogger()
logger.debug("Debug mode.")


@banner
@timeit
def crude(lattice, cell, rc=1.1):
    "Neighboring pair list by a crude double loop."
    rc2 = rc**2
    count = 0
    for i in range(len(lattice)):
        for j in range(i):
            d = lattice[i] - lattice[j]
            d -= np.floor(d + 0.5)
            d = d @ cell
            if d @ d < rc2:
                count += 1
    return count


@banner
@timeit
def numpyish(lattice, cell, rc=1.1):
    "Neighboring pair list by numpy fancy array."
    # cross-differences
    M = lattice[:, None, :] - lattice[None, :, :]
    # wrap
    M -= np.floor(M + 0.5)
    # in absolute coordinate
    M = M @ cell
    d = (M * M).sum(2)
    return d[(d < rc**2) & (0 < d)].shape[0] / 2


@banner
@timeit
def pairlist_py(lattice, cell, rc=1.1):
    "Neighboring pair list by pairlist in pure python."
    count = 0
    for i, j, d in pl.pairs_iter(
        lattice, maxdist=rc, cell=cell, _engine=(pairs_py, pairs2_py)
    ):
        count += 1
    return count


@timeit
@banner
def pairlist_c(lattice, cell, rc=1.1):
    "Neighboring pair list by pairlist in c."
    count = 0
    for i, j, d in pl.pairs_iter(lattice, maxdist=rc, cell=cell):
        count += 1
    return count


lattice, cell = FaceCenteredCubic(10)

print(crude(lattice, cell), "pairs")
print(numpyish(lattice, cell), "pairs")
print(pairlist_py(lattice, cell), "pairs")
print(pairlist_c(lattice, cell), "pairs")

benchmark

Algorithm

A simple cell division algorithm is implemented.

Demo

It requires GenIce to make the test data.

% make test

Requirements

  • python
  • numpy

Bugs

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

pairlist-0.5.1.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

pairlist-0.5.1.3-cp311-cp311-macosx_14_0_arm64.whl (13.8 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

File details

Details for the file pairlist-0.5.1.3.tar.gz.

File metadata

  • Download URL: pairlist-0.5.1.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.4 Darwin/23.3.0

File hashes

Hashes for pairlist-0.5.1.3.tar.gz
Algorithm Hash digest
SHA256 72ab5143c8757397d63cc4d666d92ba4632a83c45f43f3e5c6f72b0e16b85981
MD5 8d09ca04f014c04f817152d63cb14fa8
BLAKE2b-256 02d515dcbaf977f7b57cf65028ea59940abbaaa422fdf37f50a2c85c69a1c51d

See more details on using hashes here.

File details

Details for the file pairlist-0.5.1.3-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pairlist-0.5.1.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 05e31b5eed2bbae3ffcf833937348d5badae5f0c888b30a4a0cac126719afbc4
MD5 1c419e4f4817e47f55e652c757dc6c71
BLAKE2b-256 9d10203d3ba2eaefbdb7dd79a795343b9e2dee4e8b31d93c294ed65d20b101e6

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