From f75dab6c71c11a603b4d6da1df1de1fdf2a788d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:01:32 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/api_cc/src/DeepPot.cc | 1392 +++++++++++++++++++--------------- 1 file changed, 786 insertions(+), 606 deletions(-) diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index efe78417d3..e7e89b5cd5 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -42,667 +42,847 @@ void DeepPot::init(const std::string& model, backend = deepmd::DPBackend::PyTorch; } else if (model.length() >= 3 && model.substr(model.length() - 3) == ".pb") { backend = deepmd::DPBackend::TensorFlow; + } else { + throw deepmd::deepmd_exception("Unsupported model file format"); } - else { - throw deepmd::deepmd_exception("Unsupported model file format"); - } - if (deepmd::DPBackend::TensorFlow == backend) { + if (deepmd::DPBackend::TensorFlow == backend) { #ifdef BUILD_TENSORFLOW - dp = std::make_shared(model, gpu_rank, file_content); + dp = std::make_shared(model, gpu_rank, file_content); #else - throw deepmd::deepmd_exception("TensorFlow backend is not built"); + throw deepmd::deepmd_exception("TensorFlow backend is not built"); #endif - } else if (deepmd::DPBackend::PyTorch == backend) { - // throw deepmd::deepmd_exception("PyTorch backend is not supported yet"); + } else if (deepmd::DPBackend::PyTorch == backend) { + // throw deepmd::deepmd_exception("PyTorch backend is not supported yet"); #ifdef BUILD_PYTORCH - dp = std::make_shared(model, gpu_rank, file_content); + dp = std::make_shared(model, gpu_rank, file_content); #else - throw deepmd::deepmd_exception("PyTorch backend is not built"); + throw deepmd::deepmd_exception("PyTorch backend is not built"); #endif - } else if (deepmd::DPBackend::Paddle == backend) { - throw deepmd::deepmd_exception( - "PaddlePaddle backend is not supported yet"); - } else { - throw deepmd::deepmd_exception("Unknown file type"); - } - inited = true; + } else if (deepmd::DPBackend::Paddle == backend) { + throw deepmd::deepmd_exception("PaddlePaddle backend is not supported yet"); + } else { + throw deepmd::deepmd_exception("Unknown file type"); } + inited = true; +} - void DeepPot::print_summary(const std::string& pre) const { - deepmd::print_summary(pre); - } +void DeepPot::print_summary(const std::string& pre) const { + deepmd::print_summary(pre); +} - template - void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam_, - const std::vector& aparam_) { - std::vector dener_; - std::vector datom_energy_, datom_virial_; - dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, - dcoord_, datype_, dbox, fparam_, aparam_); - dener = dener_[0]; - } +template +void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector dener_; + std::vector datom_energy_, datom_virial_; + dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, fparam_, aparam_); + dener = dener_[0]; +} - template - void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam_, - const std::vector& aparam_) { - std::vector datom_energy_, datom_virial_; - dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, - datype_, dbox, fparam_, aparam_); - } +template +void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector datom_energy_, datom_virial_; + dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, fparam_, aparam_); +} - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template - void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam_, - const std::vector& aparam__) { - std::vector dener_; - std::vector datom_energy_, datom_virial_; - dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, - dcoord_, datype_, dbox, nghost, lmp_list, ago, fparam_, - aparam__); - dener = dener_[0]; - } +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template +void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam_, + const std::vector& aparam__) { + std::vector dener_; + std::vector datom_energy_, datom_virial_; + dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); + dener = dener_[0]; +} - template - void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam_, - const std::vector& aparam__) { - std::vector datom_energy_, datom_virial_; - dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, - datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); - } +template +void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam_, + const std::vector& aparam__) { + std::vector datom_energy_, datom_virial_; + dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); +} - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template - void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - std::vector dener_; - dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, - dcoord_, datype_, dbox, fparam_, aparam_); - dener = dener_[0]; - } - template - void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, - datype_, dbox, fparam_, aparam_); - } +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template +void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector dener_; + dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, fparam_, aparam_); + dener = dener_[0]; +} +template +void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, fparam_, aparam_); +} - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const std::vector& fparam, const std::vector& aparam); - - template - void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam_, - const std::vector& aparam__) { - std::vector dener_; - dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, - dcoord_, datype_, dbox, nghost, lmp_list, ago, fparam_, - aparam__); - dener = dener_[0]; - } - template - void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam_, - const std::vector& aparam__) { - dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, - datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); - } +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template +void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam_, + const std::vector& aparam__) { + std::vector dener_; + dp->computew(dener_, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); + dener = dener_[0]; +} +template +void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam_, + const std::vector& aparam__) { + dp->computew(dener, dforce_, dvirial, datom_energy_, datom_virial_, dcoord_, + datype_, dbox, nghost, lmp_list, ago, fparam_, aparam__); +} - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - template void DeepPot::compute( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const std::vector& dcoord_, - const std::vector& datype_, const std::vector& dbox, - const int nghost, const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam_); - - // mixed type - template - void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - std::vector dener_; - std::vector datom_energy_, datom_virial_; - dp->computew_mixed_type(dener_, dforce_, dvirial, datom_energy_, - datom_virial_, nframes, dcoord_, datype_, dbox, - fparam_, aparam_); - dener = dener_[0]; - } - template - void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - std::vector datom_energy_, datom_virial_; - dp->computew_mixed_type(dener, dforce_, dvirial, datom_energy_, - datom_virial_, nframes, dcoord_, datype_, dbox, - fparam_, aparam_); - } +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +template void DeepPot::compute(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_); + +// mixed type +template +void DeepPot::compute_mixed_type(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector dener_; + std::vector datom_energy_, datom_virial_; + dp->computew_mixed_type(dener_, dforce_, dvirial, datom_energy_, + datom_virial_, nframes, dcoord_, datype_, dbox, + fparam_, aparam_); + dener = dener_[0]; +} +template +void DeepPot::compute_mixed_type(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector datom_energy_, datom_virial_; + dp->computew_mixed_type(dener, dforce_, dvirial, datom_energy_, datom_virial_, + nframes, dcoord_, datype_, dbox, fparam_, aparam_); +} - template void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template - void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - std::vector dener_; - dp->computew_mixed_type(dener_, dforce_, dvirial, datom_energy_, - datom_virial_, nframes, dcoord_, datype_, dbox, - fparam_, aparam_); - dener = dener_[0]; - } - template - void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam_, - const std::vector& aparam_) { - dp->computew_mixed_type(dener, dforce_, dvirial, datom_energy_, - datom_virial_, nframes, dcoord_, datype_, dbox, - fparam_, aparam_); - } +template void DeepPot::compute_mixed_type( + ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template +void DeepPot::compute_mixed_type(ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + std::vector dener_; + dp->computew_mixed_type(dener_, dforce_, dvirial, datom_energy_, + datom_virial_, nframes, dcoord_, datype_, dbox, + fparam_, aparam_); + dener = dener_[0]; +} +template +void DeepPot::compute_mixed_type(std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam_, + const std::vector& aparam_) { + dp->computew_mixed_type(dener, dforce_, dvirial, datom_energy_, datom_virial_, + nframes, dcoord_, datype_, dbox, fparam_, aparam_); +} - template void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - ENERGYTYPE & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - template void DeepPot::compute_mixed_type( - std::vector & dener, std::vector & dforce_, - std::vector & dvirial, std::vector & datom_energy_, - std::vector & datom_virial_, const int& nframes, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const std::vector& fparam, - const std::vector& aparam); - - double DeepPot::cutoff() const { return dp->cutoff(); } - - int DeepPot::numb_types() const { return dp->numb_types(); } - - int DeepPot::numb_types_spin() const { return dp->numb_types_spin(); } - - int DeepPot::dim_fparam() const { return dp->dim_fparam(); } - - int DeepPot::dim_aparam() const { return dp->dim_aparam(); } - - void DeepPot::get_type_map(std::string & type_map) { - dp->get_type_map(type_map); - } +template void DeepPot::compute_mixed_type( + ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + ENERGYTYPE& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPot::compute_mixed_type( + std::vector& dener, + std::vector& dforce_, + std::vector& dvirial, + std::vector& datom_energy_, + std::vector& datom_virial_, + const int& nframes, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const std::vector& fparam, + const std::vector& aparam); + +double DeepPot::cutoff() const { return dp->cutoff(); } + +int DeepPot::numb_types() const { return dp->numb_types(); } + +int DeepPot::numb_types_spin() const { return dp->numb_types_spin(); } + +int DeepPot::dim_fparam() const { return dp->dim_fparam(); } + +int DeepPot::dim_aparam() const { return dp->dim_aparam(); } + +void DeepPot::get_type_map(std::string& type_map) { + dp->get_type_map(type_map); +} - bool DeepPot::is_aparam_nall() const { return dp->is_aparam_nall(); } +bool DeepPot::is_aparam_nall() const { return dp->is_aparam_nall(); } - DeepPotModelDevi::DeepPotModelDevi() : inited(false), numb_models(0) {} +DeepPotModelDevi::DeepPotModelDevi() : inited(false), numb_models(0) {} - DeepPotModelDevi::DeepPotModelDevi( - const std::vector& models, const int& gpu_rank, - const std::vector& file_contents) - : inited(false), numb_models(0) { - init(models, gpu_rank, file_contents); - } +DeepPotModelDevi::DeepPotModelDevi( + const std::vector& models, + const int& gpu_rank, + const std::vector& file_contents) + : inited(false), numb_models(0) { + init(models, gpu_rank, file_contents); +} - DeepPotModelDevi::~DeepPotModelDevi() {} +DeepPotModelDevi::~DeepPotModelDevi() {} - void DeepPotModelDevi::init(const std::vector& models, - const int& gpu_rank, - const std::vector& file_contents) { - if (inited) { - std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " - "nothing at the second call of initializer" - << std::endl; - return; - } - numb_models = models.size(); - if (numb_models == 0) { - throw deepmd::deepmd_exception("no model is specified"); - } - dps.resize(numb_models); - for (unsigned int ii = 0; ii < numb_models; ++ii) { - dps[ii].init(models[ii], gpu_rank, - file_contents.size() > ii ? file_contents[ii] : ""); - } - inited = true; +void DeepPotModelDevi::init(const std::vector& models, + const int& gpu_rank, + const std::vector& file_contents) { + if (inited) { + std::cerr << "WARNING: deepmd-kit should not be initialized twice, do " + "nothing at the second call of initializer" + << std::endl; + return; } - - template - void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, - const std::vector& aparam_) { - 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, nghost, lmp_list, ago, fparam, aparam_); - } + numb_models = models.size(); + if (numb_models == 0) { + throw deepmd::deepmd_exception("no model is specified"); } + dps.resize(numb_models); + for (unsigned int ii = 0; ii < numb_models; ++ii) { + dps[ii].init(models[ii], gpu_rank, + file_contents.size() > ii ? file_contents[ii] : ""); + } + inited = true; +} - template void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam); - - template - void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - std::vector> & all_atom_energy, - std::vector> & all_atom_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, - const std::vector& aparam_) { - if (numb_models == 0) { - return; - } - all_energy.resize(numb_models); - all_force.resize(numb_models); - all_virial.resize(numb_models); - all_atom_energy.resize(numb_models); - all_atom_virial.resize(numb_models); - for (unsigned ii = 0; ii < numb_models; ++ii) { - dps[ii].compute(all_energy[ii], all_force[ii], all_virial[ii], - all_atom_energy[ii], all_atom_virial[ii], dcoord_, - datype_, dbox, nghost, lmp_list, ago, fparam, aparam_); - } +template +void DeepPotModelDevi::compute(std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_) { + 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, nghost, lmp_list, ago, fparam, aparam_); } +} - template void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - std::vector> & all_atom_energy, - std::vector> & all_atom_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam); - - template void DeepPotModelDevi::compute( - std::vector & all_energy, - std::vector> & all_force, - std::vector> & all_virial, - std::vector> & all_atom_energy, - std::vector> & all_atom_virial, - const std::vector& dcoord_, const std::vector& datype_, - const std::vector& dbox, const int nghost, - const InputNlist& lmp_list, const int& ago, - const std::vector& fparam, const std::vector& aparam); - - template - void DeepPotModelDevi::compute_avg(VALUETYPE & dener, - const std::vector& all_energy) { - assert(all_energy.size() == numb_models); - if (numb_models == 0) { - return; - } +template void DeepPotModelDevi::compute( + std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPotModelDevi::compute( + std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam); + +template +void DeepPotModelDevi::compute( + std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + std::vector>& all_atom_energy, + std::vector>& all_atom_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam_) { + if (numb_models == 0) { + return; + } + all_energy.resize(numb_models); + all_force.resize(numb_models); + all_virial.resize(numb_models); + all_atom_energy.resize(numb_models); + all_atom_virial.resize(numb_models); + for (unsigned ii = 0; ii < numb_models; ++ii) { + dps[ii].compute(all_energy[ii], all_force[ii], all_virial[ii], + all_atom_energy[ii], all_atom_virial[ii], dcoord_, datype_, + dbox, nghost, lmp_list, ago, fparam, aparam_); + } +} - dener = 0; - for (unsigned ii = 0; ii < numb_models; ++ii) { - dener += all_energy[ii]; - } - dener /= (VALUETYPE)(numb_models); +template void DeepPotModelDevi::compute( + std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + std::vector>& all_atom_energy, + std::vector>& all_atom_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam); + +template void DeepPotModelDevi::compute( + std::vector& all_energy, + std::vector>& all_force, + std::vector>& all_virial, + std::vector>& all_atom_energy, + std::vector>& all_atom_virial, + const std::vector& dcoord_, + const std::vector& datype_, + const std::vector& dbox, + const int nghost, + const InputNlist& lmp_list, + const int& ago, + const std::vector& fparam, + const std::vector& aparam); + +template +void DeepPotModelDevi::compute_avg(VALUETYPE& dener, + const std::vector& all_energy) { + assert(all_energy.size() == numb_models); + if (numb_models == 0) { + return; } - template void DeepPotModelDevi::compute_avg( - double& dener, const std::vector& all_energy); + dener = 0; + for (unsigned ii = 0; ii < numb_models; ++ii) { + dener += all_energy[ii]; + } + dener /= (VALUETYPE)(numb_models); +} - template void DeepPotModelDevi::compute_avg( - float& dener, const std::vector& all_energy); +template void DeepPotModelDevi::compute_avg( + double& dener, const std::vector& all_energy); - template - void DeepPotModelDevi::compute_avg( - std::vector & avg, - const std::vector>& xx) { - assert(xx.size() == numb_models); - if (numb_models == 0) { - return; - } +template void DeepPotModelDevi::compute_avg( + float& dener, const std::vector& all_energy); - avg.resize(xx[0].size()); - fill(avg.begin(), avg.end(), VALUETYPE(0.)); +template +void DeepPotModelDevi::compute_avg( + std::vector& avg, + const std::vector>& xx) { + assert(xx.size() == numb_models); + if (numb_models == 0) { + return; + } - for (unsigned ii = 0; ii < numb_models; ++ii) { - for (unsigned jj = 0; jj < avg.size(); ++jj) { - avg[jj] += xx[ii][jj]; - } - } + avg.resize(xx[0].size()); + fill(avg.begin(), avg.end(), VALUETYPE(0.)); + for (unsigned ii = 0; ii < numb_models; ++ii) { for (unsigned jj = 0; jj < avg.size(); ++jj) { - avg[jj] /= VALUETYPE(numb_models); + avg[jj] += xx[ii][jj]; } } - template void DeepPotModelDevi::compute_avg( - std::vector & avg, const std::vector>& xx); - - template void DeepPotModelDevi::compute_avg( - std::vector & avg, const std::vector>& xx); - - template - void DeepPotModelDevi::compute_std( - std::vector & std, const std::vector& avg, - const std::vector>& xx, const int& stride) { - assert(xx.size() == numb_models); - if (numb_models == 0) { - return; - } - - unsigned ndof = avg.size(); - unsigned nloc = ndof / stride; - assert(nloc * stride == ndof); - - std.resize(nloc); - fill(std.begin(), std.end(), VALUETYPE(0.)); - - for (unsigned ii = 0; ii < numb_models; ++ii) { - for (unsigned jj = 0; jj < nloc; ++jj) { - const VALUETYPE* tmp_f = &(xx[ii][static_cast(jj) * stride]); - const VALUETYPE* tmp_avg = &(avg[static_cast(jj) * stride]); - for (unsigned dd = 0; dd < stride; ++dd) { - VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; - std[jj] += vdiff * vdiff; - } - } - } - - for (unsigned jj = 0; jj < nloc; ++jj) { - std[jj] = sqrt(std[jj] / VALUETYPE(numb_models)); - } + for (unsigned jj = 0; jj < avg.size(); ++jj) { + avg[jj] /= VALUETYPE(numb_models); } +} - template void DeepPotModelDevi::compute_std( - std::vector & std, const std::vector& avg, - const std::vector>& xx, const int& stride); +template void DeepPotModelDevi::compute_avg( + std::vector& avg, const std::vector>& xx); - template void DeepPotModelDevi::compute_std( - std::vector & std, const std::vector& avg, - const std::vector>& xx, const int& stride); +template void DeepPotModelDevi::compute_avg( + std::vector& avg, const std::vector>& xx); - template - void DeepPotModelDevi::compute_std_e( - std::vector & std, const std::vector& avg, - const std::vector>& xx) { - compute_std(std, avg, xx, 1); +template +void DeepPotModelDevi::compute_std( + std::vector& std, + const std::vector& avg, + const std::vector>& xx, + const int& stride) { + assert(xx.size() == numb_models); + if (numb_models == 0) { + return; } - template void DeepPotModelDevi::compute_std_e( - std::vector & std, const std::vector& avg, - const std::vector>& xx); - - template void DeepPotModelDevi::compute_std_e( - std::vector & std, const std::vector& avg, - const std::vector>& xx); + unsigned ndof = avg.size(); + unsigned nloc = ndof / stride; + assert(nloc * stride == ndof); - template - void DeepPotModelDevi::compute_std_f( - std::vector & std, const std::vector& avg, - const std::vector>& xx) { - compute_std(std, avg, xx, 3); - } + std.resize(nloc); + fill(std.begin(), std.end(), VALUETYPE(0.)); - template void DeepPotModelDevi::compute_std_f( - std::vector & std, const std::vector& avg, - const std::vector>& xx); - - template void DeepPotModelDevi::compute_std_f( - std::vector & std, const std::vector& avg, - const std::vector>& xx); - - template - void DeepPotModelDevi::compute_relative_std( - std::vector & std, const std::vector& avg, - const VALUETYPE eps, const int& stride) { - unsigned ndof = avg.size(); - unsigned nloc = std.size(); - assert(nloc * stride == ndof); - - for (unsigned ii = 0; ii < nloc; ++ii) { - const VALUETYPE* tmp_avg = &(avg[static_cast(ii) * stride]); - VALUETYPE f_norm = 0.0; + for (unsigned ii = 0; ii < numb_models; ++ii) { + for (unsigned jj = 0; jj < nloc; ++jj) { + const VALUETYPE* tmp_f = &(xx[ii][static_cast(jj) * stride]); + const VALUETYPE* tmp_avg = &(avg[static_cast(jj) * stride]); for (unsigned dd = 0; dd < stride; ++dd) { - f_norm += tmp_avg[dd] * tmp_avg[dd]; + VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; + std[jj] += vdiff * vdiff; } - f_norm = sqrt(f_norm); - std[ii] /= f_norm + eps; } } - template void DeepPotModelDevi::compute_relative_std( - std::vector & std, const std::vector& avg, - const double eps, const int& stride); + for (unsigned jj = 0; jj < nloc; ++jj) { + std[jj] = sqrt(std[jj] / VALUETYPE(numb_models)); + } +} - template void DeepPotModelDevi::compute_relative_std( - std::vector & std, const std::vector& avg, const float eps, - const int& stride); +template void DeepPotModelDevi::compute_std( + std::vector& std, + const std::vector& avg, + const std::vector>& xx, + const int& stride); + +template void DeepPotModelDevi::compute_std( + std::vector& std, + const std::vector& avg, + const std::vector>& xx, + const int& stride); + +template +void DeepPotModelDevi::compute_std_e( + std::vector& std, + const std::vector& avg, + const std::vector>& xx) { + compute_std(std, avg, xx, 1); +} - template - void DeepPotModelDevi::compute_relative_std_f( - std::vector & std, const std::vector& avg, - const VALUETYPE eps) { - compute_relative_std(std, avg, eps, 3); +template void DeepPotModelDevi::compute_std_e( + std::vector& std, + const std::vector& avg, + const std::vector>& xx); + +template void DeepPotModelDevi::compute_std_e( + std::vector& std, + const std::vector& avg, + const std::vector>& xx); + +template +void DeepPotModelDevi::compute_std_f( + std::vector& std, + const std::vector& avg, + const std::vector>& xx) { + compute_std(std, avg, xx, 3); +} + +template void DeepPotModelDevi::compute_std_f( + std::vector& std, + const std::vector& avg, + const std::vector>& xx); + +template void DeepPotModelDevi::compute_std_f( + std::vector& std, + const std::vector& avg, + const std::vector>& xx); + +template +void DeepPotModelDevi::compute_relative_std(std::vector& std, + const std::vector& avg, + const VALUETYPE eps, + const int& stride) { + unsigned ndof = avg.size(); + unsigned nloc = std.size(); + assert(nloc * stride == ndof); + + for (unsigned ii = 0; ii < nloc; ++ii) { + const VALUETYPE* tmp_avg = &(avg[static_cast(ii) * stride]); + VALUETYPE f_norm = 0.0; + for (unsigned dd = 0; dd < stride; ++dd) { + f_norm += tmp_avg[dd] * tmp_avg[dd]; + } + f_norm = sqrt(f_norm); + std[ii] /= f_norm + eps; } +} + +template void DeepPotModelDevi::compute_relative_std( + std::vector& std, + const std::vector& avg, + const double eps, + const int& stride); + +template void DeepPotModelDevi::compute_relative_std( + std::vector& std, + const std::vector& avg, + const float eps, + const int& stride); + +template +void DeepPotModelDevi::compute_relative_std_f(std::vector& std, + const std::vector& avg, + const VALUETYPE eps) { + compute_relative_std(std, avg, eps, 3); +} - template void DeepPotModelDevi::compute_relative_std_f( - std::vector & std, const std::vector& avg, - const double eps); +template void DeepPotModelDevi::compute_relative_std_f( + std::vector& std, const std::vector& avg, const double eps); - template void DeepPotModelDevi::compute_relative_std_f( - std::vector & std, const std::vector& avg, const float eps); +template void DeepPotModelDevi::compute_relative_std_f( + std::vector& std, const std::vector& avg, const float eps);