deepmd.tf.infer.deep_eval
Module Contents
Classes
TensorFlow backend implementation for DeepEval. | |
Common methods for DeepPot, DeepWFC, DeepPolar, ... |
- class deepmd.tf.infer.deep_eval.DeepEval(model_file: pathlib.Path, output_def: deepmd.dpmodel.output_def.ModelOutputDef, *args: list, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | deepmd.tf.utils.batch_size.AutoBatchSize = False, input_map: dict | None = None, neighbor_list=None, **kwargs: dict)[source]
Bases:
deepmd.infer.deep_eval.DeepEvalBackend
TensorFlow backend implementation for DeepEval.
- Parameters:
- model_file
Path
The name of the frozen model file.
- output_def
ModelOutputDef
The output definition of the model.
- *args
list
Positional arguments.
- load_prefix: str
The prefix in the load computational graph
- default_tf_graphbool
If uses the default tf graph, otherwise build a new tf graph for evaluation
- auto_batch_sizebool or
int
orAutomaticBatchSize
, default:False
If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- input_map
dict
,optional
The input map for tf.import_graph_def. Only work with default tf graph
- 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 model_type: deepmd.infer.deep_eval.DeepEval[source]
Get type of model.
:type:str
- _graph_compatable() bool [source]
Check the model compatability.
- Returns:
- bool
If the model stored in the graph file is compatable with the current code
- static _load_graph(frozen_graph_filename: pathlib.Path, prefix: str = 'load', default_tf_graph: bool = False, input_map: dict | None = None)[source]
- static sort_input(coord: numpy.ndarray, atom_type: numpy.ndarray, sel_atoms: List[int] | None = None)[source]
Sort atoms in the system according their types.
- Parameters:
- coord
The coordinates of atoms. Should be of shape [nframes, natoms, 3]
- atom_type
The type of atoms Should be of shape [natoms]
- sel_atoms
The selected atoms by type
- Returns:
coord_out
The coordinates after sorting
atom_type_out
The atom types after sorting
idx_map
The index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]
sel_atom_type
Only output if sel_atoms is not None The sorted selected atom types
sel_idx_map
Only output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.
- static reverse_map(vec: numpy.ndarray, imap: List[int]) numpy.ndarray [source]
Reverse mapping of a vector according to the index map.
- Parameters:
- vec
Input vector. Be of shape [nframes, natoms, -1]
- imap
Index map. Be of shape [natoms]
- Returns:
vec_out
Reverse mapped vector.
- make_natoms_vec(atom_types: numpy.ndarray) numpy.ndarray [source]
Make the natom vector used by deepmd-kit.
- Parameters:
- atom_types
The type of atoms
- Returns:
natoms
The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: number of local atoms natoms[1]: total number of atoms held by this processor natoms[i]: 2 <= i < Ntypes+2, number of type i atoms
- eval_typeebd() numpy.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.tf.infer import DeepPotential >>> dp = DeepPotential("graph.pb") >>> dp.eval_typeebd()
- build_neighbor_list(coords: numpy.ndarray, cell: numpy.ndarray | None, atype: numpy.ndarray, imap: numpy.ndarray, neighbor_list)[source]
Make the mesh with neighbor list for a single frame.
- Parameters:
- coords
np.ndarray
The coordinates of atoms. Should be of shape [natoms, 3]
- cell
Optional
[np.ndarray
] The cell of the system. Should be of shape [3, 3]
- atype
np.ndarray
The type of atoms. Should be of shape [natoms]
- imap
np.ndarray
The index map of atoms. Should be of shape [natoms]
- neighbor_list
ase.neighborlist.NewPrimitiveNeighborList
ASE neighbor list. The following method or attribute will be used/set: bothways, self_interaction, update, build, first_neigh, pair_second, offset_vec.
- coords
- Returns:
- natoms_vec
np.ndarray
The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: nloc natoms[1]: nall natoms[i]: 2 <= i < Ntypes+2, number of type i atoms for nloc
- coords
np.ndarray
The coordinates of atoms, including ghost atoms. Should be of shape [nframes, nall, 3]
- atype
np.ndarray
The type of atoms, including ghost atoms. Should be of shape [nall]
- mesh
np.ndarray
The mesh in nei_mode=4.
- imap
np.ndarray
The index map of atoms. Should be of shape [nall]
- ghost_map
np.ndarray
The index map of ghost atoms. Should be of shape [nghost]
- natoms_vec
- get_sel_type() numpy.ndarray | None [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.
- _eval_func(inner_func: Callable, numb_test: int, natoms: int) Callable [source]
Wrapper method with auto batch size.
- _get_natoms_and_nframes(coords: numpy.ndarray, atom_types: List[int] | numpy.ndarray) Tuple[int, int] [source]
- eval(coords: numpy.ndarray, cells: numpy.ndarray, atom_types: numpy.ndarray, atomic: bool = False, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, efield: numpy.ndarray | None = None, **kwargs: Dict[str, Any]) Dict[str, numpy.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.
- efield
The external field on atoms. The array should be of size nframes x natoms x 3
- **kwargs
Other parameters
- Returns:
- output_dict
dict
The output of the evaluation. The keys are the names of the output variables, and the values are the corresponding output arrays.
- output_dict
- eval_descriptor(coords: numpy.ndarray, cells: numpy.ndarray, atom_types: numpy.ndarray, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, efield: numpy.ndarray | None = None) 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
- Returns:
descriptor
Descriptors.
- _eval_descriptor_inner(coords: numpy.ndarray, cells: numpy.ndarray, atom_types: numpy.ndarray, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, efield: numpy.ndarray | None = None) numpy.ndarray [source]
- class deepmd.tf.infer.deep_eval.DeepEvalOld(model_file: pathlib.Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | deepmd.tf.utils.batch_size.AutoBatchSize = False, input_map: dict | None = None, neighbor_list=None)[source]
Common methods for DeepPot, DeepWFC, DeepPolar, …
- Parameters:
- model_file
Path
The name of the frozen model file.
- load_prefix: str
The prefix in the load computational graph
- default_tf_graphbool
If uses the default tf graph, otherwise build a new tf graph for evaluation
- auto_batch_sizebool or
int
orAutomaticBatchSize
, default:False
If True, automatic batch size will be used. If int, it will be used as the initial batch size.
- input_map
dict
,optional
The input map for tf.import_graph_def. Only work with default tf graph
- 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.
- model_file
- _graph_compatable() bool [source]
Check the model compatability.
- Returns:
- bool
If the model stored in the graph file is compatable with the current code
- _get_tensor(tensor_name: str, attr_name: str | None = None) deepmd.tf.env.tf.Tensor [source]
Get TF graph tensor and assign it to class namespace.
- static _load_graph(frozen_graph_filename: pathlib.Path, prefix: str = 'load', default_tf_graph: bool = False, input_map: dict | None = None)[source]
- static sort_input(coord: numpy.ndarray, atom_type: numpy.ndarray, sel_atoms: List[int] | None = None, mixed_type: bool = False)[source]
Sort atoms in the system according their types.
- Parameters:
- coord
The coordinates of atoms. Should be of shape [nframes, natoms, 3]
- atom_type
The type of atoms Should be of shape [natoms]
- sel_atoms
The selected atoms by type
- 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:
coord_out
The coordinates after sorting
atom_type_out
The atom types after sorting
idx_map
The index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]
sel_atom_type
Only output if sel_atoms is not None The sorted selected atom types
sel_idx_map
Only output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.
- static reverse_map(vec: numpy.ndarray, imap: List[int]) numpy.ndarray [source]
Reverse mapping of a vector according to the index map.
- Parameters:
- vec
Input vector. Be of shape [nframes, natoms, -1]
- imap
Index map. Be of shape [natoms]
- Returns:
vec_out
Reverse mapped vector.
- make_natoms_vec(atom_types: numpy.ndarray, mixed_type: bool = False) numpy.ndarray [source]
Make the natom vector used by deepmd-kit.
- Parameters:
- atom_types
The type of atoms
- 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:
natoms
The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: number of local atoms natoms[1]: total number of atoms held by this processor natoms[i]: 2 <= i < Ntypes+2, number of type i atoms
- eval_typeebd() numpy.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.tf.infer import DeepPotential >>> dp = DeepPotential("graph.pb") >>> dp.eval_typeebd()
- build_neighbor_list(coords: numpy.ndarray, cell: numpy.ndarray | None, atype: numpy.ndarray, imap: numpy.ndarray, neighbor_list)[source]
Make the mesh with neighbor list for a single frame.
- Parameters:
- coords
np.ndarray
The coordinates of atoms. Should be of shape [natoms, 3]
- cell
Optional
[np.ndarray
] The cell of the system. Should be of shape [3, 3]
- atype
np.ndarray
The type of atoms. Should be of shape [natoms]
- imap
np.ndarray
The index map of atoms. Should be of shape [natoms]
- neighbor_list
ase.neighborlist.NewPrimitiveNeighborList
ASE neighbor list. The following method or attribute will be used/set: bothways, self_interaction, update, build, first_neigh, pair_second, offset_vec.
- coords
- Returns:
- natoms_vec
np.ndarray
The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: nloc natoms[1]: nall natoms[i]: 2 <= i < Ntypes+2, number of type i atoms for nloc
- coords
np.ndarray
The coordinates of atoms, including ghost atoms. Should be of shape [nframes, nall, 3]
- atype
np.ndarray
The type of atoms, including ghost atoms. Should be of shape [nall]
- mesh
np.ndarray
The mesh in nei_mode=4.
- imap
np.ndarray
The index map of atoms. Should be of shape [nall]
- ghost_map
np.ndarray
The index map of ghost atoms. Should be of shape [nghost]
- natoms_vec