deepmd.pt.model.atomic_model.pairtab_atomic_model
Module Contents
Classes
Pairwise tabulation energy model. |
- 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.BaseAtomicModel
Pairwise 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
int
orlist
[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 descrptor 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.
- classmethod deserialize(data) PairTabAtomicModel [source]
- compute_or_load_stat(merged: Callable[[], List[dict]] | List[dict], stat_file_path: deepmd.utils.path.DPPath | 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.Tensor
The masked atomic energy for all local atoms for all frames. (nframes, nloc, nnei)
- Raises:
Exception
If 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.Tensor
The 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.Tensor
The 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.Tensor
The atomic energy for all local atoms for all frames. (nframes, nloc, nnei)
- get_dim_aparam() int [source]
Get the number (dimension) of atomic parameters of this atomic model.