diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c911834c0..cff507abd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -47,6 +47,7 @@ Version 2022-dev - overhaul complete option handling (#704) - Fixed exciton options checking (#726) - added basis gpu runner and test to suite (#725) +- turned sigma choice into a factory (#731) Version 2021.2 (released XX.07.21) ================================== diff --git a/include/votca/xtp/sigmafactory.h b/include/votca/xtp/sigmafactory.h new file mode 100644 index 000000000..c64dee25e --- /dev/null +++ b/include/votca/xtp/sigmafactory.h @@ -0,0 +1,54 @@ +/* + * Copyright 2009-2021 The VOTCA Development Team + * (http://www.votca.org) + * + * Licensed under the Apache License, Version 2.0 (the "License") + * + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once + +#ifndef VOTCA_XTP_SIGMAFACTORY_H +#define VOTCA_XTP_SIGMAFACTORY_H + +// VOTCA includes +#include + +// Local VOTCA includes +#include "sigma_base.h" +#include "votca/xtp/rpa.h" +#include "votca/xtp/threecenter.h" + +namespace votca { +namespace xtp { + +class SigmaFactory : public tools::ObjectFactory { + private: + SigmaFactory() = default; + + public: + static void RegisterAll(void); + friend SigmaFactory &Sigma(); +}; + +inline SigmaFactory &Sigma() { + static SigmaFactory instance_; + return instance_; +} + +} // namespace xtp +} // namespace votca + +#endif // VOTCA_XTP_SIGMAFACTORY_H diff --git a/src/libxtp/factories/sigmafactory.cc b/src/libxtp/factories/sigmafactory.cc new file mode 100644 index 000000000..93c9fa378 --- /dev/null +++ b/src/libxtp/factories/sigmafactory.cc @@ -0,0 +1,38 @@ + +/* + * Copyright 2009-2021 The VOTCA Development Team + * (http://www.votca.org) + * + * Licensed under the Apache License, Version 2.0 (the "License") + * + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Local VOTCA includes +#include + +// Local private VOTCA includes +#include "self_energy_evaluators/sigma_cda.h" +#include "self_energy_evaluators/sigma_exact.h" +#include "self_energy_evaluators/sigma_ppm.h" + +namespace votca { +namespace xtp { + +void SigmaFactory::RegisterAll(void) { + Sigma().Register("cda"); + Sigma().Register("exact"); + Sigma().Register("ppm"); +} +} // namespace xtp +} // namespace votca diff --git a/src/libxtp/gwbse/gw.cc b/src/libxtp/gwbse/gw.cc index 689bfdf50..adcac45c6 100644 --- a/src/libxtp/gwbse/gw.cc +++ b/src/libxtp/gwbse/gw.cc @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 The VOTCA Development Team + * Copyright 2009-2021 The VOTCA Development Team * (http://www.votca.org) * * Licensed under the Apache License, Version 2.0 (the "License") @@ -27,24 +27,17 @@ #include "votca/xtp/gw.h" #include "votca/xtp/newton_rapson.h" #include "votca/xtp/rpa.h" -#include "votca/xtp/sigma_cda.h" -#include "votca/xtp/sigma_exact.h" -#include "votca/xtp/sigma_ppm.h" +#include "votca/xtp/sigmafactory.h" namespace votca { namespace xtp { void GW::configure(const options& opt) { + Sigma().RegisterAll(); opt_ = opt; qptotal_ = opt_.qpmax - opt_.qpmin + 1; rpa_.configure(opt_.homo, opt_.rpamin, opt_.rpamax); - if (opt_.sigma_integration == "exact") { - sigma_ = std::make_unique(Mmn_, rpa_); - } else if (opt_.sigma_integration == "cda") { - sigma_ = std::make_unique(Mmn_, rpa_); - } else if (opt_.sigma_integration == "ppm") { - sigma_ = std::make_unique(Mmn_, rpa_); - } + sigma_ = Sigma().Create(opt_.sigma_integration, Mmn_, rpa_); Sigma_base::options sigma_opt; sigma_opt.homo = opt_.homo; sigma_opt.qpmax = opt_.qpmax; diff --git a/src/libxtp/gwbse/sigma_cda.cc b/src/libxtp/self_energy_evaluators/sigma_cda.cc similarity index 98% rename from src/libxtp/gwbse/sigma_cda.cc rename to src/libxtp/self_energy_evaluators/sigma_cda.cc index fbb42eac7..faffd7f9d 100644 --- a/src/libxtp/gwbse/sigma_cda.cc +++ b/src/libxtp/self_energy_evaluators/sigma_cda.cc @@ -17,9 +17,9 @@ * */ +#include "sigma_cda.h" +#include "votca/xtp/gw.h" #include -#include -#include namespace votca { namespace xtp { diff --git a/include/votca/xtp/sigma_cda.h b/src/libxtp/self_energy_evaluators/sigma_cda.h similarity index 100% rename from include/votca/xtp/sigma_cda.h rename to src/libxtp/self_energy_evaluators/sigma_cda.h diff --git a/src/libxtp/gwbse/sigma_exact.cc b/src/libxtp/self_energy_evaluators/sigma_exact.cc similarity index 99% rename from src/libxtp/gwbse/sigma_exact.cc rename to src/libxtp/self_energy_evaluators/sigma_exact.cc index f44940deb..b92e8683a 100644 --- a/src/libxtp/gwbse/sigma_exact.cc +++ b/src/libxtp/self_energy_evaluators/sigma_exact.cc @@ -18,7 +18,7 @@ */ // Local VOTCA includes -#include "votca/xtp/sigma_exact.h" +#include "sigma_exact.h" #include "votca/xtp/rpa.h" #include "votca/xtp/threecenter.h" #include "votca/xtp/vc2index.h" diff --git a/include/votca/xtp/sigma_exact.h b/src/libxtp/self_energy_evaluators/sigma_exact.h similarity index 96% rename from include/votca/xtp/sigma_exact.h rename to src/libxtp/self_energy_evaluators/sigma_exact.h index 636d4f938..fbfc55f7b 100644 --- a/include/votca/xtp/sigma_exact.h +++ b/src/libxtp/self_energy_evaluators/sigma_exact.h @@ -21,8 +21,8 @@ #define VOTCA_XTP_SIGMA_EXACT_H // Local VOTCA includes -#include "rpa.h" -#include "sigma_base.h" +#include "votca/xtp/rpa.h" +#include "votca/xtp/sigma_base.h" namespace votca { namespace xtp { diff --git a/src/libxtp/gwbse/sigma_ppm.cc b/src/libxtp/self_energy_evaluators/sigma_ppm.cc similarity index 99% rename from src/libxtp/gwbse/sigma_ppm.cc rename to src/libxtp/self_energy_evaluators/sigma_ppm.cc index 679cbc82d..274389627 100644 --- a/src/libxtp/gwbse/sigma_ppm.cc +++ b/src/libxtp/self_energy_evaluators/sigma_ppm.cc @@ -22,8 +22,8 @@ #include // Local VOTCA includes +#include "sigma_ppm.h" #include "votca/xtp/ppm.h" -#include "votca/xtp/sigma_ppm.h" #include "votca/xtp/threecenter.h" namespace votca { diff --git a/include/votca/xtp/sigma_ppm.h b/src/libxtp/self_energy_evaluators/sigma_ppm.h similarity index 96% rename from include/votca/xtp/sigma_ppm.h rename to src/libxtp/self_energy_evaluators/sigma_ppm.h index 4b621a061..56c72e8a9 100644 --- a/include/votca/xtp/sigma_ppm.h +++ b/src/libxtp/self_energy_evaluators/sigma_ppm.h @@ -22,8 +22,8 @@ #define VOTCA_XTP_SIGMA_PPM_H // Local VOTCA includes -#include "ppm.h" -#include "sigma_base.h" +#include "votca/xtp/ppm.h" +#include "votca/xtp/sigma_base.h" namespace votca { namespace xtp { diff --git a/src/tests/test_sigma_cda.cc b/src/tests/test_sigma_cda.cc index 04c41f482..bfbe9d9d4 100644 --- a/src/tests/test_sigma_cda.cc +++ b/src/tests/test_sigma_cda.cc @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) + * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. * */ +#include "votca/xtp/sigma_base.h" #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE sigma_test @@ -30,7 +31,7 @@ #include #include #include -#include +#include #include using namespace votca::xtp; using namespace std; @@ -65,8 +66,9 @@ BOOST_AUTO_TEST_CASE(sigma_full) { rpa.setRPAInputEnergies(mo_energy); rpa.configure(4, 0, 16); - Sigma_CDA sigma(Mmn, rpa); - Sigma_CDA::options opt; + Sigma().RegisterAll(); + std::unique_ptr sigma = Sigma().Create("cda", Mmn, rpa); + Sigma_base::options opt; opt.homo = 4; opt.qpmin = 0; opt.qpmax = 16; @@ -75,9 +77,9 @@ BOOST_AUTO_TEST_CASE(sigma_full) { opt.quadrature_scheme = "legendre"; opt.order = 100; opt.alpha = 1e-3; - sigma.configure(opt); + sigma->configure(opt); - Eigen::MatrixXd x = sigma.CalcExchangeMatrix(); + Eigen::MatrixXd x = sigma->CalcExchangeMatrix(); Eigen::MatrixXd x_ref = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_cda/x_ref.mm"); @@ -90,9 +92,9 @@ BOOST_AUTO_TEST_CASE(sigma_full) { cout << x_ref << endl; } BOOST_CHECK_EQUAL(check_x, true); - sigma.PrepareScreening(); - Eigen::MatrixXd c = sigma.CalcCorrelationOffDiag(mo_energy); - c.diagonal() = sigma.CalcCorrelationDiag(mo_energy); + sigma->PrepareScreening(); + Eigen::MatrixXd c = sigma->CalcCorrelationOffDiag(mo_energy); + c.diagonal() = sigma->CalcCorrelationDiag(mo_energy); Eigen::MatrixXd c_ref_diag = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_cda/c_ref.mm"); diff --git a/src/tests/test_sigma_exact.cc b/src/tests/test_sigma_exact.cc index f2e0e15dd..34cca48e8 100644 --- a/src/tests/test_sigma_exact.cc +++ b/src/tests/test_sigma_exact.cc @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) + * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. * */ +#include "votca/xtp/sigma_base.h" #include #define BOOST_TEST_MAIN @@ -31,7 +32,7 @@ #include "votca/xtp/aobasis.h" #include "votca/xtp/orbitals.h" #include "votca/xtp/rpa.h" -#include "votca/xtp/sigma_exact.h" +#include "votca/xtp/sigmafactory.h" #include "votca/xtp/threecenter.h" using namespace votca::xtp; @@ -66,18 +67,19 @@ BOOST_AUTO_TEST_CASE(sigma_full) { RPA rpa(log, Mmn); rpa.setRPAInputEnergies(mo_energy); rpa.configure(4, 0, 16); + Sigma().RegisterAll(); + std::unique_ptr sigma = Sigma().Create("exact", Mmn, rpa); - Sigma_Exact sigma = Sigma_Exact(Mmn, rpa); - Sigma_Exact::options opt; + Sigma_base::options opt; opt.homo = 4; opt.qpmin = 0; opt.qpmax = 16; opt.rpamin = 0; opt.rpamax = 16; opt.eta = 1e-3; - sigma.configure(opt); + sigma->configure(opt); - Eigen::MatrixXd x = sigma.CalcExchangeMatrix(); + Eigen::MatrixXd x = sigma->CalcExchangeMatrix(); Eigen::MatrixXd x_ref = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_exact/x_ref.mm"); @@ -91,9 +93,9 @@ BOOST_AUTO_TEST_CASE(sigma_full) { } BOOST_CHECK_EQUAL(check_x, true); - sigma.PrepareScreening(); - Eigen::MatrixXd c = sigma.CalcCorrelationOffDiag(mo_energy); - c.diagonal() = sigma.CalcCorrelationDiag(mo_energy); + sigma->PrepareScreening(); + Eigen::MatrixXd c = sigma->CalcCorrelationOffDiag(mo_energy); + c.diagonal() = sigma->CalcCorrelationDiag(mo_energy); Eigen::MatrixXd c_ref = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_exact/c_ref.mm"); diff --git a/src/tests/test_sigma_ppm.cc b/src/tests/test_sigma_ppm.cc index 06ec7c5dc..3c7af3c9a 100644 --- a/src/tests/test_sigma_ppm.cc +++ b/src/tests/test_sigma_ppm.cc @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) + * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. * */ +#include "votca/xtp/sigma_base.h" #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE sigma_test @@ -32,7 +33,7 @@ #include "votca/xtp/orbitals.h" #include "votca/xtp/ppm.h" #include "votca/xtp/rpa.h" -#include "votca/xtp/sigma_ppm.h" +#include "votca/xtp/sigmafactory.h" #include "votca/xtp/threecenter.h" #include using namespace votca::xtp; @@ -67,18 +68,19 @@ BOOST_AUTO_TEST_CASE(sigma_full) { rpa.configure(4, 0, 16); rpa.setRPAInputEnergies(mo_energy); - Sigma_PPM sigma = Sigma_PPM(Mmn, rpa); + Sigma().RegisterAll(); + std::unique_ptr sigma = Sigma().Create("ppm", Mmn, rpa); - Sigma_PPM::options opt; + Sigma_base::options opt; opt.homo = 4; opt.qpmin = 0; opt.qpmax = 16; opt.rpamin = 0; opt.rpamax = 16; opt.eta = 1e-3; - sigma.configure(opt); + sigma->configure(opt); - Eigen::MatrixXd x = sigma.CalcExchangeMatrix(); + Eigen::MatrixXd x = sigma->CalcExchangeMatrix(); Eigen::MatrixXd x_ref = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_ppm/x_ref.mm"); @@ -92,9 +94,9 @@ BOOST_AUTO_TEST_CASE(sigma_full) { } BOOST_CHECK_EQUAL(check_x, true); - sigma.PrepareScreening(); - Eigen::MatrixXd c = sigma.CalcCorrelationOffDiag(mo_energy); - c.diagonal() = sigma.CalcCorrelationDiag(mo_energy); + sigma->PrepareScreening(); + Eigen::MatrixXd c = sigma->CalcCorrelationOffDiag(mo_energy); + c.diagonal() = sigma->CalcCorrelationDiag(mo_energy); Eigen::MatrixXd c_ref = votca::tools::EigenIO_MatrixMarket::ReadMatrix( std::string(XTP_TEST_DATA_FOLDER) + "/sigma_ppm/c_ref.mm");