Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

sponge.partition.NeighbourList

View Source On Gitee
class sponge.partition.NeighbourList(system: Molecule, cutoff: float = None, pace: int = 20, exclude_index: Tensor = None, num_neighbours: int = None, num_cell_cut: int = 1, cutoff_scale: float = 1.2, cell_cap_scale: float = 1.25, grid_num_scale: float = 2, use_grids: bool = False, cast_fp16: bool = False)[source]

Neighbour list

Parameters
  • system (Molecule) – Simulation system.

  • cutoff (float, optional) – Cut-off distance. If None is given under periodic boundary condition (PBC), the cutoff will be assigned with the default value of 1 nm. Default: None.

  • pace (int, optional) – Update frequency for neighbour list. Default: 20

  • exclude_index (Tensor, optional) – Tensor of the indices of the neighbouring atoms which could be excluded from the neighbour list. The shape of Tensor is (B,A,Ex), and the data type is int. Default: None.

  • num_neighbours (int, optional) – Maximum number of neighbours. If None is given, this value will be calculated by the ratio of the number of neighbouring grids to the total number of grids. Default: None.

  • num_cell_cut (int, optional) – Number of subdivision of grid cells according to cutoff. Default: 1

  • cutoff_scale (float, optional) – Factor to scale cutoff distance. Default: 1.2

  • cell_cap_scale (float, optional) – Scale factor for cell_capacity. Default: 1.25

  • grid_num_scale (float, optional) – Scale factor to calculate num_neighbours by ratio of grids. If num_neighbours is not None, it will not be used. Default: 2

  • use_grids (bool, optional) – Whether to use grids to calculate the neighbour list. Default: None.

  • cast_fp16 (bool, optional) – If this is set to True, the data will be cast to float16 before sort. For use with some devices that only support sorting of float16 data. Default: False.

Note

  • B: Batchsize, i.e. number of walkers of the simulation.

  • A: Number of the atoms in the simulation system.

  • N: Number of the maximum neighbouring atoms.

  • D: Dimension of position coordinates.

  • Ex: Maximum number of excluded neighbour atoms.

Supported Platforms:

Ascend GPU

Examples

>>> import sponge
>>> from sponge.partition import NeighbourList
>>> from sponge.system import Molecule
>>> system = Molecule(template='water.spce.yaml')
>>> neighbourlist = NeighbourList(system, 0.5)
>>> neighbourlist(system.coordinate, system.pbc_box)
(Tensor(shape=[1, 3, 2], dtype=Int64, value=
 [[[1, 2],
 [0, 2],
 [0, 1]]]),
 Tensor(shape=[1, 3, 2, 3], dtype=Float32, value=
 [[[[ 8.16490427e-02,  5.77358976e-02,  0.00000000e+00],
     [-8.16490427e-02,  5.77358976e-02,  0.00000000e+00]],
 [[-8.16490427e-02, -5.77358976e-02,  0.00000000e+00],
     [-1.63298085e-01,  0.00000000e+00,  0.00000000e+00]],
 [[ 8.16490427e-02, -5.77358976e-02,  0.00000000e+00],
     [ 1.63298085e-01,  0.00000000e+00,  0.00000000e+00]]]]),
 Tensor(shape=[1, 3, 2], dtype=Float32, value=
 [[[ 1.00000001e-01,  1.00000001e-01],
 [ 1.00000001e-01,  1.63298085e-01],
 [ 1.00000001e-01,  1.63298085e-01]]]),
 Tensor(shape=[1, 3, 2], dtype=Bool, value=
 [[[ True,  True],
 [ True,  True],
 [ True,  True]]]))
>>> neighbourlist.calculate(system.coordinate, system.pbc_box)
(Tensor(shape=[1, 3, 2], dtype=Int64, value=
 [[[1, 2],
 [0, 2],
 [0, 1]]]),
 Tensor(shape=[1, 3, 2], dtype=Bool, value=
 [[[ True,  True],
 [ True,  True],
 [ True,  True]]]))
>>> neighbourlist.pace
20
calculate(coordinate: Tensor, pbc_box: Tensor = None)[source]

calculate neighbour list.

Parameters
  • coordinate (Tensor) – Tensor of shape (B,A,D). Data type is float. Position coordinate.

  • pbc_box (Tensor, optional) – Tensor of shape (B,D). Data type is float. Size of PBC box.

Returns

neigh_idx (Tensor), Tensor of shape (B,A,N). Data type is int. Index of neighbouring atoms of each atoms in system.

neigh_mask (Tensor), Tensor of shape (B,A,N). Data type is bool. Mask for neighbour list neigh_idx.

Note

  • B: Batchsize, i.e. number of walkers of the simulation.

  • A: Number of the atoms in the simulation system.

  • N: Number of the maximum neighbouring atoms.

  • D: Dimension of position coordinates.

get_neighbour_list()[source]

get neighbour list.

Returns

neigh_idx (Tensor), Tensor of shape (B,A,N). Data type is int. Index of neighbouring atoms of each atoms in system.

neigh_mask (Tensor):, Tensor of shape (B,A,N). Data type is bool. Mask for neighbour list neigh_idx.

Note

  • B: Batchsize, i.e. number of walkers of the simulation.

  • A: Number of the atoms in the simulation system.

  • N: Number of the maximum neighbouring atoms.

property pace: int

Update frequency for neighbour list

Returns

int, update pace

print_info()[source]

print information of neighbour list

set_exclude_index(exclude_index: Tensor)[source]

set exclude index

Parameters

exclude_index (Tensor) – Tensor of shape (B,A,Ex). Data type is int.

update(coordinate: Tensor, pbc_box: Tensor = None)[source]

update neighbour list.

Parameters
  • coordinate (Tensor) – Tensor of shape (B,A,D). Data type is float. Position coordinate.

  • pbc_box (Tensor, optional) – Tensor of shape (B,D). Data type is float. Size of PBC box.

Returns

neigh_idx (Tensor), Tensor of shape (B,A,N). Data type is int. Index of neighbouring atoms of each atoms in system.

neigh_mask (Tensor), Tensor of shape (B,A,N). Data type is bool. Mask for neighbour list neigh_idx.

Note

  • B: Batchsize, i.e. number of walkers of the simulation.

  • A: Number of the atoms in the simulation system.

  • N: Number of the maximum neighbouring atoms.

  • D: Dimension of position coordinates.