sponge.control.Controller
- class sponge.control.Controller(system: Molecule, control_step: int = 1, **kwargs)[source]
Base class for the controller module in MindSPONGE. The
sponge.control.Controller
is used insponge.control.Updater
to control the values of seven variables during the simulation process, including coordinate, velocity, force, energy, kinetics, virial and pbc_box.- Parameters
system (
sponge.system.Molecule
) – Simulation system.control_step (int, optional) – Step interval for controller execution. Default:
1
.kwargs (dict) – Other parameters for extension.
- Inputs:
coordinate (Tensor) - Coordinate. Tensor of shape \((B, A, D)\). Data type is float. Here \(B\) is the number of walkers in simulation, \(A\) is the number of atoms and \(D\) is the spatial dimension of the simulation system, which is usually 3.
velocity (Tensor) - Velocity. Tensor of shape \((B, A, D)\). Data type is float.
force (Tensor) - Force. Tensor of shape \((B, A, D)\). Data type is float.
energy (Tensor) - Energy. Tensor of shape \((B, 1)\). Data type is float.
kinetics (Tensor) - Kinetics. Tensor of shape \((B, D)\). Data type is float.
virial (Tensor) - Virial. Tensor of shape \((B, D)\). Data type is float.
pbc_box (Tensor) - Pressure boundary condition box. Tensor of shape \((B, D)\). Data type is float.
step (int) - Simulation step. Default:
0
.
- Outputs:
coordinate, Tensor of shape \((B, A, D)\). Coordinate. Data type is float.
velocity, Tensor of shape \((B, A, D)\). Velocity. Data type is float.
force, Tensor of shape \((B, A, D)\). Force. Data type is float.
energy, Tensor of shape \((B, 1)\). Energy. Data type is float.
kinetics, Tensor of shape \((B, D)\). Kinetics. Data type is float.
virial, Tensor of shape \((B, D)\). Virial. Data type is float.
pbc_box, Tensor of shape \((B, D)\). Periodic boundary condition box. Data type is float.
- Supported Platforms:
Ascend
GPU
Examples
>>> from mindspore import Tensor >>> from sponge import Sponge, Molecule, ForceField, UpdaterMD, WithEnergyCell >>> from sponge.control import Controller >>> from sponge.callback import RunInfo >>> system = Molecule(template='water.tip3p.yaml') >>> potential = ForceField(system, parameters='SPCE') >>> withenergy = WithEnergyCell(system, potential) >>> class MyController(Controller): ... def construct(self, ... coordinate: Tensor, ... velocity: Tensor, ... force: Tensor, ... energy: Tensor, ... kinetics: Tensor, ... virial: Tensor = None, ... pbc_box: Tensor = None, ... step: int = 0, ... **kwargs): ... return super().construct(coordinate, velocity/100, ... force, energy, kinetics, ... virial, pbc_box, step, ... **kwargs) >>> velocity = Tensor([[0.1008,0.,0.],[-0.8,0.,0.],[-0.8,0.,0.]]) >>> updater = UpdaterMD( ... system=system, ... time_step=1e-3, ... velocity=velocity, ... integrator='velocity_verlet', ... temperature=300, ... controller=MyController(system) ... ) >>> mini = Sponge(withenergy, optimizer=updater) >>> run_info = RunInfo(1) >>> mini.run(5, callbacks=[run_info])
- property boltzmann: float
Boltzmann constant in current unit.
- Returns
float, Boltzmann constant in current unit.
- get_com(coordinate: Tensor, keepdims: bool = True)[source]
Get coordinate of center of mass.
- Parameters
coordinate (Tensor) – Atomic coordinates. Tensor shape is \((B, A, D)\). Data type is float.
keepdims (bool, optional) – If this is set to
True
, the second axis will be left in the result as dimensions with size one. Default:True
.
- Returns
- Tensor, the coordinate of the center of mass.
The shape is \((B, A, D)\) or \((B, D)\). Data type is float.
- get_com_velocity(velocity: Tensor, keepdims: bool = True)[source]
Calculate velocity of center of mass.
- Parameters
velocity (Tensor) – Velocity. The shape is \((B, A, D)\). Data type is float.
keepdims (bool) – If this is set to
True
, the second axis will be left in the result as dimensions with size one. Default:True
.
- Returns
- Tensor, Tensor of the velocity of the center of mass.
The shape is \((B, A, D)\) or \((B, D)\). Data type is float.
- get_kinetics(velocity: Tensor)[source]
Calculate kinetics according to velocity.
- Parameters
velocity (Tensor) – Tensor of atomic velocities. Tensor shape is \((B, A, D)\). Data type is float.
- Returns
Tensor, kinetics. Tensor shape is \((B, D)\). Data type is float.
- get_pressure(kinetics: Tensor, virial: Tensor, pbc_box: Tensor)[source]
Calculate pressure according to kinetics, viral and PBC box.
- Parameters
kinetics (Tensor) – Kinetics. Tensor shape is \((B, D)\). Data type is float.
virial (Tensor) – Virial. Tensor shape is \((B, D)\). Data type is float.
pbc_box (Tensor) – PBC box. Tensor shape is \((B, D)\). Data type is float.
- Returns
Tensor, pressure. Tensor shape is \((B, D)\). Data type is float.
- get_temperature(kinetics: Tensor = None)[source]
Calculate temperature according to velocity.
- Parameters
kinetics (Tensor) – Kinetics. Tensor shape is \((B, D)\). Data type is float. Default:
None
.- Returns
Tensor, temperature. Tensor shape is \((B)\). Data type is float.
- get_volume(pbc_box: Tensor)[source]
Calculate volume according to PBC box.
- Parameters
pbc_box (Tensor) – Tensor of PBC box. Tensor shape is \((B, D)\). Data type is float.
- Returns
Tensor, Tensor of volume. Shape is \((B)\). The data type is float.
- set_degrees_of_freedom(dofs: int)[source]
Set degrees of freedom (DOFs).
- Parameters
dofs (int) – Degrees of freedom.