deepmd.tf.infer#
Submodule containing all the implemented potentials.
Submodules#
Classes#
High-level Deep Evaluator interface. | |
Deep dipole model. | |
Deep density of states model. | |
Old tensor models from v1, which has no gradient output. | |
Deep polar model. | |
Potential energy model. | |
Deep WFC model. | |
Evaluate the reciprocal part of the Ewald sum. |
Functions#
| Factory function that forwards to DeepEval (for compatibility). |
| Python interface to calculate model deviation. |
Package Contents#
- deepmd.tf.infer.DeepPotential(*args, **kwargs) deep_eval.DeepEval[source]#
Factory function that forwards to DeepEval (for compatibility).
- Parameters:
- *args
positional arguments
- **kwargs
keyword arguments
- Returns:
DeepEvalpotentials
- class deepmd.tf.infer.DeepEval(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
abc.ABCHigh-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_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
- deep_eval#
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef#
- Abstractmethod:
Returns the output variable definitions.
- _get_natoms_and_nframes(coords: numpy.ndarray, atom_types: numpy.ndarray, mixed_type: bool = False) tuple[int, int][source]#
- _expande_atype(atype: numpy.ndarray, nframes: int, mixed_type: bool)[source]#
- eval_descriptor(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: numpy.ndarray, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, mixed_type: bool = False, **kwargs: Any) numpy.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:
descriptorDescriptors.
- eval_typeebd() numpy.ndarray[source]#
Evaluate output of type embedding network by using this model.
- Returns:
np.ndarrayThe 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:
KeyErrorIf the model does not enable type embedding.
See also
deepmd.tf.utils.type_embed.TypeEmbedNetThe 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_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.
- class deepmd.tf.infer.DeepDipole(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_tensor.DeepTensorDeep dipole model.
- Parameters:
- model_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
- class deepmd.tf.infer.DeepDOS(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_eval.DeepEvalDeep density of states model.
- Parameters:
- model_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef#
Get the output definition of this model.
- eval(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: list[int] | numpy.ndarray, atomic: bool = False, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, mixed_type: bool = False, **kwargs: Any) tuple[numpy.ndarray, Ellipsis][source]#
Evaluate energy, force, and virial. If atomic is True, also return atomic energy and atomic virial.
- Parameters:
- coords
np.ndarray The coordinates of the atoms, in shape (nframes, natoms, 3).
- cells
np.ndarray The cell vectors of the system, in shape (nframes, 9). If the system is not periodic, set it to None.
- atom_types
list[int]ornp.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.
- fparam
np.ndarray,optional The frame parameters, by default None.
- aparam
np.ndarray,optional The atomic parameters, by default None.
- mixed_typebool,
optional Whether the atom_types is mixed type, by default False.
- **kwargs
dict[str,Any] Keyword arguments.
- coords
- Returns:
energyThe energy of the system, in shape (nframes,).
forceThe force of the system, in shape (nframes, natoms, 3).
virialThe virial of the system, in shape (nframes, 9).
atomic_energyThe atomic energy of the system, in shape (nframes, natoms). Only returned when atomic is True.
atomic_virialThe atomic virial of the system, in shape (nframes, natoms, 9). Only returned when atomic is True.
- class deepmd.tf.infer.DeepGlobalPolar(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_tensor.OldDeepTensorOld tensor models from v1, which has no gradient output.
- eval(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: list[int] | numpy.ndarray, atomic: bool = False, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, mixed_type: bool = False, **kwargs) numpy.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_types
list[int]ornp.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:
tensorThe returned tensor If atomic == False then of size nframes x output_dim else of size nframes x natoms x output_dim
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef#
Get the output definition of this model.
- class deepmd.tf.infer.DeepPolar(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_tensor.DeepTensorDeep polar model.
- Parameters:
- model_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
- class deepmd.tf.infer.DeepPot(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_eval.DeepEvalPotential energy model.
- Parameters:
- model_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
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.
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef#
Get the output definition of this model.
- property output_def_mag: deepmd.dpmodel.output_def.ModelOutputDef#
Get the output definition of this model with magnetic parts.
- eval(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: list[int] | numpy.ndarray, atomic: Literal[True], fparam: numpy.ndarray | None, aparam: numpy.ndarray | None, mixed_type: bool, **kwargs: Any) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] | tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
- eval(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: list[int] | numpy.ndarray, atomic: Literal[False], fparam: numpy.ndarray | None, aparam: numpy.ndarray | None, mixed_type: bool, **kwargs: Any) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] | tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]
- eval(coords: numpy.ndarray, cells: numpy.ndarray | None, atom_types: list[int] | numpy.ndarray, atomic: bool, fparam: numpy.ndarray | None, aparam: numpy.ndarray | None, mixed_type: bool, **kwargs: Any) tuple[numpy.ndarray, Ellipsis]
Evaluate energy, force, and virial. If atomic is True, also return atomic energy and atomic virial.
- Parameters:
- coords
np.ndarray The coordinates of the atoms, in shape (nframes, natoms, 3).
- cells
np.ndarray The cell vectors of the system, in shape (nframes, 9). If the system is not periodic, set it to None.
- atom_types
list[int]ornp.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.
- fparam
np.ndarray,optional The frame parameters, by default None.
- aparam
np.ndarray,optional The atomic parameters, by default None.
- mixed_typebool,
optional Whether the atom_types is mixed type, by default False.
- **kwargs
dict[str,Any] Keyword arguments.
- coords
- Returns:
energyThe energy of the system, in shape (nframes,).
forceThe force of the system, in shape (nframes, natoms, 3).
virialThe virial of the system, in shape (nframes, 9).
atomic_energyThe atomic energy of the system, in shape (nframes, natoms). Only returned when atomic is True.
atomic_virialThe atomic virial of the system, in shape (nframes, natoms, 9). Only returned when atomic is True.
hessianThe Hessian matrix of the system, in shape (nframes, 3 * natoms, 3 * natoms). Returned when available.
- class deepmd.tf.infer.DeepWFC(model_file: str, *args: Any, auto_batch_size: bool | int | deepmd.utils.batch_size.AutoBatchSize = True, neighbor_list: ase.neighborlist.NewPrimitiveNeighborList | None = None, **kwargs: Any)[source]#
Bases:
deepmd.infer.deep_tensor.OldDeepTensorDeep WFC model.
- Parameters:
- model_file
Path The name of the frozen model file.
- *args
list Positional arguments.
- auto_batch_sizebool or
intorAutoBatchSize, default:True If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- neighbor_list
ase.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.
- **kwargs
dict Keyword arguments.
- model_file
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef#
Get the output definition of this model.
- class deepmd.tf.infer.EwaldRecp(hh, beta)[source]#
Evaluate the reciprocal part of the Ewald sum.
- hh#
- beta#
- sess#
- eval(coord: numpy.ndarray, charge: numpy.ndarray, box: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
Evaluate.
- Parameters:
- coord
The coordinates of atoms
- charge
The atomic charge
- box
The simulation region. PBC is assumed
- Returns:
eThe energy
fThe force
vThe virial
- deepmd.tf.infer.calc_model_devi(coord, box, atype, models, fname=None, frequency=1, mixed_type=False, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, real_data: dict | None = None, atomic: bool = False, relative: float | None = None, relative_v: float | None = None)[source]#
Python interface to calculate model deviation.
- Parameters:
- coord
numpy.ndarray, n_frames x n_atoms x 3 Coordinates of system to calculate
- box
numpy.ndarrayorNone, n_frames x 3 x 3 Box to specify periodic boundary condition. If None, no pbc will be used
- atype
numpy.ndarray, n_atoms x 1 Atom types
- models
listofDeepPotmodels Models used to evaluate deviation
- fname
strorNone File to dump results, default None
- frequency
int 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
- fparam
numpy.ndarray frame specific parameters
- aparam
numpy.ndarray atomic specific parameters
- real_data
dict,optional real data to calculate RMS real error
- atomicbool, default:
False If True, calculate the force model deviation of each atom.
- relative
float, 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_v
float, 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.
- coord
- Returns:
- model_devi
numpy.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.
- model_devi
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)