torchani.neighbors#
Modular neighborlists to improve scaling for large systems
Functions
|
|
|
|
|
|
|
|
Compute the rectangular unit cell that minimally bounds a set of coords. |
|
|
|
|
|
|
|
Discard neighbors that don't belong to the same molecule |
|
Discard neighbors with distances that lie outside of the given cutoff |
|
|
|
|
|
|
|
Takes a set of potential neighbor idxs and narrows it down to true neighbors |
|
Converts output of a neighborlist calculation into triples of atoms |
|
Reconstruct shift values used to calculate neighbors |
|
|
Classes
Compute pairs of neighbors using the best algorithm for the system size |
|
Compute pairs of neighbors. |
|
Compute pairs of neighbors using the 'Cell List' algorithm. |
|
This class is experimental and requires the compiled Cell-List extension |
|
Base class for modules that compute pairs of neighbors. |
|
Holds pairs of atoms that are neighbors. |
|
Holds groups of 3 atoms that are neighbors. |
|
Compute pairs of neighbors. |
- class torchani.neighbors.Neighbors(indices, distances, diff_vectors)[source]#
Holds pairs of atoms that are neighbors. Result of a neighborlist calculation
- class torchani.neighbors.Triples(central_idxs, side_idxs, diff_signs, distances, diff_vectors)[source]#
Holds groups of 3 atoms that are neighbors. Result of
neighbors_to_triples
- torchani.neighbors.discard_inter_molecule_pairs(neighbors, molecule_idxs)[source]#
Discard neighbors that don’t belong to the same molecule
- torchani.neighbors.discard_outside_cutoff(neighbors, cutoff)[source]#
Discard neighbors with distances that lie outside of the given cutoff
- torchani.neighbors.narrow_down(cutoff, elem_idxs, coords, neighbor_idxs, shifts=None)[source]#
Takes a set of potential neighbor idxs and narrows it down to true neighbors
- torchani.neighbors.compute_bounding_cell(coords, eps=0.001, displace=True, square=False)[source]#
Compute the rectangular unit cell that minimally bounds a set of coords.
Optionally displace the coords so that they fully lie inside the cell. Displacing the coordinates causes small floating point differences which have a negligible effect on energies and forces. The
eps
value is used to add padding to the cell.
- class torchani.neighbors.Neighborlist(*args, **kwargs)[source]#
Base class for modules that compute pairs of neighbors. Can support PBC.
Subclasses must override
Neighborlist.forward
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type:
- class torchani.neighbors.AllPairs(*args, **kwargs)[source]#
Compute pairs of neighbors. Uses a naive algorithm.
This is a naive implementation, with \(O(N^2)\) scaling. It computes all pairs and then discards those that are further away from the cutoff. Supports PBC.
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type:
- class torchani.neighbors.FastCellList[source]#
This class is experimental and requires the compiled Cell-List extension
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type:
- class torchani.neighbors.CellList(*args, **kwargs)[source]#
Compute pairs of neighbors using the ‘Cell List’ algorithm.
This is a linearly scaling implementation that uses the ‘cell list’ algorithm. It subdivides space into cells and then computes all pairs within each cell and between each cell and neighboring cells. and then discards those that are further away from the cutoff.
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type:
- class torchani.neighbors.AdaptiveList(threshold=190, threshold_nopbc=1770)[source]#
Compute pairs of neighbors using the best algorithm for the system size
This is a linearly scaling implementation that uses the ‘cell list’ algorithm for large system sizes and the naive ‘all pairs’ for small sizes.
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type:
- class torchani.neighbors.VerletCellList(skin=1.0)[source]#
Compute pairs of neighbors. Uses a cell-list algorithm with ‘verlet’ skin.
- forward(cutoff, species, coords, cell=None, pbc=None)[source]#
Calculate all pairs of atoms that are neighbors, given a cutoff.
- Parameters:
cutoff (float) – Cutoff value for the neighborlist. Pairs further away than this are not included.
species (Tensor) – An int
torch.Tensor
that stores the element indices of a batch of molecules, (for example after conversion withtorchani.nn.SpeciesConverter
). Shape is(molecules, 3)
.coords (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is
(molecules, atoms, 3)
. All ANI models use Angstrom.cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by
torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]])
.pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions.
pbc=torch.tensor([True, True, True])
fully enables PBC andpbc=None
(ortorch.tensor([False, False, False])
). fully disables it.
- Returns:
typing.NamedTuple
with all pairs of atoms that are neighbors.- Return type: