votca 2024.1-dev
Loading...
Searching...
No Matches
Overlap_filter.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Local VOTCA includes
21#include "votca/xtp/aomatrix.h"
22
23// Local private VOTCA includes
24#include "Overlap_filter.h"
25
26namespace votca {
27namespace xtp {
28
30 threshold_ = options.get(".").as<double>();
31}
32
33void Overlap_filter::Info(Logger& log) const {
34 if (threshold_ == 0.0) {
36 << "Using overlap filter with no threshold " << std::flush;
37 } else {
39 << "Using overlap filter with threshold " << threshold_ << std::flush;
40 }
41}
42
43Eigen::VectorXd Overlap_filter::CalculateOverlap(const Orbitals& orb,
44 QMStateType type) const {
45 AOOverlap S_ao;
46 S_ao.Fill(orb.getDftBasis());
47
48 Eigen::MatrixXd coeffs = CalcAOCoeffs(orb, type);
49 if (type.isSingleParticleState()) {
50 return (coeffs.transpose() * S_ao.Matrix() * laststatecoeff_).cwiseAbs();
51 } else {
52
53 Index basis = orb.getBasisSetSize();
54 Eigen::VectorXd overlap = Eigen::VectorXd::Zero(coeffs.cols());
55#pragma omp parallel for schedule(dynamic)
56 for (Index i = 0; i < coeffs.cols(); i++) {
57 {
58 Eigen::VectorXd state = coeffs.col(i).head(basis * basis);
59 Eigen::Map<const Eigen::MatrixXd> mat(state.data(), basis, basis);
60 Eigen::VectorXd laststate = laststatecoeff_.head(basis * basis);
61 Eigen::Map<const Eigen::MatrixXd> lastmat(laststate.data(), basis,
62 basis);
63
64 overlap(i) = (mat * S_ao.Matrix() * lastmat.transpose())
65 .cwiseProduct(S_ao.Matrix())
66 .sum();
67 }
68 if (!orb.getTDAApprox()) {
69 Eigen::VectorXd state = coeffs.col(i).tail(basis * basis);
70 Eigen::Map<const Eigen::MatrixXd> mat(state.data(), basis, basis);
71 Eigen::VectorXd laststate = laststatecoeff_.tail(basis * basis);
72 Eigen::Map<const Eigen::MatrixXd> lastmat(laststate.data(), basis,
73 basis);
74
75 overlap(i) -= (mat * S_ao.Matrix() * lastmat.transpose())
76 .cwiseProduct(S_ao.Matrix())
77 .sum();
78 }
79 }
80 return overlap.cwiseAbs();
81 }
82}
83
85 const Orbitals& orb, QMStateType type) const {
86 Eigen::MatrixXd coeffs;
87 Index nostates = orb.NumberofStates(type);
88 Index bse_cmax = orb.getBSEcmax();
89 Index bse_cmin = orb.getBSEcmin();
90 Index bse_vmax = orb.getBSEvmax();
91 Index bse_vmin = orb.getBSEvmin();
92 Index bse_vtotal = bse_vmax - bse_vmin + 1;
93 Index bse_ctotal = bse_cmax - bse_cmin + 1;
94 Index basis = orb.getBasisSetSize();
95 Index bse_size_ao = basis * basis;
96 auto occlevels = orb.MOs().eigenvectors().middleCols(bse_vmin, bse_vtotal);
97 auto virtlevels = orb.MOs().eigenvectors().middleCols(bse_cmin, bse_ctotal);
98
99 if (orb.getTDAApprox()) {
100 coeffs.resize(bse_size_ao, nostates);
101 } else {
102 coeffs.resize(2 * bse_size_ao, nostates);
103 }
104#pragma omp parallel for schedule(dynamic)
105 for (Index i = 0; i < nostates; i++) {
106 {
107 Eigen::VectorXd exciton;
108 if (type == QMStateType::Singlet) {
109 exciton = orb.BSESinglets().eigenvectors().col(i);
110 } else {
111 exciton = orb.BSETriplets().eigenvectors().col(i);
112 }
113 Eigen::Map<const Eigen::MatrixXd> mat(exciton.data(), bse_ctotal,
114 bse_vtotal);
115 const Eigen::MatrixXd aomatrix =
116 occlevels * mat.transpose() * virtlevels.transpose();
117 coeffs.col(i).head(bse_size_ao) =
118 Eigen::Map<const Eigen::VectorXd>(aomatrix.data(), bse_size_ao);
119 }
120 if (!orb.getTDAApprox()) {
121 Eigen::VectorXd exciton;
122 if (type == QMStateType::Singlet) {
123 exciton = orb.BSESinglets().eigenvectors2().col(i);
124 } else {
125 exciton = orb.BSETriplets().eigenvectors2().col(i);
126 }
127 Eigen::Map<const Eigen::MatrixXd> mat(exciton.data(), bse_ctotal,
128 bse_vtotal);
129 const Eigen::MatrixXd aomatrix =
130 occlevels * mat.transpose() * virtlevels.transpose();
131 coeffs.col(i).tail(bse_size_ao) =
132 Eigen::Map<const Eigen::VectorXd>(aomatrix.data(), bse_size_ao);
133 }
134 }
135 return coeffs;
136}
137
138Eigen::MatrixXd Overlap_filter::CalcAOCoeffs(const Orbitals& orb,
139 QMStateType type) const {
140 Eigen::MatrixXd coeffs;
141 if (type.isSingleParticleState()) {
142 if (type == QMStateType::DQPstate) {
144 } else {
145 coeffs = orb.MOs().eigenvectors();
146 }
147 } else {
148 coeffs = CalcExcitonAORepresentation(orb, type);
149 }
150 return coeffs;
151}
152
154 Eigen::MatrixXd aocoeffs = CalcAOCoeffs(orb, state.Type());
155 Index offset = 0;
156 if (state.Type() == QMStateType::DQPstate) {
157 offset = orb.getGWAmin();
158 }
159 laststatecoeff_ = aocoeffs.col(state.StateIdx() - offset);
160}
161
162std::vector<Index> Overlap_filter::CalcIndeces(const Orbitals& orb,
163 QMStateType type) const {
164 Index offset = 0;
165 if (type.isGWState()) {
166 offset = orb.getGWAmin();
167 }
168 Eigen::VectorXd Overlap = CalculateOverlap(orb, type);
169 return ReduceAndSortIndecesUp(Overlap, offset, threshold_);
170}
171
173 w(laststatecoeff_, "laststatecoeff");
174 w(threshold_, "threshold");
175}
176
178 r(laststatecoeff_, "laststatecoeff");
179 r(threshold_, "threshold");
180}
181
182} // namespace xtp
183} // namespace votca
const Eigen::MatrixXd & eigenvectors2() const
Definition eigensystem.h:36
const Eigen::MatrixXd & eigenvectors() const
Definition eigensystem.h:33
class to manage program options with xml serialization functionality
Definition property.h:55
Property & get(const std::string &key)
get existing property
Definition property.cc:79
T as() const
return value as type
Definition property.h:283
void Fill(const AOBasis &aobasis) final
const Eigen::MatrixXd & Matrix() const
Definition aomatrix.h:52
Logger is used for thread-safe output of messages.
Definition logger.h:164
container for molecular orbitals
Definition orbitals.h:46
Index getBSEvmax() const
Definition orbitals.h:286
const tools::EigenSystem & BSETriplets() const
Definition orbitals.h:324
Index getBSEcmin() const
Definition orbitals.h:288
Eigen::MatrixXd CalculateQParticleAORepresentation() const
Definition orbitals.cc:217
const tools::EigenSystem & BSESinglets() const
Definition orbitals.h:334
Index getBSEcmax() const
Definition orbitals.h:290
bool getTDAApprox() const
Definition orbitals.h:269
Index getBSEvmin() const
Definition orbitals.h:284
Index getBasisSetSize() const
Definition orbitals.h:64
Index getGWAmin() const
Definition orbitals.h:249
const tools::EigenSystem & MOs() const
Definition orbitals.h:122
Index NumberofStates(QMStateType type) const
Definition orbitals.h:135
const AOBasis & getDftBasis() const
Definition orbitals.h:208
void WriteToCpt(CheckpointWriter &w) final
void UpdateHist(const Orbitals &orb, QMState state) final
void ReadFromCpt(CheckpointReader &r) final
Eigen::MatrixXd CalcExcitonAORepresentation(const Orbitals &orb, QMStateType type) const
void Initialize(const tools::Property &options) final
void Info(Logger &log) const final
Eigen::VectorXd CalculateOverlap(const Orbitals &orb, QMStateType type) const
Eigen::VectorXd laststatecoeff_
std::vector< Index > CalcIndeces(const Orbitals &orb, QMStateType type) const final
Eigen::MatrixXd CalcAOCoeffs(const Orbitals &orb, QMStateType type) const
bool isGWState() const
Definition qmstate.h:85
bool isSingleParticleState() const
Definition qmstate.h:80
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
Index StateIdx() const
Definition qmstate.h:154
const QMStateType & Type() const
Definition qmstate.h:151
std::vector< Index > ReduceAndSortIndecesUp(const Eigen::VectorXd &overlap, Index offset, double threshold) const
#define XTP_LOG(level, log)
Definition logger.h:40
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26