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.optimizer.UpdaterMD

View Source On Gitee
class sponge.optimizer.UpdaterMD(system: Molecule, time_step: float = 0.001, velocity: Union[Tensor, ndarray, List[float]] = None, temperature: float = None, pressure: float = None, integrator: Union[Integrator, str] = 'leap_frog', thermostat: Union[Thermostat, str] = 'berendsen', barostat: Union[Barostat, str] = 'berendsen', constraint: Union[Constraint, List[Constraint], str] = None, controller: Union[Controller, List[Controller]] = None, weight_decay: float = 0.0, loss_scale: float = 1.0, **kwargs)[source]

A updater for molecular dynamics (MD) simulation, which is the subclass of Updater.

UpdaterMD uses four different Controllers to control the different variables in the simulation process. The integrator is used for update the atomic coordinates and velocities, the thermostat is used for temperature coupling, the barostat is used for pressure coupling, and the constraint is used for bond constraint.

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

  • time_step (float, optional) – Time step. Default: 1e-3.

  • velocity (Union[Tensor, ndarray, List[float]], optional) – Array of atomic velocity. The shape of array is (A,D) or (B,A,D). Here B is the number of walkers in simulation, A is the number of atoms, D is the spatial dimension of the simulation system, which is usually 3. Data type is float. Default: None.

  • temperature (float, optional) – Reference temperature for coupling. Only valid if thermostat is set to type str. Default: None.

  • pressure (float, optional) – Reference pressure for temperature coupling. Only valid if barostat is set to type str. Default: None.

  • integrator (Union[sponge.control.Integrator, str], optional) – Integrator for MD simulation. It can be an object of Integrator or the str of an integrator name. Default: 'leap_frog'

  • thermostat (Union[sponge.control.Thermostat, str], optional) – Thermostat for temperature coupling. It can be an object of sponge.control.Thermostat or the str of a thermostat name. If a str is given, then it will only valid if the temperature is not None. Default: 'berendsen'

  • barostat (Union[sponge.control.Barostat, str], optional) – Barostat for pressure coupling. It can be an object of Barostat or the str of a barostat name. If a str is given, then it will only valid if the pressure is not None. Default: 'berendsen'.

  • constraint (Union[sponge.control.Constraint, List[sponge.control.Constraint]], optional) – Constraint controller(s) for bond constraint. Default: None.

  • controller (Union[sponge.control.Controller, List[sponge.control.Controller]], optional) – Other controller(s). It will work after the four specific controllers (integrator, thermostat, barostat and constraint). Default: None.

  • weight_decay (float, optional) – An value for the weight decay. Default: 0.0.

  • loss_scale (float, optional) – A value for the loss scale. Default: 1.0.

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

  • force (Tensor) - Force on each atoms of the simulation system. Tensor of shape (B,A,D). Here A is the number of atoms, D is the spatial dimension of the simulation system, which is usually 3.

  • virial (Tensor) - Virial tensor of the simulation system. Tensor of shape (B,D,D). Data type is float. Default: None.

Outputs:
  • success (bool) - whether successfully finish the current optimization step and move to next step.

Supported Platforms:

Ascend GPU

Examples

>>> from sponge import UpdaterMD, Molecule
>>> from mindspore import Tensor
>>> system = Molecule(template='water.tip3p.yaml')
>>> velocity = Tensor([[0.1008,0.,0.],[-0.8,0.,0.],[-0.8,0.,0.]])
>>> opt = UpdaterMD(system=system,
... time_step=1e-3,
... velocity=velocity,
... integrator='leap_frog',
... temperature=None,
... thermostat=None)
>>> # In actual usage, the energy and force are calculated by the
>>> # potential cell or the neural network model
>>> print(opt.coordinate.value())
>>> # [[[ 0. 0. 0. ]
>>> # [ 0.07907964 0.06120793 0. ]
>>> # [-0.07907964 0.06120793 0. ]]]
>>> force = Tensor([[0.,0.,0.],[0.,0.,0.],[0.,0.,0.]])
>>> opt(energy=Tensor([0.0]), force=force)
>>> print(opt.coordinate.value())
>>> # [[[ 0.0001008 0. 0. ]
>>> # [ 0.07827964 0.06120793 0. ]
>>> # [-0.07987964 0.06120793 0. ]]]
property ref_press

Reference pressure for barostat.

Returns

float, reference pressure for barostat.

property ref_temp

Reference temperature for thermostat.

Returns

float, reference temperature for thermostat.

set_barostat(barostat: Barostat, pressure: float = None)[source]

Set barostat

Parameters
  • barostat (Barostat) – Barostat for pressure coupling.

  • pressure (float) – Reference pressure for barostat.

set_constraint(constraint: Union[Constraint, List[Constraint]])[source]

Set constraint.

Parameters

constraint (Union[sponge.control.Constraint, List[sponge.control.Constraint]]) – Constraint controller(s) for bond constraint.

set_pressure(pressure: float)[source]

Set reference pressure for barostat

Parameters

pressure (float) – Reference pressure for barostat.

set_temperature(temperature: float)[source]

Set reference temperature for thermostat

Parameters

temperature (float) – Reference temperature for thermostat.

set_thermostat(thermostat: Thermostat, temperature: float = None)[source]

Set thermostat

Parameters
  • thermostat (Thermostat) – Thermostat for temperature coupling.

  • temperature (float) – Reference temperature for thermostat.