deepmd.tf
Root of the deepmd package, exposes all public classes and submodules.
Subpackages
deepmd.tf.cluster
deepmd.tf.descriptor
deepmd.tf.descriptor.descriptor
deepmd.tf.descriptor.hybrid
deepmd.tf.descriptor.loc_frame
deepmd.tf.descriptor.se
deepmd.tf.descriptor.se_a
deepmd.tf.descriptor.se_a_ebd
deepmd.tf.descriptor.se_a_ebd_v2
deepmd.tf.descriptor.se_a_ef
deepmd.tf.descriptor.se_a_mask
deepmd.tf.descriptor.se_atten
deepmd.tf.descriptor.se_atten_v2
deepmd.tf.descriptor.se_r
deepmd.tf.descriptor.se_t
deepmd.tf.entrypoints
deepmd.tf.entrypoints.compress
deepmd.tf.entrypoints.convert
deepmd.tf.entrypoints.doc
deepmd.tf.entrypoints.freeze
deepmd.tf.entrypoints.gui
deepmd.tf.entrypoints.ipi
deepmd.tf.entrypoints.main
deepmd.tf.entrypoints.neighbor_stat
deepmd.tf.entrypoints.test
deepmd.tf.entrypoints.train
deepmd.tf.entrypoints.transfer
deepmd.tf.fit
deepmd.tf.infer
deepmd.tf.loggers
deepmd.tf.loss
deepmd.tf.model
deepmd.tf.nvnmd
deepmd.tf.op
deepmd.tf.op._add_flt_nvnmd_grad
deepmd.tf.op._copy_flt_nvnmd_grad
deepmd.tf.op._dotmul_flt_nvnmd_grad
deepmd.tf.op._flt_nvnmd_grad
deepmd.tf.op._gelu
deepmd.tf.op._map_flt_nvnmd_grad
deepmd.tf.op._matmul_fitnet_nvnmd_grad
deepmd.tf.op._matmul_flt2fix_nvnmd
deepmd.tf.op._matmul_flt_nvnmd_grad
deepmd.tf.op._mul_flt_nvnmd_grad
deepmd.tf.op._prod_force_grad
deepmd.tf.op._prod_force_se_a_grad
deepmd.tf.op._prod_force_se_a_mask_grad
deepmd.tf.op._prod_force_se_r_grad
deepmd.tf.op._prod_virial_grad
deepmd.tf.op._prod_virial_se_a_grad
deepmd.tf.op._prod_virial_se_r_grad
deepmd.tf.op._quantize_nvnmd_grad
deepmd.tf.op._soft_min_force_grad
deepmd.tf.op._soft_min_virial_grad
deepmd.tf.op._tabulate_grad
deepmd.tf.op._tanh4_flt_nvnmd_grad
deepmd.tf.train
deepmd.tf.utils
deepmd.tf.utils.argcheck
deepmd.tf.utils.batch_size
deepmd.tf.utils.compat
deepmd.tf.utils.compress
deepmd.tf.utils.convert
deepmd.tf.utils.data
deepmd.tf.utils.data_system
deepmd.tf.utils.errors
deepmd.tf.utils.finetune
deepmd.tf.utils.graph
deepmd.tf.utils.learning_rate
deepmd.tf.utils.multi_init
deepmd.tf.utils.neighbor_stat
deepmd.tf.utils.network
deepmd.tf.utils.nlist
deepmd.tf.utils.pair_tab
deepmd.tf.utils.parallel_op
deepmd.tf.utils.path
deepmd.tf.utils.plugin
deepmd.tf.utils.random
deepmd.tf.utils.region
deepmd.tf.utils.serialization
deepmd.tf.utils.sess
deepmd.tf.utils.spin
deepmd.tf.utils.tabulate
deepmd.tf.utils.type_embed
deepmd.tf.utils.update_sel
deepmd.tf.utils.weight_avg
Submodules
Package Contents
Classes
TensorFlow backend implementation for DeepEval. | |
|
Functions
| Factory function that forwards to DeepEval (for compatbility). |
- class deepmd.tf.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
Get type of model.
:type:str
- property sess: deepmd.tf.env.tf.Session
Get TF session.
- _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]
- deepmd.tf.DeepPotential(*args, **kwargs) deep_eval.DeepEval [source]
Factory function that forwards to DeepEval (for compatbility).
- Parameters:
- *args
positional arguments
- **kwargs
keyword arguments
- Returns:
DeepEval
potentials
- 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
- 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}
- build_fv_graph() deepmd.tf.env.tf.Tensor [source]
Build the computational graph for the force and virial inference.
- 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_e
The energy modification
tot_f
The force modification
tot_v
The virial modification
- 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.