deepmd.tf.infer package
Submodule containing all the implemented potentials.
- class deepmd.tf.infer.DeepDOS(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet 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
- 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.
- property output_def: ModelOutputDef
Get the output definition of this model.
- class deepmd.tf.infer.DeepDipole(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
- class deepmd.tf.infer.DeepEval(model_file: str, *args, **kwargs)[source]
Bases:
DeepEvalBackendTensorFlow 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
intorAutomaticBatchSize, 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
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
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.
Evaluate output of type embedding network by using this model.
Get the number (dimension) of atomic parameters of this DP.
Get the number (dimension) of frame parameters of this DP.
Check if the model has efield.
Get the number of atom types of this model.
Get the number of spin atom types of this model.
Get the number of DOS.
get_rcut()Get the cut-off radius of this model.
Get the selected atom types of this model.
Get the type map (element name of the atom types) of this model.
make_natoms_vec(atom_types)Make the natom vector used by deepmd-kit.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms])Sort atoms in the system according their types.
- build_neighbor_list(coords: ndarray, cell: Optional[ndarray], atype: ndarray, imap: 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
- eval(coords: ndarray, cells: ndarray, atom_types: ndarray, atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None) 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.
- efield
The external field on atoms. The array should be of size nframes x natoms x 3
- 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: ndarray, cells: ndarray, atom_types: ndarray, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None) 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
descriptorDescriptors.
- eval_typeebd() 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.tf.infer import DeepPotential >>> dp = DeepPotential("graph.pb") >>> dp.eval_typeebd()
- get_sel_type() Optional[ndarray][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.
- make_natoms_vec(atom_types: ndarray) ndarray[source]
Make the natom vector used by deepmd-kit.
- Parameters
- atom_types
The type of atoms
- Returns
natomsThe 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
- property model_type: DeepEvalWrapper
Get type of model.
:type:str
- static reverse_map(vec: ndarray, imap: List[int]) 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_outReverse mapped vector.
- property sess: Session
Get TF session.
- static sort_input(coord: ndarray, atom_type: ndarray, sel_atoms: Optional[List[int]] = 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_outThe coordinates after sorting
atom_type_outThe atom types after sorting
idx_mapThe index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]
sel_atom_typeOnly output if sel_atoms is not None The sorted selected atom types
sel_idx_mapOnly output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.
- class deepmd.tf.infer.DeepGlobalPolar(model_file: str, *args, **kwargs)[source]
Bases:
DeepTensor- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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_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
- class deepmd.tf.infer.DeepPolar(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
- class deepmd.tf.infer.DeepPot(model_file: str, *args, **kwargs)[source]
Bases:
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.
- Attributes
has_efieldCheck if the model has efield.
output_defGet 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
- 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.
- property output_def: ModelOutputDef
Get the output definition of this model.
- deepmd.tf.infer.DeepPotential(*args, **kwargs) DeepEval[source]
Factory function that forwards to DeepEval (for compatbility).
- Parameters
- *args
positional arguments
- **kwargs
keyword arguments
- Returns
DeepEvalpotentials
- class deepmd.tf.infer.DeepWFC(model_file: str, *args, **kwargs)[source]
Bases:
DeepTensorDeep 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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
- class deepmd.tf.infer.DipoleChargeModifier(model_name: str, model_charge_map: List[float], sys_charge_map: List[float], ewald_h: float = 1, ewald_beta: float = 1)[source]
Bases:
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}
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
Build the computational graph for the force and virial inference.
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
eval(coord, box, atype[, eval_fv])Evaluate the modification.
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()Unsupported in this model.
get_dim_fparam()Unsupported in this model.
get_ntypes()Get the number of atom types of this model.
get_rcut()Get the cut-off 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.
make_natoms_vec(atom_types[, mixed_type])Make the natom vector used by deepmd-kit.
modify_data(data, data_sys)Modify data.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms, ...])Sort atoms in the system according their types.
- eval(coord: ndarray, box: ndarray, atype: ndarray, eval_fv: bool = True) Tuple[ndarray, ndarray, 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
- modify_data(data: dict, data_sys: 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.
- class deepmd.tf.infer.EwaldRecp(hh, beta)[source]
Bases:
objectEvaluate the reciprocal part of the Ewald sum.
Methods
eval(coord, charge, box)Evaluate.
- deepmd.tf.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
- 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)
Submodules
deepmd.tf.infer.data_modifier module
- class deepmd.tf.infer.data_modifier.DipoleChargeModifier(model_name: str, model_charge_map: List[float], sys_charge_map: List[float], ewald_h: float = 1, ewald_beta: float = 1)[source]
Bases:
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}
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
Build the computational graph for the force and virial inference.
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
eval(coord, box, atype[, eval_fv])Evaluate the modification.
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()Unsupported in this model.
get_dim_fparam()Unsupported in this model.
get_ntypes()Get the number of atom types of this model.
get_rcut()Get the cut-off 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.
make_natoms_vec(atom_types[, mixed_type])Make the natom vector used by deepmd-kit.
modify_data(data, data_sys)Modify data.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms, ...])Sort atoms in the system according their types.
- eval(coord: ndarray, box: ndarray, atype: ndarray, eval_fv: bool = True) Tuple[ndarray, ndarray, 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
- modify_data(data: dict, data_sys: 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.
deepmd.tf.infer.deep_dipole module
- class deepmd.tf.infer.deep_dipole.DeepDipole(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
deepmd.tf.infer.deep_dos module
- class deepmd.tf.infer.deep_dos.DeepDOS(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet 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
- 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.
- property output_def: ModelOutputDef
Get the output definition of this model.
deepmd.tf.infer.deep_eval module
- class deepmd.tf.infer.deep_eval.DeepEval(model_file: str, *args, **kwargs)[source]
Bases:
DeepEvalBackendTensorFlow 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
intorAutomaticBatchSize, 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
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
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.
Evaluate output of type embedding network by using this model.
Get the number (dimension) of atomic parameters of this DP.
Get the number (dimension) of frame parameters of this DP.
Check if the model has efield.
Get the number of atom types of this model.
Get the number of spin atom types of this model.
Get the number of DOS.
get_rcut()Get the cut-off radius of this model.
Get the selected atom types of this model.
Get the type map (element name of the atom types) of this model.
make_natoms_vec(atom_types)Make the natom vector used by deepmd-kit.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms])Sort atoms in the system according their types.
- build_neighbor_list(coords: ndarray, cell: Optional[ndarray], atype: ndarray, imap: 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
- eval(coords: ndarray, cells: ndarray, atom_types: ndarray, atomic: bool = False, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None) 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.
- efield
The external field on atoms. The array should be of size nframes x natoms x 3
- 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: ndarray, cells: ndarray, atom_types: ndarray, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None) 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
descriptorDescriptors.
- eval_typeebd() 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.tf.infer import DeepPotential >>> dp = DeepPotential("graph.pb") >>> dp.eval_typeebd()
- get_sel_type() Optional[ndarray][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.
- make_natoms_vec(atom_types: ndarray) ndarray[source]
Make the natom vector used by deepmd-kit.
- Parameters
- atom_types
The type of atoms
- Returns
natomsThe 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
- property model_type: DeepEvalWrapper
Get type of model.
:type:str
- static reverse_map(vec: ndarray, imap: List[int]) 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_outReverse mapped vector.
- property sess: Session
Get TF session.
- static sort_input(coord: ndarray, atom_type: ndarray, sel_atoms: Optional[List[int]] = 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_outThe coordinates after sorting
atom_type_outThe atom types after sorting
idx_mapThe index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]
sel_atom_typeOnly output if sel_atoms is not None The sorted selected atom types
sel_idx_mapOnly output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.
- class deepmd.tf.infer.deep_eval.DeepEvalOld(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: Union[bool, int, AutoBatchSize] = False, input_map: Optional[dict] = None, neighbor_list=None)[source]
Bases:
objectCommon 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
intorAutomaticBatchSize, 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
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
Evaluate output of type embedding network by using this model.
make_natoms_vec(atom_types[, mixed_type])Make the natom vector used by deepmd-kit.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms, ...])Sort atoms in the system according their types.
- build_neighbor_list(coords: ndarray, cell: Optional[ndarray], atype: ndarray, imap: 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
- eval_typeebd() 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.tf.infer import DeepPotential >>> dp = DeepPotential("graph.pb") >>> dp.eval_typeebd()
- make_natoms_vec(atom_types: ndarray, mixed_type: bool = False) 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
natomsThe 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
- static reverse_map(vec: ndarray, imap: List[int]) 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_outReverse mapped vector.
- property sess: Session
Get TF session.
- static sort_input(coord: ndarray, atom_type: ndarray, sel_atoms: Optional[List[int]] = 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_outThe coordinates after sorting
atom_type_outThe atom types after sorting
idx_mapThe index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]
sel_atom_typeOnly output if sel_atoms is not None The sorted selected atom types
sel_idx_mapOnly output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.
deepmd.tf.infer.deep_polar module
- class deepmd.tf.infer.deep_polar.DeepGlobalPolar(model_file: str, *args, **kwargs)[source]
Bases:
DeepTensor- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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_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
- class deepmd.tf.infer.deep_polar.DeepPolar(model_file: str, *args, **kwargs)[source]
Bases:
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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
deepmd.tf.infer.deep_pot module
- class deepmd.tf.infer.deep_pot.DeepPot(model_file: str, *args, **kwargs)[source]
Bases:
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.
- Attributes
has_efieldCheck if the model has efield.
output_defGet 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
- 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.
- property output_def: ModelOutputDef
Get the output definition of this model.
deepmd.tf.infer.deep_tensor module
- class deepmd.tf.infer.deep_tensor.DeepTensor(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, input_map: Optional[dict] = None, neighbor_list=None)[source]
Bases:
DeepEvalOldEvaluates a tensor model.
- Parameters
- model_file: str
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
- input_map
dict,optional The input map for tf.import_graph_def. Only work with default tf graph
- neighbor_list
ase.neighborlist.NeighborList,optional The neighbor list object. If None, then build the native neighbor list.
- Attributes
model_typeGet type of model.
model_versionGet version of model.
sessGet TF session.
Methods
build_neighbor_list(coords, cell, atype, ...)Make the mesh with neighbor list for a single frame.
eval(coords, cells, atom_types[, atomic, ...])Evaluate the model.
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 the number (dimension) of atomic parameters of this DP.
Get the number (dimension) of frame parameters of this DP.
Get the number of atom types of this model.
get_rcut()Get the cut-off radius of this model.
Get the selected atom types of this model.
Get the type map (element name of the atom types) of this model.
make_natoms_vec(atom_types[, mixed_type])Make the natom vector used by deepmd-kit.
reverse_map(vec, imap)Reverse mapping of a vector according to the index map.
sort_input(coord, atom_type[, sel_atoms, ...])Sort atoms in the system according their types.
- eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = True, fparam: Optional[ndarray] = None, aparam: Optional[ndarray] = None, efield: Optional[ndarray] = None, mixed_type: bool = False) 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
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
tensorThe 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: ndarray, atom_types: List[int], atomic: bool = False, fparam: Optional[array] = None, aparam: Optional[array] = None, efield: Optional[array] = None, mixed_type: bool = False) 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
- 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
tensorThe global tensor. shape: [nframes x nout]
forceThe component-wise force (negative derivative) on each atom. shape: [nframes x nout x natoms x 3]
virialThe component-wise virial of the tensor. shape: [nframes x nout x 9]
atom_tensorThe atomic tensor. Only returned when atomic == True shape: [nframes x natoms x nout]
atom_virialThe atomic virial. Only returned when atomic == True shape: [nframes x nout x natoms x 9]
- tensors: ClassVar[Dict[str, str]] = {'t_box': 't_box:0', 't_coord': 't_coord:0', 't_mesh': 't_mesh:0', 't_natoms': 't_natoms:0', 't_ntypes': 'descrpt_attr/ntypes:0', 't_ouput_dim': 'model_attr/output_dim:0', 't_rcut': 'descrpt_attr/rcut:0', 't_sel_type': 'model_attr/sel_type:0', 't_tmap': 'model_attr/tmap:0', 't_type': 't_type:0'}
deepmd.tf.infer.deep_wfc module
- class deepmd.tf.infer.deep_wfc.DeepWFC(model_file: str, *args, **kwargs)[source]
Bases:
DeepTensorDeep 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
- Attributes
has_efieldCheck if the model has efield.
output_defGet the output definition of this model.
output_tensor_nameThe 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.
deepmd.tf.infer.ewald_recp module
deepmd.tf.infer.model_devi module
- deepmd.tf.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
- 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)
- deepmd.tf.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
- es
numpy.ndarray size of `n_models x n_frames x 1
- real_e
numpy.ndarray real energy, size of n_frames x 1. If given, the RMS real error is calculated instead.
- es
- Returns
- max_devi_e
numpy.ndarray maximum deviation of energy
- max_devi_e
- deepmd.tf.infer.model_devi.calc_model_devi_f(fs: ndarray, real_f: Optional[ndarray] = None, relative: Optional[float] = None, atomic: bool = False) Tuple[ndarray, ...][source]
Calculate model deviation of force.
- Parameters
- fs
numpy.ndarray size of n_models x n_frames x n_atoms x 3
- real_f
numpy.ndarrayorNone real force, size of n_frames x n_atoms x 3. If given, the RMS real error is calculated instead.
- 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.
- atomicbool, default:
False Whether return deviation of force in all atoms
- fs
- Returns
- max_devi_f
numpy.ndarray maximum deviation of force in all atoms
- min_devi_f
numpy.ndarray minimum deviation of force in all atoms
- avg_devi_f
numpy.ndarray average deviation of force in all atoms
- fs_devi
numpy.ndarray deviation of force in all atoms, returned if atomic=True
- max_devi_f
- deepmd.tf.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
- vs
numpy.ndarray size of n_models x n_frames x 9
- real_v
numpy.ndarray real virial, size of n_frames x 9. If given, the RMS real error is calculated instead.
- relative
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.
- vs
- Returns
- max_devi_v
numpy.ndarray maximum deviation of virial in 9 elements
- min_devi_v
numpy.ndarray minimum deviation of virial in 9 elements
- avg_devi_v
numpy.ndarray average deviation of virial in 9 elements
- max_devi_v
- deepmd.tf.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
- models
list A list of paths of models to use for making model deviation
- system
str The path of system to make model deviation calculation
- set_prefix
str The set prefix of the system
- output
str The output file for model deviation results
- frequency
int 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.
- 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.
- **kwargs
Arbitrary keyword arguments.
- models
- deepmd.tf.infer.model_devi.write_model_devi_out(devi: ndarray, fname: str, header: str = '', atomic: bool = False)[source]
Write output of model deviation.
- Parameters
- devi
numpy.ndarray the first column is the steps index
- fname
str the file name to dump
- header
str, default=”” the header to dump
- atomicbool, default:
False whether atomic model deviation is printed
- devi