nblist
torch_admp.nblist
Neighbor list utilities for torch-admp.
This module provides functions and classes for building and managing neighbor lists used in molecular simulations, including implementations for both periodic and non-periodic boundary conditions.
TorchNeighborList(cutoff: float)
Bases: Module
Torch-compatible neighbor list implementation.
Adapted from the curator library for JIT compatibility: https://github.com/Yangxinsix/curator/tree/master curator.data.TorchNeighborList
Initialize the TorchNeighborList.
| PARAMETER | DESCRIPTION |
|---|---|
cutoff
|
Cutoff distance for neighbor list construction
TYPE:
|
Source code in torch_admp/nblist.py
forward(positions: torch.Tensor, box: Optional[torch.Tensor] = None) -> torch.Tensor
Compute neighbor list for given positions.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
box
|
Simulation box vectors, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Tensor of atom pairs |
Source code in torch_admp/nblist.py
forward_obc(positions: torch.Tensor) -> torch.Tensor
Compute neighbor list for open boundary conditions.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Tensor of atom pairs |
Source code in torch_admp/nblist.py
forward_pbc(positions: torch.Tensor, box: torch.Tensor) -> torch.Tensor
Compute neighbor list for periodic boundary conditions.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
box
|
Simulation box vectors
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Tensor of atom pairs |
Source code in torch_admp/nblist.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
get_buffer_scales() -> torch.Tensor
Get the buffer scales for atom pairs.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Buffer scales for each pair |
get_ds() -> torch.Tensor
Get the distances between atom pairs.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Distances between atom pairs |
get_pairs() -> torch.Tensor
pairs_buffer_scales(pairs: torch.Tensor) -> torch.Tensor
staticmethod
Calculate buffer scales for atom pairs.
Returns 1 if pair_i < pair_j, else 0. Used to exclude repeated pairs and buffer pairs.
| PARAMETER | DESCRIPTION |
|---|---|
pairs
|
Tensor of atom pairs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Buffer scales for each pair |
Source code in torch_admp/nblist.py
pairs_ds(positions: torch.Tensor, pairs: torch.Tensor, box: Optional[torch.Tensor] = None, pbc_flag: bool = True) -> torch.Tensor
staticmethod
Calculate distances between atom pairs.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
pairs
|
Tensor of atom pairs
TYPE:
|
box
|
Simulation box vectors, by default None
TYPE:
|
pbc_flag
|
Whether to apply periodic boundary conditions, by default True
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Distances between atom pairs |
Source code in torch_admp/nblist.py
set_buffer_scales(buffer_scales: torch.Tensor) -> None
Set the buffer scales for atom pairs.
| PARAMETER | DESCRIPTION |
|---|---|
buffer_scales
|
Buffer scales for each pair
TYPE:
|
Source code in torch_admp/nblist.py
set_ds(ds: torch.Tensor) -> None
Set the distances between atom pairs.
| PARAMETER | DESCRIPTION |
|---|---|
ds
|
Distances between atom pairs
TYPE:
|
set_pairs(pairs: torch.Tensor) -> None
Set the atom pairs.
| PARAMETER | DESCRIPTION |
|---|---|
pairs
|
Tensor of atom pairs
TYPE:
|
wrap_positions(positions: torch.Tensor, box: torch.Tensor) -> torch.Tensor
Wrap positions into the unit cell.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
box
|
Simulation box vectors
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Wrapped positions |
Source code in torch_admp/nblist.py
check_cutoff(box: torch.Tensor, cutoff: float) -> None
Check whether the sphere of cutoff radius is inside the box.
| PARAMETER | DESCRIPTION |
|---|---|
box
|
Simulation box vectors
TYPE:
|
cutoff
|
Cutoff radius
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If cutoff is larger than half the minimum height of the box |
Source code in torch_admp/nblist.py
dp_nblist(positions: torch.Tensor, box: Optional[torch.Tensor], nnei: int, rcut: float)
Build neighbor list data based on DP (Deep Potential) functions.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
box
|
Simulation box vectors
TYPE:
|
nnei
|
Number of neighbors
TYPE:
|
rcut
|
Cutoff radius
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Tuple containing (pairs, ds, buffer_scales) |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If deepmd.pt is not available |
Source code in torch_admp/nblist.py
make_ds(extended_pairs: torch.Tensor, extended_coord: torch.Tensor, pairs_mask: torch.Tensor) -> torch.Tensor
Calculate the i-j distance from the neighbor list.
| PARAMETER | DESCRIPTION |
|---|---|
extended_pairs
|
npairs_all x 2,
TYPE:
|
extended_coord
|
nframes x nall x 3, extended coordinates
TYPE:
|
pairs_mask
|
npairs_all, mask for the local pairs (i < j)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ds
|
npairs_loc, i-j distance
TYPE:
|
Source code in torch_admp/nblist.py
make_extended_pairs(nlist: torch.Tensor) -> torch.Tensor
Return the pairs between local and extended indices.
| PARAMETER | DESCRIPTION |
|---|---|
nlist
|
nframes x nloc x nsel, neighbor list between local and extended indices
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
extended_pairs
|
[[i1, j1], [i2, j2], ...], in which i is the local index and j is the extended index
TYPE:
|
Source code in torch_admp/nblist.py
make_local_pairs(extended_pairs: torch.Tensor, mapping: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
Return the pairs between local indices.
| PARAMETER | DESCRIPTION |
|---|---|
extended_pairs
|
npairs_all x 2,
TYPE:
|
mapping
|
nframes x nall, index from extended to local
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
local_pairs
|
npairs_loc x 2, [[i1, j1], [i2, j2], ...], in which i and j are the local indices of the atoms (i < j)
TYPE:
|
mask
|
npairs_all, mask for the local pairs (i < j)
TYPE:
|
Source code in torch_admp/nblist.py
sort_pairs(pairs: torch.Tensor) -> torch.Tensor
Sort atom pairs lexicographically.
Sorts pairs first by the first index, then by the second index.
| PARAMETER | DESCRIPTION |
|---|---|
pairs
|
Tensor of atom pairs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Sorted tensor of atom pairs |
Source code in torch_admp/nblist.py
vesin_nblist(positions: torch.Tensor, box: torch.Tensor, rcut: float)
Build neighbor list using the Vesin library.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions
TYPE:
|
box
|
Simulation box vectors
TYPE:
|
rcut
|
Cutoff radius
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Tuple containing (pairs, ds, buffer_scales) |