diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index d0430d39d0..273344ffb6 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -38,850 +38,669 @@ void DeepPot::init(const std::string& model, return; } if (model.length() >= 4 && model.substr(model.length() - 4) == ".pth") { - DPBackend backend = deepmd::DPBackend::PyTorch; - } else if (model.length() >= 3 && model.substr(model.length() - 3) == ".pb") { - DPBackend backend = deepmd::DPBackend::TensorFlow; + DPBackend backend = deepmd::DPBackend::PyTorch; + } else if (model.length() >= 3 && model.substr(model.length() - 3) == ".pb") { + DPBackend backend = deepmd::DPBackend::TensorFlow; else { - throw deepmd::deepmd_exception("Unsupported model file format"); + 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"); + } 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; } - 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] : ""); + 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; } - 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_) { - 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, + 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, - 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); + + 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, - 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, + 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; + } - dener = 0; - for (unsigned ii = 0; ii < numb_models; ++ii) { - dener += all_energy[ii]; + dener = 0; + for (unsigned ii = 0; ii < numb_models; ++ii) { + dener += all_energy[ii]; + } + dener /= (VALUETYPE)(numb_models); } - dener /= (VALUETYPE)(numb_models); -} -template void DeepPotModelDevi::compute_avg( - double& dener, const std::vector& all_energy); + template void DeepPotModelDevi::compute_avg( + double& dener, const std::vector& all_energy); -template void DeepPotModelDevi::compute_avg( - float& dener, const std::vector& all_energy); + template void DeepPotModelDevi::compute_avg( + float& 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( + std::vector & avg, + const std::vector>& xx) { + assert(xx.size() == numb_models); + if (numb_models == 0) { + return; + } - avg.resize(xx[0].size()); - fill(avg.begin(), avg.end(), VALUETYPE(0.)); + 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] += xx[ii][jj]; + } + } - for (unsigned ii = 0; ii < numb_models; ++ii) { for (unsigned jj = 0; jj < avg.size(); ++jj) { - avg[jj] += xx[ii][jj]; + avg[jj] /= VALUETYPE(numb_models); } } - for (unsigned jj = 0; jj < avg.size(); ++jj) { - avg[jj] /= VALUETYPE(numb_models); + 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)); + } } -} -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( + 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) { - 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) { + compute_std(std, avg, xx, 1); } - unsigned ndof = avg.size(); - unsigned nloc = ndof / stride; - assert(nloc * stride == ndof); + template void DeepPotModelDevi::compute_std_e( + std::vector & std, const std::vector& avg, + const std::vector>& xx); - std.resize(nloc); - fill(std.begin(), std.end(), VALUETYPE(0.)); + template void DeepPotModelDevi::compute_std_e( + std::vector & std, const std::vector& avg, + const std::vector>& xx); - 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]); + 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) { - VALUETYPE vdiff = tmp_f[dd] - tmp_avg[dd]; - std[jj] += vdiff * vdiff; + f_norm += tmp_avg[dd] * tmp_avg[dd]; } + f_norm = sqrt(f_norm); + std[ii] /= f_norm + eps; } } - for (unsigned jj = 0; jj < nloc; ++jj) { - std[jj] = sqrt(std[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_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( + std::vector & std, const std::vector& avg, + const double eps, const int& stride); -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_relative_std( + std::vector & std, const std::vector& avg, const float eps, + const int& stride); -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_f( + std::vector & std, const std::vector& avg, + const VALUETYPE eps) { + compute_relative_std(std, avg, eps, 3); } -} - -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);