deepmd.infer package

class deepmd.infer.DeepPot(model_file: str, *args, **kwargs)[source]

Bases: DeepEval

Potential energy model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Examples

>>> from deepmd.infer import DeepPot
>>> import numpy as np
>>> dp = DeepPot("graph.pb")
>>> coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
>>> cell = np.diag(10 * np.ones(3)).reshape([1, -1])
>>> atype = [1, 0, 1]
>>> e, f, v = dp.eval(coord, cell, atype)

where e, f and v are predicted energy, force and virial of the system, respectively.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate energy, force, and virial.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

eval(coords: ndarray, cells: Optional[ndarray], atom_types: Union[List[int], ndarray], atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: Dict[str, Any]) Tuple[ndarray, ...][source]

Evaluate energy, force, and virial. If atomic is True, also return atomic energy and atomic virial.

Parameters
coordsnp.ndarray

The coordinates of the atoms, in shape (nframes, natoms, 3).

cellsnp.ndarray

The cell vectors of the system, in shape (nframes, 9). If the system is not periodic, set it to None.

atom_typesList[int] or np.ndarray

The types of the atoms. If mixed_type is False, the shape is (natoms,); otherwise, the shape is (nframes, natoms).

atomicbool, optional

Whether to return atomic energy and atomic virial, by default False.

fparamnp.ndarray, optional

The frame parameters, by default None.

aparamnp.ndarray, optional

The atomic parameters, by default None.

mixed_typebool, optional

Whether the atom_types is mixed type, by default False.

**kwargsDict[str, Any]

Keyword arguments.

Returns
energy

The energy of the system, in shape (nframes,).

force

The force of the system, in shape (nframes, natoms, 3).

virial

The virial of the system, in shape (nframes, 9).

atomic_energy

The atomic energy of the system, in shape (nframes, natoms). Only returned when atomic is True.

atomic_virial

The atomic virial of the system, in shape (nframes, natoms, 9). Only returned when atomic is True.

property output_def: ModelOutputDef

Get the output definition of this model.

deepmd.infer.calc_model_devi(coord, box, atype, models, fname=None, frequency=1, mixed_type=False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, real_data: Optional[dict] = None, atomic: bool = False, relative: Optional[float] = None, relative_v: Optional[float] = None)[source]

Python interface to calculate model deviation.

Parameters
coordnumpy.ndarray, n_frames x n_atoms x 3

Coordinates of system to calculate

boxnumpy.ndarray or None, n_frames x 3 x 3

Box to specify periodic boundary condition. If None, no pbc will be used

atypenumpy.ndarray, n_atoms x 1

Atom types

modelslist of DeepPot models

Models used to evaluate deviation

fnamestr or None

File to dump results, default None

frequencyint

Steps between frames (if the system is given by molecular dynamics engine), default 1

mixed_typebool

Whether the input atype is in mixed_type format or not

fparamnumpy.ndarray

frame specific parameters

aparamnumpy.ndarray

atomic specific parameters

real_datadict, optional

real data to calculate RMS real error

atomicbool, default: False

If True, calculate the force model deviation of each atom.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

relative_vfloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

Returns
model_devinumpy.ndarray, n_frames x 8

Model deviation results. The first column is index of steps, the other 7 columns are max_devi_v, min_devi_v, avg_devi_v, max_devi_f, min_devi_f, avg_devi_f, devi_e.

Examples

>>> from deepmd.tf.infer import calc_model_devi
>>> from deepmd.tf.infer import DeepPot as DP
>>> import numpy as np
>>> coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
>>> cell = np.diag(10 * np.ones(3)).reshape([1, -1])
>>> atype = [1, 0, 1]
>>> graphs = [DP("graph.000.pb"), DP("graph.001.pb")]
>>> model_devi = calc_model_devi(coord, cell, atype, graphs)

Submodules

deepmd.infer.deep_dipole module

class deepmd.infer.deep_dipole.DeepDipole(model_file: str, *args, **kwargs)[source]

Bases: DeepTensor

Deep dipole model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

output_tensor_name

The name of the tensor.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

property output_tensor_name: str

The name of the tensor.

deepmd.infer.deep_dos module

class deepmd.infer.deep_dos.DeepDOS(model_file: str, *args, **kwargs)[source]

Bases: DeepEval

Deep density of states model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate energy, force, and virial.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

get_numb_dos

eval(coords: ndarray, cells: Optional[ndarray], atom_types: Union[List[int], ndarray], atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: Dict[str, Any]) Tuple[ndarray, ...][source]

Evaluate energy, force, and virial. If atomic is True, also return atomic energy and atomic virial.

Parameters
coordsnp.ndarray

The coordinates of the atoms, in shape (nframes, natoms, 3).

cellsnp.ndarray

The cell vectors of the system, in shape (nframes, 9). If the system is not periodic, set it to None.

atom_typesList[int] or np.ndarray

The types of the atoms. If mixed_type is False, the shape is (natoms,); otherwise, the shape is (nframes, natoms).

atomicbool, optional

Whether to return atomic energy and atomic virial, by default False.

fparamnp.ndarray, optional

The frame parameters, by default None.

aparamnp.ndarray, optional

The atomic parameters, by default None.

mixed_typebool, optional

Whether the atom_types is mixed type, by default False.

**kwargsDict[str, Any]

Keyword arguments.

Returns
energy

The energy of the system, in shape (nframes,).

force

The force of the system, in shape (nframes, natoms, 3).

virial

The virial of the system, in shape (nframes, 9).

atomic_energy

The atomic energy of the system, in shape (nframes, natoms). Only returned when atomic is True.

atomic_virial

The atomic virial of the system, in shape (nframes, natoms, 9). Only returned when atomic is True.

get_numb_dos() int[source]
property output_def: ModelOutputDef

Get the output definition of this model.

deepmd.infer.deep_eval module

class deepmd.infer.deep_eval.DeepEval(model_file: str, *args, **kwargs)[source]

Bases: ABC

High-level Deep Evaluator interface.

The specific DeepEval, such as DeepPot and DeepTensor, should inherit from this class. This class provides a high-level interface on the top of the low-level interface.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Returns the output variable definitions.

Methods

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

eval_descriptor(coords: ndarray, cells: Optional[ndarray], atom_types: ndarray, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: Dict[str, Any]) ndarray[source]

Evaluate descriptors by using this DP.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns
descriptor

Descriptors.

eval_typeebd() ndarray[source]

Evaluate output of type embedding network by using this model.

Returns
np.ndarray

The output of type embedding network. The shape is [ntypes, o_size], where ntypes is the number of types, and o_size is the number of nodes in the output layer.

Raises
KeyError

If the model does not enable type embedding.

See also

deepmd.tf.utils.type_embed.TypeEmbedNet

The type embedding network.

Examples

Get the output of type embedding network of graph.pb:

>>> from deepmd.infer import DeepPotential
>>> dp = DeepPotential("graph.pb")
>>> dp.eval_typeebd()
get_dim_aparam() int[source]

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam() int[source]

Get the number (dimension) of frame parameters of this DP.

get_ntypes() int[source]

Get the number of atom types of this model.

get_ntypes_spin() int[source]

Get the number of spin atom types of this model.

get_rcut() float[source]

Get the cutoff radius of this model.

get_sel_type() List[int][source]

Get the selected atom types of this model.

Only atoms with selected atom types have atomic contribution to the result of the model. If returning an empty list, all atom types are selected.

get_type_map() List[str][source]

Get the type map (element name of the atom types) of this model.

property has_efield: bool

Check if the model has efield.

abstract property output_def: ModelOutputDef

Returns the output variable definitions.

class deepmd.infer.deep_eval.DeepEvalBackend(model_file: str, *args, **kwargs)[source]

Bases: ABC

Low-level Deep Evaluator interface.

Backends should inherbit implement this interface. High-level interface will be built on top of this.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
model_type

The the evaluator of the model type.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the energy, force and virial by using this DP.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_has_efield()

Check if the model has efield.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_numb_dos()

Get the number of DOS.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

abstract eval(coords: ndarray, cells: ndarray, atom_types: ndarray, atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, **kwargs: Dict[str, Any]) Dict[str, ndarray][source]

Evaluate the energy, force and virial by using this DP.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Calculate the atomic energy and virial

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

**kwargs

Other parameters

Returns
output_dictdict

The output of the evaluation. The keys are the names of the output variables, and the values are the corresponding output arrays.

eval_descriptor(coords: ndarray, cells: ndarray, atom_types: ndarray, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: Dict[str, Any]) ndarray[source]

Evaluate descriptors by using this DP.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns
descriptor

Descriptors.

eval_typeebd() ndarray[source]

Evaluate output of type embedding network by using this model.

Returns
np.ndarray

The output of type embedding network. The shape is [ntypes, o_size], where ntypes is the number of types, and o_size is the number of nodes in the output layer.

Raises
KeyError

If the model does not enable type embedding.

abstract get_dim_aparam() int[source]

Get the number (dimension) of atomic parameters of this DP.

abstract get_dim_fparam() int[source]

Get the number (dimension) of frame parameters of this DP.

get_has_efield()[source]

Check if the model has efield.

abstract get_ntypes() int[source]

Get the number of atom types of this model.

abstract get_ntypes_spin() int[source]

Get the number of spin atom types of this model.

get_numb_dos() int[source]

Get the number of DOS.

abstract get_rcut() float[source]

Get the cutoff radius of this model.

abstract get_sel_type() List[int][source]

Get the selected atom types of this model.

Only atoms with selected atom types have atomic contribution to the result of the model. If returning an empty list, all atom types are selected.

abstract get_type_map() List[str][source]

Get the type map (element name of the atom types) of this model.

abstract property model_type: DeepEval

The the evaluator of the model type.

deepmd.infer.deep_polar module

class deepmd.infer.deep_polar.DeepGlobalPolar(model_file: str, *args, **kwargs)[source]

Bases: DeepTensor

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

output_tensor_name

The name of the tensor.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

eval(coords: ndarray, cells: Optional[ndarray], atom_types: Union[List[int], ndarray], atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: dict) ndarray[source]

Evaluate the model.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_typeslist[int] or np.ndarray

The atom types The list should contain natoms ints

atomic

If True (default), return the atomic tensor Otherwise return the global tensor

fparam

Not used in this model

aparam

Not used in this model

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns
tensor

The returned tensor If atomic == False then of size nframes x output_dim else of size nframes x natoms x output_dim

property output_tensor_name: str

The name of the tensor.

class deepmd.infer.deep_polar.DeepPolar(model_file: str, *args, **kwargs)[source]

Bases: DeepTensor

Deep polar model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

output_tensor_name

The name of the tensor.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

property output_tensor_name: str

The name of the tensor.

deepmd.infer.deep_pot module

class deepmd.infer.deep_pot.DeepPot(model_file: str, *args, **kwargs)[source]

Bases: DeepEval

Potential energy model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Examples

>>> from deepmd.infer import DeepPot
>>> import numpy as np
>>> dp = DeepPot("graph.pb")
>>> coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
>>> cell = np.diag(10 * np.ones(3)).reshape([1, -1])
>>> atype = [1, 0, 1]
>>> e, f, v = dp.eval(coord, cell, atype)

where e, f and v are predicted energy, force and virial of the system, respectively.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate energy, force, and virial.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

eval(coords: ndarray, cells: Optional[ndarray], atom_types: Union[List[int], ndarray], atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: Dict[str, Any]) Tuple[ndarray, ...][source]

Evaluate energy, force, and virial. If atomic is True, also return atomic energy and atomic virial.

Parameters
coordsnp.ndarray

The coordinates of the atoms, in shape (nframes, natoms, 3).

cellsnp.ndarray

The cell vectors of the system, in shape (nframes, 9). If the system is not periodic, set it to None.

atom_typesList[int] or np.ndarray

The types of the atoms. If mixed_type is False, the shape is (natoms,); otherwise, the shape is (nframes, natoms).

atomicbool, optional

Whether to return atomic energy and atomic virial, by default False.

fparamnp.ndarray, optional

The frame parameters, by default None.

aparamnp.ndarray, optional

The atomic parameters, by default None.

mixed_typebool, optional

Whether the atom_types is mixed type, by default False.

**kwargsDict[str, Any]

Keyword arguments.

Returns
energy

The energy of the system, in shape (nframes,).

force

The force of the system, in shape (nframes, natoms, 3).

virial

The virial of the system, in shape (nframes, 9).

atomic_energy

The atomic energy of the system, in shape (nframes, natoms). Only returned when atomic is True.

atomic_virial

The atomic virial of the system, in shape (nframes, natoms, 9). Only returned when atomic is True.

property output_def: ModelOutputDef

Get the output definition of this model.

deepmd.infer.deep_tensor module

class deepmd.infer.deep_tensor.DeepTensor(model_file: str, *args, **kwargs)[source]

Bases: DeepEval

Deep Tensor Model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

output_tensor_name

The name of the tensor.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

eval(coords: ndarray, cells: Optional[ndarray], atom_types: Union[List[int], ndarray], atomic: bool = True, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: dict) ndarray[source]

Evaluate the model.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_typeslist[int] or np.ndarray

The atom types The list should contain natoms ints

atomic

If True (default), return the atomic tensor Otherwise return the global tensor

fparam

Not used in this model

aparam

Not used in this model

efield

Not used in this model

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns
tensor

The returned tensor If atomic == False then of size nframes x output_dim else of size nframes x natoms x output_dim

eval_full(coords: ndarray, cells: Optional[ndarray], atom_types: ndarray, atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, mixed_type: bool = False, **kwargs: dict) Tuple[ndarray, ...][source]

Evaluate the model with interface similar to the energy model. Will return global tensor, component-wise force and virial and optionally atomic tensor and atomic virial.

Parameters
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Whether to calculate atomic tensor and virial

fparam

Not used in this model

aparam

Not used in this model

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns
tensor

The global tensor. shape: [nframes x nout]

force

The component-wise force (negative derivative) on each atom. shape: [nframes x nout x natoms x 3]

virial

The component-wise virial of the tensor. shape: [nframes x nout x 9]

atom_tensor

The atomic tensor. Only returned when atomic == True shape: [nframes x natoms x nout]

atom_virial

The atomic virial. Only returned when atomic == True shape: [nframes x nout x natoms x 9]

property output_def: ModelOutputDef

Get the output definition of this model.

abstract property output_tensor_name: str

The name of the tensor.

deepmd.infer.deep_wfc module

class deepmd.infer.deep_wfc.DeepWFC(model_file: str, *args, **kwargs)[source]

Bases: DeepTensor

Deep WFC model.

Parameters
model_filePath

The name of the frozen model file.

*argslist

Positional arguments.

auto_batch_sizebool or int or AutoBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

neighbor_listase.neighborlist.NewPrimitiveNeighborList, optional

The ASE neighbor list class to produce the neighbor list. If None, the neighbor list will be built natively in the model.

**kwargsdict

Keyword arguments.

Attributes
has_efield

Check if the model has efield.

output_def

Get the output definition of this model.

output_tensor_name

The name of the tensor.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this DP.

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_ntypes_spin()

Get the number of spin atom types of this model.

get_rcut()

Get the cutoff radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

property output_tensor_name: str

The name of the tensor.

deepmd.infer.model_devi module

deepmd.infer.model_devi.calc_model_devi(coord, box, atype, models, fname=None, frequency=1, mixed_type=False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, real_data: Optional[dict] = None, atomic: bool = False, relative: Optional[float] = None, relative_v: Optional[float] = None)[source]

Python interface to calculate model deviation.

Parameters
coordnumpy.ndarray, n_frames x n_atoms x 3

Coordinates of system to calculate

boxnumpy.ndarray or None, n_frames x 3 x 3

Box to specify periodic boundary condition. If None, no pbc will be used

atypenumpy.ndarray, n_atoms x 1

Atom types

modelslist of DeepPot models

Models used to evaluate deviation

fnamestr or None

File to dump results, default None

frequencyint

Steps between frames (if the system is given by molecular dynamics engine), default 1

mixed_typebool

Whether the input atype is in mixed_type format or not

fparamnumpy.ndarray

frame specific parameters

aparamnumpy.ndarray

atomic specific parameters

real_datadict, optional

real data to calculate RMS real error

atomicbool, default: False

If True, calculate the force model deviation of each atom.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

relative_vfloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

Returns
model_devinumpy.ndarray, n_frames x 8

Model deviation results. The first column is index of steps, the other 7 columns are max_devi_v, min_devi_v, avg_devi_v, max_devi_f, min_devi_f, avg_devi_f, devi_e.

Examples

>>> from deepmd.tf.infer import calc_model_devi
>>> from deepmd.tf.infer import DeepPot as DP
>>> import numpy as np
>>> coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
>>> cell = np.diag(10 * np.ones(3)).reshape([1, -1])
>>> atype = [1, 0, 1]
>>> graphs = [DP("graph.000.pb"), DP("graph.001.pb")]
>>> model_devi = calc_model_devi(coord, cell, atype, graphs)
deepmd.infer.model_devi.calc_model_devi_e(es: ndarray, real_e: Optional[ndarray] = None) ndarray[source]

Calculate model deviation of total energy per atom.

Here we don’t use the atomic energy, as the decomposition of energy is arbitrary and not unique. There is no fitting target for atomic energy.

Parameters
esnumpy.ndarray

size of `n_models x n_frames x 1

real_enumpy.ndarray

real energy, size of n_frames x 1. If given, the RMS real error is calculated instead.

Returns
max_devi_enumpy.ndarray

maximum deviation of energy

deepmd.infer.model_devi.calc_model_devi_f(fs: ndarray, real_f: Optional[ndarray] = None, relative: Optional[float] = None, atomic: Literal[False] = False) Tuple[ndarray, ndarray, ndarray][source]
deepmd.infer.model_devi.calc_model_devi_f(fs: ndarray, real_f: Optional[ndarray] = None, relative: Optional[float] = None, *, atomic: Literal[True]) Tuple[ndarray, ndarray, ndarray, ndarray]

Calculate model deviation of force.

Parameters
fsnumpy.ndarray

size of n_models x n_frames x n_atoms x 3

real_fnumpy.ndarray or None

real force, size of n_frames x n_atoms x 3. If given, the RMS real error is calculated instead.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

atomicbool, default: False

Whether return deviation of force in all atoms

Returns
max_devi_fnumpy.ndarray

maximum deviation of force in all atoms

min_devi_fnumpy.ndarray

minimum deviation of force in all atoms

avg_devi_fnumpy.ndarray

average deviation of force in all atoms

fs_devinumpy.ndarray

deviation of force in all atoms, returned if atomic=True

deepmd.infer.model_devi.calc_model_devi_v(vs: ndarray, real_v: Optional[ndarray] = None, relative: Optional[float] = None) Tuple[ndarray, ndarray, ndarray][source]

Calculate model deviation of virial.

Parameters
vsnumpy.ndarray

size of n_models x n_frames x 9

real_vnumpy.ndarray

real virial, size of n_frames x 9. If given, the RMS real error is calculated instead.

relativefloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

Returns
max_devi_vnumpy.ndarray

maximum deviation of virial in 9 elements

min_devi_vnumpy.ndarray

minimum deviation of virial in 9 elements

avg_devi_vnumpy.ndarray

average deviation of virial in 9 elements

deepmd.infer.model_devi.make_model_devi(*, models: list, system: str, set_prefix: str, output: str, frequency: int, real_error: bool = False, atomic: bool = False, relative: Optional[float] = None, relative_v: Optional[float] = None, **kwargs)[source]

Make model deviation calculation.

Parameters
modelslist

A list of paths of models to use for making model deviation

systemstr

The path of system to make model deviation calculation

set_prefixstr

The set prefix of the system

outputstr

The output file for model deviation results

frequencyint

The number of steps that elapse between writing coordinates in a trajectory by a MD engine (such as Gromacs / Lammps). This paramter is used to determine the index in the output file.

real_errorbool, default: False

If True, calculate the RMS real error instead of model deviation.

atomicbool, default: False

If True, calculate the force model deviation of each atom.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

relative_vfloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

**kwargs

Arbitrary keyword arguments.

deepmd.infer.model_devi.write_model_devi_out(devi: ndarray, fname: str, header: str = '', atomic: bool = False)[source]

Write output of model deviation.

Parameters
devinumpy.ndarray

the first column is the steps index

fnamestr

the file name to dump

headerstr, default=””

the header to dump

atomicbool, default: False

whether atomic model deviation is printed