diff --git a/source/api_c/include/c_api.h b/source/api_c/include/c_api.h index a4bdb6f422..7826e9aa18 100644 --- a/source/api_c/include/c_api.h +++ b/source/api_c/include/c_api.h @@ -162,20 +162,22 @@ extern void DP_DeepPotCompute(DP_DeepPot* dp, double* atomic_virial); /** - * @brief Evaluate the energy, force, magnetic force and virial by using a DP with spin input. (double version) + * @brief Evaluate the energy, force, magnetic force and virial by using a DP + *with spin input. (double version) * @attention The number of frames is assumed to be 1. * @param[in] dp The DP to use. * @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] spin The spins of atoms, [0, 0, 0] if no spin. The array should be + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be *of size natoms x 3. * @param[in] atype The atom types. The array should contain natoms ints. * @param[in] box The cell of the region. The array should be of size 9. Pass *NULL if pbc is not used. * @param[out] energy Output energy. * @param[out] force Output force. The array should be of size natoms x 3. - * @param[out] force_mag Output magnetic force. The array should be of size natoms x 3. + * @param[out] force_mag Output magnetic 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. @@ -185,17 +187,17 @@ extern void DP_DeepPotCompute(DP_DeepPot* dp, *Pass NULL if not required. **/ extern void DP_DeepPotComputeSP(DP_DeepPot* dp, - const int natom, - const double* coord, - const double* spin, - const int* atype, - const double* cell, - double* energy, - double* force, - double* force_mag, - double* virial, - double* atomic_energy, - double* atomic_virial); + const int natom, + const double* coord, + const double* spin, + const int* atype, + const double* cell, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial); /** * @brief Evaluate the energy, force and virial by using a DP. (float version) @@ -229,20 +231,22 @@ extern void DP_DeepPotComputef(DP_DeepPot* dp, float* atomic_virial); /** - * @brief Evaluate the energy, force, magnetic force and virial by using a DP with spin input. (float version) + * @brief Evaluate the energy, force, magnetic force and virial by using a DP + *with spin input. (float version) * @attention The number of frames is assumed to be 1. * @param[in] dp The DP to use. * @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] spin The spins of atoms, [0, 0, 0] if no spin. The array should be + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be *of size natoms x 3. * @param[in] atype The atom types. The array should contain natoms ints. * @param[in] box The cell of the region. The array should be of size 9. Pass *NULL if pbc is not used. * @param[out] energy Output energy. * @param[out] force Output force. The array should be of size natoms x 3. - * @param[out] force_mag Output magnetic force. The array should be of size natoms x 3. + * @param[out] force_mag Output magnetic 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. @@ -252,17 +256,17 @@ extern void DP_DeepPotComputef(DP_DeepPot* dp, *Pass NULL if not required. **/ extern void DP_DeepPotComputefSP(DP_DeepPot* dp, - const int natom, - const float* coord, - const float* spin, - const int* atype, - const float* cell, - double* energy, - float* force, - float* force_mag, - float* virial, - float* atomic_energy, - float* atomic_virial); + const int natom, + const float* coord, + const float* spin, + const int* atype, + const float* cell, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial); /** * @brief Evaluate the energy, force and virial by using a DP with the neighbor @@ -412,15 +416,16 @@ extern void DP_DeepPotCompute2(DP_DeepPot* dp, double* atomic_virial); /** - * @brief Evaluate the energy, force, magnetic force and virial by using a DP with spin input. (double version) + * @brief Evaluate the energy, force, magnetic force and virial by using a DP + *with spin input. (double version) * @version 2 * @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] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be + *of size nframes x natoms x 3. * @param[in] atype The atom types. The array should contain natoms ints. * @param[in] box The cell of the region. The array should be of size 9. Pass *NULL if pbc is not used. @@ -440,20 +445,20 @@ extern void DP_DeepPotCompute2(DP_DeepPot* dp, *Pass NULL if not required. **/ extern void DP_DeepPotCompute2SP(DP_DeepPot* dp, - const int nframes, - const int natom, - const double* coord, - const double* spin, - const int* atype, - const double* cell, - const double* fparam, - const double* aparam, - double* energy, - double* force, - double* force_mag, - double* virial, - double* atomic_energy, - double* atomic_virial); + const int nframes, + const int natom, + const double* coord, + const double* spin, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial); /** * @brief Evaluate the energy, force and virial by using a DP. (float version) @@ -495,15 +500,16 @@ extern void DP_DeepPotComputef2(DP_DeepPot* dp, float* atomic_virial); /** - * @brief Evaluate the energy, force, magnetic force and virial by using a DP with spin input. (float version) + * @brief Evaluate the energy, force, magnetic force and virial by using a DP + *with spin input. (float version) * @version 2 * @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] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be + *of size nframes x natoms x 3. * @param[in] atype The atom types. The array should contain natoms ints. * @param[in] box The cell of the region. The array should be of size 9. Pass *NULL if pbc is not used. @@ -523,20 +529,20 @@ extern void DP_DeepPotComputef2(DP_DeepPot* dp, *Pass NULL if not required. **/ extern void DP_DeepPotComputef2SP(DP_DeepPot* dp, - const int nframes, - const int natom, - const float* coord, - const float* spin, - const int* atype, - const float* cell, - const float* fparam, - const float* aparam, - double* energy, - float* force, - float* force_mag, - float* virial, - float* atomic_energy, - float* atomic_virial); + const int nframes, + const int natom, + const float* coord, + const float* spin, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial); /** * @brief Evaluate the energy, force and virial by using a DP with the neighbor diff --git a/source/api_c/include/deepmd.hpp b/source/api_c/include/deepmd.hpp index a952075789..ede64be1bb 100644 --- a/source/api_c/include/deepmd.hpp +++ b/source/api_c/include/deepmd.hpp @@ -98,59 +98,61 @@ inline void _DP_DeepPotCompute(DP_DeepPot *dp, // support spin template inline void _DP_DeepPotComputeSP(DP_DeepPot *dp, - const int nframes, - const int natom, - const FPTYPE *coord, - const FPTYPE *spin, - const int *atype, - const FPTYPE *cell, - const FPTYPE *fparam, - const FPTYPE *aparam, - double *energy, - FPTYPE *force, - FPTYPE *force_mag, - FPTYPE *virial, - FPTYPE *atomic_energy, - FPTYPE *atomic_virial); + const int nframes, + const int natom, + const FPTYPE *coord, + const FPTYPE *spin, + const int *atype, + const FPTYPE *cell, + const FPTYPE *fparam, + const FPTYPE *aparam, + double *energy, + FPTYPE *force, + FPTYPE *force_mag, + FPTYPE *virial, + FPTYPE *atomic_energy, + FPTYPE *atomic_virial); template <> inline void _DP_DeepPotComputeSP(DP_DeepPot *dp, - const int nframes, - const int natom, - const double *coord, - const double *spin, - const int *atype, - const double *cell, - const double *fparam, - const double *aparam, - double *energy, - double *force, - double *force_mag, - double *virial, - double *atomic_energy, - double *atomic_virial) { - DP_DeepPotCompute2SP(dp, nframes, natom, coord, spin, atype, cell, fparam, aparam, - energy, force, force_mag, virial, atomic_energy, atomic_virial); + const int nframes, + const int natom, + const double *coord, + const double *spin, + const int *atype, + const double *cell, + const double *fparam, + const double *aparam, + double *energy, + double *force, + double *force_mag, + double *virial, + double *atomic_energy, + double *atomic_virial) { + DP_DeepPotCompute2SP(dp, nframes, natom, coord, spin, atype, cell, fparam, + aparam, energy, force, force_mag, virial, atomic_energy, + atomic_virial); } template <> inline void _DP_DeepPotComputeSP(DP_DeepPot *dp, - const int nframes, - const int natom, - const float *coord, - const float *spin, - const int *atype, - const float *cell, - const float *fparam, - const float *aparam, - double *energy, - float *force, - float *force_mag, - float *virial, - float *atomic_energy, - float *atomic_virial) { - DP_DeepPotComputef2SP(dp, nframes, natom, coord, spin, atype, cell, fparam, aparam, - energy, force, force_mag, virial, atomic_energy, atomic_virial); + const int nframes, + const int natom, + const float *coord, + const float *spin, + const int *atype, + const float *cell, + const float *fparam, + const float *aparam, + double *energy, + float *force, + float *force_mag, + float *virial, + float *atomic_energy, + float *atomic_virial) { + DP_DeepPotComputef2SP(dp, nframes, natom, coord, spin, atype, cell, fparam, + aparam, energy, force, force_mag, virial, atomic_energy, + atomic_virial); } template @@ -941,15 +943,16 @@ class DeepPot { }; // support spin /** - * @brief Evaluate the energy, force, magnetic force and virial by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force and virial by using this + *DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. * @param[out] virial The virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9 (PBC) or empty (no PBC). @@ -999,9 +1002,9 @@ class DeepPot { const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; - _DP_DeepPotComputeSP(dp, nframes, natoms, coord_, spin_, atype_, box_, - fparam__, aparam__, ener_, force_, force_mag_, virial_, - nullptr, nullptr); + _DP_DeepPotComputeSP(dp, nframes, natoms, coord_, spin_, atype_, + box_, fparam__, aparam__, ener_, force_, + force_mag_, virial_, nullptr, nullptr); DP_CHECK_OK(DP_DeepPotCheckOK, dp); }; /** @@ -1072,8 +1075,8 @@ class DeepPot { }; /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. @@ -1082,8 +1085,8 @@ class DeepPot { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9 (PBC) or empty (no PBC). @@ -1140,9 +1143,9 @@ class DeepPot { const VALUETYPE *fparam__ = !fparam_.empty() ? &fparam_[0] : nullptr; const VALUETYPE *aparam__ = !aparam_.empty() ? &aparam_[0] : nullptr; - _DP_DeepPotCompute(dp, nframes, natoms, coord_, spin_, atype_, box_, - fparam__, aparam__, ener_, force_, force_mag_, virial_, - atomic_ener_, atomic_virial_); + _DP_DeepPotCompute( + dp, nframes, natoms, coord_, spin_, atype_, box_, fparam__, aparam__, + ener_, force_, force_mag_, virial_, atomic_ener_, atomic_virial_); DP_CHECK_OK(DP_DeepPotCheckOK, dp); }; diff --git a/source/api_c/src/c_api.cc b/source/api_c/src/c_api.cc index 85166cb598..f54e89fdc0 100644 --- a/source/api_c/src/c_api.cc +++ b/source/api_c/src/c_api.cc @@ -254,20 +254,20 @@ template void DP_DeepPotCompute_variant(DP_DeepPot* dp, // support spin template inline void DP_DeepPotCompute_variant_sp(DP_DeepPot* dp, - const int nframes, - const int natoms, - const VALUETYPE* coord, - const VALUETYPE* spin, - const int* atype, - const VALUETYPE* cell, - const VALUETYPE* fparam, - const VALUETYPE* aparam, - double* energy, - VALUETYPE* force, - VALUETYPE* force_mag, - VALUETYPE* virial, - VALUETYPE* atomic_energy, - VALUETYPE* atomic_virial) { + const int nframes, + const int natoms, + const VALUETYPE* coord, + const VALUETYPE* spin, + const int* atype, + const VALUETYPE* cell, + const VALUETYPE* fparam, + const VALUETYPE* aparam, + double* energy, + VALUETYPE* force, + VALUETYPE* force_mag, + VALUETYPE* virial, + VALUETYPE* atomic_energy, + VALUETYPE* atomic_virial) { // init C++ vectors from C arrays std::vector coord_(coord, coord + nframes * natoms * 3); std::vector spin_(spin, spin + nframes * natoms * 3); @@ -288,8 +288,8 @@ inline void DP_DeepPotCompute_variant_sp(DP_DeepPot* dp, std::vector e; std::vector f, fm, v, ae, av; - DP_REQUIRES_OK(dp, dp->dp.compute(e, f, fm, v, ae, av, coord_, spin_, atype_, cell_, - fparam_, aparam_)); + DP_REQUIRES_OK(dp, dp->dp.compute(e, f, fm, v, ae, av, coord_, spin_, atype_, + cell_, fparam_, aparam_)); // copy from C++ vectors to C arrays, if not NULL pointer if (energy) { std::copy(e.begin(), e.end(), energy); @@ -312,37 +312,36 @@ inline void DP_DeepPotCompute_variant_sp(DP_DeepPot* dp, } template void DP_DeepPotCompute_variant_sp(DP_DeepPot* dp, - const int nframes, - const int natoms, - const double* coord, - const double* spin, - const int* atype, - const double* cell, - const double* fparam, - const double* aparam, - double* energy, - double* force, - double* force_mag, - double* virial, - double* atomic_energy, - double* atomic_virial); + const int nframes, + const int natoms, + const double* coord, + const double* spin, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial); template void DP_DeepPotCompute_variant_sp(DP_DeepPot* dp, - const int nframes, - const int natoms, - const float* coord, - const float* spin, - const int* atype, - const float* cell, - const float* fparam, - const float* aparam, - double* energy, - float* force, - float* force_mag, - float* virial, - float* atomic_energy, - float* atomic_virial); - + const int nframes, + const int natoms, + const float* coord, + const float* spin, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial); template inline void DP_DeepPotComputeNList_variant(DP_DeepPot* dp, @@ -1322,20 +1321,20 @@ void DP_DeepPotCompute(DP_DeepPot* dp, atomic_virial); } void DP_DeepPotComputeSP(DP_DeepPot* dp, - const int natoms, - const double* coord, - const double* spin, - const int* atype, - const double* cell, - double* energy, - double* force, - double* force_mag, - double* virial, - double* atomic_energy, - double* atomic_virial) { - DP_DeepPotCompute_variant_sp(dp, 1, natoms, coord, spin, atype, cell, NULL, - NULL, energy, force, force_mag, virial, atomic_energy, - atomic_virial); + const int natoms, + const double* coord, + const double* spin, + const int* atype, + const double* cell, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { + DP_DeepPotCompute_variant_sp(dp, 1, natoms, coord, spin, atype, cell, + NULL, NULL, energy, force, force_mag, + virial, atomic_energy, atomic_virial); } void DP_DeepPotComputef(DP_DeepPot* dp, @@ -1354,20 +1353,20 @@ void DP_DeepPotComputef(DP_DeepPot* dp, } void DP_DeepPotComputefSP(DP_DeepPot* dp, - const int natoms, - const float* coord, - const float* spin, - const int* atype, - const float* cell, - double* energy, - float* force, - float* force_mag, - float* virial, - float* atomic_energy, - float* atomic_virial) { - DP_DeepPotCompute_variant_sp(dp, 1, natoms, coord, spin, atype, cell, NULL, - NULL, energy, force, force_mag, virial, atomic_energy, - atomic_virial); + const int natoms, + const float* coord, + const float* spin, + const int* atype, + const float* cell, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { + DP_DeepPotCompute_variant_sp(dp, 1, natoms, coord, spin, atype, cell, + NULL, NULL, energy, force, force_mag, + virial, atomic_energy, atomic_virial); } void DP_DeepPotComputeNList(DP_DeepPot* dp, @@ -1465,23 +1464,23 @@ void DP_DeepPotCompute2(DP_DeepPot* dp, atomic_energy, atomic_virial); } void DP_DeepPotCompute2SP(DP_DeepPot* dp, - const int nframes, - const int natoms, - const double* coord, - const double* spin, - const int* atype, - const double* cell, - const double* fparam, - const double* aparam, - double* energy, - double* force, - double* force_mag, - double* virial, - double* atomic_energy, - double* atomic_virial) { - DP_DeepPotCompute_variant_sp(dp, nframes, natoms, coord, spin, atype, cell, - fparam, aparam, energy, force, force_mag, virial, - atomic_energy, atomic_virial); + const int nframes, + const int natoms, + const double* coord, + const double* spin, + const int* atype, + const double* cell, + const double* fparam, + const double* aparam, + double* energy, + double* force, + double* force_mag, + double* virial, + double* atomic_energy, + double* atomic_virial) { + DP_DeepPotCompute_variant_sp( + dp, nframes, natoms, coord, spin, atype, cell, fparam, aparam, energy, + force, force_mag, virial, atomic_energy, atomic_virial); } void DP_DeepPotComputef2(DP_DeepPot* dp, @@ -1503,23 +1502,23 @@ void DP_DeepPotComputef2(DP_DeepPot* dp, } void DP_DeepPotComputef2SP(DP_DeepPot* dp, - const int nframes, - const int natoms, - const float* coord, - const float* spin, - const int* atype, - const float* cell, - const float* fparam, - const float* aparam, - double* energy, - float* force, - float* force_mag, - float* virial, - float* atomic_energy, - float* atomic_virial) { - DP_DeepPotCompute_variant_sp(dp, nframes, natoms, coord, spin, atype, cell, - fparam, aparam, energy, force, force_mag, virial, - atomic_energy, atomic_virial); + const int nframes, + const int natoms, + const float* coord, + const float* spin, + const int* atype, + const float* cell, + const float* fparam, + const float* aparam, + double* energy, + float* force, + float* force_mag, + float* virial, + float* atomic_energy, + float* atomic_virial) { + DP_DeepPotCompute_variant_sp( + dp, nframes, natoms, coord, spin, atype, cell, fparam, aparam, energy, + force, force_mag, virial, atomic_energy, atomic_virial); } void DP_DeepPotComputeNList2(DP_DeepPot* dp, diff --git a/source/api_cc/include/DeepPot.h b/source/api_cc/include/DeepPot.h index 9173470dec..eaf9995794 100644 --- a/source/api_cc/include/DeepPot.h +++ b/source/api_cc/include/DeepPot.h @@ -89,8 +89,8 @@ class DeepPotBase { /** @} */ /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @note The double precision interface is used by i-PI, GROMACS, ABACUS, and *CP2k. * @param[out] ener The system energy. @@ -101,8 +101,8 @@ class DeepPotBase { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -204,8 +204,8 @@ class DeepPotBase { /** @} */ /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @note The double precision interface is used by LAMMPS and AMBER. * @param[out] ener The system energy. * @param[out] force The force on each atom. @@ -215,8 +215,8 @@ class DeepPotBase { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -435,15 +435,16 @@ class DeepPot { const std::vector& aparam = std::vector()); /** @} */ /** - * @brief Evaluate the energy, force, magnetic force and virial by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force and virial by using this + *DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. * @param[out] virial The virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -530,15 +531,16 @@ class DeepPot { const std::vector& aparam = std::vector()); /** @} */ /** - * @brief Evaluate the energy, force, magnetic force and virial by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force and virial by using this + *DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. * @param[out] virial The virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -632,8 +634,8 @@ class DeepPot { /** @} */ /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. @@ -642,8 +644,8 @@ class DeepPot { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -742,8 +744,8 @@ class DeepPot { /** @} */ /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. @@ -752,8 +754,8 @@ class DeepPot { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -1076,15 +1078,16 @@ class DeepPotModelDevi { const std::vector& aparam = std::vector()); /** - * @brief Evaluate the energy, force, magnetic force and virial by using these DP models with spin input. + * @brief Evaluate the energy, force, magnetic force and virial by using these + *DP models with spin input. * @param[out] all_ener The system energies of all models. * @param[out] all_force The forces on each atom of all models. * @param[out] all_force_mag The magnetic forces on each atom of all models. * @param[out] all_virial The virials of all models. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -1157,8 +1160,8 @@ class DeepPotModelDevi { const std::vector& aparam = std::vector()); /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using these DP models with spin input. + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using these DP models with spin input. * @param[out] all_ener The system energies of all models. * @param[out] all_force The forces on each atom of all models. * @param[out] all_force_mag The magnetic forces on each atom of all models. @@ -1167,8 +1170,8 @@ class DeepPotModelDevi { * @param[out] all_atom_virial The atomic virials of all models. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. diff --git a/source/api_cc/include/DeepPotPT.h b/source/api_cc/include/DeepPotPT.h index 39a2e43488..d77b7fa485 100644 --- a/source/api_cc/include/DeepPotPT.h +++ b/source/api_cc/include/DeepPotPT.h @@ -74,10 +74,10 @@ class DeepPotPT : public DeepPotBase { const std::vector& fparam, const std::vector& aparam, const bool atomic); - - /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + + /** + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. @@ -86,8 +86,8 @@ class DeepPotPT : public DeepPotBase { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. @@ -156,10 +156,10 @@ class DeepPotPT : public DeepPotBase { const std::vector& fparam, const std::vector& aparam, const bool atomic); - - /** - * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial - *by using this DP with spin input. + + /** + * @brief Evaluate the energy, force, magnetic force, virial, atomic energy, + *and atomic virial by using this DP with spin input. * @param[out] ener The system energy. * @param[out] force The force on each atom. * @param[out] force_mag The magnetic force on each atom. @@ -168,8 +168,8 @@ class DeepPotPT : public DeepPotBase { * @param[out] atom_virial The atomic virial. * @param[in] coord The coordinates of atoms. The array should be of size *nframes x natoms x 3. - * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should be of size - *nframes x natoms x 3. + * @param[in] spin The spins of atoms, [0, 0, 0] if no spin. The array should + *be of size nframes x natoms x 3. * @param[in] atype The atom types. The list should contain natoms ints. * @param[in] box The cell of the region. The array should be of size nframes *x 9. diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index 3af999b641..d69e749ac2 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -148,8 +148,9 @@ void DeepPot::compute(ENERGYTYPE& dener, const std::vector& aparam_) { std::vector dener_; std::vector datom_energy_, datom_virial_; - dp->computew(dener_, dforce_, dforce_mag_, dvirial, datom_energy_, datom_virial_, dcoord_, - dspin_, datype_, dbox, fparam_, aparam_, false); + dp->computew(dener_, dforce_, dforce_mag_, dvirial, datom_energy_, + datom_virial_, dcoord_, dspin_, datype_, dbox, fparam_, aparam_, + false); dener = dener_[0]; } @@ -165,8 +166,9 @@ void DeepPot::compute(std::vector& dener, const std::vector& fparam_, const std::vector& aparam_) { std::vector datom_energy_, datom_virial_; - dp->computew(dener, dforce_, dforce_mag_, dvirial, datom_energy_, datom_virial_, dcoord_, - dspin_, datype_, dbox, fparam_, aparam_, false); + dp->computew(dener, dforce_, dforce_mag_, dvirial, datom_energy_, + datom_virial_, dcoord_, dspin_, datype_, dbox, fparam_, aparam_, + false); } template void DeepPot::compute(ENERGYTYPE& dener, @@ -213,7 +215,6 @@ template void DeepPot::compute(std::vector& dener, const std::vector& fparam, const std::vector& aparam); - template void DeepPot::compute(ENERGYTYPE& dener, std::vector& dforce_, @@ -487,8 +488,9 @@ void DeepPot::compute(ENERGYTYPE& dener, const std::vector& fparam_, const std::vector& aparam_) { std::vector dener_; - dp->computew(dener_, dforce_, dforce_mag_, dvirial, datom_energy_, datom_virial_, dcoord_, - dspin_, datype_, dbox, fparam_, aparam_, true); + dp->computew(dener_, dforce_, dforce_mag_, dvirial, datom_energy_, + datom_virial_, dcoord_, dspin_, datype_, dbox, fparam_, aparam_, + true); dener = dener_[0]; } template @@ -504,8 +506,9 @@ void DeepPot::compute(std::vector& dener, const std::vector& dbox, const std::vector& fparam_, const std::vector& aparam_) { - dp->computew(dener, dforce_, dforce_mag_, dvirial, datom_energy_, datom_virial_, dcoord_, - dspin_, datype_, dbox, fparam_, aparam_, true); + dp->computew(dener, dforce_, dforce_mag_, dvirial, datom_energy_, + datom_virial_, dcoord_, dspin_, datype_, dbox, fparam_, aparam_, + true); } template void DeepPot::compute(ENERGYTYPE& dener, std::vector& dforce_, @@ -559,7 +562,6 @@ template void DeepPot::compute(std::vector& dener, const std::vector& fparam, const std::vector& aparam); - template void DeepPot::compute(ENERGYTYPE& dener, std::vector& dforce_, diff --git a/source/api_cc/src/DeepPotTF.cc b/source/api_cc/src/DeepPotTF.cc index 882e1a55f0..9e85a2bdbf 100644 --- a/source/api_cc/src/DeepPotTF.cc +++ b/source/api_cc/src/DeepPotTF.cc @@ -695,7 +695,7 @@ void DeepPotTF::compute(ENERGYVTYPE& dener, const std::vector& fparam_, const std::vector& aparam_, const bool atomic) { - std::cout<<"not support"<( @@ -758,7 +758,6 @@ template void DeepPotTF::compute>( const std::vector& aparam, const bool atomic); - template void DeepPotTF::compute(ENERGYVTYPE& dener, std::vector& dforce_, @@ -1254,8 +1253,8 @@ void DeepPotTF::computew(std::vector& ener, const std::vector& fparam, const std::vector& aparam, const bool atomic) { - compute(ener, force, force_mag, virial, atom_energy, atom_virial, coord, spin, atype, box, - fparam, aparam, atomic); + compute(ener, force, force_mag, virial, atom_energy, atom_virial, coord, spin, + atype, box, fparam, aparam, atomic); } void DeepPotTF::computew(std::vector& ener, std::vector& force, @@ -1270,8 +1269,8 @@ void DeepPotTF::computew(std::vector& ener, const std::vector& fparam, const std::vector& aparam, const bool atomic) { - compute(ener, force, force_mag, virial, atom_energy, atom_virial, coord, spin, atype, box, - fparam, aparam, atomic); + compute(ener, force, force_mag, virial, atom_energy, atom_virial, coord, spin, + atype, box, fparam, aparam, atomic); } void DeepPotTF::computew(std::vector& ener, std::vector& force, diff --git a/source/api_cc/tests/test_deeppot_dpa1_pt_spin.cc b/source/api_cc/tests/test_deeppot_dpa1_pt_spin.cc index 538794517f..df325ab5de 100644 --- a/source/api_cc/tests/test_deeppot_dpa1_pt_spin.cc +++ b/source/api_cc/tests/test_deeppot_dpa1_pt_spin.cc @@ -23,9 +23,9 @@ class TestInferDeepPotDpaPtSpin : public ::testing::Test { std::vector coord = {12.83, 2.56, 2.18, 12.09, 2.87, 2.74, 00.25, 3.32, 1.68, 3.36, 3.00, 1.81, 3.51, 2.51, 2.60, 4.27, 3.22, 1.56}; - std::vector spin = {0.13, 0.02, 0.03, 0., 0., 0., 0., 0., 0., + std::vector spin = {0.13, 0.02, 0.03, 0., 0., 0., 0., 0., 0., 0.14, 0.10, 0.12, 0., 0., 0., 0., 0., 0.}; - + std::vector atype = {0, 1, 1, 0, 1, 1}; std::vector box = {13., 0., 0., 0., 13., 0., 0., 0., 13.}; // Generated by the following Python code: @@ -37,7 +37,7 @@ class TestInferDeepPotDpaPtSpin : public ::testing::Test { // 3.51, 2.51, 2.60, 4.27, 3.22, 1.56 // ]).reshape(1, -1) // spin = np.array([ - // 0.13, 0.02, 0.03, 0., 0., 0., 0., 0., 0., + // 0.13, 0.02, 0.03, 0., 0., 0., 0., 0., 0., // 0.14, 0.10, 0.12, 0., 0., 0., 0., 0., 0. // ]).reshape(1, -1) // atype = np.array([0, 1, 1, 0, 1, 1]) @@ -47,23 +47,36 @@ class TestInferDeepPotDpaPtSpin : public ::testing::Test { // np.set_printoptions(precision=16) // print(f"{e.ravel()=} {f.ravel()=} {fm.ravel()=} {ae.ravel()=}") - std::vector expected_e = { - -5.835211567762678, -5.071189078159807, -5.044361601406714, - -5.582324154346981, -5.059906899269188, -5.074135576182056}; + std::vector expected_e = {-5.835211567762678, -5.071189078159807, + -5.044361601406714, -5.582324154346981, + -5.059906899269188, -5.074135576182056}; std::vector expected_f = { - -0.0619881702551019, 0.0646720543680939, 0.2137632336140025, - 0.037800173877136 , -0.096327623008356 , -0.1531911892384847, - -0.112204927558682 , 0.0299145670766557, -0.0589474826303666, + -0.0619881702551019, 0.0646720543680939, 0.2137632336140025, + 0.037800173877136, -0.096327623008356, -0.1531911892384847, + -0.112204927558682, 0.0299145670766557, -0.0589474826303666, 0.2278904556868233, 0.0382061907026398, 0.0888060647788163, - -0.0078898845686437, 0.0019385598635839, -0.0791616129664364, - -0.083607647181527 , -0.0384037490026167, -0.0112690135575317}; + -0.0078898845686437, 0.0019385598635839, -0.0791616129664364, + -0.083607647181527, -0.0384037490026167, -0.0112690135575317}; std::vector expected_fm = { - -3.0778301386623275, -1.3135930534661662, -0.8332043979367366, - 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, - -0.5452347545527696, -0.2051506559632127, -0.4908015055951312, - 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0,}; + -3.0778301386623275, + -1.3135930534661662, + -0.8332043979367366, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -0.5452347545527696, + -0.2051506559632127, + -0.4908015055951312, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + }; int natoms; double expected_tot_e; @@ -144,7 +157,8 @@ TYPED_TEST(TestInferDeepPotDpaPtSpin, cpu_build_nlist_atomic) { deepmd::DeepPot& dp = this->dp; double ener; std::vector force, force_mag, virial, atom_ener, atom_vir; - dp.compute(ener, force, force_mag, virial, atom_ener, atom_vir, coord, spin, atype, box); + dp.compute(ener, force, force_mag, virial, atom_ener, atom_vir, coord, spin, + atype, box); EXPECT_EQ(force.size(), natoms * 3); EXPECT_EQ(force_mag.size(), natoms * 3); diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 6df66ff8ed..695d0879f6 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -903,7 +903,8 @@ void PairDeepMD::compute(int eflag, int vflag) { try { const vector &dcoord_const = dcoord; const vector &dspin_const = dspin; - deep_pot.compute(dener, dforce, dforce_mag, dvirial, dcoord_const, dspin_const, dtype, dbox); + deep_pot.compute(dener, dforce, dforce_mag, dvirial, dcoord_const, + dspin_const, dtype, dbox); } catch (deepmd_compat::deepmd_exception &e) { error->one(FLERR, e.what()); }