sponge.colvar.Center

View Source On Gitee
class sponge.colvar.Center(atoms: Union[AtomsBase, Tensor, ndarray, list], mass: Union[Tensor, ndarray, list] = None, batched: bool = False, keep_in_box: bool = False, keepdims: bool = None, axis: int = - 2, name: str = 'atoms_center')[source]

Center of specific atoms

Parameters
  • atoms (Union[AtomsBase, Tensor, ndarray, list]) – Specific atoms or virtual atoms of shape (…, G, D). G means number of the group of atoms to be averaged. D means spatial dimension of the simulation system. Usually is 3.

  • mass (Union[Tensor, ndarray, list]) – Array of the mass of the atoms to calculate the center of mass (COM). The shape of Tensor is (…, G) or (B, …, G), and the data type is float. If it is None, the geometric center of coordinate will be calculated. Default: None. B means Batchsize, i.e. number of walkers in simulation.

  • batched (bool) – Whether the first dimension of index and mass is the batch size. Default: False.

  • keep_in_box (bool) – Whether to displace the coordinate in PBC box. Default: False.

  • keepdims (bool) – If this is set to True, the axis which is reduced will be left, and the shape the center will be (…, 1, D). If this is set to False, the shape of the center will be (…, D). if None, its value will be determined according to the rank (number of dimension) of the input atoms: False if the rank is greater than 2, otherwise True. Default: None.

  • axis (int) – Axis along which the average of position are coumputed. Default: -2

  • name (str) – Name of the Colvar. Default: 'atoms_center'

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> from mindspore import Tensor
>>> from sponge.colvar import Center
>>> crd = Tensor(np.random.random((4, 3)), ms.float32)
>>> mass = Tensor(np.random.random(4), ms.float32)
>>> atoms = Tensor([0, 2], ms.int32)
>>> ct = Center(atoms, mass[atoms])
>>> ct(crd)
Tensor(shape=[1, 3], dtype=Float32, value=
[[ 7.61003494e-01,  6.70868099e-01,  5.67968249e-01]])
set_mass(mass: Tensor, batched: bool = False)[source]

set the mass of atoms