deepmd.tf#
Root of the deepmd package, exposes all public classes and submodules.
Submodules#
Classes#
High-level Deep Evaluator interface. | |
Functions#
| Factory function that forwards to DeepEval (for compatibility). |
Package Contents#
- class deepmd.tf.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
- property output_def: deepmd.dpmodel.output_def.ModelOutputDef[source]#
- Abstractmethod:
Returns the output variable definitions.
- serialize() dict[str, Any][source]#
Serialize the loaded model as a model tree.
Most backends return the lossless, weight-bearing
modelsubtree from the serialized file payload. JAX.savedmodelinputs are the known exception: they are reconstructed from the model definition script and therefore do not preserve trained weights.
- _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) numpy.ndarray[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, dtype: str = 'native', **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.
- dtype
Output dtype:
"fp32","fp64", or"native".
- Returns:
descriptorDescriptors.
- eval_fitting_last_layer(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, dtype: str = 'native', **kwargs: Any) numpy.ndarray[source]#
Evaluate fitting before last layer 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.
- dtype
Output dtype:
"fp32","fp64", or"native".
- Returns:
fittingFitting output before last layer.
- eval_embedding(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, dtype: str = 'fp32', **kwargs: Any) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
Evaluate the descriptor, atomic feature, and structural feature.
A single forward pass produces all three embeddings without force or virial autograd. The descriptor is the per-atom local-environment representation; the atomic feature is the activation after the last fitting hidden layer; the structural feature is the masked atom-sum of the atomic feature, a whole-structure summary. For models with a single shared fitting network, projecting the structural feature through the fitting output layer reproduces the (bias-free) total energy. The output precision is selected by
dtypeand defaults to float32.- 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.
- 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.
- dtype
Output dtype:
"fp32","fp64", or"native".
- Returns:
descriptorThe per-atom descriptor, of size nframes x natoms x dim_descriptor.
atomic_featureThe per-atom last hidden activation, of size nframes x natoms x dim_hidden.
structural_featureThe per-structure pooled feature, of size nframes x dim_hidden.
- Raises:
NotImplementedErrorIf the loaded model does not support embedding extraction.
- 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()
- _standard_input(coords: numpy.ndarray | list, cells: numpy.ndarray | list | None, atom_types: numpy.ndarray | list, fparam: numpy.ndarray | list | None, aparam: numpy.ndarray | list | None, mixed_type: bool) tuple[numpy.ndarray, numpy.ndarray | None, numpy.ndarray, numpy.ndarray | None, numpy.ndarray | None][source]#
- 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_sel_natoms(atype: numpy.ndarray) int[source]#
- get_ntypes_spin() int[source]#
Get the number of spin atom types of this model. Only used in old implement.
- get_observed_types() dict[source]#
Get observed types (elements) of the model during data statistics.
- get_model() Any[source]#
Get the model module implemented by the deep learning framework.
For PyTorch, this returns the nn.Module. For Paddle, this returns the paddle.nn.Layer. For TensorFlow, this returns the graph. For dpmodel, this returns the BaseModel.
- Returns:
modelThe model module implemented by the deep learning framework.
- deepmd.tf.DeepPotential(*args: object, **kwargs: object) deep_eval.DeepEval[source]#
Factory function that forwards to DeepEval (for compatibility).
- Parameters:
- *args
positional arguments
- **kwargs
keyword arguments
- Returns:
DeepEvalpotentials
- class deepmd.tf.DipoleChargeModifier(model_name: str, model_charge_map: list[float], sys_charge_map: list[float], ewald_h: float = 1, ewald_beta: float = 1)[source]#
Bases:
deepmd.tf.infer.deep_dipole.DeepDipoleOld,deepmd.tf.modifier.base_modifier.BaseModifier- Parameters:
- model_name
The model file for the DeepDipole model
- model_charge_map
Gives the amount of charge for the wfcc
- sys_charge_map
Gives the amount of charge for the real atoms
- ewald_h
Grid spacing of the reciprocal part of Ewald sum. Unit: A
- ewald_beta
Splitting parameter of the Ewald sum. Unit: A^{-1}
- classmethod deserialize(data: dict) deepmd.tf.modifier.base_modifier.BaseModifier[source]#
Deserialize the modifier.
- Parameters:
- data
dict The serialized data
- data
- Returns:
BaseModelThe deserialized modifier
- build_fv_graph() deepmd.tf.env.tf.Tensor[source]#
Build the computational graph for the force and virial inference.
- _build_fv_graph_inner() tuple[deepmd.tf.env.tf.Tensor, deepmd.tf.env.tf.Tensor, deepmd.tf.env.tf.Tensor][source]#
- eval(coord: numpy.ndarray, box: numpy.ndarray, atype: numpy.ndarray, eval_fv: bool = True) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
Evaluate the modification.
- Parameters:
- coord
The coordinates of atoms
- box
The simulation region. PBC is assumed
- atype
The atom types
- eval_fv
Evaluate force and virial
- Returns:
tot_eThe energy modification
tot_fThe force modification
tot_vThe virial modification
- _eval_fv(coords: numpy.ndarray, cells: numpy.ndarray, atom_types: numpy.ndarray, ext_f: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
- _extend_system(coord: numpy.ndarray, box: numpy.ndarray, atype: numpy.ndarray, charge: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#
- modify_data(data: dict, data_sys: deepmd.tf.utils.data.DeepmdData) None[source]#
Modify data.
- Parameters:
- data
Internal data of DeepmdData. Be a dict, has the following keys - coord coordinates - box simulation box - type atom types - find_energy tells if data has energy - find_force tells if data has force - find_virial tells if data has virial - energy energy - force force - virial virial
- data_sys
DeepmdData The data system.
- static get_params_from_frozen_model(model: deepmd.tf.infer.DeepEval) dict[source]#
Extract modifier parameters from a DeepEval model.