deepmd.pt.utils.ase_calc#

Classes#

DPCalculator

Implementation of ASE deepmd calculator.

Module Contents#

class deepmd.pt.utils.ase_calc.DPCalculator(model: str | pathlib.Path, label: str = 'DP', type_dict: dict[str, int] | None = None, neighbor_list=None, head=None, **kwargs)#

Bases: ase.calculators.calculator.Calculator

Implementation of ASE deepmd calculator.

Implemented properties are energy, forces and stress

Parameters:
modelUnion[str, Path]

path to the model

labelstr, optional

calculator label, by default “DP”

type_dictdict[str, int], optional

mapping of element types and their numbers, best left None and the calculator will infer this information from model, by default None

neighbor_listase.neighborlist.NeighborList, optional

The neighbor list object. If None, then build the native neighbor list.

headUnion[str, None], optional

a specific model branch choosing from pretrained model, by default None

Examples

Compute potential energy

>>> from ase import Atoms
>>> from deepmd.tf.calculator import DP
>>> water = Atoms('H2O',
>>>             positions=[(0.7601, 1.9270, 1),
>>>                        (1.9575, 1, 1),
>>>                        (1., 1., 1.)],
>>>             cell=[100, 100, 100],
>>>             calculator=DP(model="frozen_model.pb"))
>>> print(water.get_potential_energy())
>>> print(water.get_forces())

Run BFGS structure optimization

>>> from ase.optimize import BFGS
>>> dyn = BFGS(water)
>>> dyn.run(fmax=1e-6)
>>> print(water.get_positions())
name = 'DP'#
implemented_properties: ClassVar[list[str]] = ['energy', 'free_energy', 'forces', 'virial', 'stress']#

Properties calculator can handle (energy, forces, …)

dp#
calculate(atoms: ase.Atoms | None = None, properties: list[str] = ['energy', 'forces', 'virial'], system_changes: list[str] = all_changes) None#

Run calculation with deepmd model.

Parameters:
atomsOptional[Atoms], optional

atoms object to run the calculation on, by default None

propertieslist[str], optional

unused, only for function signature compatibility, by default [“energy”, “forces”, “stress”]

system_changeslist[str], optional

unused, only for function signature compatibility, by default all_changes