Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #731 from votca/sigma_factory
Browse files Browse the repository at this point in the history
made the choice of sigma a factory
  • Loading branch information
junghans authored Jul 29, 2021
2 parents f3bbe78 + b105421 commit 9cfeb74
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==================================
Expand Down
54 changes: 54 additions & 0 deletions include/votca/xtp/sigmafactory.h
Original file line number Diff line number Diff line change
@@ -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 <votca/tools/objectfactory.h>

// 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<std::string, Sigma_base,
TCMatrix_gwbse &, RPA &> {
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
38 changes: 38 additions & 0 deletions src/libxtp/factories/sigmafactory.cc
Original file line number Diff line number Diff line change
@@ -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 <votca/xtp/sigmafactory.h>

// 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<Sigma_CDA>("cda");
Sigma().Register<Sigma_Exact>("exact");
Sigma().Register<Sigma_PPM>("ppm");
}
} // namespace xtp
} // namespace votca
15 changes: 4 additions & 11 deletions src/libxtp/gwbse/gw.cc
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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<Sigma_Exact>(Mmn_, rpa_);
} else if (opt_.sigma_integration == "cda") {
sigma_ = std::make_unique<Sigma_CDA>(Mmn_, rpa_);
} else if (opt_.sigma_integration == "ppm") {
sigma_ = std::make_unique<Sigma_PPM>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*
*/

#include "sigma_cda.h"
#include "votca/xtp/gw.h"
#include <votca/tools/constants.h>
#include <votca/xtp/gw.h>
#include <votca/xtp/sigma_cda.h>

namespace votca {
namespace xtp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <votca/tools/globals.h>

// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 11 additions & 9 deletions src/tests/test_sigma_cda.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,6 +13,7 @@
* limitations under the License.
*
*/
#include "votca/xtp/sigma_base.h"
#define BOOST_TEST_MAIN

#define BOOST_TEST_MODULE sigma_test
Expand All @@ -30,7 +31,7 @@
#include <libint2/initialize.h>
#include <votca/xtp/aobasis.h>
#include <votca/xtp/orbitals.h>
#include <votca/xtp/sigma_cda.h>
#include <votca/xtp/sigmafactory.h>
#include <votca/xtp/threecenter.h>
using namespace votca::xtp;
using namespace std;
Expand Down Expand Up @@ -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_base> sigma = Sigma().Create("cda", Mmn, rpa);
Sigma_base::options opt;
opt.homo = 4;
opt.qpmin = 0;
opt.qpmax = 16;
Expand All @@ -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");
Expand All @@ -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");
Expand Down
20 changes: 11 additions & 9 deletions src/tests/test_sigma_exact.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,6 +13,7 @@
* limitations under the License.
*
*/
#include "votca/xtp/sigma_base.h"
#include <libint2/initialize.h>
#define BOOST_TEST_MAIN

Expand All @@ -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;
Expand Down Expand Up @@ -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_base> 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");
Expand All @@ -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");
Expand Down
20 changes: 11 additions & 9 deletions src/tests/test_sigma_ppm.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,6 +13,7 @@
* limitations under the License.
*
*/
#include "votca/xtp/sigma_base.h"
#define BOOST_TEST_MAIN

#define BOOST_TEST_MODULE sigma_test
Expand All @@ -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 <libint2/initialize.h>
using namespace votca::xtp;
Expand Down Expand Up @@ -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_base> 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");
Expand All @@ -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");
Expand Down

0 comments on commit 9cfeb74

Please sign in to comment.