Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: model devi C/C++ API without nlist #3647

Merged
merged 10 commits into from
Apr 6, 2024
30 changes: 30 additions & 0 deletions source/api_cc/include/DeepPot.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,36 @@ class DeepPotModelDevi {
const std::vector<std::string>& file_contents =
std::vector<std::string>());

/**
* @brief Evaluate the energy, force and virial by using these DP models.
* @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_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] 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.
* @param[in] fparam The frame parameter. The array can be of size :
* nframes x dim_fparam.
* dim_fparam. Then all frames are assumed to be provided with the same
*fparam.
* @param[in] aparam The atomic parameter The array can be of size :
* nframes x natoms x dim_aparam.
* natoms x dim_aparam. Then all frames are assumed to be provided with the
*same aparam. dim_aparam. Then all frames and atoms are provided with the
*same aparam.
**/
template <typename VALUETYPE>
void compute(std::vector<ENERGYTYPE>& all_ener,
std::vector<std::vector<VALUETYPE> >& all_force,
std::vector<std::vector<VALUETYPE> >& all_virial,
const std::vector<VALUETYPE>& coord,
njzjz marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<int>& atype,
const std::vector<VALUETYPE>& box,
const std::vector<VALUETYPE>& fparam = std::vector<VALUETYPE>(),
const std::vector<VALUETYPE>& aparam = std::vector<VALUETYPE>());

/**
* @brief Evaluate the energy, force and virial by using these DP models.
* @param[out] all_ener The system energies of all models.
Expand Down
42 changes: 42 additions & 0 deletions source/api_cc/src/DeepPot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,48 @@ void DeepPotModelDevi::init(const std::vector<std::string>& models,
inited = true;
}

template <typename VALUETYPE>
void DeepPotModelDevi::compute(std::vector<ENERGYTYPE>& all_energy,
std::vector<std::vector<VALUETYPE>>& all_force,
std::vector<std::vector<VALUETYPE>>& all_virial,
const std::vector<VALUETYPE>& dcoord_,
const std::vector<int>& datype_,
const std::vector<VALUETYPE>& dbox,
const std::vector<VALUETYPE>& fparam,
const std::vector<VALUETYPE>& aparam_) {
// without nlist
if (numb_models == 0) {
return;
}
all_energy.resize(numb_models);
all_force.resize(numb_models);
all_virial.resize(numb_models);
for (unsigned ii = 0; ii < numb_models; ++ii) {
dps[ii].compute(all_energy[ii], all_force[ii], all_virial[ii], dcoord_,
datype_, dbox, fparam, aparam_);
}
}

template void DeepPotModelDevi::compute<double>(
std::vector<ENERGYTYPE>& all_energy,
std::vector<std::vector<double>>& all_force,
std::vector<std::vector<double>>& all_virial,
const std::vector<double>& dcoord_,
const std::vector<int>& datype_,
const std::vector<double>& dbox,
const std::vector<double>& fparam,
const std::vector<double>& aparam);

template void DeepPotModelDevi::compute<float>(
std::vector<ENERGYTYPE>& all_energy,
std::vector<std::vector<float>>& all_force,
std::vector<std::vector<float>>& all_virial,
const std::vector<float>& dcoord_,
const std::vector<int>& datype_,
const std::vector<float>& dbox,
const std::vector<float>& fparam,
const std::vector<float>& aparam);

template <typename VALUETYPE>
void DeepPotModelDevi::compute(std::vector<ENERGYTYPE>& all_energy,
std::vector<std::vector<VALUETYPE>>& all_force,
Expand Down