diff --git a/deepmd/pt_expt/utils/serialization.py b/deepmd/pt_expt/utils/serialization.py index 88bd839454..9c03783574 100644 --- a/deepmd/pt_expt/utils/serialization.py +++ b/deepmd/pt_expt/utils/serialization.py @@ -460,6 +460,9 @@ def _collect_metadata(model: torch.nn.Module, is_spin: bool = False) -> dict: "nnei": sum(model.get_sel()), "dim_fparam": model.get_dim_fparam(), "dim_aparam": model.get_dim_aparam(), + "dim_chg_spin": ( + model.get_dim_chg_spin() if hasattr(model, "get_dim_chg_spin") else 0 + ), "mixed_types": model.mixed_types(), "has_default_fparam": model.has_default_fparam(), "default_fparam": model.get_default_fparam(), diff --git a/doc/third-party/lammps-command.md b/doc/third-party/lammps-command.md index 70df75d22d..3cc5d955cc 100644 --- a/doc/third-party/lammps-command.md +++ b/doc/third-party/lammps-command.md @@ -49,7 +49,7 @@ pair_style deepmd models ... keyword value ... - models = frozen model(s) to compute the interaction. If multiple models are provided, then only the first model serves to provide energy and force prediction for each timestep of molecular dynamics, and the model deviation will be computed among all models every `out_freq` timesteps. -- keyword = _out_file_ or _out_freq_ or _fparam_ or _fparam_from_compute_ or _aparam_from_compute_ or _atomic_ or _relative_ or _relative_v_ or _aparam_ or _ttm_ +- keyword = _out_file_ or _out_freq_ or _fparam_ or _fparam_from_compute_ or _aparam_from_compute_ or _charge_spin_ or _atomic_ or _relative_ or _relative_v_ or _aparam_ or _ttm_
out_file value = filename
@@ -62,6 +62,8 @@ pair_style deepmd models ... keyword value ...
id = compute id used to update the frame parameter.
aparam_from_compute value = id
id = compute id used to update the atom parameter.
+ charge_spin value = parameters
+ parameters = the per-frame charge/spin values (dim_chg_spin numbers) required by models trained with a charge/spin embedding (e.g. DPA-3 with add_chg_spin_ebd). If omitted, the model's stored default_chg_spin is used.
atomic = no value is required.
If this keyword is set, the force model deviation of each atom will be output.
relative value = level
@@ -88,6 +90,8 @@ compute TEMP all temp
pair_style deepmd ener.pb aparam_from_compute 1
compute 1 all ke/atom
+
+pair_style deepmd dpa3.pth charge_spin 1.0 2.0
```
### Description
@@ -112,6 +116,7 @@ If the keyword `fparam` is set, the given frame parameter(s) will be fed to the
If the keyword `fparam_from_compute` is set, the global parameter(s) from compute command (e.g., temperature from [compute temp command](https://docs.lammps.org/compute_temp.html)) will be fed to the model as the frame parameter(s).
If the keyword `aparam_from_compute` is set, the atomic parameter(s) from compute command (e.g., per-atom translational kinetic energy from [compute ke/atom command](https://docs.lammps.org/compute_ke_atom.html)) will be fed to the model as the atom parameter(s).
If the keyword `aparam` is set, the given atomic parameter(s) will be fed to the model, where each atom is assumed to have the same atomic parameter(s).
+If the keyword `charge_spin` is set, the given per-frame charge/spin value(s) will be fed to models that were trained with a charge/spin embedding (e.g. DPA-3 with `add_chg_spin_ebd`). If the keyword is not set, the model's stored `default_chg_spin` (if any) is used.
If the keyword `ttm` is set, electronic temperatures from [fix ttm command](https://docs.lammps.org/fix_ttm.html) will be fed to the model as the atomic parameters.
Only a single `pair_coeff` command is used with the deepmd style which specifies atom names. These are mapped to LAMMPS atom types (integers from 1 to Ntypes) by specifying Ntypes additional arguments after `* *` in the `pair_coeff` command.
diff --git a/source/api_c/include/c_api.h b/source/api_c/include/c_api.h
index 358480b0ad..31b9e0626c 100644
--- a/source/api_c/include/c_api.h
+++ b/source/api_c/include/c_api.h
@@ -12,7 +12,7 @@ extern "C" {
/** C API version. Bumped whenever the API is changed.
* @since API version 22
*/
-#define DP_C_API_VERSION 26
+#define DP_C_API_VERSION 27
/**
* @brief Neighbor list.
@@ -675,6 +675,198 @@ extern void DP_DeepPotComputeNListf2(DP_DeepPot* dp,
float* atomic_energy,
float* atomic_virial);
+/**
+ * @brief Evaluate the energy, force and virial by using a DP. (double version,
+ *with charge_spin)
+ * @version 3
+ * @param[in] dp The DP to use.
+ * @param[in] nframes The number of frames.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be of
+ *size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy.
+ * @param[out] force Output force. The array should be of size natoms x 3.
+ * @param[out] virial Output virial. The array should be of size 9.
+ * @param[out] atomic_energy Output atomic energy. The array should be of size
+ *natoms.
+ * @param[out] atomic_virial Output atomic virial. The array should be of size
+ *natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+extern void DP_DeepPotCompute3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial);
+
+/**
+ * @brief Evaluate the energy, force and virial by using a DP. (float version,
+ *with charge_spin)
+ * @version 3
+ * @param[in] dp The DP to use.
+ * @param[in] nframes The number of frames.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be of
+ *size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy.
+ * @param[out] force Output force. The array should be of size natoms x 3.
+ * @param[out] virial Output virial. The array should be of size 9.
+ * @param[out] atomic_energy Output atomic energy. The array should be of size
+ *natoms.
+ * @param[out] atomic_virial Output atomic virial. The array should be of size
+ *natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+extern void DP_DeepPotComputef3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial);
+
+/**
+ * @brief Evaluate the energy, force and virial by using a DP with the neighbor
+ *list. (double version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP to use.
+ * @param[in] nframes The number of frames.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] nghost The number of ghost atoms.
+ * @param[in] nlist The neighbor list.
+ * @param[in] ago Update the internal neighbour list if ago is 0.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be of
+ *size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy.
+ * @param[out] force Output force. The array should be of size natoms x 3.
+ * @param[out] virial Output virial. The array should be of size 9.
+ * @param[out] atomic_energy Output atomic energy. The array should be of size
+ *natoms.
+ * @param[out] atomic_virial Output atomic virial. The array should be of size
+ *natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+extern void DP_DeepPotComputeNList3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial);
+
+/**
+ * @brief Evaluate the energy, force and virial by using a DP with the neighbor
+ *list. (float version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP to use.
+ * @param[in] nframes The number of frames.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] nghost The number of ghost atoms.
+ * @param[in] nlist The neighbor list.
+ * @param[in] ago Update the internal neighbour list if ago is 0.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be of
+ *size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy.
+ * @param[out] force Output force. The array should be of size natoms x 3.
+ * @param[out] virial Output virial. The array should be of size 9.
+ * @param[out] atomic_energy Output atomic energy. The array should be of size
+ *natoms.
+ * @param[out] atomic_virial Output atomic virial. The array should be of size
+ *natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+extern void DP_DeepPotComputeNListf3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial);
+
/**
* @brief Evaluate the energy, force, magnetic force and virial by using a DP
*spin model with the neighbor list. (float version)
@@ -1346,6 +1538,206 @@ void DP_DeepPotModelDeviComputeNListf2(DP_DeepPotModelDevi* dp,
float* atomic_energy,
float* atomic_virial);
+/**
+ * @brief Evaluate energy, force and virial with a DP model deviation.
+ *(double version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP model deviation to use.
+ * @param[in] nframes The number of frames. Only 1 is supported.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array should be
+ *of size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy of all models.
+ * @param[out] force Output force of all models. The array should be of size
+ *nmodels x natoms x 3.
+ * @param[out] virial Output virial of all models. The array should be of size
+ *nmodels x 9.
+ * @param[out] atomic_energy Output atomic energy of all models. The array
+ *should be of size nmodels x natoms.
+ * @param[out] atomic_virial Output atomic virial of all models. The array
+ *should be of size nmodels x natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+void DP_DeepPotModelDeviCompute3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial);
+
+/**
+ * @brief Evaluate energy, force and virial with a DP model deviation.
+ *(float version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP model deviation to use.
+ * @param[in] nframes The number of frames. Only 1 is supported.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array should be
+ *of size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy of all models.
+ * @param[out] force Output force of all models. The array should be of size
+ *nmodels x natoms x 3.
+ * @param[out] virial Output virial of all models. The array should be of size
+ *nmodels x 9.
+ * @param[out] atomic_energy Output atomic energy of all models. The array
+ *should be of size nmodels x natoms.
+ * @param[out] atomic_virial Output atomic virial of all models. The array
+ *should be of size nmodels x natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+void DP_DeepPotModelDeviComputef3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial);
+
+/**
+ * @brief Evaluate energy, force and virial with a DP model deviation and a
+ *neighbor list. (double version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP model deviation to use.
+ * @param[in] nframes The number of frames. Only 1 is supported.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] nghost The number of ghost atoms.
+ * @param[in] nlist The neighbor list.
+ * @param[in] ago Update the internal neighbour list if ago is 0.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array should be
+ *of size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy of all models.
+ * @param[out] force Output force of all models. The array should be of size
+ *nmodels x natoms x 3.
+ * @param[out] virial Output virial of all models. The array should be of size
+ *nmodels x 9.
+ * @param[out] atomic_energy Output atomic energy of all models. The array
+ *should be of size nmodels x natoms.
+ * @param[out] atomic_virial Output atomic virial of all models. The array
+ *should be of size nmodels x natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+void DP_DeepPotModelDeviComputeNList3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial);
+
+/**
+ * @brief Evaluate energy, force and virial with a DP model deviation and a
+ *neighbor list. (float version, with charge_spin)
+ * @version 3
+ * @param[in] dp The DP model deviation to use.
+ * @param[in] nframes The number of frames. Only 1 is supported.
+ * @param[in] natoms The number of atoms.
+ * @param[in] coord The coordinates of atoms. The array should be of size natoms
+ *x 3.
+ * @param[in] atype The atom types. The array should contain natoms ints.
+ * @param[in] cell The cell of the region. The array should be of size 9. Pass
+ *NULL if pbc is not used.
+ * @param[in] nghost The number of ghost atoms.
+ * @param[in] nlist The neighbor list.
+ * @param[in] ago Update the internal neighbour list if ago is 0.
+ * @param[in] fparam The frame parameters. The array can be of size nframes x
+ *dim_fparam.
+ * @param[in] aparam The atom parameters. The array can be of size nframes x
+ *natoms x dim_aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array should be
+ *of size nframes x dim_chg_spin. Pass NULL to use the model's stored
+ *default_chg_spin.
+ * @param[out] energy Output energy of all models.
+ * @param[out] force Output force of all models. The array should be of size
+ *nmodels x natoms x 3.
+ * @param[out] virial Output virial of all models. The array should be of size
+ *nmodels x 9.
+ * @param[out] atomic_energy Output atomic energy of all models. The array
+ *should be of size nmodels x natoms.
+ * @param[out] atomic_virial Output atomic virial of all models. The array
+ *should be of size nmodels x natoms x 9.
+ * @warning The output arrays should be allocated before calling this function.
+ *Pass NULL if not required.
+ * @since API version 27
+ **/
+void DP_DeepPotModelDeviComputeNListf3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial);
+
/**
* @brief Evaluate the energy, force, magnetic force and virial by using a DP
*spin model deviation with neighbor list. (float version)
@@ -1583,6 +1975,15 @@ int DP_DeepPotGetDimFParam(DP_DeepPot* dp);
*/
int DP_DeepPotGetDimAParam(DP_DeepPot* dp);
+/**
+ * @brief Get the dimension of the charge/spin input of a DP.
+ * @param[in] dp The DP to use.
+ * @return The dimension of the charge/spin input (0 if the model has no
+ * charge/spin embedding).
+ * @since API version 27
+ */
+int DP_DeepPotGetDimChgSpin(DP_DeepPot* dp);
+
/**
* @brief Check whether the atomic dimension of atomic parameters is nall
* instead of nloc.
@@ -1630,6 +2031,14 @@ int DP_DeepPotModelDeviGetDimFParam(DP_DeepPotModelDevi* dp);
*/
int DP_DeepPotModelDeviGetDimAParam(DP_DeepPotModelDevi* dp);
+/**
+ * @brief Get the dimension of the charge/spin input of a DP Model Deviation.
+ * @param[in] dp The DP Model Deviation to use.
+ * @return The dimension of the charge/spin input (0 if none).
+ * @since API version 27
+ */
+int DP_DeepPotModelDeviGetDimChgSpin(DP_DeepPotModelDevi* dp);
+
/**
* @brief Check whether the atomic dimension of atomic parameters is nall
* instead of nloc.
diff --git a/source/api_c/include/deepmd.hpp b/source/api_c/include/deepmd.hpp
index c3ca40b75f..1a68d0e227 100644
--- a/source/api_c/include/deepmd.hpp
+++ b/source/api_c/include/deepmd.hpp
@@ -53,6 +53,7 @@ inline void _DP_DeepPotCompute(DP_DeepPot* dp,
const FPTYPE* cell,
const FPTYPE* fparam,
const FPTYPE* aparam,
+ const FPTYPE* charge_spin,
double* energy,
FPTYPE* force,
FPTYPE* virial,
@@ -68,13 +69,22 @@ inline void _DP_DeepPotCompute(DP_DeepPot* dp,
const double* cell,
const double* fparam,
const double* aparam,
+ const double* charge_spin,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial) {
- DP_DeepPotCompute2(dp, nframes, natom, coord, atype, cell, fparam, aparam,
- energy, force, virial, atomic_energy, atomic_virial);
+ // charge_spin == nullptr keeps the version-2 entry point so models without a
+ // charge/spin embedding still work against an older libdeepmd_c.
+ if (charge_spin) {
+ DP_DeepPotCompute3(dp, nframes, natom, coord, atype, cell, fparam, aparam,
+ charge_spin, energy, force, virial, atomic_energy,
+ atomic_virial);
+ } else {
+ DP_DeepPotCompute2(dp, nframes, natom, coord, atype, cell, fparam, aparam,
+ energy, force, virial, atomic_energy, atomic_virial);
+ }
}
template <>
@@ -86,13 +96,20 @@ inline void _DP_DeepPotCompute(DP_DeepPot* dp,
const float* cell,
const float* fparam,
const float* aparam,
+ const float* charge_spin,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial) {
- DP_DeepPotComputef2(dp, nframes, natom, coord, atype, cell, fparam, aparam,
- energy, force, virial, atomic_energy, atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotComputef3(dp, nframes, natom, coord, atype, cell, fparam, aparam,
+ charge_spin, energy, force, virial, atomic_energy,
+ atomic_virial);
+ } else {
+ DP_DeepPotComputef2(dp, nframes, natom, coord, atype, cell, fparam, aparam,
+ energy, force, virial, atomic_energy, atomic_virial);
+ }
}
// support spin
@@ -167,6 +184,7 @@ inline void _DP_DeepPotComputeNList(DP_DeepPot* dp,
const int ago,
const FPTYPE* fparam,
const FPTYPE* aparam,
+ const FPTYPE* charge_spin,
double* energy,
FPTYPE* force,
FPTYPE* virial,
@@ -185,14 +203,21 @@ inline void _DP_DeepPotComputeNList(DP_DeepPot* dp,
const int ago,
const double* fparam,
const double* aparam,
+ const double* charge_spin,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial) {
- DP_DeepPotComputeNList2(dp, nframes, natom, coord, atype, cell, nghost, nlist,
- ago, fparam, aparam, energy, force, virial,
- atomic_energy, atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotComputeNList3(dp, nframes, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, charge_spin, energy,
+ force, virial, atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotComputeNList2(dp, nframes, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, energy, force, virial,
+ atomic_energy, atomic_virial);
+ }
}
template <>
@@ -207,14 +232,21 @@ inline void _DP_DeepPotComputeNList(DP_DeepPot* dp,
const int ago,
const float* fparam,
const float* aparam,
+ const float* charge_spin,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial) {
- DP_DeepPotComputeNListf2(dp, nframes, natom, coord, atype, cell, nghost,
- nlist, ago, fparam, aparam, energy, force, virial,
- atomic_energy, atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotComputeNListf3(dp, nframes, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, charge_spin, energy,
+ force, virial, atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotComputeNListf2(dp, nframes, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, energy, force, virial,
+ atomic_energy, atomic_virial);
+ }
}
// support spin
@@ -347,6 +379,7 @@ inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp,
const FPTYPE* cell,
const FPTYPE* fparam,
const FPTYPE* aparam,
+ const FPTYPE* charge_spin,
double* energy,
FPTYPE* force,
FPTYPE* virial,
@@ -361,14 +394,21 @@ inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp,
const double* cell,
const double* fparam,
const double* aparam,
+ const double* charge_spin,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial) {
- DP_DeepPotModelDeviCompute2(dp, 1, natom, coord, atype, cell, fparam, aparam,
- energy, force, virial, atomic_energy,
- atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotModelDeviCompute3(dp, 1, natom, coord, atype, cell, fparam,
+ aparam, charge_spin, energy, force, virial,
+ atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotModelDeviCompute2(dp, 1, natom, coord, atype, cell, fparam,
+ aparam, energy, force, virial, atomic_energy,
+ atomic_virial);
+ }
}
template <>
@@ -379,14 +419,21 @@ inline void _DP_DeepPotModelDeviCompute(DP_DeepPotModelDevi* dp,
const float* cell,
const float* fparam,
const float* aparam,
+ const float* charge_spin,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial) {
- DP_DeepPotModelDeviComputef2(dp, 1, natom, coord, atype, cell, fparam, aparam,
- energy, force, virial, atomic_energy,
- atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotModelDeviComputef3(dp, 1, natom, coord, atype, cell, fparam,
+ aparam, charge_spin, energy, force, virial,
+ atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotModelDeviComputef2(dp, 1, natom, coord, atype, cell, fparam,
+ aparam, energy, force, virial, atomic_energy,
+ atomic_virial);
+ }
}
template
@@ -456,6 +503,7 @@ inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp,
const int ago,
const FPTYPE* fparam,
const FPTYPE* aparam,
+ const FPTYPE* charge_spin,
double* energy,
FPTYPE* force,
FPTYPE* virial,
@@ -473,14 +521,21 @@ inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp,
const int ago,
const double* fparam,
const double* aparam,
+ const double* charge_spin,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial) {
- DP_DeepPotModelDeviComputeNList2(dp, 1, natom, coord, atype, cell, nghost,
- nlist, ago, fparam, aparam, energy, force,
- virial, atomic_energy, atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotModelDeviComputeNList3(
+ dp, 1, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam,
+ charge_spin, energy, force, virial, atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotModelDeviComputeNList2(dp, 1, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, energy, force,
+ virial, atomic_energy, atomic_virial);
+ }
}
template <>
@@ -494,14 +549,21 @@ inline void _DP_DeepPotModelDeviComputeNList(DP_DeepPotModelDevi* dp,
const int ago,
const float* fparam,
const float* aparam,
+ const float* charge_spin,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial) {
- DP_DeepPotModelDeviComputeNListf2(dp, 1, natom, coord, atype, cell, nghost,
- nlist, ago, fparam, aparam, energy, force,
- virial, atomic_energy, atomic_virial);
+ if (charge_spin) {
+ DP_DeepPotModelDeviComputeNListf3(
+ dp, 1, natom, coord, atype, cell, nghost, nlist, ago, fparam, aparam,
+ charge_spin, energy, force, virial, atomic_energy, atomic_virial);
+ } else {
+ DP_DeepPotModelDeviComputeNListf2(dp, 1, natom, coord, atype, cell, nghost,
+ nlist, ago, fparam, aparam, energy, force,
+ virial, atomic_energy, atomic_virial);
+ }
}
template
@@ -800,6 +862,34 @@ inline double* _DP_Get_Energy_Pointer(double& vec, const int nframes) {
namespace deepmd {
namespace hpp {
+/**
+ * @brief Validate a runtime charge_spin vector and return a raw pointer to it
+ * (or nullptr when empty, which falls back to the model's default_chg_spin).
+ * @param[in] charge_spin The per-frame charge/spin values.
+ * @param[in] dchgspin The model's charge/spin dimension (0 if unsupported).
+ * @param[in] nframes The number of frames.
+ * @return charge_spin.data() if non-empty and valid, otherwise nullptr.
+ */
+template
+inline const FPTYPE* validate_charge_spin(
+ const std::vector& charge_spin,
+ const int dchgspin,
+ const unsigned int nframes) {
+ if (charge_spin.empty()) {
+ return nullptr;
+ }
+ if (dchgspin == 0) {
+ throw deepmd::hpp::deepmd_exception(
+ "charge_spin was provided, but this model does not support "
+ "charge/spin conditioning");
+ }
+ if (charge_spin.size() != static_cast(nframes) * dchgspin) {
+ throw deepmd::hpp::deepmd_exception(
+ "the dim of charge_spin provided is not consistent with what the "
+ "model uses");
+ }
+ return charge_spin.data();
+}
/**
* @brief Neighbor list.
**/
@@ -1027,7 +1117,7 @@ class DeepPot : public DeepBaseModel {
/**
* @brief DP constructor without initialization.
**/
- DeepPot() : dp(nullptr) {};
+ DeepPot() : dp(nullptr), dchgspin(0) {};
~DeepPot() { DP_DeleteDeepPot(dp); };
/**
* @brief DP constructor with initialization.
@@ -1038,7 +1128,7 @@ class DeepPot : public DeepBaseModel {
DeepPot(const std::string& model,
const int& gpu_rank = 0,
const std::string& file_content = "")
- : dp(nullptr) {
+ : dp(nullptr), dchgspin(0) {
try {
init(model, gpu_rank, file_content);
} catch (...) {
@@ -1069,11 +1159,22 @@ class DeepPot : public DeepBaseModel {
DP_CHECK_OK(DP_DeepPotCheckOK, dp);
dfparam = DP_DeepPotGetDimFParam(dp);
daparam = DP_DeepPotGetDimAParam(dp);
+ dchgspin = DP_DeepPotGetDimChgSpin(dp);
aparam_nall = DP_DeepPotIsAParamNAll(dp);
has_default_fparam_ = DP_DeepPotHasDefaultFParam(dp);
dpbase = (DP_DeepBaseModel*)dp;
};
+ /**
+ * @brief Get the dimension of the charge/spin embedding input.
+ * @return The dimension of the charge/spin input (0 if the model has no
+ *charge/spin embedding).
+ **/
+ int dim_chg_spin() const {
+ assert(dp);
+ return dchgspin;
+ }
+
/**
* @brief Evaluate the energy, force and virial by using this DP.
* @param[out] ener The system energy.
@@ -1092,6 +1193,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
* @warning Natoms should not be zero when computing multiple frames.
**/
template
@@ -1103,7 +1208,8 @@ class DeepPot : public DeepBaseModel {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1;
assert(nframes * natoms * 3 == coord.size());
@@ -1124,10 +1230,14 @@ class DeepPot : public DeepBaseModel {
tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ // charge_spin routes to the version-3 C API; nullptr keeps version-2 so
+ // non-charge_spin models still work against an older libdeepmd_c.
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
_DP_DeepPotCompute(dp, nframes, natoms, coord_, atype_, box_,
- fparam__, aparam__, ener_, force_, virial_,
- nullptr, nullptr);
+ fparam__, aparam__, charge_spin__, ener_,
+ force_, virial_, nullptr, nullptr);
DP_CHECK_OK(DP_DeepPotCheckOK, dp);
};
/**
@@ -1151,6 +1261,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
* @warning Natoms should not be zero when computing multiple frames.
**/
template
@@ -1164,7 +1278,8 @@ class DeepPot : public DeepBaseModel {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1;
assert(nframes * natoms * 3 == coord.size());
@@ -1190,10 +1305,12 @@ class DeepPot : public DeepBaseModel {
tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
- _DP_DeepPotCompute(dp, nframes, natoms, coord_, atype_, box_,
- fparam__, aparam__, ener_, force_, virial_,
- atomic_ener_, atomic_virial_);
+ _DP_DeepPotCompute(
+ dp, nframes, natoms, coord_, atype_, box_, fparam__, aparam__,
+ charge_spin__, ener_, force_, virial_, atomic_ener_, atomic_virial_);
DP_CHECK_OK(DP_DeepPotCheckOK, dp);
};
@@ -1219,6 +1336,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
* @warning Natoms should not be zero when computing multiple frames.
**/
template
@@ -1233,7 +1354,8 @@ class DeepPot : public DeepBaseModel {
const InputNlist& lmp_list,
const int& ago,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1;
assert(nframes * natoms * 3 == coord.size());
@@ -1257,10 +1379,13 @@ class DeepPot : public DeepBaseModel {
aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
- _DP_DeepPotComputeNList(
- dp, nframes, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago,
- fparam__, aparam__, ener_, force_, virial_, nullptr, nullptr);
+ _DP_DeepPotComputeNList(dp, nframes, natoms, coord_, atype_,
+ box_, nghost, lmp_list.nl, ago, fparam__,
+ aparam__, charge_spin__, ener_, force_,
+ virial_, nullptr, nullptr);
DP_CHECK_OK(DP_DeepPotCheckOK, dp);
};
/**
@@ -1287,6 +1412,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
* @warning Natoms should not be zero when computing multiple frames.
**/
template
@@ -1303,7 +1432,8 @@ class DeepPot : public DeepBaseModel {
const InputNlist& lmp_list,
const int& ago,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = natoms > 0 ? coord.size() / natoms / 3 : 1;
assert(nframes * natoms * 3 == coord.size());
@@ -1332,11 +1462,13 @@ class DeepPot : public DeepBaseModel {
aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
_DP_DeepPotComputeNList(dp, nframes, natoms, coord_, atype_,
box_, nghost, lmp_list.nl, ago, fparam__,
- aparam__, ener_, force_, virial_,
- atomic_ener_, atomic_virial_);
+ aparam__, charge_spin__, ener_, force_,
+ virial_, atomic_ener_, atomic_virial_);
DP_CHECK_OK(DP_DeepPotCheckOK, dp);
};
/**
@@ -1465,6 +1597,7 @@ class DeepPot : public DeepBaseModel {
private:
DP_DeepPot* dp;
+ int dchgspin;
};
class DeepSpin : public DeepBaseModel {
@@ -1881,6 +2014,11 @@ class DeepBaseModelDevi {
assert(dpbase);
return has_default_fparam_;
}
+ /**
+ * @brief Get the dimension of the charge/spin input.
+ * @return Always 0; charge_spin is not supported via the C-API path.
+ **/
+ int dim_chg_spin() const { return 0; }
/**
* @param[out] avg The average of vectors.
* @param[in] xx The vectors of all models.
@@ -2048,13 +2186,14 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
/**
* @brief DP model deviation constructor without initialization.
**/
- DeepPotModelDevi() : dp(nullptr) {};
+ DeepPotModelDevi() : dp(nullptr), dchgspin(0) {};
~DeepPotModelDevi() { DP_DeleteDeepPotModelDevi(dp); };
/**
* @brief DP model deviation constructor with initialization.
* @param[in] models The names of the frozen model file.
**/
- DeepPotModelDevi(const std::vector& models) : dp(nullptr) {
+ DeepPotModelDevi(const std::vector& models)
+ : dp(nullptr), dchgspin(0) {
try {
init(models);
} catch (...) {
@@ -2103,11 +2242,22 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
numb_models = models.size();
dfparam = DP_DeepPotModelDeviGetDimFParam(dp);
daparam = DP_DeepPotModelDeviGetDimAParam(dp);
+ dchgspin = DP_DeepPotModelDeviGetDimChgSpin(dp);
aparam_nall = DP_DeepPotModelDeviIsAParamNAll(dp);
has_default_fparam_ = DP_DeepPotModelDeviHasDefaultFParam(dp);
dpbase = (DP_DeepBaseModelDevi*)dp;
};
+ /**
+ * @brief Get the dimension of the charge/spin input.
+ * @return The dimension of the charge/spin input (0 if the models have no
+ *charge/spin embedding).
+ **/
+ int dim_chg_spin() const {
+ assert(dp);
+ return dchgspin;
+ }
+
/**
* @brief Evaluate the energy, force and virial by using this DP model
*deviation.
@@ -2127,6 +2277,10 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
**/
template
void compute(
@@ -2137,7 +2291,9 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
+ // charge_spin is not supported via the C-API model-deviation path.
unsigned int natoms = atype.size();
unsigned int nframes = 1;
assert(natoms * 3 == coord.size());
@@ -2163,10 +2319,12 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
- _DP_DeepPotModelDeviCompute(dp, natoms, coord_, atype_, box_,
- fparam__, aparam__, ener_, force_,
- virial_, nullptr, nullptr);
+ _DP_DeepPotModelDeviCompute(
+ dp, natoms, coord_, atype_, box_, fparam__, aparam__, charge_spin__,
+ ener_, force_, virial_, nullptr, nullptr);
DP_CHECK_OK(DP_DeepPotModelDeviCheckOK, dp);
// reshape
@@ -2206,6 +2364,10 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
**/
template
void compute(
@@ -2218,7 +2380,9 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
+ // charge_spin is not supported via the C-API model-deviation path.
unsigned int natoms = atype.size();
unsigned int nframes = 1;
assert(natoms * 3 == coord.size());
@@ -2248,10 +2412,12 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
tile_fparam_aparam(aparam_, nframes, natoms * daparam, aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
_DP_DeepPotModelDeviCompute(
- dp, natoms, coord_, atype_, box_, fparam__, aparam__, ener_, force_,
- virial_, atomic_ener_, atomic_virial_);
+ dp, natoms, coord_, atype_, box_, fparam__, aparam__, charge_spin__,
+ ener_, force_, virial_, atomic_ener_, atomic_virial_);
DP_CHECK_OK(DP_DeepPotModelDeviCheckOK, dp);
// reshape
@@ -2303,6 +2469,10 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
**/
template
void compute(
@@ -2316,7 +2486,8 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
const InputNlist& lmp_list,
const int& ago,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = 1;
assert(natoms * 3 == coord.size());
@@ -2345,10 +2516,12 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
_DP_DeepPotModelDeviComputeNList(
dp, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, fparam__,
- aparam__, ener_, force_, virial_, nullptr, nullptr);
+ aparam__, charge_spin__, ener_, force_, virial_, nullptr, nullptr);
DP_CHECK_OK(DP_DeepPotModelDeviCheckOK, dp);
// reshape
@@ -2391,6 +2564,10 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The per-frame charge/spin input. The array can be
+ *of size nframes x dim_chg_spin. Then all frames are assumed to be provided
+ *with the same charge_spin. Leave it empty to use the model's stored
+ *default_chg_spin.
**/
template
void compute(
@@ -2406,7 +2583,8 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
const InputNlist& lmp_list,
const int& ago,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector()) {
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector()) {
unsigned int natoms = atype.size();
unsigned int nframes = 1;
assert(natoms * 3 == coord.size());
@@ -2439,10 +2617,13 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
aparam);
const VALUETYPE* fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr;
const VALUETYPE* aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr;
+ const VALUETYPE* charge_spin__ =
+ validate_charge_spin(charge_spin, dchgspin, nframes);
_DP_DeepPotModelDeviComputeNList(
dp, natoms, coord_, atype_, box_, nghost, lmp_list.nl, ago, fparam__,
- aparam__, ener_, force_, virial_, atomic_ener_, atomic_virial_);
+ aparam__, charge_spin__, ener_, force_, virial_, atomic_ener_,
+ atomic_virial_);
DP_CHECK_OK(DP_DeepPotModelDeviCheckOK, dp);
// reshape
@@ -2474,6 +2655,7 @@ class DeepPotModelDevi : public DeepBaseModelDevi {
private:
DP_DeepPotModelDevi* dp;
+ int dchgspin;
};
class DeepSpinModelDevi : public DeepBaseModelDevi {
diff --git a/source/api_c/src/c_api.cc b/source/api_c/src/c_api.cc
index b0e789648e..1346bfbf20 100644
--- a/source/api_c/src/c_api.cc
+++ b/source/api_c/src/c_api.cc
@@ -251,7 +251,8 @@ inline void DP_DeepPotCompute_variant(DP_DeepPot* dp,
VALUETYPE* force,
VALUETYPE* virial,
VALUETYPE* atomic_energy,
- VALUETYPE* atomic_virial) {
+ VALUETYPE* atomic_virial,
+ const VALUETYPE* charge_spin = nullptr) {
// init C++ vectors from C arrays
std::vector coord_(coord, coord + nframes * natoms * 3);
std::vector atype_(atype, atype + natoms);
@@ -268,15 +269,22 @@ inline void DP_DeepPotCompute_variant(DP_DeepPot* dp,
if (aparam) {
aparam_.assign(aparam, aparam + nframes * natoms * dp->daparam);
}
+ // charge_spin is converted to double for the api_cc::DeepPot interface
+ // (the compute backend stores/uses charge_spin as float64).
+ std::vector charge_spin_;
+ if (charge_spin) {
+ charge_spin_.assign(charge_spin,
+ charge_spin + nframes * dp->dp.dim_chg_spin());
+ }
std::vector e;
std::vector f, v, ae, av;
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
- fparam_, aparam_));
+ fparam_, aparam_, charge_spin_));
} else {
- DP_REQUIRES_OK(
- dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_, aparam_));
+ DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_,
+ aparam_, charge_spin_));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (energy) {
@@ -308,7 +316,8 @@ template void DP_DeepPotCompute_variant(DP_DeepPot* dp,
double* force,
double* virial,
double* atomic_energy,
- double* atomic_virial);
+ double* atomic_virial,
+ const double* charge_spin);
template void DP_DeepPotCompute_variant(DP_DeepPot* dp,
const int nframes,
@@ -322,7 +331,8 @@ template void DP_DeepPotCompute_variant(DP_DeepPot* dp,
float* force,
float* virial,
float* atomic_energy,
- float* atomic_virial);
+ float* atomic_virial,
+ const float* charge_spin);
// support spin
template
inline void DP_DeepSpinCompute_variant(DP_DeepSpin* dp,
@@ -416,22 +426,24 @@ template void DP_DeepSpinCompute_variant(DP_DeepSpin* dp,
float* atomic_virial);
template
-inline void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
- const int nframes,
- const int natoms,
- const VALUETYPE* coord,
- const int* atype,
- const VALUETYPE* cell,
- const int nghost,
- const DP_Nlist* nlist,
- const int ago,
- const VALUETYPE* fparam,
- const VALUETYPE* aparam,
- double* energy,
- VALUETYPE* force,
- VALUETYPE* virial,
- VALUETYPE* atomic_energy,
- VALUETYPE* atomic_virial) {
+inline void DP_DeepPotComputeNList_variant(
+ DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const VALUETYPE* coord,
+ const int* atype,
+ const VALUETYPE* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const VALUETYPE* fparam,
+ const VALUETYPE* aparam,
+ double* energy,
+ VALUETYPE* force,
+ VALUETYPE* virial,
+ VALUETYPE* atomic_energy,
+ VALUETYPE* atomic_virial,
+ const VALUETYPE* charge_spin = nullptr) {
// init C++ vectors from C arrays
std::vector coord_(coord, coord + nframes * natoms * 3);
std::vector atype_(atype, atype + natoms);
@@ -451,16 +463,24 @@ inline void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
(dp->aparam_nall ? natoms : (natoms - nghost)) *
dp->daparam);
}
+ // charge_spin is converted to double for the api_cc::DeepPot interface
+ // (the compute backend stores/uses charge_spin as float64).
+ std::vector charge_spin_;
+ if (charge_spin) {
+ charge_spin_.assign(charge_spin,
+ charge_spin + nframes * dp->dp.dim_chg_spin());
+ }
std::vector e;
std::vector f, v, ae, av;
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_, nghost,
- nlist->nl, ago, fparam_, aparam_));
+ nlist->nl, ago, fparam_, aparam_, charge_spin_));
} else {
- DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost,
- nlist->nl, ago, fparam_, aparam_));
+ DP_REQUIRES_OK(
+ dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost, nlist->nl,
+ ago, fparam_, aparam_, charge_spin_));
}
// copy from C++ vectors to C arrays, if not NULL pointer
if (energy) {
@@ -495,7 +515,8 @@ template void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
double* force,
double* virial,
double* atomic_energy,
- double* atomic_virial);
+ double* atomic_virial,
+ const double* charge_spin);
template void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
const int nframes,
@@ -512,7 +533,8 @@ template void DP_DeepPotComputeNList_variant(DP_DeepPot* dp,
float* force,
float* virial,
float* atomic_energy,
- float* atomic_virial);
+ float* atomic_virial,
+ const float* charge_spin);
// support spin
template
@@ -708,19 +730,21 @@ inline void flatten_vector(std::vector& onedv,
}
template
-void DP_DeepPotModelDeviCompute_variant(DP_DeepPotModelDevi* dp,
- const int nframes,
- const int natoms,
- const VALUETYPE* coord,
- const int* atype,
- const VALUETYPE* cell,
- const VALUETYPE* fparam,
- const VALUETYPE* aparam,
- double* energy,
- VALUETYPE* force,
- VALUETYPE* virial,
- VALUETYPE* atomic_energy,
- VALUETYPE* atomic_virial) {
+void DP_DeepPotModelDeviCompute_variant(
+ DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const VALUETYPE* coord,
+ const int* atype,
+ const VALUETYPE* cell,
+ const VALUETYPE* fparam,
+ const VALUETYPE* aparam,
+ double* energy,
+ VALUETYPE* force,
+ VALUETYPE* virial,
+ VALUETYPE* atomic_energy,
+ VALUETYPE* atomic_virial,
+ const VALUETYPE* charge_spin = nullptr) {
if (nframes > 1) {
throw std::runtime_error("nframes > 1 not supported yet");
}
@@ -740,16 +764,23 @@ void DP_DeepPotModelDeviCompute_variant(DP_DeepPotModelDevi* dp,
if (aparam) {
aparam_.assign(aparam, aparam + nframes * natoms * dp->daparam);
}
+ // charge_spin is converted to double for the api_cc::DeepPot interface
+ // (the compute backend stores/uses charge_spin as float64).
+ std::vector charge_spin_;
+ if (charge_spin) {
+ charge_spin_.assign(charge_spin,
+ charge_spin + nframes * dp->dp.dim_chg_spin());
+ }
// different from DeepPot
std::vector e;
std::vector> f, v, ae, av;
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_,
- fparam_, aparam_));
+ fparam_, aparam_, charge_spin_));
} else {
- DP_REQUIRES_OK(
- dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_, aparam_));
+ DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, fparam_,
+ aparam_, charge_spin_));
}
// 2D vector to 2D array, flatten first
if (energy) {
@@ -790,21 +821,24 @@ template void DP_DeepPotModelDeviCompute_variant(
double* force,
double* virial,
double* atomic_energy,
- double* atomic_virial);
+ double* atomic_virial,
+ const double* charge_spin);
-template void DP_DeepPotModelDeviCompute_variant(DP_DeepPotModelDevi* dp,
- const int nframes,
- const int natoms,
- const float* coord,
- const int* atype,
- const float* cell,
- const float* fparam,
- const float* aparam,
- double* energy,
- float* force,
- float* virial,
- float* atomic_energy,
- float* atomic_virial);
+template void DP_DeepPotModelDeviCompute_variant(
+ DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const float* fparam,
+ const float* aparam,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial,
+ const float* charge_spin);
template
void DP_DeepSpinModelDeviCompute_variant(DP_DeepSpinModelDevi* dp,
@@ -919,22 +953,24 @@ template void DP_DeepSpinModelDeviCompute_variant(
float* atomic_virial);
template
-void DP_DeepPotModelDeviComputeNList_variant(DP_DeepPotModelDevi* dp,
- const int nframes,
- const int natoms,
- const VALUETYPE* coord,
- const int* atype,
- const VALUETYPE* cell,
- const int nghost,
- const DP_Nlist* nlist,
- const int ago,
- const VALUETYPE* fparam,
- const VALUETYPE* aparam,
- double* energy,
- VALUETYPE* force,
- VALUETYPE* virial,
- VALUETYPE* atomic_energy,
- VALUETYPE* atomic_virial) {
+void DP_DeepPotModelDeviComputeNList_variant(
+ DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const VALUETYPE* coord,
+ const int* atype,
+ const VALUETYPE* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const VALUETYPE* fparam,
+ const VALUETYPE* aparam,
+ double* energy,
+ VALUETYPE* force,
+ VALUETYPE* virial,
+ VALUETYPE* atomic_energy,
+ VALUETYPE* atomic_virial,
+ const VALUETYPE* charge_spin = nullptr) {
if (nframes > 1) {
throw std::runtime_error("nframes > 1 not supported yet");
}
@@ -956,6 +992,13 @@ void DP_DeepPotModelDeviComputeNList_variant(DP_DeepPotModelDevi* dp,
aparam,
aparam + (dp->aparam_nall ? natoms : (natoms - nghost)) * dp->daparam);
}
+ // charge_spin is converted to double for the api_cc::DeepPot interface
+ // (the compute backend stores/uses charge_spin as float64).
+ std::vector charge_spin_;
+ if (charge_spin) {
+ charge_spin_.assign(charge_spin,
+ charge_spin + nframes * dp->dp.dim_chg_spin());
+ }
// different from DeepPot
std::vector e;
std::vector> f, v, ae, av;
@@ -963,10 +1006,11 @@ void DP_DeepPotModelDeviComputeNList_variant(DP_DeepPotModelDevi* dp,
if (atomic_energy || atomic_virial) {
DP_REQUIRES_OK(
dp, dp->dp.compute(e, f, v, ae, av, coord_, atype_, cell_, nghost,
- nlist->nl, ago, fparam_, aparam_));
+ nlist->nl, ago, fparam_, aparam_, charge_spin_));
} else {
- DP_REQUIRES_OK(dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost,
- nlist->nl, ago, fparam_, aparam_));
+ DP_REQUIRES_OK(
+ dp, dp->dp.compute(e, f, v, coord_, atype_, cell_, nghost, nlist->nl,
+ ago, fparam_, aparam_, charge_spin_));
}
// 2D vector to 2D array, flatten first
if (energy) {
@@ -1010,7 +1054,8 @@ template void DP_DeepPotModelDeviComputeNList_variant(
double* force,
double* virial,
double* atomic_energy,
- double* atomic_virial);
+ double* atomic_virial,
+ const double* charge_spin);
template void DP_DeepPotModelDeviComputeNList_variant(
DP_DeepPotModelDevi* dp,
@@ -1028,7 +1073,8 @@ template void DP_DeepPotModelDeviComputeNList_variant(
float* force,
float* virial,
float* atomic_energy,
- float* atomic_virial);
+ float* atomic_virial,
+ const float* charge_spin);
// support spin multi model.
template
@@ -1702,6 +1748,90 @@ void DP_DeepPotComputeNListf2(DP_DeepPot* dp,
aparam, energy, force, virial, atomic_energy, atomic_virial);
}
+// charge_spin-aware variants (version 3): same as the version-2 functions
+// plus a per-frame charge_spin input (nframes x dim_chg_spin, always double).
+void DP_DeepPotCompute3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial) {
+ DP_DeepPotCompute_variant(dp, nframes, natoms, coord, atype, cell,
+ fparam, aparam, energy, force, virial,
+ atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotComputef3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial) {
+ DP_DeepPotCompute_variant(dp, nframes, natoms, coord, atype, cell,
+ fparam, aparam, energy, force, virial,
+ atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotComputeNList3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial) {
+ DP_DeepPotComputeNList_variant(
+ dp, nframes, natoms, coord, atype, cell, nghost, nlist, ago, fparam,
+ aparam, energy, force, virial, atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotComputeNListf3(DP_DeepPot* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial) {
+ DP_DeepPotComputeNList_variant(
+ dp, nframes, natoms, coord, atype, cell, nghost, nlist, ago, fparam,
+ aparam, energy, force, virial, atomic_energy, atomic_virial, charge_spin);
+}
+
void DP_DeepSpinComputeNListf2(DP_DeepSpin* dp,
const int nframes,
const int natoms,
@@ -1970,6 +2100,89 @@ void DP_DeepPotModelDeviComputeNListf2(DP_DeepPotModelDevi* dp,
aparam, energy, force, virial, atomic_energy, atomic_virial);
}
+// charge_spin-aware model-deviation variants (version 3).
+void DP_DeepPotModelDeviCompute3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial) {
+ DP_DeepPotModelDeviCompute_variant(
+ dp, nframes, natoms, coord, atype, cell, fparam, aparam, energy, force,
+ virial, atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotModelDeviComputef3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial) {
+ DP_DeepPotModelDeviCompute_variant(
+ dp, nframes, natoms, coord, atype, cell, fparam, aparam, energy, force,
+ virial, atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotModelDeviComputeNList3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const double* coord,
+ const int* atype,
+ const double* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const double* fparam,
+ const double* aparam,
+ const double* charge_spin,
+ double* energy,
+ double* force,
+ double* virial,
+ double* atomic_energy,
+ double* atomic_virial) {
+ DP_DeepPotModelDeviComputeNList_variant(
+ dp, nframes, natoms, coord, atype, cell, nghost, nlist, ago, fparam,
+ aparam, energy, force, virial, atomic_energy, atomic_virial, charge_spin);
+}
+
+void DP_DeepPotModelDeviComputeNListf3(DP_DeepPotModelDevi* dp,
+ const int nframes,
+ const int natoms,
+ const float* coord,
+ const int* atype,
+ const float* cell,
+ const int nghost,
+ const DP_Nlist* nlist,
+ const int ago,
+ const float* fparam,
+ const float* aparam,
+ const float* charge_spin,
+ double* energy,
+ float* force,
+ float* virial,
+ float* atomic_energy,
+ float* atomic_virial) {
+ DP_DeepPotModelDeviComputeNList_variant(
+ dp, nframes, natoms, coord, atype, cell, nghost, nlist, ago, fparam,
+ aparam, energy, force, virial, atomic_energy, atomic_virial, charge_spin);
+}
+
void DP_DeepSpinModelDeviComputeNListf2(DP_DeepSpinModelDevi* dp,
const int nframes,
const int natoms,
@@ -2089,6 +2302,8 @@ int DP_DeepPotGetDimAParam(DP_DeepPot* dp) {
return DP_DeepBaseModelGetDimAParam(static_cast(dp));
}
+int DP_DeepPotGetDimChgSpin(DP_DeepPot* dp) { return dp->dp.dim_chg_spin(); }
+
bool DP_DeepPotIsAParamNAll(DP_DeepPot* dp) {
return DP_DeepBaseModelIsAParamNAll(static_cast(dp));
}
@@ -2125,6 +2340,10 @@ int DP_DeepPotModelDeviGetDimAParam(DP_DeepPotModelDevi* dp) {
static_cast(dp));
}
+int DP_DeepPotModelDeviGetDimChgSpin(DP_DeepPotModelDevi* dp) {
+ return dp->dp.dim_chg_spin();
+}
+
bool DP_DeepPotModelDeviIsAParamNAll(DP_DeepPotModelDevi* dp) {
return DP_DeepBaseModelDeviIsAParamNAll(
static_cast(dp));
diff --git a/source/api_cc/include/DeepPot.h b/source/api_cc/include/DeepPot.h
index 6a30eed7ea..177513ebb0 100644
--- a/source/api_cc/include/DeepPot.h
+++ b/source/api_cc/include/DeepPot.h
@@ -198,6 +198,115 @@ class DeepPotBackend : public DeepBaseModelBackend {
const std::vector& aparam,
const bool atomic) = 0;
/** @} */
+
+ /**
+ * @brief Get dimension of charge/spin condition inputs.
+ * Returns 0 for backends that do not support charge/spin conditioning.
+ **/
+ virtual int dim_chg_spin() const { return 0; }
+
+ // charge_spin-aware computew overloads. Default implementations call the
+ // existing pure-virtual overloads (ignoring charge_spin) so that backends
+ // that do not support charge/spin do not need any changes. DeepPotPTExpt
+ // overrides these to thread charge_spin through to the model.
+ virtual void computew(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew(ener, force, virial, atom_energy, atom_virial, coord, atype, box,
+ fparam, aparam, atomic);
+ }
+ virtual void computew(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew(ener, force, virial, atom_energy, atom_virial, coord, atype, box,
+ fparam, aparam, atomic);
+ }
+ virtual void computew(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const int nghost,
+ const InputNlist& inlist,
+ const int& ago,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew(ener, force, virial, atom_energy, atom_virial, coord, atype, box,
+ nghost, inlist, ago, fparam, aparam, atomic);
+ }
+ virtual void computew(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const int nghost,
+ const InputNlist& inlist,
+ const int& ago,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew(ener, force, virial, atom_energy, atom_virial, coord, atype, box,
+ nghost, inlist, ago, fparam, aparam, atomic);
+ }
+ virtual void computew_mixed_type(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const int& nframes,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew_mixed_type(ener, force, virial, atom_energy, atom_virial, nframes,
+ coord, atype, box, fparam, aparam, atomic);
+ }
+ virtual void computew_mixed_type(std::vector& ener,
+ std::vector& force,
+ std::vector& virial,
+ std::vector& atom_energy,
+ std::vector& atom_virial,
+ const int& nframes,
+ const std::vector& coord,
+ const std::vector& atype,
+ const std::vector& box,
+ const std::vector& fparam,
+ const std::vector& aparam,
+ const std::vector& charge_spin,
+ const bool atomic) {
+ computew_mixed_type(ener, force, virial, atom_energy, atom_virial, nframes,
+ coord, atype, box, fparam, aparam, atomic);
+ }
};
/**
@@ -249,6 +358,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The charge/spin parameter. The array can be of size
+ *nframes x dim_chg_spin.
+ * dim_chg_spin. Then all frames are assumed to be provided with the same
+ *charge_spin. Leave it empty to use the model's stored default_chg_spin.
* @{
**/
template
@@ -259,7 +372,8 @@ class DeepPot : public DeepBaseModel {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector());
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector());
template
void compute(std::vector& ener,
std::vector& force,
@@ -268,7 +382,8 @@ class DeepPot : public DeepBaseModel {
const std::vector& atype,
const std::vector& box,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector());
+ const std::vector& aparam = std::vector(),
+ const std::vector& charge_spin = std::vector());
/** @} */
/**
* @brief Evaluate the energy, force and virial by using this DP.
@@ -291,6 +406,10 @@ class DeepPot : public DeepBaseModel {
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam.
+ * @param[in] charge_spin The charge/spin parameter. The array can be of size
+ *nframes x dim_chg_spin.
+ * dim_chg_spin. Then all frames are assumed to be provided with the same
+ *charge_spin. Leave it empty to use the model's stored default_chg_spin.
* @{
**/
template
@@ -304,7 +423,8 @@ class DeepPot : public DeepBaseModel {
const InputNlist& inlist,
const int& ago,
const std::vector& fparam = std::vector(),
- const std::vector& aparam = std::vector());
+ const std::vector& aparam = std::vector(),
+ const std::vector