votca 2026-dev
Loading...
Searching...
No Matches
excitonfollow.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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// Standard includes
21#include <stdexcept>
22
23// Local VOTCA includes
24#include "votca/xtp/aobasis.h"
25#include "votca/xtp/aomatrix.h"
28
29namespace votca {
30namespace xtp {
31
32Eigen::MatrixXd MixedAOOverlap(const Orbitals& a, const Orbitals& b) {
33 const QMMolecule& ma = a.QMAtoms();
34 const QMMolecule& mb = b.QMAtoms();
35 if (ma.size() != mb.size()) {
36 throw std::runtime_error("MixedAOOverlap: different numbers of atoms");
37 }
38 for (Index i = 0; i < ma.size(); ++i) {
39 if (ma[i].getElement() != mb[i].getElement()) {
40 throw std::runtime_error("MixedAOOverlap: different atoms");
41 }
42 }
43 if (a.getDFTbasisName() != b.getDFTbasisName()) {
44 throw std::runtime_error("MixedAOOverlap: different basis sets");
45 }
46 if (a.getBasisSetSize() != b.getBasisSetSize()) {
47 throw std::runtime_error("MixedAOOverlap: basis size mismatch");
48 }
50}
51
52namespace {
53// AO representation C_v M^T C_c^T of the exciton column (X or Y)
54Eigen::MatrixXd ExcitonAO(const Orbitals& orb, const Eigen::VectorXd& col) {
55 const Index vmin = orb.getBSEvmin();
56 const Index nv = orb.getBSEvmax() - vmin + 1;
57 const Index cmin = orb.getBSEcmin();
58 const Index nc = orb.getBSEcmax() - cmin + 1;
59 const Eigen::MatrixXd& C = orb.MOs().eigenvectors();
60 Eigen::Map<const Eigen::MatrixXd> m(col.data(), nc, nv);
61 return C.middleCols(vmin, nv) * m.transpose() *
62 C.middleCols(cmin, nc).transpose();
63}
64
65const tools::EigenSystem& Excitons(const Orbitals& orb, QMStateType type) {
66 if (type == QMStateType::Singlet) {
67 if (!orb.hasBSESinglets()) {
68 throw std::runtime_error("ExcitonOverlaps: no BSE singlets");
69 }
70 return orb.BSESinglets();
71 } else if (type == QMStateType::Triplet) {
72 if (!orb.hasBSETriplets()) {
73 throw std::runtime_error("ExcitonOverlaps: no BSE triplets");
74 }
75 return orb.BSETriplets();
76 }
77 throw std::runtime_error("ExcitonOverlaps: singlets or triplets only");
78}
79} // namespace
80
81Eigen::VectorXd ExcitonOverlaps(const Orbitals& ref, const QMState& ref_state,
82 const Orbitals& cur, QMStateType type) {
83 const tools::EigenSystem& eref = Excitons(ref, ref_state.Type());
84 const tools::EigenSystem& ecur = Excitons(cur, type);
85 const Index k = ref_state.StateIdx();
86 if (k < 0 || k >= eref.eigenvectors().cols()) {
87 throw std::runtime_error("ExcitonOverlaps: reference state not stored");
88 }
89 const Eigen::MatrixXd S = MixedAOOverlap(ref, cur); // ref x cur
90 // reference exciton carried to the current basis, then to the current
91 // occupied x virtual MO pairs: T = C_v^T S^T A_ref S C_c (nv x nc)
92 const Index vmin = cur.getBSEvmin();
93 const Index nv = cur.getBSEvmax() - vmin + 1;
94 const Index cmin = cur.getBSEcmin();
95 const Index nc = cur.getBSEcmax() - cmin + 1;
96 const Eigen::MatrixXd& C = cur.MOs().eigenvectors();
97 const Eigen::MatrixXd SCv = S * C.middleCols(vmin, nv);
98 const Eigen::MatrixXd SCc = S * C.middleCols(cmin, nc);
99 auto project = [&](const Eigen::VectorXd& col) {
100 const Eigen::MatrixXd A = ExcitonAO(ref, col);
101 // stored like the exciton columns: (c, v), column major
102 const Eigen::MatrixXd T = (SCv.transpose() * A * SCc).transpose();
103 return Eigen::VectorXd(
104 Eigen::Map<const Eigen::VectorXd>(T.data(), T.size()));
105 };
106 Eigen::VectorXd ov =
107 ecur.eigenvectors().transpose() * project(eref.eigenvectors().col(k));
108 const bool full = !ref.getTDAApprox() && !cur.getTDAApprox() &&
109 eref.eigenvectors2().cols() > 0 &&
110 ecur.eigenvectors2().cols() > 0;
111 if (full) {
112 ov -=
113 ecur.eigenvectors2().transpose() * project(eref.eigenvectors2().col(k));
114 }
115 return ov.cwiseAbs();
116}
117
118} // namespace xtp
119} // namespace votca
const Eigen::MatrixXd & eigenvectors2() const
Definition eigensystem.h:36
const Eigen::MatrixXd & eigenvectors() const
Definition eigensystem.h:33
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
Index getBSEvmax() const
Return the highest valence orbital included in BSE.
Definition orbitals.h:468
Index getBSEcmin() const
Return the lowest conduction orbital included in BSE.
Definition orbitals.h:471
Index getBSEcmax() const
Return the highest conduction orbital included in BSE.
Definition orbitals.h:474
bool getTDAApprox() const
Return whether the Tamm-Dancoff approximation is enabled.
Definition orbitals.h:446
Index getBSEvmin() const
Return the lowest valence orbital included in BSE.
Definition orbitals.h:465
Index getBasisSetSize() const
Return the number of AO basis functions in the DFT basis.
Definition orbitals.h:72
const tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
Definition orbitals.h:192
const QMMolecule & QMAtoms() const
Return read-only access to the molecular geometry.
Definition orbitals.h:262
const std::string & getDFTbasisName() const
Return the DFT basis-set name.
Definition orbitals.h:362
const AOBasis & getDftBasis() const
Return the DFT AO basis, throwing if it has not been initialized.
Definition orbitals.h:372
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
Index StateIdx() const
Definition qmstate.h:157
const QMStateType & Type() const
Definition qmstate.h:154
Charge transport classes.
Definition ERIs.h:28
Eigen::MatrixXd MixedAOOverlap(const Orbitals &a, const Orbitals &b)
Eigen::MatrixXd ComputeMixedOverlap(const AOBasis &row, const AOBasis &col)
Eigen::VectorXd ExcitonOverlaps(const Orbitals &ref, const QMState &ref_state, const Orbitals &cur, QMStateType type)
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26