sponge.potential.EnergyCell

View Source On Gitee
class sponge.potential.EnergyCell(name: str = 'energy', length_unit: str = 'nm', energy_unit: str = 'kj/mol', use_pbc: bool = None, **kwargs)[source]

Base class for energy terms. EnergyCell is usually used as a base class for individual energy terms in a classical force field. As the force field parameters usually has units, the units of the EnergyCell as an energy term should be the same as the units of the force field parameters, and not equal to the global units.

Note

B: Batchsize, i.e. number of walkers in simulation

Parameters
  • name (str) – Name of energy. Default: 'energy'

  • length_unit (str) – Length unit. If None is given, it will be assigned with the global length unit. Default: 'nm'

  • energy_unit (str) – Energy unit. If None is given, it will be assigned with the global energy unit. Default: 'kj/mol'

  • use_pbc (bool) – Whether to use periodic boundary condition. Default: None.

  • kwargs (dict) – Other parameters dictionary.

Returns

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

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore import Tensor
>>> from mindspore.nn import Adam
>>> from sponge.potential import EnergyCell, ForceFieldBase
>>> from sponge import WithEnergyCell, Sponge
>>> from sponge.callback import RunInfo
>>> class MyEnergy(EnergyCell):
...     def construct(self, coordinate: Tensor, **kwargs):
...         return coordinate.sum()[None, None]
>>> # system represents a custom molecular system
>>> potential = MyEnergy(system)
>>> forcefield = ForceFieldBase(potential)
>>> withenergy = WithEnergyCell(system, forcefield)
>>> opt = Adam(system.trainable_params(), 1e-3)
>>> mini = Sponge(withenergy, optimizer=opt)
>>> run_info = RunInfo(5)
>>> mini.run(10, callbacks=[run_info])
[MindSPONGE] Started simulation at 2024-03-22 11:08:34
[MindSPONGE] Step: 5, E_pot: 0.31788814
[MindSPONGE] Step: 10, E_pot: 0.13788882
[MindSPONGE] Finished simulation at 2024-03-22 11:08:35
[MindSPONGE] Simulation time: 0.98 seconds.
--------------------------------------------------------------------------------
static check_system(system: Molecule)[source]

Check if the system needs to calculate this energy term

Parameters

system (Molecule) – System.

convert_energy_from(unit: str)[source]

Convert energy from outside unit to inside unit.

Parameters

unit (str) – Energy unit.

Returns

float, energy according from a specified units.

convert_energy_to(unit: str)[source]

Convert energy from inside unit to outside unit.

Parameters

unit (str) – Energy unit.

Returns

float, energy according to a specified units.

property energy_unit: str

Energy unit.

Returns

str, energy unit.

property length_unit: str

Length unit.

Returns

str, length unit.

property name: str

Name of energy.

Returns

str, name of energy.

set_cutoff(cutoff: float, unit: str = None)[source]

Set cutoff distances.

Parameters
  • cutoff (float) – Cutoff distances.

  • unit (str) – Length unit. Default: None.

set_input_unit(length_unit: Union[str, Units, Length])[source]

Set the length unit for the input coordinates.

Parameters

length_unit (Union[str, Units, Length]) – The length unit for the input coordinates.

set_pbc(use_pbc: bool)[source]

Set whether to use periodic boundary condition.

Parameters

use_pbc (bool) – Whether to use periodic boundary condition.

set_units(length_unit: str = None, energy_unit: str = None, units: Units = None)[source]

Set length and energy units.

Parameters
  • length_unit (str) – Length unit. Only valid when units is None . Default: None

  • energy_unit (str) – Energy unit. Only valid when units is None . Default: None

  • units (Units) – Units object. Default: None

property use_pbc: bool

Whether to use periodic boundary condition.

Returns

bool, the flag used to judge whether to use periodic boundary condition.