TorchScript API reference

class vesin.torch.NeighborList(cutoff: float, full_list: bool, sorted: bool = False, algorithm: str = 'auto')

A neighbor list calculator that can be used with TorchScript.

Parameters:
  • cutoff – spherical cutoff for this neighbor list

  • full_list – should we return each pair twice (as i-j and j-i) or only once

  • sorted – Should the neighbor list be sorted? If True, the returned pairs will be sorted by the first point index (i). The order of the second point index (j) and shifts in the list of pairs is unspecified.

  • algorithm – algorithm to use when computing the neighbor list. One of "auto", "brute_force", or "cell_list".

compute(points: Tensor, box: Tensor, periodic: bool | Tensor, quantities: str = 'ij', copy: bool = True) List[Tensor]

Compute the neighbor list for the system defined by positions, box, and periodic; returning the requested quantities.

quantities can contain any combination of the following values:

  • "i" to get the index of the first point in the pair

  • "j" to get the index of the second point in the pair

  • "P" to get the indexes of the two points in the pair simultaneously

  • "S" to get the periodic shift of the pair

  • "d" to get the distance between points in the pair

  • "D" to get the distance vector between points in the pair

Parameters:
  • points – positions of all points in the system

  • box – bounding box of the system

  • periodic – should we use periodic boundary conditions? This can be a single boolean to enable/disable periodic boundary conditions in all directions, or a tensor of three booleans (one for each direction).

  • quantities – quantities to return, defaults to “ij”

  • copy – should we copy the returned quantities, defaults to True. Setting this to False might be a bit faster, but the returned tensors are view inside this class, and will be invalidated whenever this class is garbage collected or used to run a new calculation.

Returns:

list of torch.Tensor as indicated by quantities.

TorchScript API reference (C++)

using vesin_torch::NeighborList = torch::intrusive_ptr<NeighborListHolder>

NeighborListHolder should be manipulated through a torch::intrusive_ptr

class NeighborListHolder : public torch::CustomClassHolder

Neighbor list calculator compatible with TorchScript.

Public Functions

NeighborListHolder(double cutoff, bool full_list, bool sorted = false, std::string algorithm = "auto")

Create a new calculator with the given cutoff.

Parameters:
  • cutoff – the spherical cutoff radius

  • full_list – whether pairs should be included twice in the output (both as i-j and j-i) or only once

  • sorted – whether pairs should be sorted by the first point index in

  • algorithm – the algorithm to use for neighbor list calculation. One of "auto", "brute_force", or "cell_list".

~NeighborListHolder()
std::vector<torch::Tensor> compute(torch::Tensor points, torch::Tensor box, torch::Tensor periodic, std::string quantities, bool copy = true)

Compute the neighbor list for the system defined by positions, box, and periodic; returning the requested quantities.

quantities can contain any combination of the following values:

- `"i"` to get the index of the first point in the pair
- `"j"` to get the index of the second point in the pair
- `"P"` to get the indexes of the two points in the pair simultaneously
- `"S"` to get the periodic shift of the pair
- `"d"` to get the distance between points in the pair
- `"D"` to get the distance vector between points in the pair

Parameters:
  • points – positions of all points in the system

  • box – bounding box of the system

  • periodic – should we use periodic boundary conditions?

  • quantities – quantities to return, defaults to “ij”

  • copy – should we copy the returned quantities, defaults to true. Setting this to False might be a bit faster, but the returned tensors are view inside this class, and will be invalidated whenever this class is garbage collected or used to run a new calculation.

Returns:

a list of torch::Tensor as indicated by quantities.

inline double cutoff() const

Get the cutoff radius of the neighbor list.

inline bool full_list() const

Get whether pairs should be included twice in the output.

inline bool sorted() const

Get whether pairs should be sorted in the output.

inline std::string algorithm() const

Get the algorithm used for neighbor list calculation.