votca 2026-dev
Loading...
Searching...
No Matches
bse.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// Standard includes
21#include <chrono>
22#include <cmath>
23#include <iostream>
24#include <sstream>
25
26// VOTCA includes
27#include <votca/tools/linalg.h>
28
29// Local VOTCA includes
30#include "votca/xtp/bse.h"
40#include "votca/xtp/rpa.h"
41#include "votca/xtp/vc2index.h"
42
43using std::flush;
44
45namespace votca {
46namespace xtp {
47
48namespace {
49double DavidsonToleranceValue(const std::string& tol) {
50 if (tol == "loose") {
51 return 1e-3;
52 } else if (tol == "normal") {
53 return 1e-4;
54 } else if (tol == "strict") {
55 return 1e-5;
56 } else if (tol == "lapack") {
57 return 1e-9;
58 }
59 throw std::runtime_error(tol + " is not a valid Davidson tolerance");
60}
61} // namespace
62
63void BSE::configure(const options& opt, const Eigen::VectorXd& RPAInputEnergies,
64 const Eigen::MatrixXd& Hqp_in) {
65 opt_ = opt;
66 bse_vmax_ = opt_.homo;
67 bse_cmin_ = opt_.homo + 1;
68 bse_vtotal_ = bse_vmax_ - opt_.vmin + 1;
69 bse_ctotal_ = opt_.cmax - bse_cmin_ + 1;
71 max_dyn_iter_ = opt_.max_dyn_iter;
72 dyn_tolerance_ = opt_.dyn_tolerance;
73 if (opt_.use_Hqp_offdiag) {
74 Hqp_ = AdjustHqpSize(Hqp_in, RPAInputEnergies);
75 } else {
76 Hqp_ = AdjustHqpSize(Hqp_in, RPAInputEnergies).diagonal().asDiagonal();
77 }
78 SetupDirectInteractionOperator(RPAInputEnergies, 0.0);
79}
80
82 const options& opt, const Eigen::VectorXd& RPAInputEnergies,
83 const Eigen::MatrixXd& Hqp_in, const Eigen::VectorXd& epsilon_0_inv) {
84 opt_ = opt;
85 bse_vmax_ = opt_.homo;
86 bse_cmin_ = opt_.homo + 1;
87 bse_vtotal_ = bse_vmax_ - opt_.vmin + 1;
88 bse_ctotal_ = opt_.cmax - bse_cmin_ + 1;
90 max_dyn_iter_ = opt_.max_dyn_iter;
91 dyn_tolerance_ = opt_.dyn_tolerance;
92 if (opt_.use_Hqp_offdiag) {
93 Hqp_ = AdjustHqpSize(Hqp_in, RPAInputEnergies);
94 } else {
95 Hqp_ = AdjustHqpSize(Hqp_in, RPAInputEnergies).diagonal().asDiagonal();
96 }
97 epsilon_0_inv_ = epsilon_0_inv;
99}
100
102 Orbitals& orb) const {
103 if (type == QMStateType::Singlet) {
104 return orb.BSESinglets();
105 } else if (type == QMStateType::Triplet) {
106 return orb.BSETriplets();
107 } else {
108 throw std::runtime_error(
109 "Unsupported QMStateType in BSE::GetBSEEigenSystem");
110 }
111}
112
114 const Orbitals& orb) const {
115 if (type == QMStateType::Singlet) {
116 return orb.BSESinglets();
117 } else if (type == QMStateType::Triplet) {
118 return orb.BSETriplets();
119 } else {
120 throw std::runtime_error(
121 "Unsupported QMStateType in BSE::GetBSEEigenSystem");
122 }
123}
124
125std::string BSE::StateEnergiesHeader(const QMStateType& type) const {
126 if (type == QMStateType::Singlet) {
127 return " ====== singlet energies (eV) ====== ";
128 } else if (type == QMStateType::Triplet) {
129 return " ====== triplet energies (eV) ====== ";
130 } else {
131 throw std::runtime_error(
132 "Unsupported QMStateType in BSE::StateEnergiesHeader");
133 }
134}
135
136std::string BSE::StateShortLabel(const QMStateType& type) const {
137 if (type == QMStateType::Singlet) {
138 return "S";
139 } else if (type == QMStateType::Triplet) {
140 return "T";
141 } else {
142 throw std::runtime_error("Unsupported QMStateType in BSE::StateShortLabel");
143 }
144}
145
146std::string BSE::StateDynamicLabel(const QMStateType& type) const {
147 if (type == QMStateType::Singlet) {
148 return "singlet";
149 } else if (type == QMStateType::Triplet) {
150 return "triplet";
151 } else {
152 throw std::runtime_error(
153 "Unsupported QMStateType in BSE::StateDynamicLabel");
154 }
155}
156
157double BSE::ExchangePrefactor(const QMStateType& type) const {
158 if (type == QMStateType::Singlet) {
159 return 2.0;
160 } else if (type == QMStateType::Triplet) {
161 return 0.0;
162 } else {
163 throw std::runtime_error(
164 "Unsupported QMStateType in BSE::ExchangePrefactor");
165 }
166}
167
168Eigen::MatrixXd BSE::AdjustHqpSize(const Eigen::MatrixXd& Hqp,
169 const Eigen::VectorXd& RPAInputEnergies) {
170
171 Index hqp_size = bse_vtotal_ + bse_ctotal_;
172 Index gwsize = opt_.qpmax - opt_.qpmin + 1;
173 Index RPAoffset = opt_.vmin - opt_.rpamin;
174 Eigen::MatrixXd Hqp_BSE = Eigen::MatrixXd::Zero(hqp_size, hqp_size);
175
176 if (opt_.vmin >= opt_.qpmin) {
177 Index start = opt_.vmin - opt_.qpmin;
178 if (opt_.cmax <= opt_.qpmax) {
179 Hqp_BSE = Hqp.block(start, start, hqp_size, hqp_size);
180 } else {
181 Index virtoffset = gwsize - start;
182 Hqp_BSE.topLeftCorner(virtoffset, virtoffset) =
183 Hqp.block(start, start, virtoffset, virtoffset);
184
185 Index virt_extra = opt_.cmax - opt_.qpmax;
186 Hqp_BSE.diagonal().tail(virt_extra) =
187 RPAInputEnergies.segment(RPAoffset + virtoffset, virt_extra);
188 }
189 }
190
191 if (opt_.vmin < opt_.qpmin) {
192 Index occ_extra = opt_.qpmin - opt_.vmin;
193 Hqp_BSE.diagonal().head(occ_extra) =
194 RPAInputEnergies.segment(RPAoffset, occ_extra);
195
196 Hqp_BSE.block(occ_extra, occ_extra, gwsize, gwsize) = Hqp;
197
198 if (opt_.cmax > opt_.qpmax) {
199 Index virtoffset = occ_extra + gwsize;
200 Index virt_extra = opt_.cmax - opt_.qpmax;
201 Hqp_BSE.diagonal().tail(virt_extra) =
202 RPAInputEnergies.segment(RPAoffset + virtoffset, virt_extra);
203 }
204 }
205
206 return Hqp_BSE;
207}
208
209void BSE::setReactionField(const Eigen::MatrixXd& R, bool include_kreac) {
210 reaction_field_ = R;
211 include_kreac_ = include_kreac;
213 : Eigen::MatrixXd();
214}
215
216// The BSE operators read slices and rows up to the highest conduction level;
217// the dielectric matrix reads all rows of the occupied slices. Only those
218// are rotated (see TCMatrix_gwbse::MultiplyRightWithAuxMatrixLeading).
219void BSE::RotateIntoScreeningFrame(const Eigen::MatrixXd& U) {
220 const Index occupied_slices = opt_.homo + 1 - opt_.rpamin;
221 const Index lead = opt_.cmax + 1 - opt_.rpamin;
222 Mmn_.MultiplyRightWithAuxMatrixLeading(U, occupied_slices, lead);
223}
224
226 const bool environment = reaction_field_.size() > 0;
227 const bool dressed_route = environment && include_kreac_;
228 // Dressed: every pairing of two M's is through u = v + v_reac, so eps
229 // below is the environment-screened one and Kx carries K_reac. Bare:
230 // Kx stays v, and W_tot is assembled explicitly below. GW may have left
231 // the integrals either way.
232 if (dressed_route && Mmn_.Dressed() &&
233 (Mmn_.Dressing().rows() != dressing_.rows() ||
234 !Mmn_.Dressing().isApprox(dressing_, 1e-14))) {
235 // GW dressed with another reaction field (e.g. inactive_screening in the
236 // plasmon-pole model: GW with the environment only, BSE with
237 // environment and inactive region together)
238 Mmn_.UndressAuxIndex();
239 }
240 if (dressed_route && !Mmn_.Dressed()) {
241 Mmn_.DressAuxIndex(dressing_);
242 } else if (!dressed_route && Mmn_.Dressed()) {
243 Mmn_.UndressAuxIndex();
244 }
245}
246
247// W = vectors diag(values) vectors^T in the current frame of the
248// integrals, as the operators use it: the inverse of epsilon without its
249// non-positive modes, or W_tot of the bare environment route.
251 const Eigen::VectorXd& RPAInputEnergies, double energy,
252 DFTTimings& timings) const {
253 RPA rpa = RPA(log_, Mmn_);
254 rpa.configure(opt_.homo, opt_.rpamin, opt_.rpamax);
255 rpa.setRPAInputEnergies(RPAInputEnergies);
256 rpa.setTimings(&timings);
257 const Eigen::MatrixXd screening = rpa.calculate_epsilon_r(energy);
258
259 auto t = timings.Measure("eigensolver");
260 if (reaction_field_.size() > 0 && !include_kreac_) {
261 // Operators expect M U with U orthogonal and diag(epsilon_0_inv_) the
262 // screened interaction in that frame: Kd = M U d U^T M^T and
263 // Kx = M U U^T M^T = M M^T = v. So diagonalize W_tot, not eps, and
264 // hand its eigenvalues over as epsilon_0_inv_.
265 const Index n = screening.rows();
266 const Eigen::MatrixXd I = Eigen::MatrixXd::Identity(n, n);
267 // 1 + R and u^-1 + eps - 1 are positive definite (Cholesky, LU if not)
268 const Eigen::MatrixXd u_inv =
269 InverseSPD(I + Mmn_.ToCurrentAuxFrame(reaction_field_));
270 Eigen::MatrixXd W = InverseSPD(u_inv + screening - I);
271 W = 0.5 * (W + W.transpose()).eval();
272 return SymmetricEigen(W);
273 }
274
275 SymmetricEigenSystem es = SymmetricEigen(screening);
276 for (Index i = 0; i < es.values.size(); ++i) {
277 es.values(i) = (es.values(i) > 1e-8) ? 1 / es.values(i) : 0.0;
278 }
279 return es;
280}
281
283 const Eigen::VectorXd& RPAInputEnergies, double energy) {
284 ReleaseDirectCaches(); // the integrals and the screening change
286 DFTTimings timings;
288 ScreenedInteraction(RPAInputEnergies, energy, timings);
289 {
290 auto t = timings.Measure("rotation");
292 }
293 epsilon_0_inv_ = std::move(W.values);
294 XTP_LOG(Log::error, log_) << TimeStamp() << " BSE screening at " << energy
295 << " Ha: " << timings.Format() << flush;
296}
297
298template <typename BSE_OPERATOR>
300 std::shared_ptr<SymmetricTiles> cache) const {
302 opt.cmax = opt_.cmax;
303 opt.homo = opt_.homo;
304 opt.qpmin = opt_.qpmin;
305 opt.rpamin = opt_.rpamin;
306 opt.vmin = opt_.vmin;
307 H.configure(opt);
308 H.set_direct_cache(std::move(cache));
309}
310
312
313void BSE::DecideDirectCaches(bool coupling) const {
314 const Index n = bse_size_;
315 const double need = SymmetricTiles::Bytes(n);
316 // what is kept but not built yet does not show in the resident memory
317 double pending = 0.0;
318 for (const auto* c : {&direct_caches_.hd, &direct_caches_.hd2}) {
319 if (*c != nullptr && !(*c)->built()) {
320 pending += need;
321 }
322 }
323 double available = MemoryBudget::AvailableBytes() - pending;
324 std::ostringstream msg;
325 msg.precision(3);
326 msg << " BSE direct terms (lower triangle, " << need * 1e-9 << " GB each):";
327 auto decide = [&](std::shared_ptr<SymmetricTiles>& cache, bool& decided,
328 const char* name) {
329 if (decided) {
330 msg << " " << name << (cache ? " kept (reused)" : " not kept") << ";";
331 return;
332 }
333 decided = true;
334 if (need <= available) {
335 cache = std::make_shared<SymmetricTiles>();
336 available -= need;
337 msg << " " << name << " kept;";
338 } else {
339 msg << " " << name << " not kept;";
340 }
341 };
342 decide(direct_caches_.hd, direct_caches_.hd_decided, "Hd");
343 if (coupling) {
344 decide(direct_caches_.hd2, direct_caches_.hd2_decided, "Hd2");
345 }
346 msg << " " << MemoryBudget::Describe();
347 const Index missing = Index(direct_caches_.hd == nullptr) +
348 Index(coupling && direct_caches_.hd2 == nullptr);
349 if (missing > 0) {
350 // what the process holds now plus the matrices, with the margin
351 const double resident = std::max(0.0, MemoryBudget::ResidentBytes());
352 // the needed terms not built yet, and one kept but unbuilt otherwise
353 auto unbuilt = [](const std::shared_ptr<SymmetricTiles>& c) {
354 return c == nullptr || !c->built();
355 };
356 double extra = unbuilt(direct_caches_.hd) ? need : 0.0;
357 if (coupling ? unbuilt(direct_caches_.hd2)
358 : (direct_caches_.hd2 && !direct_caches_.hd2->built())) {
359 extra += need;
360 }
361 const double wanted = resident + extra;
362 msg << "; --memory " << std::ceil(1.1 * wanted * 1e-9 + 1.0)
363 << " or more would keep all";
364 }
365 XTP_LOG(Log::error, log_) << TimeStamp() << msg.str() << flush;
366}
367
375
377 orb.setTDAApprox(opt_.useTDA);
378 if (opt_.useTDA) {
380 } else {
382 }
384
385 if (reaction_field_.size() > 0) {
386 const Eigen::VectorXd kreac =
389 << TimeStamp() << " Environment K_reac (linear-response part), "
390 << (include_kreac_ ? "included" : "NOT included, estimate only")
391 << ", first order [eV]:" << flush;
392 for (Index i = 0; i < kreac.size(); ++i) {
394 << (boost::format(" S = %1$4d Omega = %2$+1.4f eV <K_reac> = "
395 "%3$+1.4f eV") %
396 (i + 1) %
398 (kreac(i) * tools::conv::hrt2ev))
399 .str()
400 << flush;
401 }
402 }
403}
404
406 bool tda) const {
407 // The transition density of each state in the auxiliary basis,
408 // d = sum_vc (X+Y)_vc M_v,c, and <K_reac> = 2 d^T R d: the singlet
409 // spin factor of Kx, which K_reac shares, times the first-order change
410 // (X+Y)^T dK (X+Y) that a perturbation entering A and B alike produces.
411 const Eigen::MatrixXd Rc = Mmn_.ToCurrentAuxFrame(reaction_field_);
412 const Index vmin = opt_.vmin - opt_.rpamin;
413 const Index cmin = bse_cmin_ - opt_.rpamin;
414 const Index nstates = es.eigenvalues().size();
415 Eigen::VectorXd result = Eigen::VectorXd::Zero(nstates);
416#pragma omp parallel for schedule(dynamic)
417 for (Index s = 0; s < nstates; ++s) {
418 Eigen::VectorXd coeffs = es.eigenvectors().col(s);
419 if (!tda) {
420 coeffs += es.eigenvectors2().col(s);
421 }
422 const Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), bse_ctotal_,
424 Eigen::VectorXd d = Eigen::VectorXd::Zero(Mmn_.auxsize());
425 for (Index v = 0; v < bse_vtotal_; ++v) {
426 d +=
427 Mmn_[v + vmin].middleRows(cmin, bse_ctotal_).transpose() * mat.col(v);
428 }
429 result(s) = 2.0 * d.dot(Rc * d);
430 }
431 return result;
432}
433
435 orb.setTDAApprox(opt_.useTDA);
436 if (opt_.useTDA) {
438 } else {
440 }
441}
442
444
445 DecideDirectCaches(false);
449 << TimeStamp() << " Setup TDA singlet hamiltonian " << flush;
450 return solve_hermitian(Hs);
451}
452
459
466
467template <typename BSE_OPERATOR>
469
470 std::chrono::time_point<std::chrono::system_clock> start =
471 std::chrono::system_clock::now();
472
473 tools::EigenSystem result;
474
476
477 DS.set_correction(opt_.davidson_correction);
478 DS.set_tolerance(opt_.davidson_tolerance);
479 DS.set_size_update(opt_.davidson_update);
480 DS.set_iter_max(opt_.davidson_maxiter);
481 DS.set_max_search_space(10 * opt_.nmax);
482 DS.solve(h, opt_.nmax);
483 result.eigenvalues() = DS.eigenvalues();
484 result.eigenvectors() = DS.eigenvectors();
485
486 std::chrono::time_point<std::chrono::system_clock> end =
487 std::chrono::system_clock::now();
488 std::chrono::duration<double> elapsed_time = end - start;
489
490 XTP_LOG(Log::info, log_) << TimeStamp() << " Diagonalization done in "
491 << elapsed_time.count() << " secs" << flush;
492
493 return result;
494}
495
506
517
518template <typename BSE_OPERATOR_A, typename BSE_OPERATOR_B>
520 BSE_OPERATOR_B& Bop) const {
521 // Hermitian (A-B)(A+B) form: one application of A and of B per new
522 // vector. Falls back to the general non-Hermitian Davidson if A-B or A+B
523 // is not positive definite.
524 try {
526 fopt.tolerance = DavidsonToleranceValue(opt_.davidson_tolerance);
527 fopt.max_iterations = opt_.davidson_maxiter;
528 fopt.max_subspace = 10 * opt_.nmax;
529 FullBSEDavidson solver(log_, fopt);
530 return solver.Solve(Aop, Bop, opt_.nmax);
531 } catch (const std::runtime_error& error) {
533 << TimeStamp() << " " << error.what()
534 << "; using the non-Hermitian Davidson solver" << flush;
535 }
536
537 std::chrono::time_point<std::chrono::system_clock> start =
538 std::chrono::system_clock::now();
539
540 // operator
542
543 // Davidson solver
545 DS.set_correction(opt_.davidson_correction);
546 DS.set_tolerance(opt_.davidson_tolerance);
547 DS.set_size_update(opt_.davidson_update);
548 DS.set_iter_max(opt_.davidson_maxiter);
549 DS.set_max_search_space(10 * opt_.nmax);
550 DS.set_matrix_type("HAM");
551 Eigen::MatrixXd initial_guess = BuildFullBSEXRankedInitialGuess(
552 Aop.diagonal(), Bop.diagonal(), opt_.nmax);
553
554 DS.solve(Hop, opt_.nmax, initial_guess);
555
556 // results
557 tools::EigenSystem result;
558 result.eigenvalues() = DS.eigenvalues();
559 Eigen::MatrixXd tmpX = DS.eigenvectors().topRows(Aop.rows());
560 Eigen::MatrixXd tmpY = DS.eigenvectors().bottomRows(Bop.rows());
561
562 // normalization so that X^T X - Y^T Y = 1
563 if (const Index bad = NormalizeExcitationVectors(tmpX, tmpY); bad > 0) {
565 << TimeStamp() << " WARNING: " << bad
566 << " BSE root(s) without positive X^2 - Y^2 norm (not converged?)"
567 << flush;
568 }
569 result.eigenvectors() = tmpX;
570 result.eigenvectors2() = tmpY;
571
572 std::chrono::time_point<std::chrono::system_clock> end =
573 std::chrono::system_clock::now();
574 std::chrono::duration<double> elapsed_time = end - start;
575
576 XTP_LOG(Log::info, log_) << TimeStamp() << " Diagonalization done in "
577 << elapsed_time.count() << " secs" << flush;
578
579 return result;
580}
581
582void BSE::printFragInfo(const std::vector<QMFragment<BSE_Population>>& frags,
583 Index state) const {
584 for (const QMFragment<BSE_Population>& frag : frags) {
585 double dq = frag.value().H[state] + frag.value().E[state];
586 double qeff = dq + frag.value().Gs;
588 << boost::format(
589 " Fragment %1$4d -- hole: %2$5.1f%% electron: "
590 "%3$5.1f%% dQ: %4$+5.2f Qeff: %5$+5.2f") %
591 int(frag.getId()) % (100.0 * frag.value().H[state]) %
592 (-100.0 * frag.value().E[state]) % dq % qeff
593 << flush;
594 }
595 return;
596}
597
598void BSE::PrintWeights(const Eigen::VectorXd& weights) const {
600 for (Index i_bse = 0; i_bse < bse_size_; ++i_bse) {
601 double weight = weights(i_bse);
602 if (weight > opt_.min_print_weight) {
604 << boost::format(
605 " HOMO-%1$-3d -> LUMO+%2$-3d : %3$3.1f%%") %
606 (opt_.homo - vc.v(i_bse)) % (vc.c(i_bse) - opt_.homo - 1) %
607 (100.0 * weight)
608 << flush;
609 }
610 }
611 return;
612}
613
615 const Orbitals& orb) const {
616
618
619 Eigen::VectorXd oscs = orb.Oscillatorstrengths();
620 Interaction act = Analyze_eh_interaction(type, orb);
621
622 if (fragments.size() > 0) {
623 Lowdin low;
624 low.CalcChargeperFragment(fragments, orb, type);
625 }
626
627 const tools::EigenSystem& bse = GetBSEEigenSystem(type, orb);
628 const Eigen::VectorXd& energies = bse.eigenvalues();
629
630 double hrt2ev = tools::conv::hrt2ev;
631 XTP_LOG(Log::error, log_) << StateEnergiesHeader(type) << flush;
632 for (Index i = 0; i < opt_.nmax; ++i) {
633 Eigen::VectorXd weights = bse.eigenvectors().col(i).cwiseAbs2();
634 if (!orb.getTDAApprox()) {
635 weights -= bse.eigenvectors2().col(i).cwiseAbs2();
636 }
637
638 double osc = oscs[i];
639 // On the dressed route (environment with K_reac) the exchange operator
640 // acts on integrals dressed with (1+R)^1/2, so its expectation value is
641 // that of K_x + K_reac. Label it as such.
642 const bool dressed = reaction_field_.size() > 0 && include_kreac_;
643 const std::string kx_label = dressed ? "<K_x+K_reac>" : "<K_x>";
645 << boost::format(
646 " %1$2s = %2$4d Omega = %3$+1.12f eV lamdba = %4$+3.2f nm "
647 "<FT> = %5$+1.4f %8$s = %6$+1.4f <K_d> = %7$+1.4f") %
648 StateShortLabel(type) % (i + 1) % (hrt2ev * energies(i)) %
649 (1240.0 / (hrt2ev * energies(i))) %
650 (hrt2ev * act.qp_contrib(i)) %
651 (hrt2ev * act.exchange_contrib(i)) %
652 (hrt2ev * act.direct_contrib(i)) % kx_label
653 << flush;
654
655 const Eigen::Vector3d& trdip = orb.TransitionDipoles()[i];
657 << boost::format(
658 " TrDipole length gauge[e*bohr] dx = %1$+1.4f dy = "
659 "%2$+1.4f dz = %3$+1.4f |d|^2 = %4$+1.4f f = %5$+1.4f") %
660 trdip[0] % trdip[1] % trdip[2] % (trdip.squaredNorm()) % osc
661 << flush;
662
663 PrintWeights(weights);
664 if (fragments.size() > 0) {
665 printFragInfo(fragments, i);
666 }
667
668 XTP_LOG(Log::error, log_) << flush;
669 }
670 return;
671}
672
674 const Orbitals& orb) const {
675
677 Interaction act = Analyze_eh_interaction(type, orb);
678
679 if (fragments.size() > 0) {
680 Lowdin low;
681 low.CalcChargeperFragment(fragments, orb, type);
682 }
683
684 const tools::EigenSystem& bse = GetBSEEigenSystem(type, orb);
685 const Eigen::VectorXd& energies = bse.eigenvalues();
686
687 XTP_LOG(Log::error, log_) << StateEnergiesHeader(type) << flush;
688 for (Index i = 0; i < opt_.nmax; ++i) {
689 Eigen::VectorXd weights = bse.eigenvectors().col(i).cwiseAbs2();
690 if (!orb.getTDAApprox()) {
691 weights -= bse.eigenvectors2().col(i).cwiseAbs2();
692 }
693
695 << boost::format(
696 " %1$2s = %2$4d Omega = %3$+1.12f eV lamdba = %4$+3.2f nm "
697 "<FT> = %5$+1.4f <K_d> = %6$+1.4f") %
698 StateShortLabel(type) % (i + 1) %
699 (tools::conv::hrt2ev * energies(i)) %
700 (1240.0 / (tools::conv::hrt2ev * energies(i))) %
703 << flush;
704
705 PrintWeights(weights);
706 if (fragments.size() > 0) {
707 printFragInfo(fragments, i);
708 }
709 XTP_LOG(Log::error, log_) << boost::format(" ") << flush;
710 }
711
712 return;
713}
714
715template <class OP>
716Eigen::VectorXd ExpValue(const Eigen::MatrixXd& state1, OP OPxstate2) {
717 return state1.cwiseProduct(OPxstate2.eval()).colwise().sum().transpose();
718}
719
720Eigen::VectorXd ExpValue(const Eigen::MatrixXd& state1,
721 const Eigen::MatrixXd& OPxstate2) {
722 return state1.cwiseProduct(OPxstate2).colwise().sum().transpose();
723}
724
725template <typename BSE_OPERATOR>
727 const QMStateType& type, const Orbitals& orb, const BSE_OPERATOR& H) const {
728
729 const tools::EigenSystem& BSECoefs = GetBSEEigenSystem(type, orb);
730
731 ExpectationValues expectation_values;
732
733 const Eigen::MatrixXd temp = H * BSECoefs.eigenvectors();
734
735 expectation_values.direct_term = ExpValue(BSECoefs.eigenvectors(), temp);
736 if (!orb.getTDAApprox()) {
737 expectation_values.direct_term +=
738 ExpValue(BSECoefs.eigenvectors2(), H * BSECoefs.eigenvectors2());
739 expectation_values.cross_term =
740 2 * ExpValue(BSECoefs.eigenvectors2(), temp);
741 } else {
742 expectation_values.cross_term = Eigen::VectorXd::Zero(0);
743 }
744 return expectation_values;
745}
746
747// Composition of the excitation energy in terms of QP, direct (screened),
748// and exchance contributions in the BSE
749// Full BSE:
750//
751// | A* | | H K | | A |
752// | -B* | | -K -H | | B | = A*.H.A + B*.H.B + 2A*.K.B
753//
754// with: H = H_qp + H_d + eta.H_x
755// K = H_d2 + eta.H_x
756//
757// reports composition for FULL BSE as
758// <FT> = A*.H_qp.A + B*.H_qp.B
759// <Kx> = eta.(A*.H_x.A + B*.H_x.B + 2A*.H_x.B)
760// <Kd> = A*.H_d.A + B*.H_d.B + 2A*.H_d2.B
761namespace {
762// A kept direct term for the analysis only if it is built already: building
763// it for the few states of the analysis would cost more than it saves.
764std::shared_ptr<SymmetricTiles> ReusableCache(
765 const std::shared_ptr<SymmetricTiles>& cache) {
766 return (cache != nullptr && cache->built()) ? cache : nullptr;
767}
768} // namespace
769
771 const Orbitals& orb) const {
772 Interaction analysis;
773 {
776 ExpectationValues expectation_values =
777 ExpectationValue_Operator(type, orb, hqp);
778 analysis.qp_contrib = expectation_values.direct_term;
779 }
780 {
781 // the direct terms of the solve, if kept, are not rebuilt here
783 configureBSEOperator(hd, ReusableCache(direct_caches_.hd));
784 ExpectationValues expectation_values =
785 ExpectationValue_Operator(type, orb, hd);
786 analysis.direct_contrib = expectation_values.direct_term;
787 }
788 if (!orb.getTDAApprox()) {
789 // only the cross term 2 Y.Hd2.X: Hd2 on X alone
791 configureBSEOperator(hd2, ReusableCache(direct_caches_.hd2));
792 const tools::EigenSystem& coefs = GetBSEEigenSystem(type, orb);
793 analysis.direct_contrib +=
794 2 * ExpValue(coefs.eigenvectors2(), hd2 * coefs.eigenvectors());
795 }
796
797 double xpref = ExchangePrefactor(type);
798 if (xpref != 0.0) {
801 ExpectationValues expectation_values =
802 ExpectationValue_Operator(type, orb, hx);
803 analysis.exchange_contrib = xpref * expectation_values.direct_term;
804 if (!orb.getTDAApprox()) {
805 analysis.exchange_contrib += xpref * expectation_values.cross_term;
806 }
807 } else {
808 analysis.exchange_contrib =
809 Eigen::VectorXd::Zero(analysis.direct_contrib.size());
810 }
811
812 return analysis;
813}
814
815double BSE::state_matrix_bytes_ = 1e9;
816
817namespace {
818using RowMajorMatrix =
819 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
820
821// Number of hole levels per pass, so that the stacked intermediates of one
822// pass stay within the given bytes.
823Index HoleChunk(Index vtotal, Index ctotal, Index auxsize, double bytes) {
824 const double per_level =
825 8.0 * double(auxsize) * double(ctotal + 2 * std::max(vtotal, ctotal));
826 return std::clamp<Index>(Index(bytes / per_level), 1, vtotal);
827}
828
829// sum_PQ W_PQ G_PQ for W = vectors diag(values) vectors^T
830double ContractScreened(const SymmetricEigenSystem& W,
831 const Eigen::MatrixXd& G) {
832 const Eigen::MatrixXd GPhi = G * W.vectors;
833 return (W.vectors.cwiseProduct(GPhi).colwise().sum().transpose().array() *
834 W.values.array())
835 .sum();
836}
837} // namespace
838
839// G with <A|Hd|B> = -sum_PQ W_PQ G_PQ, summed over the pairs (A, B), for the
840// screened direct term Hd(v1c1, v2c2) = -M[c1](c2,:) W M[v1](v2,:)^T:
841// G = sum_{v1 v2} b_{v1v2} a_{v1v2}^T, a_{v1v2} = M[v1](v2,:),
842// b_{v1v2} = sum_{c1 c2} A(v1,c1) B(v2,c2) M[c1](c2,:).
844 const std::vector<std::pair<const Eigen::VectorXd*,
845 const Eigen::VectorXd*>>& pairs) const {
846 const Index vmin = opt_.vmin - opt_.rpamin;
847 const Index cmin = bse_cmin_ - opt_.rpamin;
848 const Index vt = bse_vtotal_;
849 const Index ct = bse_ctotal_;
850 const Index N = Mmn_.auxsize();
851 const Index chunk = HoleChunk(vt, ct, N, state_matrix_bytes_);
852 Eigen::MatrixXd G = Eigen::MatrixXd::Zero(N, N);
853 for (Index v0 = 0; v0 < vt; v0 += chunk) {
854 const Index nc = std::min(chunk, vt - v0);
855 // rows j * vt + v1: b_{v1, v0 + j}
856 Eigen::MatrixXd b = Eigen::MatrixXd::Zero(nc * vt, N);
857 for (const auto& pair : pairs) {
858 // coefficient vectors as (c, v) matrices, index v * ct + c
859 Eigen::Map<const Eigen::MatrixXd> A(pair.first->data(), ct, vt);
860 Eigen::Map<const Eigen::MatrixXd> B(pair.second->data(), ct, vt);
861 const Eigen::MatrixXd Bchunk = B.middleCols(v0, nc).transpose();
862 // T[j](c1, :) = sum_c2 B(v0 + j, c2) M[c1](c2, :)
863 std::vector<RowMajorMatrix> T(std::size_t(nc), RowMajorMatrix(ct, N));
864#pragma omp parallel for schedule(dynamic)
865 for (Index c1 = 0; c1 < ct; ++c1) {
866 const Eigen::MatrixXd t = Bchunk * Mmn_[c1 + cmin].middleRows(cmin, ct);
867 for (Index j = 0; j < nc; ++j) {
868 T[std::size_t(j)].row(c1) = t.row(j);
869 }
870 }
871#pragma omp parallel for schedule(dynamic)
872 for (Index j = 0; j < nc; ++j) {
873 b.middleRows(j * vt, vt).noalias() += A.transpose() * T[std::size_t(j)];
874 }
875 }
876 Eigen::MatrixXd a(nc * vt, N);
877#pragma omp parallel for schedule(dynamic)
878 for (Index v1 = 0; v1 < vt; ++v1) {
879 for (Index j = 0; j < nc; ++j) {
880 a.row(j * vt + v1) = Mmn_[v1 + vmin].row(vmin + v0 + j);
881 }
882 }
883 G.noalias() += b.transpose() * a;
884 }
885 return G;
886}
887
888// G with <A|Hd2|B> = -sum_PQ W_PQ G_PQ for the screened coupling term
889// Hd2(v1c1, v2c2) = -M[v1](c2,:) W M[c1](v2,:)^T:
890// G = sum_{c1 v2} b_{c1v2} a_{c1v2}^T, a_{c1v2} = M[c1](v2,:),
891// b_{c1v2} = sum_{v1 c2} A(v1,c1) B(v2,c2) M[v1](c2,:).
892Eigen::MatrixXd BSE::CouplingTermDensity(const Eigen::VectorXd& Avec,
893 const Eigen::VectorXd& Bvec) const {
894 const Index vmin = opt_.vmin - opt_.rpamin;
895 const Index cmin = bse_cmin_ - opt_.rpamin;
896 const Index vt = bse_vtotal_;
897 const Index ct = bse_ctotal_;
898 const Index N = Mmn_.auxsize();
899 const Index chunk = HoleChunk(vt, ct, N, state_matrix_bytes_);
900 Eigen::Map<const Eigen::MatrixXd> A(Avec.data(), ct, vt);
901 Eigen::Map<const Eigen::MatrixXd> B(Bvec.data(), ct, vt);
902 Eigen::MatrixXd G = Eigen::MatrixXd::Zero(N, N);
903 for (Index v0 = 0; v0 < vt; v0 += chunk) {
904 const Index nc = std::min(chunk, vt - v0);
905 const Eigen::MatrixXd Bchunk = B.middleCols(v0, nc).transpose();
906 // U[j](v1, :) = sum_c2 B(v0 + j, c2) M[v1](c2, :)
907 std::vector<RowMajorMatrix> U(std::size_t(nc), RowMajorMatrix(vt, N));
908#pragma omp parallel for schedule(dynamic)
909 for (Index v1 = 0; v1 < vt; ++v1) {
910 const Eigen::MatrixXd u = Bchunk * Mmn_[v1 + vmin].middleRows(cmin, ct);
911 for (Index j = 0; j < nc; ++j) {
912 U[std::size_t(j)].row(v1) = u.row(j);
913 }
914 }
915 // rows j * ct + c1: b_{c1, v0 + j} and a_{c1, v0 + j}
916 Eigen::MatrixXd b(nc * ct, N);
917#pragma omp parallel for schedule(dynamic)
918 for (Index j = 0; j < nc; ++j) {
919 b.middleRows(j * ct, ct).noalias() = A * U[std::size_t(j)];
920 }
921 Eigen::MatrixXd a(nc * ct, N);
922#pragma omp parallel for schedule(dynamic)
923 for (Index c1 = 0; c1 < ct; ++c1) {
924 for (Index j = 0; j < nc; ++j) {
925 a.row(j * ct + c1) = Mmn_[c1 + cmin].row(vmin + v0 + j);
926 }
927 }
928 G.noalias() += b.transpose() * a;
929 }
930 return G;
931}
932
933// Dynamical Screening in BSE as perturbation to static excitation energies
934// as in Phys. Rev. B 80, 241405 (2009) for the TDA case
935//
936// The integrals stay in the frame of the static screening set up in
937// configure, where W(0) = diag(epsilon_0_inv_). For each state, the
938// screened terms <X|Hd|X> + <Y|Hd|Y> + 2<Y|Hd2|X> are -sum_PQ W_PQ G_PQ with
939// state matrices G built once, so W(w) at the next frequency costs one
940// dielectric matrix and its eigenvectors: no pass over the BSE Hamiltonian
941// and no rotation of the integrals per state and step.
943 Orbitals& orb) {
944 // no BSE operators from here on: free the kept direct terms
946
947 const tools::EigenSystem& BSECoefs = GetBSEEigenSystem(type, orb);
948 const Eigen::VectorXd& RPAInputEnergies = orb.RPAInputEnergies();
949 const bool full = !orb.getTDAApprox();
950
951 const Eigen::VectorXd& BSEenergies = BSECoefs.eigenvalues();
952
953 // initial copy of static BSE energies to dynamic
954 Eigen::VectorXd BSEenergies_dynamic = BSEenergies;
955 // convergence per state: last |dE| and iterations done
956 Eigen::VectorXd last_change = Eigen::VectorXd::Zero(BSEenergies.size());
957 Eigen::VectorXd iterations = Eigen::VectorXd::Zero(BSEenergies.size());
958
959 for (Index i_exc = 0; i_exc < BSEenergies.size(); i_exc++) {
960 XTP_LOG(Log::info, log_) << "Dynamical Screening BSE, Excitation " << i_exc
961 << " static " << BSEenergies(i_exc) << flush;
962
963 const Eigen::VectorXd X = BSECoefs.eigenvectors().col(i_exc);
964 Eigen::VectorXd Y;
965 std::vector<std::pair<const Eigen::VectorXd*, const Eigen::VectorXd*>>
966 pairs{{&X, &X}};
967 if (full) {
968 Y = BSECoefs.eigenvectors2().col(i_exc);
969 pairs.emplace_back(&Y, &Y);
970 }
971 const Eigen::MatrixXd Gd = DirectTermDensity(pairs);
972 Eigen::MatrixXd G2;
973 if (full) {
974 G2 = CouplingTermDensity(Y, X);
975 }
976 // screened direct contribution for W(w), or for the static W(0)
977 auto Hd = [&](const SymmetricEigenSystem* W) {
978 double value = (W != nullptr) ? ContractScreened(*W, Gd)
979 : epsilon_0_inv_.dot(Gd.diagonal());
980 if (full) {
981 value += 2 * ((W != nullptr) ? ContractScreened(*W, G2)
982 : epsilon_0_inv_.dot(G2.diagonal()));
983 }
984 return -value;
985 };
986 const double Hd_static_contribution = Hd(nullptr);
987
988 for (Index iter = 0; iter < max_dyn_iter_; iter++) {
989
990 // screened interaction at the last energy as screening frequency
991 double old_energy = BSEenergies_dynamic(i_exc);
992 DFTTimings timings;
993 const SymmetricEigenSystem W =
994 ScreenedInteraction(RPAInputEnergies, old_energy, timings);
995
996 // new energy perturbatively
997 BSEenergies_dynamic(i_exc) =
998 BSEenergies(i_exc) + Hd_static_contribution - Hd(&W);
999
1001 << "Dynamical Screening BSE, excitation " << i_exc << " iteration "
1002 << iter << " dynamic " << BSEenergies_dynamic(i_exc) << flush;
1003
1004 last_change(i_exc) = std::abs(BSEenergies_dynamic(i_exc) - old_energy);
1005 iterations(i_exc) = double(iter + 1);
1006 // check tolerance
1007 if (last_change(i_exc) < dyn_tolerance_) {
1008 break;
1009 }
1010 }
1011 }
1012 {
1013 Index n_unconverged = 0;
1014 for (Index i = 0; i < last_change.size(); ++i) {
1015 n_unconverged += (last_change(i) >= dyn_tolerance_) ? 1 : 0;
1016 }
1018 << TimeStamp() << " Dynamical screening ("
1019 << ((type == QMStateType::Singlet) ? "singlets" : "triplets")
1020 << "): " << n_unconverged << " of " << last_change.size()
1021 << " states not converged after " << max_dyn_iter_
1022 << " iterations (tolerance " << dyn_tolerance_
1023 << " Ha; largest last change "
1024 << last_change.maxCoeff() * tools::conv::hrt2ev << " eV)" << flush;
1025 }
1026
1027 double hrt2ev = tools::conv::hrt2ev;
1028
1029 if (type == QMStateType::Singlet) {
1030 orb.BSESinglets_dynamic() = BSEenergies_dynamic;
1031 orb.BSESinglets_dynamic_change() = last_change;
1032 orb.BSESinglets_dynamic_iterations() = iterations;
1033 XTP_LOG(Log::error, log_) << " ====== singlet energies with perturbative "
1034 "dynamical screening (eV) ====== "
1035 << flush;
1036 Eigen::VectorXd oscs = orb.Oscillatorstrengths();
1037 for (Index i = 0; i < opt_.nmax; ++i) {
1038 double osc = oscs[i];
1040 << boost::format(
1041 " S(dynamic) = %1$4d Omega = %2$+1.12f eV lamdba = %3$+3.2f "
1042 "nm f = %4$+1.4f") %
1043 (i + 1) % (hrt2ev * BSEenergies_dynamic(i)) %
1044 (1240.0 / (hrt2ev * BSEenergies_dynamic(i))) %
1045 (osc * BSEenergies_dynamic(i) / BSEenergies(i))
1046 << flush;
1047 }
1048
1049 } else if (type == QMStateType::Triplet) {
1050 orb.BSETriplets_dynamic() = BSEenergies_dynamic;
1051 orb.BSETriplets_dynamic_change() = last_change;
1052 orb.BSETriplets_dynamic_iterations() = iterations;
1053 XTP_LOG(Log::error, log_) << " ====== triplet energies with perturbative "
1054 "dynamical screening (eV) ====== "
1055 << flush;
1056 for (Index i = 0; i < opt_.nmax; ++i) {
1058 << boost::format(
1059 " T(dynamic) = %1$4d Omega = %2$+1.12f eV lamdba = %3$+3.2f "
1060 "nm ") %
1061 (i + 1) % (hrt2ev * BSEenergies_dynamic(i)) %
1062 (1240.0 / (hrt2ev * BSEenergies_dynamic(i)))
1063 << flush;
1064 }
1065
1066 } else {
1067 throw std::runtime_error(
1068 "Unsupported QMStateType in BSE::Perturbative_DynamicalScreening");
1069 }
1070}
1071
1072} // namespace xtp
1073} // namespace votca
const Eigen::MatrixXd & eigenvectors2() const
Definition eigensystem.h:36
const Eigen::VectorXd & eigenvalues() const
Definition eigensystem.h:30
const Eigen::MatrixXd & eigenvectors() const
Definition eigensystem.h:33
void setReactionField(const Eigen::MatrixXd &R, bool include_kreac)
Screen by a static polarizable environment (embedded BSE).
Definition bse.cc:209
void Solve_singlets(Orbitals &orb) const
Definition bse.cc:376
static double state_matrix_bytes_
Definition bse.h:145
DirectCaches direct_caches_
Definition bse.h:189
void DecideDirectCaches(bool coupling) const
Definition bse.cc:313
void printFragInfo(const std::vector< QMFragment< BSE_Population > > &frags, Index state) const
Definition bse.cc:582
void PrintWeights(const Eigen::VectorXd &weights) const
Definition bse.cc:598
std::string StateDynamicLabel(const QMStateType &type) const
Definition bse.cc:146
double dyn_tolerance_
Definition bse.h:155
void configure_with_precomputed_screening(const options &opt, const Eigen::VectorXd &RPAEnergies, const Eigen::MatrixXd &Hqp_in, const Eigen::VectorXd &epsilon_0_inv)
Definition bse.cc:81
void Analyze_singlets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
Definition bse.cc:614
Eigen::MatrixXd DirectTermDensity(const std::vector< std::pair< const Eigen::VectorXd *, const Eigen::VectorXd * > > &pairs) const
Definition bse.cc:843
tools::EigenSystem Solve_triplets_BTDA() const
Definition bse.cc:507
Eigen::VectorXd ReactionFieldExchange(const tools::EigenSystem &es, bool tda) const
Definition bse.cc:405
TripletOperator_TDA getTripletOperator_TDA() const
Definition bse.cc:460
void MatchDressingToRoute()
Definition bse.cc:225
SingletOperator_TDA getSingletOperator_TDA() const
Definition bse.cc:453
options opt_
Definition bse.h:132
tools::EigenSystem Solve_singlets_BTDA() const
Definition bse.cc:496
Index bse_vmax_
Definition bse.h:148
Index bse_cmin_
Definition bse.h:149
void Perturbative_DynamicalScreening(const QMStateType &type, Orbitals &orb)
Definition bse.cc:942
void Analyze_triplets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
Definition bse.cc:673
void SetupDirectInteractionOperator(const Eigen::VectorXd &DFTenergies, double energy)
Definition bse.cc:282
void configure(const options &opt, const Eigen::VectorXd &RPAEnergies, const Eigen::MatrixXd &Hqp_in)
Definition bse.cc:63
Eigen::MatrixXd Hqp_
Definition bse.h:160
tools::EigenSystem & GetBSEEigenSystem(const QMStateType &type, Orbitals &orb) const
Definition bse.cc:101
Eigen::VectorXd epsilon_0_inv_
Definition bse.h:157
SymmetricEigenSystem ScreenedInteraction(const Eigen::VectorXd &RPAInputEnergies, double energy, DFTTimings &timings) const
Definition bse.cc:250
void configureBSEOperator(BSE_OPERATOR &H, std::shared_ptr< SymmetricTiles > cache=nullptr) const
Definition bse.cc:299
ExpectationValues ExpectationValue_Operator(const QMStateType &type, const Orbitals &orb, const BSE_OPERATOR &H) const
Definition bse.cc:726
Interaction Analyze_eh_interaction(const QMStateType &type, const Orbitals &orb) const
Definition bse.cc:770
Index bse_ctotal_
Definition bse.h:152
double ExchangePrefactor(const QMStateType &type) const
Definition bse.cc:157
TCMatrix_gwbse & Mmn_
Definition bse.h:159
void RotateIntoScreeningFrame(const Eigen::MatrixXd &U)
Definition bse.cc:219
Index bse_size_
Definition bse.h:150
tools::EigenSystem Solve_singlets_TDA() const
Definition bse.cc:443
Eigen::MatrixXd reaction_field_
Definition bse.h:162
bool include_kreac_
Definition bse.h:164
Index max_dyn_iter_
Definition bse.h:154
tools::EigenSystem solve_hermitian(BSE_OPERATOR &h) const
Definition bse.cc:468
void Solve_triplets(Orbitals &orb) const
Definition bse.cc:434
Logger & log_
Definition bse.h:147
void ReleaseDirectCaches() const
Definition bse.cc:311
tools::EigenSystem Solve_nonhermitian_Davidson(BSE_OPERATOR_A &Aop, BSE_OPERATOR_B &Bop) const
Definition bse.cc:519
Eigen::MatrixXd AdjustHqpSize(const Eigen::MatrixXd &Hqp_in, const Eigen::VectorXd &RPAInputEnergies)
Definition bse.cc:168
Eigen::MatrixXd CouplingTermDensity(const Eigen::VectorXd &Avec, const Eigen::VectorXd &Bvec) const
Definition bse.cc:892
Index bse_vtotal_
Definition bse.h:151
std::string StateShortLabel(const QMStateType &type) const
Definition bse.cc:136
tools::EigenSystem Solve_triplets_TDA() const
Definition bse.cc:368
Eigen::MatrixXd dressing_
Definition bse.h:163
std::string StateEnergiesHeader(const QMStateType &type) const
Definition bse.cc:125
Wall-clock accounting for the parts of a DFT run.
Definition dfttimings.h:45
Scope Measure(const std::string &name)
Definition dfttimings.h:74
std::string Format() const
The entries on one line, "name 1.23 s, name 4.56 s".
Definition dfttimings.cc:58
Use Davidson algorithm to solve A*V=E*V.
void set_max_search_space(Index N)
Eigen::VectorXd eigenvalues() const
void solve(const MatrixReplacement &A, Index neigen, Index size_initial_guess=0)
void set_matrix_type(std::string mt)
void set_correction(std::string method)
void set_size_update(std::string update_size)
void set_tolerance(std::string tol)
Eigen::MatrixXd eigenvectors() const
static Eigen::MatrixXd DressingMatrix(const Eigen::MatrixXd &R)
S = (1 + R)^(1/2), the dressing of the auxiliary index that turns the bare interaction into u = v + v...
Lowest roots of the full (non-TDA) BSE.
tools::EigenSystem Solve(const OpA &A, const OpB &B, Index nroots)
static std::string Describe()
e.g. "budget 400 GB, 46.1 GB in use" or "no --memory given"
static double ResidentBytes()
Resident memory of the process (-1 if unknown on this platform).
static double AvailableBytes()
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
const tools::EigenSystem & BSETriplets() const
Return read-only access to triplet BSE eigenpairs.
Definition orbitals.h:541
void CalcCoupledTransition_Dipoles()
Definition orbitals.cc:778
const tools::EigenSystem & BSESinglets() const
Return read-only access to singlet BSE eigenpairs.
Definition orbitals.h:554
bool getTDAApprox() const
Return whether the Tamm-Dancoff approximation is enabled.
Definition orbitals.h:460
Eigen::VectorXd & BSESinglets_dynamic_iterations()
Definition orbitals.h:605
Eigen::VectorXd Oscillatorstrengths() const
Definition orbitals.cc:661
const std::vector< Eigen::Vector3d > & TransitionDipoles() const
Return the stored transition dipole moments.
Definition orbitals.h:626
Eigen::VectorXd & BSETriplets_dynamic_iterations()
Definition orbitals.h:611
const Eigen::VectorXd & RPAInputEnergies() const
Return read-only access to the RPA input energies.
Definition orbitals.h:501
const Eigen::VectorXd & BSETriplets_dynamic() const
Return dynamically screened triplet BSE energies.
Definition orbitals.h:581
Eigen::VectorXd & BSESinglets_dynamic_change()
Definition orbitals.h:593
void setTDAApprox(bool usedTDA)
Enable or disable the Tamm-Dancoff approximation flag.
Definition orbitals.h:458
const Eigen::VectorXd & BSESinglets_dynamic() const
Return dynamically screened singlet BSE energies.
Definition orbitals.h:566
Eigen::VectorXd & BSETriplets_dynamic_change()
Definition orbitals.h:599
void CalcChargeperFragment(std::vector< QMFragment< BSE_Population > > &frags, const Orbitals &orbitals, QMStateType type) const
void setRPAInputEnergies(const Eigen::VectorXd &rpaenergies)
Definition rpa.h:69
void setTimings(DFTTimings *timings)
Times the dielectric-matrix builds in these timings (optional).
Definition rpa.h:55
Eigen::MatrixXd calculate_epsilon_r(double frequency) const
Definition rpa.h:61
void configure(Index homo, Index rpamin, Index rpamax)
Definition rpa.h:41
static double Bytes(Index n, Index tile=DefaultTile)
Bytes the tiles of an n x n matrix need.
Timestamp returns the current time as a string Example: cout << TimeStamp().
Definition logger.h:224
This class transforms a pair of indices v,c into a compound index I, via I=ctotal*v+c the fast dimens...
Definition vc2index.h:36
Index c(Index index) const
Definition vc2index.h:48
Index v(Index index) const
Definition vc2index.h:46
#define XTP_LOG(level, log)
Definition logger.h:40
const double hrt2ev
Definition constants.h:53
Charge transport classes.
Definition ERIs.h:28
Index NormalizeExcitationVectors(Eigen::MatrixXd &X, Eigen::MatrixXd &Y)
Eigen::VectorXd ExpValue(const Eigen::MatrixXd &state1, OP OPxstate2)
Definition bse.cc:716
SymmetricEigenSystem SymmetricEigen(const Eigen::MatrixXd &A, bool vectors=true)
With vectors = false only the eigenvalues are computed.
BSE_OPERATOR< 1, 0, 0, 0 > HqpOperator
BSE_OPERATOR< 0, 0, 1, 0 > HdOperator
BSE_OPERATOR< 0, 0, 0, 1 > Hd2Operator
BSE_OPERATOR< 1, 2, 1, 0 > SingletOperator_TDA
Definition bse.h:40
Populationanalysis< true > Lowdin
Eigen::MatrixXd BuildFullBSEXRankedInitialGuess(const Eigen::VectorXd &adiag, const Eigen::VectorXd &bdiag, Index nroots)
Build an initial guess for full-BSE Davidson diagonalization.
BSE_OPERATOR< 1, 0, 1, 0 > TripletOperator_TDA
Definition bse.h:41
BSE_OPERATOR< 0, 2, 0, 1 > SingletOperator_BTDA_B
BSE_OPERATOR< 0, 1, 0, 0 > HxOperator
Eigen::MatrixXd InverseSPD(const Eigen::MatrixXd &A)
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Eigen::VectorXd direct_term
Definition bse.h:141
Eigen::VectorXd cross_term
Definition bse.h:142
Eigen::VectorXd qp_contrib
Definition bse.h:137
Eigen::VectorXd exchange_contrib
Definition bse.h:135
Eigen::VectorXd direct_contrib
Definition bse.h:136