sponge.core.WithEnergyCell

View Source On Gitee
class sponge.core.WithEnergyCell(system: Molecule, potential: PotentialCell, bias: Union[Bias, List[Bias]] = None, cutoff: float = None, neighbour_list: NeighbourList = None, wrapper: EnergyWrapper = None, **kwargs)[source]

Cell that wraps the simulation system with the potential energy function. This Cell calculates the value of the potential energy of the system at the current coordinates and returns it.

Parameters
  • system (sponge.system.Molecule) – Simulation system.

  • potential (sponge.potential.PotentialCell) – Potential energy function cell.

  • bias (Union[sponge.potential.Bias, List[sponge.potential.Bias]], optional) – Bias potential function cell. Default: None.

  • cutoff (float, optional) – Cut-off distance for neighbour list. If None is given, it will be assigned as the cutoff value of the of potential energy. Default: None.

  • neighbour_list (sponge.partition.NeighbourList, optional) – Neighbour list. Default: None.

  • wrapper (sponge.sampling.wrapper.EnergyWrapper, optional) – Network to wrap and process potential and bias. Default: None.

  • kwargs (dict) – Other arguments.

Inputs:
Outputs:
  • energy (Tensor) - with shape of \((B, 1)\). Total potential energy. Here B is the batch size, i.e. the number of walkers in simulation. Data type is float.

Supported Platforms:

Ascend GPU

Examples

>>> from sponge import WithEnergyCell, RunOneStepCell, Sponge
>>> from sponge.callback import RunInfo
>>> from sponge.system import Molecule
>>> from sponge.potential.forcefield import ForceField
>>> from sponge.optimizer import Updater
>>> system = Molecule(template='water.tip3p.yaml')
>>> potential = ForceField(system, parameters='SPCE')
>>> optimizer = Updater(system, controller=None, time_step=1e-3)
>>> sim = WithEnergyCell(system, potential)
>>> one_step = RunOneStepCell(energy=sim, optimizer=optimizer)
>>> md = Sponge(one_step)
>>> run_info = RunInfo(800)
>>> md.run(2000, callbacks=[run_info])
>>> # Output example:
>>> # [MindSPONGE] Started simulation at 2024-04-29 01:02:10
>>> # [MindSPONGE] Compilation Time: 0.66s
>>> # [MindSPONGE] Step: 0, E_pot: 1.4293396, E_kin: 0.0, E_tot: 1.
>>> # 4293396, Temperature: 0.0, Time: 662.63ms
>>> # [MindSPONGE] Step: 800, E_pot: 1.4293396, E_kin: 0.0, E_tot: 1.
>>> # 4293396, Temperature: 0.0, Time: 13.77ms
>>> # [MindSPONGE] Step: 1600, E_pot: 1.4293396, E_kin: 0.0, E_tot: 1.
>>> # 4293396, Temperature: 0.0, Time: 14.82ms
>>> # [MindSPONGE] Finished simulation at 2024-04-29 01:02:39
>>> # [MindSPONGE] Simulation time: 29.03 seconds.
property bias: mindspore.common.tensor.Tensor

Tensor of the total bias potential.

Returns

Tensor, Tensor of shape \((B, 1)\). Data type is float.

property bias_names: list

Name of bias potential energies.

Returns

list[str], the bias potential energies.

bias_pace(index: int = 0)[source]

Return the update freqenucy for bias potential.

Parameters

index (int) – Index of bias potential. Default: 0.

Returns

int, update freqenucy.

property biases: mindspore.common.tensor.Tensor

Tensor of bias potential components.

Returns

Tensor, Tensor of shape \((B, V)\). Data type is float.

calc_biases()[source]

Calculate the bias potential terms.

Returns

Tensor, Tensor of shape \((B, V)\). Data type is float. Bias potential terms.

calc_energies()[source]

Calculate the energy terms of the potential energy.

Returns

Tensor, Tensor of shape \((B, U)\). Data type is float. Energy terms.

property cutoff: mindspore.common.tensor.Tensor

Cutoff distance for neighbour list.

Returns

Tensor, cutoff distance.

property energies: mindspore.common.tensor.Tensor

Tensor of potential energy components.

Returns

Tensor, Tensor of shape (B, U). Data type is float.

property energy_names: list

Names of energy terms.

Returns

list[str], names of energy terms.

property energy_unit: str

Energy unit.

Returns

str, energy unit.

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.

property length_unit: str

Length unit.

Returns

str, length unit.

property neighbour_list_pace: int

Update step for neighbour list.

Returns

int, update steps.

property num_biases: int

Number of bias potential energies \(V\).

Returns

int, number of bias potential energies.

property num_energies: int

Number of energy terms \(U\).

Returns

int, number of energy terms.

set_pbc_grad(grad_box: bool)[source]

Set whether to calculate the gradient of PBC box.

Parameters

grad_box (bool) – Whether to calculate the gradient of PBC box.

update_bias(step: int)[source]

Update bias potential.

Parameters

step (int) – Current simulation step. If it can be divided by update frequency, update the bias potential.

update_neighbour_list()[source]

Update 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.

update_wrapper(step: int)[source]

Update energy wrapper.

Parameters

step (int) – Current simulation step. If it can be divided by update frequency, update the energy wrapper.