deepmd.dpmodel.atomic_model.linear_atomic_model#
Classes#
Linear model makes linear combinations of several existing models. | |
Model linearly combine a list of AtomicModels. |
Module Contents#
- class deepmd.dpmodel.atomic_model.linear_atomic_model.LinearEnergyAtomicModel(models: list[deepmd.dpmodel.atomic_model.base_atomic_model.BaseAtomicModel], type_map: list[str], **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.atomic_model.base_atomic_model.BaseAtomicModelLinear model makes linear combinations of several existing models.
The linear model combines predictions from multiple atomic models:
\[E^i = \sum_{k=1}^{K} w_k \cdot E_k^i,\]where \(E_k^i\) is the energy predicted by the \(k\)-th sub-model for atom \(i\), and \(w_k\) is the corresponding weight.
This is useful for combining different interaction types, e.g., DP + ZBL for short-range repulsion, or DP + D3 for dispersion corrections.
- Parameters:
- 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: Any | None = 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.
- set_case_embd(case_idx: int) None[source]#
Set the case embedding of this atomic model by the given case_idx, typically concatenated with the output of the descriptor and fed into the fitting net.
- get_model_nsels() list[int][source]#
Get the processed sels for each individual models. Not distinguishing types.
- enable_compression(min_nbor_dist: float, table_extrapolate: float = 5, table_stride_1: float = 0.01, table_stride_2: float = 0.1, check_frequency: int = -1) None[source]#
Compress model.
- Parameters:
- min_nbor_dist
The nearest distance between atoms
- table_extrapolate
The scale of model extrapolation
- table_stride_1
The uniform stride of the first table
- table_stride_2
The uniform stride of the second table
- check_frequency
The overflow check frequency
- forward_atomic(extended_coord: deepmd.dpmodel.array_api.Array, extended_atype: deepmd.dpmodel.array_api.Array, nlist: deepmd.dpmodel.array_api.Array, mapping: deepmd.dpmodel.array_api.Array | None = None, fparam: deepmd.dpmodel.array_api.Array | None = None, aparam: deepmd.dpmodel.array_api.Array | None = None) dict[str, deepmd.dpmodel.array_api.Array][source]#
Return atomic prediction.
- Parameters:
- extended_coord
coordinates in extended region, (nframes, nall * 3)
- extended_atype
atomic type in extended region, (nframes, nall)
- nlist
neighbor list, (nframes, nloc, nsel).
- mapping
mapps the extended indices to local indices.
- fparam
frame parameter. (nframes, ndf)
- aparam
atomic parameter. (nframes, nloc, nda)
- Returns:
result_dictthe result dict, defined by the fitting net output def.
- static remap_atype(ori_map: list[str], new_map: list[str]) deepmd.dpmodel.array_api.Array[source]#
This method is used to map the atype from the common type_map to the original type_map of indivial AtomicModels.
- Parameters:
- Returns:
- fitting_output_def() deepmd.dpmodel.output_def.FittingOutputDef[source]#
Get the output def of developer implemented atomic models.
- classmethod deserialize(data: dict) LinearEnergyAtomicModel[source]#
- compute_or_load_stat(sampled_func: collections.abc.Callable[[], list[dict]], stat_file_path: deepmd.utils.path.DPPath | None = None, compute_or_load_out_stat: bool = True, preset_observed_type: list[str] | None = None) None[source]#
Compute or load the statistics parameters of the model.
For LinearEnergyAtomicModel, this first computes input stats for each sub-model (without output stats), then computes its own output stats.
- Parameters:
- sampled_func
The lazy sampled function to get data frames from different data systems.
- stat_file_path
The path to the stat file.
- compute_or_load_out_statbool
Whether to compute the output statistics.
- _compute_weight(extended_coord: deepmd.dpmodel.array_api.Array, extended_atype: deepmd.dpmodel.array_api.Array, nlists_: list[deepmd.dpmodel.array_api.Array]) list[deepmd.dpmodel.array_api.Array][source]#
This should be a list of user defined weights that matches the number of models to be combined.
- class deepmd.dpmodel.atomic_model.linear_atomic_model.DPZBLLinearEnergyAtomicModel(dp_model: deepmd.dpmodel.atomic_model.dp_atomic_model.DPAtomicModel, zbl_model: deepmd.dpmodel.atomic_model.pairtab_atomic_model.PairTabAtomicModel, sw_rmin: float, sw_rmax: float, type_map: list[str], smin_alpha: float | None = 0.1, **kwargs: Any)[source]#
Bases:
LinearEnergyAtomicModelModel linearly combine a list of AtomicModels.
- Parameters:
- dp_model
The DPAtomicModel being combined.
- zbl_model
The PairTable model being combined.
- sw_rmin
The lower boundary of the interpolation between short-range tabulated interaction and DP.
- sw_rmax
The upper boundary of the interpolation between short-range tabulated interaction and DP.
- type_map
Mapping atom type to the name (str) of the type. For example type_map[1] gives the name of the type 1.
- smin_alpha
The short-range tabulated interaction will be switched according to the distance of the nearest neighbor. This distance is calculated by softmin.
- classmethod deserialize(data: Any) DPZBLLinearEnergyAtomicModel[source]#
- set_case_embd(case_idx: int) None[source]#
Set the case embedding of this atomic model by the given case_idx, typically concatenated with the output of the descriptor and fed into the fitting net.
- _compute_weight(extended_coord: deepmd.dpmodel.array_api.Array, extended_atype: deepmd.dpmodel.array_api.Array, nlists_: list[deepmd.dpmodel.array_api.Array]) list[deepmd.dpmodel.array_api.Array][source]#
ZBL weight.
- Returns:
list[Array]the atomic ZBL weight for interpolation. (nframes, nloc, 1)