deepmd.pt.model.atomic_model.pairtab_atomic_model#
Classes#
Pairwise tabulation energy model. |
Module Contents#
- class deepmd.pt.model.atomic_model.pairtab_atomic_model.PairTabAtomicModel(tab_file: str, rcut: float, sel: int | list[int], type_map: list[str], **kwargs)[source]#
Bases:
deepmd.pt.model.atomic_model.base_atomic_model.BaseAtomicModelPairwise tabulation energy model.
This model can be used to tabulate the pairwise energy between atoms for either short-range or long-range interactions, such as D3, LJ, ZBL, etc. It should not be used alone, but rather as one submodel of a linear (sum) model, such as DP+D3.
Do not put the model on the first model of a linear model, since the linear model fetches the type map from the first model.
At this moment, the model does not smooth the energy at the cutoff radius, so one needs to make sure the energy has been smoothed to zero.
- Parameters:
- tab_file
str The path to the tabulation file.
- rcut
float The cutoff radius.
- sel
intorlist[int] The maxmum number of atoms in the cut-off radius.
- type_map
list[str] Mapping atom type to the name (str) of the type. For example type_map[1] gives the name of the type 1.
- rcond
float,optional The condition number for the regression of atomic energy.
- atom_ener
Specifying atomic energy contribution in vacuum. The set_davg_zero key in the descriptor should be set.
- tab_file
- _set_pairtab(tab_file: str, rcut: float) deepmd.utils.pair_tab.PairTab[source]#
- fitting_output_def() deepmd.dpmodel.FittingOutputDef[source]#
Get the output def of developer implemented atomic models.
- get_nsel() int[source]#
Returns the total number of selected neighboring atoms in the cut-off radius.
- mixed_types() bool[source]#
If true, the model 1. assumes total number of atoms aligned across frames; 2. uses a neighbor list that does not distinguish different atomic types.
If false, the model 1. assumes total number of atoms of each atom type aligned across frames; 2. uses a neighbor list that distinguishes different atomic types.
- need_sorted_nlist_for_lower() bool[source]#
Returns whether the atomic model needs sorted nlist when using forward_lower.
- change_type_map(type_map: list[str], model_with_new_type_stat=None) None[source]#
Change the type related params to new ones, according to type_map and the original one in the model. If there are new types in type_map, statistics will be updated accordingly to model_with_new_type_stat for these new types.
- classmethod deserialize(data) PairTabAtomicModel[source]#
- compute_or_load_stat(merged: Callable[[], list[dict]] | list[dict], stat_file_path: deepmd.utils.path.DPPath | None = None) None[source]#
Compute the output statistics (e.g. energy bias) for the fitting net from packed data.
- Parameters:
- merged
Union[Callable[[],list[dict]],list[dict]] - list[dict]: A list of data samples from various data systems.
Each element, merged[i], is a data dictionary containing keys: torch.Tensor originating from the i-th data system.
- Callable[[], list[dict]]: A lazy function that returns data samples in the above format
only when needed. Since the sampling process can be slow and memory-intensive, the lazy function helps by only sampling once.
- stat_file_path
Optional[DPPath] The path to the stat file.
- merged
- forward_atomic(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, comm_dict: dict[str, torch.Tensor] | None = None) dict[str, torch.Tensor][source]#
- _pair_tabulated_inter(nlist: torch.Tensor, i_type: torch.Tensor, j_type: torch.Tensor, rr: torch.Tensor) torch.Tensor[source]#
Pairwise tabulated energy.
- Parameters:
- nlist
torch.Tensor The unmasked neighbour list. (nframes, nloc)
- i_type
torch.Tensor The integer representation of atom type for all local atoms for all frames. (nframes, nloc)
- j_type
torch.Tensor The integer representation of atom type for all neighbour atoms of all local atoms for all frames. (nframes, nloc, nnei)
- rr
torch.Tensor The salar distance vector between two atoms. (nframes, nloc, nnei)
- nlist
- Returns:
torch.TensorThe masked atomic energy for all local atoms for all frames. (nframes, nloc, nnei)
- Raises:
ExceptionIf the distance is beyond the table.
Notes
This function is used to calculate the pairwise energy between two atoms. It uses a table containing cubic spline coefficients calculated in PairTab.
- static _get_pairwise_dist(coords: torch.Tensor, nlist: torch.Tensor) torch.Tensor[source]#
Get pairwise distance dr.
- Parameters:
- coords
torch.Tensor The coordinate of the atoms, shape of (nframes, nall, 3).
- nlist
The masked nlist, shape of (nframes, nloc, nnei)
- coords
- Returns:
torch.TensorThe pairwise distance between the atoms (nframes, nloc, nnei).
- static _extract_spline_coefficient(i_type: torch.Tensor, j_type: torch.Tensor, idx: torch.Tensor, tab_data: torch.Tensor, nspline: int) torch.Tensor[source]#
Extract the spline coefficient from the table.
- Parameters:
- i_type
torch.Tensor The integer representation of atom type for all local atoms for all frames. (nframes, nloc)
- j_type
torch.Tensor The integer representation of atom type for all neighbour atoms of all local atoms for all frames. (nframes, nloc, nnei)
- idx
torch.Tensor The index of the spline coefficient. (nframes, nloc, nnei)
- tab_data
torch.Tensor The table storing all the spline coefficient. (ntype, ntype, nspline, 4)
- nspline
int The number of splines in the table.
- i_type
- Returns:
torch.TensorThe spline coefficient. (nframes, nloc, nnei, 4), shape may be squeezed.
- static _calculate_ener(coef: torch.Tensor, uu: torch.Tensor) torch.Tensor[source]#
Calculate energy using spline coeeficients.
- Parameters:
- coef
torch.Tensor The spline coefficients. (nframes, nloc, nnei, 4)
- uu
torch.Tensor The atom displancemnt used in interpolation and extrapolation (nframes, nloc, nnei)
- coef
- Returns:
torch.TensorThe atomic energy for all local atoms for all frames. (nframes, nloc, nnei)
- get_sel_type() list[int][source]#
Get the selected atom types of this model.
Only atoms with selected atom types have atomic contribution to the result of the model. If returning an empty list, all atom types are selected.