votca 2026-dev
Loading...
Searching...
No Matches
orbitals.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 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 <cstdio>
22#include <fstream>
23#include <iomanip>
24#include <numeric>
25
26// Local VOTCA includes
27#include "votca/tools/version.h"
28#include "votca/xtp/aomatrix.h"
29#include "votca/xtp/orbitals.h"
31#include "votca/xtp/qmstate.h"
32#include "votca/xtp/vc2index.h"
33
34namespace votca {
35namespace xtp {
36
45
46Orbitals::Orbitals() : atoms_("", 0) { ; }
47
56std::vector<Index> Orbitals::CheckDegeneracy(Index level,
57 double energy_difference) const {
58 if (this->hasUnrestrictedOrbitals()) {
59 throw std::runtime_error(
60 "Checking degeneracy not implemented for open-shell systems.");
61 }
62 std::vector<Index> result;
63 if (level > mos_.eigenvalues().size()) {
64 throw std::runtime_error(
65 "Level for degeneracy is higher than maximum level");
66 }
67 double MOEnergyLevel = mos_.eigenvalues()(level);
68
69 for (Index i = 0; i < mos_.eigenvalues().size(); ++i) {
70 if (std::abs(mos_.eigenvalues()(i) - MOEnergyLevel) < energy_difference) {
71 result.push_back(i);
72 }
73 }
74
75 if (result.empty()) {
76 result.push_back(level);
77 }
78 return result;
79}
80
81std::vector<Index> Orbitals::SortEnergies() {
82 if (this->hasUnrestrictedOrbitals()) {
83 throw std::runtime_error(
84 "MO sorting not implemented for open-shell systems.");
85 }
86 std::vector<Index> index = std::vector<Index>(mos_.eigenvalues().size());
87 std::iota(index.begin(), index.end(), 0);
88 std::stable_sort(index.begin(), index.end(), [this](Index i1, Index i2) {
89 return this->MOs().eigenvalues()[i1] < this->MOs().eigenvalues()[i2];
90 });
91 return index;
92}
93
99void Orbitals::SetupDftBasis(std::string basis_name) {
100 if (this->QMAtoms().size() == 0) {
101 throw std::runtime_error("Can't setup AOBasis without atoms");
102 }
103 BasisSet bs;
104 bs.Load(basis_name);
105 dftbasis_.Fill(bs, this->QMAtoms());
106}
107
108void Orbitals::SetupAuxBasis(std::string aux_basis_name) {
109 if (this->QMAtoms().size() == 0) {
110 throw std::runtime_error("Can't setup Aux AOBasis without atoms");
111 }
112 BasisSet bs;
113 bs.Load(aux_basis_name);
114 auxbasis_.Fill(bs, this->QMAtoms());
115}
116
117// Return the density change relative to the ground state. For excited states
118// this corresponds to the response density Delta P, whereas for charged states
119// it returns the projector that must be added to or removed from the ground-
120// state density.
121Eigen::MatrixXd Orbitals::DensityMatrixWithoutGS(const QMState& state) const {
122 if (this->hasUnrestrictedOrbitals() &&
123 state.Type() != QMStateType::ExcitonUKS) {
124 throw std::runtime_error(
125 "DensityMatrixWithoutGS not implemented for open-shell systems "
126 "except ExcitonUKS.");
127 }
128 if (state.Type().isExciton()) {
129 std::array<Eigen::MatrixXd, 2> DMAT = DensityMatrixExcitedState(state);
130 return DMAT[1] - DMAT[0];
131 } else if (state.Type().isKSState() || state.Type().isPQPState()) {
132 return DensityMatrixKSstate(state);
133 } else if (state.Type() == QMStateType::DQPstate) {
134 Eigen::MatrixXd DMATQP = DensityMatrixQuasiParticle(state);
135 if (state.StateIdx() > getHomo()) {
136 return DMATQP;
137 } else {
138 return -DMATQP;
139 }
140 } else {
141 throw std::runtime_error(
142 "DensityMatrixWithoutGS does not yet implement QMStateType:" +
143 state.Type().ToLongString());
144 }
145}
146
147// Return the full AO density associated with the requested state. Depending
148// on the state type this is the ground-state density with the corresponding
149// particle, hole, or excitonic correction added on top.
150Eigen::MatrixXd Orbitals::DensityMatrixFull(const QMState& state) const {
151 if (state.isTransition()) {
152 return this->TransitionDensityMatrix(state);
153 }
154 Eigen::MatrixXd result = this->DensityMatrixGroundState();
155
156 // PbE: the inactive density belongs to the embedded MOs (active
157 // occupation). After the embedding the object may also hold the full
158 // reference MOs with the full occupation, whose density is complete.
159 if (getCalculationType() != "NoEmbedding" &&
161 result += getInactiveDensity();
162 }
163 if (state.Type().isExciton()) {
164 std::array<Eigen::MatrixXd, 2> DMAT = DensityMatrixExcitedState(state);
165 result = result - DMAT[0] + DMAT[1]; // Ground state + hole_contribution +
166 // electron contribution
167 } else if (state.Type() == QMStateType::DQPstate) {
168 Eigen::MatrixXd DMATQP = DensityMatrixQuasiParticle(state);
169 if (state.StateIdx() > getHomo()) {
170 result += DMATQP;
171 } else {
172 result -= DMATQP;
173 }
174 } else if (state.Type() == QMStateType::KSstate ||
175 state.Type() == QMStateType::PQPstate) {
176 Eigen::MatrixXd DMATKS = DensityMatrixKSstate(state);
177 if (state.StateIdx() <= getHomo()) {
178 result -= DMATKS;
179 } else {
180 result += DMATKS;
181 }
182 } else if (state.Type() == QMStateType::Hole ||
183 state.Type() == QMStateType::Electron) {
184 if (!this->hasUnrestrictedOrbitals()) {
185 throw std::runtime_error("QMStateType:" + state.Type().ToLongString() +
186 " requires an openshell calculation");
187 }
188 } else if (state.Type() != QMStateType::Gstate) {
189 throw std::runtime_error(
190 "DensityMatrixFull does not yet implement QMStateType:" +
191 state.Type().ToLongString());
192 }
193 return result;
194}
195
196// Determine ground state density matrix
197/*Eigen::MatrixXd Orbitals::DensityMatrixGroundState() const {
198 if (!hasMOs()) {
199 throw std::runtime_error("Orbitals file does not contain MO coefficients");
200 }
201 Eigen::MatrixXd occstates = mos_.eigenvectors().leftCols(occupied_levels_);
202 Eigen::MatrixXd dmatGS = occstates * occstates.transpose();
203 if (this->hasUnrestrictedOrbitals()) {
204 Eigen::MatrixXd occstates_beta =
205 mos_beta_.eigenvectors().leftCols(occupied_levels_beta_);
206 dmatGS += occstates_beta * occstates_beta.transpose();
207 } else {
208 dmatGS *= 2.0;
209 }
210 return dmatGS;
211}*/
212
213// Ground-state one-particle density in the AO basis.
214//
215// For unrestricted calculations the total density is assembled as
216//
217// P = P^alpha + P^beta,
218//
219// with P^sigma = C_occ^sigma (C_occ^sigma)^T.
220//
221// For restricted cases the spin-resolved helper reconstructs the same object
222// from the shared spatial orbitals together with the stored alpha/beta
223// occupation pattern.
224Eigen::MatrixXd Orbitals::DensityMatrixGroundState() const {
226 return spin[0] + spin[1];
227}
228
229// Density matrix for a single KS orbital
230// One-orbital projector in the AO basis,
231//
232// P^(k)_(mu,nu) = C_(mu,k) C_(nu,k),
233//
234// used for adding or removing a single KS occupation relative to the ground
235// state.
236Eigen::MatrixXd Orbitals::DensityMatrixKSstate(const QMState& state) const {
237 if (this->hasUnrestrictedOrbitals()) {
238 throw std::runtime_error(
239 "DensityMatrixKSstate not implemented for open-shell systems.");
240 }
241 if (!hasMOs()) {
242 throw std::runtime_error("Orbitals file does not contain MO coefficients");
243 }
244 if (state.Type() != QMStateType::KSstate &&
245 state.Type() != QMStateType::PQPstate) {
246 throw std::runtime_error("State:" + state.ToString() +
247 " is not a Kohn Sham state");
248 }
249 Eigen::VectorXd KSstate = mos_.eigenvectors().col(state.StateIdx());
250 Eigen::MatrixXd dmatKS = KSstate * KSstate.transpose();
251 return dmatKS;
252}
253
254Eigen::MatrixXd Orbitals::BSEOrbitals() const {
255 Eigen::MatrixXd C = mos_.eigenvectors();
256 if (is_qsgw_) {
257 if (!hasQPdiag()) {
258 throw std::runtime_error(
259 "Orbitals: QSGW flag set, but no QSGW orbitals (QPdiag) stored");
260 }
261 const Index qptotal = qpmax_ - qpmin_ + 1;
262 C.middleCols(qpmin_, qptotal) =
263 mos_.eigenvectors().middleCols(qpmin_, qptotal) *
264 QPdiag_.eigenvectors();
265 }
266 return C;
267}
268
270 if (!hasQPdiag()) {
271 throw std::runtime_error("Orbitals file does not contain QP coefficients");
272 }
273 return mos_.eigenvectors().middleCols(qpmin_, qpmax_ - qpmin_ + 1) *
274 QPdiag_.eigenvectors();
275}
276
277// Determine QuasiParticle Density Matrix
278// Quasiparticle projector in the AO basis,
279//
280// P^QP_(mu,nu) = Lambda_(mu,n) Lambda_(nu,n),
281//
282// where Lambda is the AO representation of the quasiparticle eigenvectors in
283// the selected GW subspace.
285 const QMState& state) const {
286 if (this->hasUnrestrictedOrbitals()) {
287 throw std::runtime_error(
288 "DensityMatrixQuasiParticle not implemented for open-shell systems.");
289 }
290 if (state.Type() != QMStateType::DQPstate) {
291 throw std::runtime_error("State:" + state.ToString() +
292 " is not a quasiparticle state");
293 }
294 Eigen::MatrixXd lambda = CalculateQParticleAORepresentation();
295 Eigen::MatrixXd dmatQP = lambda.col(state.StateIdx() - qpmin_) *
296 lambda.col(state.StateIdx() - qpmin_).transpose();
297 return dmatQP;
298}
299
300// Electric dipole moment relative to the molecular origin,
301//
302// mu = sum_A Z_A (R_A - R_0) - Tr[P M],
303//
304// where M contains the AO dipole integrals for x, y, and z and P is the full
305// state density matrix. Transition densities omit the nuclear term and return
306// only the electronic transition dipole.
307Eigen::Vector3d Orbitals::CalcElDipole(const QMState& state) const {
308 Eigen::Vector3d nuclei_dip = Eigen::Vector3d::Zero();
309 if (!state.isTransition()) {
310 for (const QMAtom& atom : atoms_) {
311 nuclei_dip += (atom.getPos() - atoms_.getPos()) * atom.getNuccharge();
312 }
313 }
314 AOBasis basis = getDftBasis();
315 AODipole dipole;
316 dipole.setCenter(atoms_.getPos());
317 dipole.Fill(basis);
318
319 Eigen::MatrixXd dmat = this->DensityMatrixFull(state);
320 Eigen::Vector3d electronic_dip;
321 for (Index i = 0; i < 3; ++i) {
322 electronic_dip(i) = dmat.cwiseProduct(dipole.Matrix()[i]).sum();
323 }
324 return nuclei_dip - electronic_dip;
325}
326
327// AO transition density for a singlet BSE excitation.
328//
329// In TDA form this evaluates
330//
331// gamma_(mu,nu) = sqrt(2) sum_(v,c) A_(v,c) C_(mu,v) C_(nu,c),
332//
333// and for full BSE the resonant and anti-resonant amplitudes are added before
334// the AO transformation.
335Eigen::MatrixXd Orbitals::TransitionDensityMatrix(const QMState& state) const {
336
337 if (state.Type() == QMStateType::ExcitonUKS) {
338 if (!this->hasUnrestrictedOrbitals()) {
339 throw std::runtime_error(
340 "ExcitonUKS transition density requested, but no unrestricted "
341 "orbitals are present.");
342 }
343
344 const Eigen::MatrixXd& BSECoefs = BSE_uks_.eigenvectors();
345 if (BSECoefs.cols() < state.StateIdx() + 1 || BSECoefs.rows() < 2) {
346 throw std::runtime_error(
347 "Orbitals object has no information about state:" + state.ToString());
348 }
349
350 Eigen::VectorXd coeffs = BSECoefs.col(state.StateIdx());
351 if (!useTDA_) {
352 coeffs += BSE_uks_.eigenvectors2().col(state.StateIdx());
353 }
354
355 const Index alpha_vtotal = getHomoAlpha() - bse_vmin_ + 1;
356 const Index alpha_ctotal = bse_cmax_ - getLumoAlpha() + 1;
357 const Index beta_vtotal = getHomoBeta() - bse_vmin_ + 1;
358 const Index beta_ctotal = bse_cmax_ - getLumoBeta() + 1;
359
360 const Index alpha_size = alpha_vtotal * alpha_ctotal;
361 const Index beta_size = beta_vtotal * beta_ctotal;
362
363 if (coeffs.size() != alpha_size + beta_size) {
364 throw std::runtime_error(
365 "ExcitonUKS coefficient vector size does not match expected "
366 "alpha+beta BSE space dimensions.");
367 }
368
369 Eigen::MatrixXd tdm = Eigen::MatrixXd::Zero(mos_.eigenvectors().rows(),
370 mos_.eigenvectors().rows());
371
372 if (alpha_size > 0) {
373 const Eigen::VectorXd coeffs_alpha = coeffs.head(alpha_size);
374 const auto occ_alpha =
375 mos_.eigenvectors().middleCols(bse_vmin_, alpha_vtotal);
376 const auto virt_alpha =
377 mos_.eigenvectors().middleCols(getLumoAlpha(), alpha_ctotal);
378 const Eigen::Map<const Eigen::MatrixXd> mat_alpha(
379 coeffs_alpha.data(), alpha_ctotal, alpha_vtotal);
380
381 tdm += occ_alpha * mat_alpha.transpose() * virt_alpha.transpose();
382 }
383
384 if (beta_size > 0) {
385 const Eigen::VectorXd coeffs_beta = coeffs.tail(beta_size);
386 const auto occ_beta =
387 mos_beta_.eigenvectors().middleCols(bse_vmin_, beta_vtotal);
388 const auto virt_beta =
389 mos_beta_.eigenvectors().middleCols(getLumoBeta(), beta_ctotal);
390 const Eigen::Map<const Eigen::MatrixXd> mat_beta(
391 coeffs_beta.data(), beta_ctotal, beta_vtotal);
392
393 tdm += occ_beta * mat_beta.transpose() * virt_beta.transpose();
394 }
395
396 return tdm;
397 }
398
399 if (this->hasUnrestrictedOrbitals()) {
400 throw std::runtime_error(
401 "TransitionDensityMatrix not implemented for open-shell systems "
402 "except ExcitonUKS.");
403 }
404 if (state.Type() != QMStateType::Singlet) {
405 throw std::runtime_error(
406 "Spin type not known for transition density matrix. Available only for "
407 "singlet");
408 }
409 const Eigen::MatrixXd& BSECoefs = BSE_singlet_.eigenvectors();
410 if (BSECoefs.cols() < state.StateIdx() + 1 || BSECoefs.rows() < 2) {
411 throw std::runtime_error("Orbitals object has no information about state:" +
412 state.ToString());
413 }
414
415 Eigen::VectorXd coeffs = BSECoefs.col(state.StateIdx());
416
417 if (!useTDA_) {
418 coeffs += BSE_singlet_.eigenvectors2().col(state.StateIdx());
419 }
420 coeffs *= std::sqrt(2.0);
421 const Eigen::MatrixXd orbitals = BSEOrbitals();
422 auto occlevels = orbitals.middleCols(bse_vmin_, bse_vtotal_);
423 auto virtlevels = orbitals.middleCols(bse_cmin_, bse_ctotal_);
424 Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), bse_ctotal_,
426
427 return occlevels * mat.transpose() * virtlevels.transpose();
428}
429
430// Spin-summed excited-state density correction split into hole and electron
431// blocks. For full BSE the anti-resonant contribution is subtracted from the
432// resonant part, yielding the usual RPA/BSE excited-state density.
433std::array<Eigen::MatrixXd, 2> Orbitals::DensityMatrixExcitedState(
434 const QMState& state) const {
435
436 if (state.Type() == QMStateType::ExcitonUKS) {
437 if (!this->hasUnrestrictedOrbitals()) {
438 throw std::runtime_error(
439 "ExcitonUKS excited-state density requested, but no unrestricted "
440 "orbitals are present.");
441 }
442
443 const Eigen::MatrixXd& X = BSE_uks_.eigenvectors();
444 if (X.cols() < state.StateIdx() + 1 || X.rows() < 2) {
445 throw std::runtime_error(
446 "Orbitals object has no information about state:" + state.ToString());
447 }
448
449 const Index alpha_vtotal = getHomoAlpha() - bse_vmin_ + 1;
450 const Index alpha_ctotal = bse_cmax_ - getLumoAlpha() + 1;
451 const Index beta_vtotal = getHomoBeta() - bse_vmin_ + 1;
452 const Index beta_ctotal = bse_cmax_ - getLumoBeta() + 1;
453
454 const Index alpha_size = alpha_vtotal * alpha_ctotal;
455 const Index beta_size = beta_vtotal * beta_ctotal;
456
457 if (X.rows() != alpha_size + beta_size) {
458 throw std::runtime_error(
459 "ExcitonUKS coefficient vector size does not match expected "
460 "alpha+beta BSE space dimensions.");
461 }
462
463 const Index nao = mos_.eigenvectors().rows();
464 std::array<Eigen::MatrixXd, 2> dmat;
465 dmat[0] = Eigen::MatrixXd::Zero(nao, nao); // hole
466 dmat[1] = Eigen::MatrixXd::Zero(nao, nao); // electron
467
468 auto add_resonant = [&](const Eigen::VectorXd& coeffs, bool alpha_spin) {
469 if (coeffs.size() == 0) {
470 return;
471 }
472
473 const Index vtotal = alpha_spin ? alpha_vtotal : beta_vtotal;
474 const Index ctotal = alpha_spin ? alpha_ctotal : beta_ctotal;
475
476 const auto& mos_spin =
477 alpha_spin ? mos_.eigenvectors() : mos_beta_.eigenvectors();
478 const Index lumo = alpha_spin ? getLumoAlpha() : getLumoBeta();
479
480 const auto occlevels = mos_spin.middleCols(bse_vmin_, vtotal);
481 const auto virtlevels = mos_spin.middleCols(lumo, ctotal);
482
483 const Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), ctotal,
484 vtotal);
485
486 dmat[0] += occlevels * (mat.transpose() * mat) * occlevels.transpose();
487 dmat[1] += virtlevels * (mat * mat.transpose()) * virtlevels.transpose();
488 };
489
490 auto subtract_antiresonant = [&](const Eigen::VectorXd& coeffs,
491 bool alpha_spin) {
492 if (coeffs.size() == 0) {
493 return;
494 }
495
496 const Index vtotal = alpha_spin ? alpha_vtotal : beta_vtotal;
497 const Index ctotal = alpha_spin ? alpha_ctotal : beta_ctotal;
498
499 const auto& mos_spin =
500 alpha_spin ? mos_.eigenvectors() : mos_beta_.eigenvectors();
501 const Index lumo = alpha_spin ? getLumoAlpha() : getLumoBeta();
502
503 const auto occlevels = mos_spin.middleCols(bse_vmin_, vtotal);
504 const auto virtlevels = mos_spin.middleCols(lumo, ctotal);
505
506 const Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), ctotal,
507 vtotal);
508
509 // Full-BSE anti-resonant correction:
510 // hole -= virt * (B B^T) * virt^T
511 // electron -= occ * (B^T B) * occ^T
512 dmat[0] -= virtlevels * (mat * mat.transpose()) * virtlevels.transpose();
513 dmat[1] -= occlevels * (mat.transpose() * mat) * occlevels.transpose();
514 };
515
516 const Eigen::VectorXd Xstate = X.col(state.StateIdx());
517 add_resonant(Xstate.head(alpha_size), true);
518 add_resonant(Xstate.tail(beta_size), false);
519
520 if (!useTDA_) {
521 const Eigen::MatrixXd& Y = BSE_uks_.eigenvectors2();
522 if (Y.cols() < state.StateIdx() + 1 || Y.rows() != X.rows()) {
523 throw std::runtime_error(
524 "Orbitals object has inconsistent anti-resonant ExcitonUKS "
525 "coefficients for state:" +
526 state.ToString());
527 }
528
529 const Eigen::VectorXd Ystate = Y.col(state.StateIdx());
530 subtract_antiresonant(Ystate.head(alpha_size), true);
531 subtract_antiresonant(Ystate.tail(beta_size), false);
532 }
533
534 return dmat;
535 }
536
537 if (this->hasUnrestrictedOrbitals()) {
538 throw std::runtime_error(
539 "DensityMatrixExcitedState not implemented for open-shell systems "
540 "except ExcitonUKS.");
541 }
542
543 std::array<Eigen::MatrixXd, 2> dmat = DensityMatrixExcitedState_R(state);
544 if (!useTDA_) {
545 std::array<Eigen::MatrixXd, 2> dmat_AR =
547 dmat[0] -= dmat_AR[0];
548 dmat[1] -= dmat_AR[1];
549 }
550 return dmat;
551}
552
553// Excited state density matrix
554
555std::array<Eigen::MatrixXd, 2> Orbitals::DensityMatrixExcitedState_R(
556 const QMState& state) const {
557 if (!state.Type().isExciton()) {
558 throw std::runtime_error(
559 "Spin type not known for density matrix. Available are singlet and "
560 "triplet");
561 }
562
563 const Eigen::MatrixXd& BSECoefs = (state.Type() == QMStateType::Singlet)
564 ? BSE_singlet_.eigenvectors()
565 : BSE_triplet_.eigenvectors();
566 if (BSECoefs.cols() < state.StateIdx() + 1 || BSECoefs.rows() < 2) {
567 throw std::runtime_error("Orbitals object has no information about state:" +
568 state.ToString());
569 }
570 /******
571 *
572 * Density matrix for GW-BSE based excitations
573 *
574 * - electron contribution
575 * D_ab = \sum{vc} \sum{c'} A_{vc}A_{vc'} mo_a(c)mo_b(c')
576 *
577 * - hole contribution
578 * D_ab = \sum{vc} \sum{v'} A_{vc}A_{v'c} mo_a(v)mo_b(v')
579 *
580 */
581
582 Eigen::VectorXd coeffs = BSECoefs.col(state.StateIdx());
583
584 std::array<Eigen::MatrixXd, 2> dmatEX;
585 const Eigen::MatrixXd orbitals = BSEOrbitals();
586 // hole part as matrix products
587 Eigen::MatrixXd occlevels = orbitals.middleCols(bse_vmin_, bse_vtotal_);
588 dmatEX[0] = occlevels * CalcAuxMat_vv(coeffs) * occlevels.transpose();
589
590 // electron part as matrix products
591 Eigen::MatrixXd virtlevels = orbitals.middleCols(bse_cmin_, bse_ctotal_);
592 dmatEX[1] = virtlevels * CalcAuxMat_cc(coeffs) * virtlevels.transpose();
593
594 return dmatEX;
595}
596
597Eigen::MatrixXd Orbitals::CalcAuxMat_vv(const Eigen::VectorXd& coeffs) const {
598 const Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), bse_ctotal_,
600 return mat.transpose() * mat;
601}
602
603Eigen::MatrixXd Orbitals::CalcAuxMat_cc(const Eigen::VectorXd& coeffs) const {
604 const Eigen::Map<const Eigen::MatrixXd> mat(coeffs.data(), bse_ctotal_,
606 return mat * mat.transpose();
607}
608
609std::array<Eigen::MatrixXd, 2> Orbitals::DensityMatrixExcitedState_AR(
610 const QMState& state) const {
611
612 if (!state.Type().isExciton()) {
613 throw std::runtime_error(
614 "Spin type not known for density matrix. Available are singlet and "
615 "triplet");
616 }
617
618 const Eigen::MatrixXd& BSECoefs_AR = (state.Type() == QMStateType::Singlet)
619 ? BSE_singlet_.eigenvectors2()
620 : BSE_triplet_.eigenvectors2();
621 if (BSECoefs_AR.cols() < state.StateIdx() + 1 || BSECoefs_AR.rows() < 2) {
622 throw std::runtime_error("Orbitals object has no information about state:" +
623 state.ToString());
624 }
625 /******
626 *
627 * Density matrix for GW-BSE based excitations
628 *
629 * - electron contribution
630 * D_ab = \sum{vc} \sum{v'} B_{vc}B_{v'c} mo_a(v)mo_b(v')
631 *
632 * - hole contribution
633 * D_ab = \sum{vc} \sum{c'} B_{vc}B_{vc'} mo_a(c)mo_b(c')
634 *
635 *
636 * more efficient:
637 *
638 * - electron contribution
639 * D_ab = \sum{v} \sum{v'} mo_a(v)mo_b(v') [ \sum{c} B_{vc}B_{v'c} ]
640 * = \sum{v} \sum{v'} mo_a(v)mo_b(v') B_{vv'}
641 *
642 * - hole contribution
643 * D_ab = \sum{c} \sum{c'} mo_a(c)mo_b(c') [ \sum{v} B_{vc}B_{vc'} ]
644 * = \sum{c} \sum{c'} mo_a(c)mo_b(c') B_{cc'}
645 *
646 */
647
648 Eigen::VectorXd coeffs = BSECoefs_AR.col(state.StateIdx());
649
650 std::array<Eigen::MatrixXd, 2> dmatAR;
651 const Eigen::MatrixXd orbitals = BSEOrbitals();
652 Eigen::MatrixXd virtlevels = orbitals.middleCols(bse_cmin_, bse_ctotal_);
653 dmatAR[0] = virtlevels * CalcAuxMat_cc(coeffs) * virtlevels.transpose();
654 // electron part as matrix products
655 Eigen::MatrixXd occlevels = orbitals.middleCols(bse_vmin_, bse_vtotal_);
656 dmatAR[1] = occlevels * CalcAuxMat_vv(coeffs) * occlevels.transpose();
657
658 return dmatAR;
659}
660
664
665Eigen::VectorXd Orbitals::Oscillatorstrengths(const QMStateType& type) const {
666
667 const tools::EigenSystem* es = nullptr;
668
669 if (type == QMStateType::Singlet) {
670 es = &BSE_singlet_;
671 } else if (type == QMStateType::ExcitonUKS) {
672 es = &BSE_uks_;
673 } else {
674 throw std::runtime_error(
675 "Orbitals::Oscillatorstrengths only implemented for "
676 "restricted singlets and combined UKS excitons.");
677 }
678
679 Index size = Index(transition_dipoles_.size());
680 if (size > es->eigenvalues().size()) {
681 size = es->eigenvalues().size();
682 }
683
684 Eigen::VectorXd oscs = Eigen::VectorXd::Zero(size);
685 for (Index i = 0; i < size; ++i) {
686 // f = (2/3) * Omega * |d|^2
687 // Omega must be in Hartree, d in e*bohr
688 oscs(i) =
689 transition_dipoles_[i].squaredNorm() * 2.0 / 3.0 * es->eigenvalues()(i);
690 }
691 return oscs;
692}
693
694double Orbitals::getTotalStateEnergy(const QMState& state) const {
695 double total_energy = getDFTTotalEnergy();
696 if (state.Type() == QMStateType::Gstate) {
697 return total_energy;
698 }
699 total_energy += getExcitedStateEnergy(state);
700 return total_energy;
701}
702
703double Orbitals::getExcitedStateEnergy(const QMState& state) const {
704
705 double omega = 0.0;
706 if (state.isTransition()) {
707 throw std::runtime_error(
708 "Total Energy does not exist for transition state");
709 }
710
711 if (state.Type() == QMStateType::Singlet) {
712 if (BSE_singlet_.eigenvalues().size() < state.StateIdx() + 1) {
713 throw std::runtime_error("Orbitals::getTotalEnergy You want " +
714 state.ToString() +
715 " which has not been calculated");
716 }
717 omega = BSE_singlet_.eigenvalues()[state.StateIdx()];
718 } else if (state.Type() == QMStateType::Triplet) {
719 if (BSE_triplet_.eigenvalues().size() < state.StateIdx() + 1) {
720 throw std::runtime_error("Orbitals::getTotalEnergy You want " +
721 state.ToString() +
722 " which has not been calculated");
723 }
724 omega = BSE_triplet_.eigenvalues()[state.StateIdx()];
725 } else if (state.Type() == QMStateType::DQPstate) {
726 if (QPdiag_.eigenvalues().size() < state.StateIdx() + 1 - getGWAmin()) {
727 throw std::runtime_error("Orbitals::getTotalEnergy You want " +
728 state.ToString() +
729 " which has not been calculated");
730 }
731 return QPdiag_.eigenvalues()[state.StateIdx() - getGWAmin()];
732 } else if (state.Type() == QMStateType::KSstate) {
733 if (mos_.eigenvalues().size() < state.StateIdx() + 1) {
734 throw std::runtime_error("Orbitals::getTotalEnergy You want " +
735 state.ToString() +
736 " which has not been calculated");
737 }
738 return mos_.eigenvalues()[state.StateIdx()];
739 } else if (state.Type() == QMStateType::PQPstate) {
740 if (this->QPpert_energies_.rows() < state.StateIdx() + 1 - getGWAmin()) {
741 throw std::runtime_error("Orbitals::getTotalEnergy You want " +
742 state.ToString() +
743 " which has not been calculated");
744 }
745 return QPpert_energies_(state.StateIdx() - getGWAmin(), 3);
746 } else if (state.Type() == QMStateType::LMOstate) {
747 if (lmos_energies_.size() < state.StateIdx() + 1) {
748 throw std::runtime_error(
749 "Orbitals::getTotalEnergy You want " + state.ToString() +
750 " which is a LMO for virtual orbitals. Not implemented.");
751 }
752 return lmos_energies_(state.StateIdx());
753 } else {
754 throw std::runtime_error(
755 "GetTotalEnergy only knows states:singlet,triplet,KS,DQP,PQP,LMOs");
756 }
757 return omega; // e.g. hartree
758}
759
760std::array<Eigen::MatrixXd, 3> Orbitals::CalcFreeTransition_Dipoles() const {
761 const Eigen::MatrixXd orbitals = BSEOrbitals();
762 AOBasis basis = getDftBasis();
763 // Testing electric dipole AOMatrix
764 AODipole dft_dipole;
765 dft_dipole.Fill(basis);
766
767 // now transition dipole elements for free interlevel transitions
768 std::array<Eigen::MatrixXd, 3> interlevel_dipoles;
769
770 Eigen::MatrixXd empty = orbitals.middleCols(bse_cmin_, bse_ctotal_);
771 Eigen::MatrixXd occ = orbitals.middleCols(bse_vmin_, bse_vtotal_);
772 for (Index i = 0; i < 3; i++) {
773 interlevel_dipoles[i] = empty.transpose() * dft_dipole.Matrix()[i] * occ;
774 }
775 return interlevel_dipoles;
776}
777
781
783
784 transition_dipoles_.clear();
785
786 if (type == QMStateType::Singlet) {
787 std::array<Eigen::MatrixXd, 3> interlevel_dipoles =
789
790 Index numofstates = BSE_singlet_.eigenvalues().size();
791 transition_dipoles_.reserve(numofstates);
792
793 const double sqrt2 = std::sqrt(2.0);
794
795 for (Index i_exc = 0; i_exc < numofstates; ++i_exc) {
796 Eigen::VectorXd coeffs = BSE_singlet_.eigenvectors().col(i_exc);
797 if (!useTDA_) {
798 coeffs += BSE_singlet_.eigenvectors2().col(i_exc);
799 }
800
801 Eigen::Map<Eigen::MatrixXd> mat(coeffs.data(), bse_ctotal_, bse_vtotal_);
802
803 Eigen::Vector3d tdipole = Eigen::Vector3d::Zero();
804 for (Index i = 0; i < 3; ++i) {
805 tdipole[i] = mat.cwiseProduct(interlevel_dipoles[i]).sum();
806 }
807
808 // Restricted singlet:
809 // the excitation is the spin-adapted combination of alpha and beta
810 // determinants, so the total transition dipole picks up sqrt(2).
811 transition_dipoles_.push_back(-sqrt2 * tdipole);
812 }
813 return;
814 }
815
816 if (type == QMStateType::ExcitonUKS) {
818 throw std::runtime_error(
819 "Orbitals::CalcCoupledTransition_Dipoles(ExcitonUKS) requires "
820 "unrestricted alpha/beta orbitals.");
821 }
822
823 const Index alpha_homo = getHomoAlpha();
824 const Index beta_homo = getHomoBeta();
825
826 const Index alpha_vtotal = alpha_homo - bse_vmin_ + 1;
827 const Index alpha_ctotal = bse_cmax_ - (alpha_homo + 1) + 1;
828 const Index alpha_size = alpha_vtotal * alpha_ctotal;
829
830 const Index beta_vtotal = beta_homo - bse_vmin_ + 1;
831 const Index beta_ctotal = bse_cmax_ - (beta_homo + 1) + 1;
832 const Index beta_size = beta_vtotal * beta_ctotal;
833
834 if (alpha_vtotal < 0 || alpha_ctotal < 0 || beta_vtotal < 0 ||
835 beta_ctotal < 0) {
836 throw std::runtime_error(
837 "Orbitals::CalcCoupledTransition_Dipoles(ExcitonUKS): "
838 "invalid UKS BSE window.");
839 }
840
841 AOBasis basis = getDftBasis();
842 AODipole dft_dipole;
843 dft_dipole.Fill(basis);
844
845 std::array<Eigen::MatrixXd, 3> interlevel_dipoles_alpha;
846 std::array<Eigen::MatrixXd, 3> interlevel_dipoles_beta;
847
848 const Eigen::MatrixXd virt_alpha =
849 mos_.eigenvectors().middleCols(alpha_homo + 1, alpha_ctotal);
850 const Eigen::MatrixXd occ_alpha =
851 mos_.eigenvectors().middleCols(bse_vmin_, alpha_vtotal);
852
853 const Eigen::MatrixXd virt_beta =
854 mos_beta_.eigenvectors().middleCols(beta_homo + 1, beta_ctotal);
855 const Eigen::MatrixXd occ_beta =
856 mos_beta_.eigenvectors().middleCols(bse_vmin_, beta_vtotal);
857
858 for (Index i = 0; i < 3; ++i) {
859 interlevel_dipoles_alpha[i] =
860 virt_alpha.transpose() * dft_dipole.Matrix()[i] * occ_alpha;
861 interlevel_dipoles_beta[i] =
862 virt_beta.transpose() * dft_dipole.Matrix()[i] * occ_beta;
863 }
864
865 const Index numofstates = BSE_uks_.eigenvalues().size();
866 transition_dipoles_.reserve(numofstates);
867
868 for (Index i_exc = 0; i_exc < numofstates; ++i_exc) {
869 Eigen::VectorXd coeffs_x = BSE_uks_.eigenvectors().col(i_exc);
870 Eigen::VectorXd coeffs = coeffs_x;
871 if (!useTDA_) {
872 coeffs += BSE_uks_.eigenvectors2().col(i_exc);
873 }
874
875 if (coeffs.size() != alpha_size + beta_size) {
876 throw std::runtime_error(
877 "Orbitals::CalcCoupledTransition_Dipoles(ExcitonUKS): "
878 "exciton vector size does not match alpha+beta sector sizes.");
879 }
880
881 Eigen::Map<const Eigen::MatrixXd> mat_alpha(coeffs.data(), alpha_ctotal,
882 alpha_vtotal);
883 Eigen::Map<const Eigen::MatrixXd> mat_beta(coeffs.data() + alpha_size,
884 beta_ctotal, beta_vtotal);
885
886 Eigen::Vector3d tdipole = Eigen::Vector3d::Zero();
887 for (Index i = 0; i < 3; ++i) {
888 tdipole[i] = mat_alpha.cwiseProduct(interlevel_dipoles_alpha[i]).sum() +
889 mat_beta.cwiseProduct(interlevel_dipoles_beta[i]).sum();
890 }
891
892 // Combined UKS exciton:
893 // alpha and beta sectors are already explicit components of the
894 // eigenvector, so there is NO extra sqrt(2) factor here.
895 transition_dipoles_.push_back(-tdipole);
896 }
897 return;
898 }
899
900 throw std::runtime_error(
901 "Orbitals::CalcCoupledTransition_Dipoles only implemented for "
902 "restricted singlets and combined UKS excitons.");
903}
904
906 std::vector<Index> sort_index = SortEnergies();
907 tools::EigenSystem MO_copy = mos_;
908 Index size = mos_.eigenvalues().size();
909 for (Index i = 0; i < size; ++i) {
910 mos_.eigenvalues()(i) = MO_copy.eigenvalues()(sort_index[i]);
911 }
912 for (Index i = 0; i < size; ++i) {
913 mos_.eigenvectors().col(i) = MO_copy.eigenvectors().col(sort_index[i]);
914 }
915}
916
917std::vector<Index> Orbitals::SortEnergiesAlpha() {
918 // Same logic as SortEnergies, but deliberately WITHOUT its
919 // hasUnrestrictedOrbitals() guard -- this is meant to be called on an
920 // unrestricted system, sorting the alpha channel only.
921 std::vector<Index> index = std::vector<Index>(mos_.eigenvalues().size());
922 std::iota(index.begin(), index.end(), 0);
923 std::stable_sort(index.begin(), index.end(), [this](Index i1, Index i2) {
924 return this->MOs().eigenvalues()[i1] < this->MOs().eigenvalues()[i2];
925 });
926 return index;
927}
928
929std::vector<Index> Orbitals::SortEnergiesBeta() {
930 std::vector<Index> index = std::vector<Index>(mos_beta_.eigenvalues().size());
931 std::iota(index.begin(), index.end(), 0);
932 std::stable_sort(index.begin(), index.end(), [this](Index i1, Index i2) {
933 return this->MOs_beta().eigenvalues()[i1] <
934 this->MOs_beta().eigenvalues()[i2];
935 });
936 return index;
937}
938
940 std::vector<Index> sort_index = SortEnergiesAlpha();
941 tools::EigenSystem MO_copy = mos_;
942 Index size = mos_.eigenvalues().size();
943 for (Index i = 0; i < size; ++i) {
944 mos_.eigenvalues()(i) = MO_copy.eigenvalues()(sort_index[i]);
945 }
946 for (Index i = 0; i < size; ++i) {
947 mos_.eigenvectors().col(i) = MO_copy.eigenvectors().col(sort_index[i]);
948 }
949}
950
952 std::vector<Index> sort_index = SortEnergiesBeta();
954 Index size = mos_beta_.eigenvalues().size();
955 for (Index i = 0; i < size; ++i) {
956 mos_beta_.eigenvalues()(i) = MO_copy.eigenvalues()(sort_index[i]);
957 }
958 for (Index i = 0; i < size; ++i) {
959 mos_beta_.eigenvectors().col(i) = MO_copy.eigenvectors().col(sort_index[i]);
960 }
961}
962
971 const Orbitals& orbitalsB) {
972
973 // This routine constructs a block-diagonal guess only from the restricted
974 // MO coefficient matrices mos_. It therefore only makes sense for
975 // restricted closed-shell inputs.
976 if (orbitalsA.hasUnrestrictedOrbitals() ||
977 orbitalsB.hasUnrestrictedOrbitals()) {
978 throw std::runtime_error(
979 "PrepareDimerGuess currently supports only restricted orbitals.");
980 }
981
982 if (orbitalsA.getSpin() != 1 || orbitalsB.getSpin() != 1) {
983 throw std::runtime_error(
984 "PrepareDimerGuess currently supports only closed-shell singlets.");
985 }
986
987 // constructing the direct product orbA x orbB
988 Index basisA = orbitalsA.getBasisSetSize();
989 Index basisB = orbitalsB.getBasisSetSize();
990
991 // In the restricted closed-shell case, getLumo() is the number of occupied
992 // spatial orbitals, which is exactly what this block-merging logic assumes.
993 Index occA = orbitalsA.getLumo();
994 Index occB = orbitalsB.getLumo();
995
996 mos_.eigenvectors() = Eigen::MatrixXd::Zero(basisA + basisB, basisA + basisB);
997
998 // AxB = | A 0 |
999 // | 0 B |
1000 if (orbitalsA.getDFTbasisName() != orbitalsB.getDFTbasisName()) {
1001 throw std::runtime_error("Basissets of Orbitals A and B differ " +
1002 orbitalsA.getDFTbasisName() + ":" +
1003 orbitalsB.getDFTbasisName());
1004 }
1005 this->SetupDftBasis(orbitalsA.getDFTbasisName());
1006
1007 if (orbitalsA.getECPName() != orbitalsB.getECPName()) {
1008 throw std::runtime_error("ECPs of Orbitals A and B differ " +
1009 orbitalsA.getECPName() + ":" +
1010 orbitalsB.getECPName());
1011 }
1012 this->setECPName(orbitalsA.getECPName());
1013
1014 // Keep occupation metadata fully consistent for a restricted singlet.
1015 this->setNumberOfOccupiedLevels(occA + occB);
1016 this->setNumberOfOccupiedLevelsBeta(occA + occB);
1017 this->setNumberOfAlphaElectrons(occA + occB);
1018 this->setNumberOfBetaElectrons(occA + occB);
1019 this->setChargeAndSpin(orbitalsA.getCharge() + orbitalsB.getCharge(), 1);
1020
1021 this->MOs().eigenvectors().block(0, 0, basisA, basisA) =
1022 orbitalsA.MOs().eigenvectors();
1023 this->MOs().eigenvectors().block(basisA, basisA, basisB, basisB) =
1024 orbitalsB.MOs().eigenvectors();
1025
1026 this->MOs().eigenvalues() = Eigen::VectorXd::Zero(basisA + basisB);
1027 this->MOs().eigenvalues().segment(0, basisA) = orbitalsA.MOs().eigenvalues();
1028 this->MOs().eigenvalues().segment(basisA, basisB) =
1029 orbitalsB.MOs().eigenvalues();
1030
1031 this->OrderMOsbyEnergy();
1032}
1033
1047 const Orbitals& orbitalsB) {
1048 Index basisA = orbitalsA.getBasisSetSize();
1049 Index basisB = orbitalsB.getBasisSetSize();
1050
1051 if (orbitalsA.getDFTbasisName() != orbitalsB.getDFTbasisName()) {
1052 throw std::runtime_error("Basissets of Orbitals A and B differ " +
1053 orbitalsA.getDFTbasisName() + ":" +
1054 orbitalsB.getDFTbasisName());
1055 }
1056 this->SetupDftBasis(orbitalsA.getDFTbasisName());
1057
1058 if (orbitalsA.getECPName() != orbitalsB.getECPName()) {
1059 throw std::runtime_error("ECPs of Orbitals A and B differ " +
1060 orbitalsA.getECPName() + ":" +
1061 orbitalsB.getECPName());
1062 }
1063 this->setECPName(orbitalsA.getECPName());
1064
1065 // A restricted monomer's own alpha and beta MOs are identical by
1066 // construction -- MOs_beta() only holds meaningful, independent data
1067 // for a monomer that is itself already unrestricted.
1068 const Eigen::MatrixXd& A_alpha = orbitalsA.MOs().eigenvectors();
1069 const Eigen::MatrixXd& A_beta = orbitalsA.hasUnrestrictedOrbitals()
1070 ? orbitalsA.MOs_beta().eigenvectors()
1071 : orbitalsA.MOs().eigenvectors();
1072 const Eigen::MatrixXd& B_alpha = orbitalsB.MOs().eigenvectors();
1073 const Eigen::MatrixXd& B_beta = orbitalsB.hasUnrestrictedOrbitals()
1074 ? orbitalsB.MOs_beta().eigenvectors()
1075 : orbitalsB.MOs().eigenvectors();
1076
1077 const Eigen::VectorXd& A_alpha_energies = orbitalsA.MOs().eigenvalues();
1078 const Eigen::VectorXd& A_beta_energies =
1079 orbitalsA.hasUnrestrictedOrbitals() ? orbitalsA.MOs_beta().eigenvalues()
1080 : orbitalsA.MOs().eigenvalues();
1081 const Eigen::VectorXd& B_alpha_energies = orbitalsB.MOs().eigenvalues();
1082 const Eigen::VectorXd& B_beta_energies =
1083 orbitalsB.hasUnrestrictedOrbitals() ? orbitalsB.MOs_beta().eigenvalues()
1084 : orbitalsB.MOs().eigenvalues();
1085
1086 mos_.eigenvectors() = Eigen::MatrixXd::Zero(basisA + basisB, basisA + basisB);
1087 mos_.eigenvectors().block(0, 0, basisA, basisA) = A_alpha;
1088 mos_.eigenvectors().block(basisA, basisA, basisB, basisB) = B_alpha;
1089 mos_.eigenvalues() = Eigen::VectorXd::Zero(basisA + basisB);
1090 mos_.eigenvalues().segment(0, basisA) = A_alpha_energies;
1091 mos_.eigenvalues().segment(basisA, basisB) = B_alpha_energies;
1092
1093 mos_beta_.eigenvectors() =
1094 Eigen::MatrixXd::Zero(basisA + basisB, basisA + basisB);
1095 mos_beta_.eigenvectors().block(0, 0, basisA, basisA) = A_beta;
1096 mos_beta_.eigenvectors().block(basisA, basisA, basisB, basisB) = B_beta;
1097 mos_beta_.eigenvalues() = Eigen::VectorXd::Zero(basisA + basisB);
1098 mos_beta_.eigenvalues().segment(0, basisA) = A_beta_energies;
1099 mos_beta_.eigenvalues().segment(basisA, basisB) = B_beta_energies;
1100
1101 Index alpha_electrons = orbitalsA.getLumoAlpha() + orbitalsB.getLumoAlpha();
1102 Index beta_electrons = orbitalsA.getLumoBeta() + orbitalsB.getLumoBeta();
1103 this->setNumberOfOccupiedLevels(alpha_electrons);
1104 this->setNumberOfOccupiedLevelsBeta(beta_electrons);
1105 this->setNumberOfAlphaElectrons(alpha_electrons);
1106 this->setNumberOfBetaElectrons(beta_electrons);
1107 // spin is the MULTIPLICITY (2S+1) convention throughout this codebase
1108 // (spin=1 is singlet, spin=2 is doublet, etc.) -- 2S itself is exactly
1109 // the alpha-beta electron-count difference, matching how DFTEngine's
1110 // own Initialize() derives num_alpha_electrons_/num_beta_electrons_
1111 // from a user-specified charge+spin pair in the first place.
1112 Index spin = (alpha_electrons - beta_electrons) + 1;
1113 this->setChargeAndSpin(orbitalsA.getCharge() + orbitalsB.getCharge(), spin);
1114
1115 this->OrderMOsbyEnergyAlpha();
1116 this->OrderMOsbyEnergyBeta();
1117}
1118
1119void Orbitals::WriteToCpt(const std::string& filename) const {
1120 std::lock_guard<std::recursive_mutex> lock(
1123 WriteToCpt(cpf);
1124}
1125
1127 CheckpointWriter writer = f.getWriter("/QMdata");
1128 WriteToCpt(writer);
1129 WriteBasisSetsToCpt(writer);
1130}
1131
1133 CheckpointWriter dftWriter = w.openChild("dft");
1134 dftbasis_.WriteToCpt(dftWriter);
1135 CheckpointWriter auxWriter = w.openChild("aux");
1136 auxbasis_.WriteToCpt(auxWriter);
1137}
1138
1140 w(votca::tools::ToolsVersionStr(), "XTPVersion");
1141 w(orbitals_version(), "version");
1142 w(occupied_levels_, "occupied_levels");
1143 w(occupied_levels_beta_, "occupied_levels_beta");
1144 w(number_alpha_electrons_, "number_alpha_electrons");
1145 w(number_beta_electrons_, "number_beta_electrons");
1146 w(total_charge_, "charge");
1147 w(total_spin_, "spin");
1148
1149 w(mos_, "mos");
1150 w(mos_beta_, "mos_beta");
1151 w(occupations_, "occupations");
1152 w(active_electrons_, "active_electrons");
1153 // only PbE runs set it; other files keep their layout
1154 if (active_core_levels_ >= 0) {
1155 w(active_core_levels_, "active_core_levels");
1156 }
1157 w(mos_embedding_, "mos_embedding");
1158 w(lmos_, "LMOs");
1159 w(lmos_energies_, "LMOs_energies");
1160 w(inactivedensity_, "inactivedensity");
1161 w(expandedMOs_, "TruncMOsFullBasis");
1162
1163 CheckpointWriter molgroup = w.openChild("qmmolecule");
1164 atoms_.WriteToCpt(molgroup);
1165
1166 w(qm_energy_, "qm_energy");
1167 w(forces_, "forces");
1168 if (hasExcitedStateForces()) {
1169 w(excited_forces_, "excited_state_forces");
1170 w(excited_forces_state_, "excited_state_forces_state");
1171 }
1172 if (hasQPGradients()) {
1173 w(qp_gradients_, "qp_gradients");
1174 w(qp_gradient_levels_, "qp_gradient_levels");
1175 }
1176 if (hasRelaxedDensity()) {
1177 w(relaxed_density_, "relaxed_density");
1178 w(relaxed_density_state_, "relaxed_density_state");
1179 }
1180 if (hasPolarizability()) {
1181 w(polarizability_, "polarizability");
1182 }
1183 w(qm_package_, "qm_package");
1184
1185 w(rpamin_, "rpamin");
1186 w(rpamax_, "rpamax");
1187 w(qpmin_, "qpmin");
1188 w(qpmax_, "qpmax");
1189 w(bse_vmin_, "bse_vmin");
1190 w(bse_cmax_, "bse_cmax");
1191 w(functionalname_, "XCFunctional");
1192 w(grid_quality_, "XC_grid_quality");
1193 w(ScaHFX_, "ScaHFX");
1194
1195 w(useTDA_, "useTDA");
1196 w(ECP_, "ECP");
1197
1198 w(rpa_inputenergies_, "RPA_inputenergies");
1199 w(QPpert_energies_, "QPpert_energies");
1200
1201 w(QPdiag_, "QPdiag");
1202
1203 w(BSE_singlet_, "BSE_singlet");
1204
1205 w(transition_dipoles_, "transition_dipoles");
1206
1207 w(BSE_triplet_, "BSE_triplet");
1208
1209 std::uint8_t tmp = use_Hqp_offdiag_ ? 1u : 0u;
1210 w(tmp, "use_Hqp_offdiag");
1211 std::uint8_t tmp_qsgw = is_qsgw_ ? 1u : 0u;
1212 w(tmp_qsgw, "is_qsgw");
1213
1214 w(BSE_singlet_energies_dynamic_, "BSE_singlet_dynamic");
1215
1216 w(BSE_triplet_energies_dynamic_, "BSE_triplet_dynamic");
1217 if (BSE_singlet_dynamic_change_.size() > 0) {
1218 w(BSE_singlet_dynamic_change_, "BSE_singlet_dynamic_change");
1219 w(BSE_singlet_dynamic_iterations_, "BSE_singlet_dynamic_iterations");
1220 }
1221 if (BSE_triplet_dynamic_change_.size() > 0) {
1222 w(BSE_triplet_dynamic_change_, "BSE_triplet_dynamic_change");
1223 w(BSE_triplet_dynamic_iterations_, "BSE_triplet_dynamic_iterations");
1224 }
1225
1226 w(CalcType_, "CalcType");
1227
1228 // spin GW
1229 w(rpa_inputenergies_alpha_, "RPA_inputenergies_alpha");
1230 w(rpa_inputenergies_beta_, "RPA_inputenergies_beta");
1231
1232 w(QPpert_energies_alpha_, "QPpert_energies_alpha");
1233 w(QPpert_energies_beta_, "QPpert_energies_beta");
1234
1235 w(QPdiag_alpha_, "QPdiag_alpha");
1236 w(QPdiag_beta_, "QPdiag_beta");
1237
1238 w(BSE_uks_, "BSE_uks");
1239 w(BSE_uks_energies_dynamic_, "BSE_uks_dynamic");
1240}
1241
1242void Orbitals::ReadFromCpt(const std::string& filename) {
1243 std::lock_guard<std::recursive_mutex> lock(
1246 ReadFromCpt(cpf);
1247}
1248
1250 CheckpointReader reader = f.getReader("/QMdata");
1251 ReadFromCpt(reader);
1252 ReadBasisSetsFromCpt(reader);
1253}
1254
1256 CheckpointReader dftReader = r.openChild("dft");
1257 dftbasis_.ReadFromCpt(dftReader);
1258 CheckpointReader auxReader = r.openChild("aux");
1259 auxbasis_.ReadFromCpt(auxReader);
1260}
1261
1263 r(occupied_levels_, "occupied_levels");
1264 r(number_alpha_electrons_, "number_alpha_electrons");
1265
1266 int version;
1267 r(version, "version");
1268
1269 auto r_optional = [&r](auto& obj, const std::string& key) {
1270 try {
1271 r(obj, key);
1272 } catch (std::runtime_error&) {
1273 // Older checkpoints may not contain this field.
1274 }
1275 };
1276
1277 // Read qmatoms
1278 CheckpointReader molgroup = r.openChild("qmmolecule");
1279 atoms_.ReadFromCpt(molgroup);
1280
1281 r(qm_energy_, "qm_energy");
1282 try {
1283 r(forces_, "forces");
1284 } catch (std::runtime_error& e) {
1285 ; // older checkpoint files won't have this field -- leave forces_
1286 // empty (hasForces() == false), same convention as LMOs below.
1287 }
1288 r(qm_package_, "qm_package");
1289 // optional: only written if computed; older files have none
1290 r_optional(polarizability_, "polarizability");
1291 // optional: only written if computed
1292 r_optional(excited_forces_, "excited_state_forces");
1293 r_optional(excited_forces_state_, "excited_state_forces_state");
1294 r_optional(qp_gradients_, "qp_gradients");
1295 r_optional(qp_gradient_levels_, "qp_gradient_levels");
1296 r_optional(relaxed_density_, "relaxed_density");
1297 r_optional(relaxed_density_state_, "relaxed_density_state");
1298 // optional: older files have none (-1: not set)
1299 r_optional(active_core_levels_, "active_core_levels");
1300 try {
1301 r(lmos_, "LMOs");
1302 r(lmos_energies_, "LMOs_energies");
1303 } catch (std::runtime_error& e) {
1304 ;
1305 }
1306
1307 r(version, "version");
1308 r(mos_, "mos");
1309 r(mos_embedding_, "mos_embedding");
1310 r(active_electrons_, "active_electrons");
1311 r(inactivedensity_, "inactivedensity");
1312 r(CalcType_, "CalcType");
1313 r(expandedMOs_, "TruncMOsFullBasis");
1314
1315 // spin info available from version 6 or higher
1316 if (version > 5) {
1317 r(occupied_levels_beta_, "occupied_levels_beta");
1318 r(number_beta_electrons_, "number_beta_electrons");
1319 r(total_charge_, "charge");
1320 r(total_spin_, "spin");
1321 r(mos_beta_, "mos_beta");
1322 r(occupations_, "occupations");
1323 }
1324
1325 if (version < 3) {
1326 // clang-format off
1327 std::array<Index, 49> votcaOrder_old = {
1328 0, // s
1329 0, -1, 1, // p
1330 0, -1, 1, -2, 2, // d
1331 0, -1, 1, -2, 2, -3, 3, // f
1332 0, -1, 1, -2, 2, -3, 3, -4, 4, // g
1333 0, -1, 1, -2, 2, -3, 3, -4, 4,-5,5, // h
1334 0, -1, 1, -2, 2, -3, 3, -4, 4,-5,5,-6,6 // i
1335 };
1336 // clang-format on
1337
1338 std::array<Index, 49> multiplier;
1339 multiplier.fill(1);
1340 OrbReorder ord(votcaOrder_old, multiplier);
1341 ord.reorderOrbitals(mos_.eigenvectors(), this->getDftBasis());
1342 }
1343
1344 if (version < 5) { // we need to construct the basissets, NB. can only be
1345 // done after reading the atoms.
1346 std::string dft_basis_name;
1347 std::string aux_basis_name;
1348 r(dft_basis_name, "dftbasis");
1349 r(aux_basis_name, "auxbasis");
1350 this->SetupDftBasis(dft_basis_name);
1351 this->SetupAuxBasis(aux_basis_name);
1352 }
1353
1354 r(rpamin_, "rpamin");
1355 r(rpamax_, "rpamax");
1356 r(qpmin_, "qpmin");
1357 r(qpmax_, "qpmax");
1358 r(bse_vmin_, "bse_vmin");
1359 r(bse_cmax_, "bse_cmax");
1361 try {
1362 r(functionalname_, "XCFunctional");
1363 r(grid_quality_, "XC_grid_quality");
1364 } catch (std::runtime_error& e) {
1365 grid_quality_ = "medium";
1366 }
1367 r(ScaHFX_, "ScaHFX");
1368 r(useTDA_, "useTDA");
1369 r(ECP_, "ECP");
1370
1371 r(rpa_inputenergies_, "RPA_inputenergies");
1372
1373 r(QPpert_energies_, "QPpert_energies");
1374 r(QPdiag_, "QPdiag");
1375
1376 // Optional unrestricted GW data
1377 r_optional(rpa_inputenergies_alpha_, "RPA_inputenergies_alpha");
1378 r_optional(rpa_inputenergies_beta_, "RPA_inputenergies_beta");
1379
1380 r_optional(QPpert_energies_alpha_, "QPpert_energies_alpha");
1381 r_optional(QPpert_energies_beta_, "QPpert_energies_beta");
1382
1383 r_optional(QPdiag_alpha_, "QPdiag_alpha");
1384 r_optional(QPdiag_beta_, "QPdiag_beta");
1385 r_optional(BSE_uks_, "BSE_uks");
1386 r_optional(BSE_uks_energies_dynamic_, "BSE_uks_dynamic");
1387 r(BSE_singlet_, "BSE_singlet");
1388
1389 r(transition_dipoles_, "transition_dipoles");
1390
1391 r(BSE_triplet_, "BSE_triplet");
1392
1393 std::uint8_t tmp = 0;
1394 r(tmp, "use_Hqp_offdiag");
1395 use_Hqp_offdiag_ = (tmp != 0);
1396 std::uint8_t tmp_qsgw = 0;
1397 if (version > 8) {
1398 r(tmp_qsgw, "is_qsgw");
1399 }
1400 is_qsgw_ = (tmp_qsgw != 0);
1401
1402 if (version > 1) {
1403 r(BSE_singlet_energies_dynamic_, "BSE_singlet_dynamic");
1404
1405 r(BSE_triplet_energies_dynamic_, "BSE_triplet_dynamic");
1406 }
1407 r_optional(BSE_singlet_dynamic_change_, "BSE_singlet_dynamic_change");
1408 r_optional(BSE_singlet_dynamic_iterations_, "BSE_singlet_dynamic_iterations");
1409 r_optional(BSE_triplet_dynamic_change_, "BSE_triplet_dynamic_change");
1410 r_optional(BSE_triplet_dynamic_iterations_, "BSE_triplet_dynamic_iterations");
1411 // Backward compatibility for older restricted checkpoints: they may not
1412 // contain explicit electron counts, or (version-6 files written by 2025
1413 // builds, e.g. from parsed ORCA output) contain uninitialised values in
1414 // number_alpha_electrons/number_beta_electrons. A restricted singlet has
1415 // exactly occupied_levels_ electrons of each spin.
1419 }
1420}
1421
1422/*********************************************
1423 * Extensions Spin-DFT
1424 **********************************************/
1425
1426// Spin-resolved ground-state density matrices.
1427//
1428// The returned pair is (P^alpha, P^beta) with
1429//
1430// P^sigma = C_occ^sigma (C_occ^sigma)^T
1431//
1432// for unrestricted calculations. In the restricted branch the same spatial MO
1433// coefficients are reused and distributed over alpha/beta occupations according
1434// to the stored electron counts.
1436 const {
1437 if (!hasMOs()) {
1438 throw std::runtime_error("Orbitals file does not contain MO coefficients");
1439 }
1440
1441 std::array<Eigen::MatrixXd, 2> result;
1442 result[0] = Eigen::MatrixXd::Zero(mos_.eigenvectors().rows(),
1443 mos_.eigenvectors().rows());
1444 result[1] = Eigen::MatrixXd::Zero(mos_.eigenvectors().rows(),
1445 mos_.eigenvectors().rows());
1446
1448 if (occupied_levels_ > 0) {
1449 const Eigen::MatrixXd occ_a =
1450 mos_.eigenvectors().leftCols(occupied_levels_);
1451 result[0] = occ_a * occ_a.transpose();
1452 }
1453 if (occupied_levels_beta_ > 0) {
1454 const Eigen::MatrixXd occ_b =
1455 mos_beta_.eigenvectors().leftCols(occupied_levels_beta_);
1456 result[1] = occ_b * occ_b.transpose();
1457 }
1458 return result;
1459 }
1460
1461 // Restricted branch:
1462 // Prefer explicit alpha/beta electron counts, but fall back to the legacy
1463 // occupied_levels_ convention when those counts were never set.
1466
1467 if (n_alpha == 0 && n_beta == 0 && occupied_levels_ > 0) {
1468 n_alpha = occupied_levels_;
1469 n_beta = occupied_levels_;
1470 }
1471
1472 const Index n_docc = std::min(n_alpha, n_beta);
1473 const Index n_socc_alpha = n_alpha - n_docc;
1474 const Index n_socc_beta = n_beta - n_docc;
1475
1476 if (n_docc > 0) {
1477 const Eigen::MatrixXd docc = mos_.eigenvectors().leftCols(n_docc);
1478 const Eigen::MatrixXd d_docc = docc * docc.transpose();
1479 result[0] += d_docc;
1480 result[1] += d_docc;
1481 }
1482
1483 if (n_socc_alpha > 0) {
1484 const Eigen::MatrixXd socc_a =
1485 mos_.eigenvectors().middleCols(n_docc, n_socc_alpha);
1486 result[0] += socc_a * socc_a.transpose();
1487 }
1488
1489 if (n_socc_beta > 0) {
1490 const Eigen::MatrixXd socc_b =
1491 mos_.eigenvectors().middleCols(n_docc + n_socc_alpha, n_socc_beta);
1492 result[1] += socc_b * socc_b.transpose();
1493 }
1494
1495 return result;
1496}
1497
1498} // namespace xtp
1499} // namespace votca
const Eigen::VectorXd & eigenvalues() const
Definition eigensystem.h:30
const Eigen::MatrixXd & eigenvectors() const
Definition eigensystem.h:33
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
void setCenter(const Eigen::Vector3d &r)
Definition aomatrix.h:98
const std::array< Eigen::MatrixXd, 3 > & Matrix() const
Definition aomatrix.h:96
void Fill(const AOBasis &aobasis) final
void Load(const std::string &name)
Definition basisset.cc:149
CheckpointReader getReader()
CheckpointWriter getWriter()
CheckpointReader openChild(const std::string &childName) const
CheckpointWriter openChild(const std::string &childName) const
void reorderOrbitals(Eigen::MatrixXd &moCoefficients, const AOBasis &basis)
Definition orbreorder.cc:74
tools::EigenSystem QPdiag_alpha_
Definition orbitals.h:960
Eigen::MatrixXd excited_forces_
Definition orbitals.h:900
Index number_beta_electrons_
Definition orbitals.h:869
void CalcCoupledTransition_Dipoles()
Definition orbitals.cc:778
bool hasQPdiag() const
Definition orbitals.h:522
Index getCharge() const
Return the stored total charge.
Definition orbitals.h:254
bool hasPolarizability() const
Definition orbitals.h:305
Eigen::MatrixXd occupations_
Definition orbitals.h:877
Eigen::VectorXd rpa_inputenergies_
Definition orbitals.h:931
Index getHomo() const
Return the default HOMO index used by spin-agnostic callers.
Definition orbitals.h:107
bool hasQPGradients() const
Definition orbitals.h:344
Eigen::VectorXd BSE_uks_energies_dynamic_
Definition orbitals.h:964
Eigen::MatrixXd TransitionDensityMatrix(const QMState &state) const
Definition orbitals.cc:335
Eigen::MatrixXd qp_gradients_
Definition orbitals.h:902
double getDFTTotalEnergy() const
Return the stored total DFT energy.
Definition orbitals.h:292
Index getSpin() const
Return the stored spin multiplicity.
Definition orbitals.h:252
Eigen::MatrixXd CalculateQParticleAORepresentation() const
Transform quasiparticle amplitudes into the AO representation.
Definition orbitals.cc:269
std::array< Eigen::MatrixXd, 2 > DensityMatrixExcitedState_R(const QMState &state) const
Definition orbitals.cc:555
const tools::EigenSystem & MOs_beta() const
Return read-only access to beta-spin molecular orbitals.
Definition orbitals.h:202
bool hasUnrestrictedOrbitals() const
Report whether separate beta-spin orbitals are present.
Definition orbitals.h:768
Eigen::VectorXd lmos_energies_
Definition orbitals.h:882
tools::EigenSystem BSE_singlet_
Definition orbitals.h:938
std::string relaxed_density_state_
Definition orbitals.h:905
tools::EigenSystem QPdiag_beta_
Definition orbitals.h:961
void OrderMOsbyEnergyBeta()
Same as OrderMOsbyEnergyAlpha, but for the BETA channel (mos_beta_).
Definition orbitals.cc:951
void PrepareDimerGuess(const Orbitals &orbitalsA, const Orbitals &orbitalsB)
Guess for a dimer based on monomer orbitals.
Definition orbitals.cc:970
tools::EigenSystem mos_beta_
Definition orbitals.h:876
std::string grid_quality_
Definition orbitals.h:928
bool hasMOs() const
Report whether alpha/restricted molecular orbitals are available.
Definition orbitals.h:185
double getTotalStateEnergy(const QMState &state) const
Return the absolute total energy of the requested state in Hartree.
Definition orbitals.cc:694
Eigen::VectorXd BSE_triplet_energies_dynamic_
Definition orbitals.h:944
bool hasRelaxedDensity() const
Definition orbitals.h:358
void ReadBasisSetsFromCpt(CheckpointReader &r)
Deserialize attached AO basis sets from an already-open checkpoint reader.
Definition orbitals.cc:1255
std::array< Eigen::MatrixXd, 2 > DensityMatrixGroundStateSpinResolved() const
Definition orbitals.cc:1435
Eigen::MatrixXd QPpert_energies_beta_
Definition orbitals.h:958
void WriteBasisSetsToCpt(CheckpointWriter &w) const
Definition orbitals.cc:1132
std::vector< Index > CheckDegeneracy(Index level, double energy_difference) const
Definition orbitals.cc:56
Eigen::VectorXd BSE_singlet_dynamic_iterations_
Definition orbitals.h:947
Eigen::MatrixXd inactivedensity_
Definition orbitals.h:885
std::string getCalculationType() const
Return the stored calculation-type tag.
Definition orbitals.h:242
std::array< Eigen::MatrixXd, 3 > CalcFreeTransition_Dipoles() const
Definition orbitals.cc:760
Eigen::MatrixXd forces_
Definition orbitals.h:899
Eigen::MatrixXd CalcAuxMat_cc(const Eigen::VectorXd &coeffs) const
Definition orbitals.cc:603
Eigen::VectorXd BSE_triplet_dynamic_change_
Definition orbitals.h:946
std::vector< Index > qp_gradient_levels_
Definition orbitals.h:903
Eigen::MatrixXd polarizability_
Definition orbitals.h:906
Eigen::MatrixXd expandedMOs_
Definition orbitals.h:886
void setNumberOfAlphaElectrons(Index electrons)
Store the total number of alpha electrons.
Definition orbitals.h:139
Eigen::VectorXd Oscillatorstrengths() const
Definition orbitals.cc:661
std::vector< Eigen::Vector3d > transition_dipoles_
Definition orbitals.h:939
static constexpr int orbitals_version()
Definition orbitals.h:972
std::string functionalname_
Definition orbitals.h:927
Eigen::MatrixXd lmos_
Definition orbitals.h:881
Eigen::MatrixXd DensityMatrixWithoutGS(const QMState &state) const
Definition orbitals.cc:121
Eigen::MatrixXd DensityMatrixFull(const QMState &state) const
Definition orbitals.cc:150
Eigen::MatrixXd CalcAuxMat_vv(const Eigen::VectorXd &coeffs) const
Definition orbitals.cc:597
Eigen::MatrixXd relaxed_density_
Definition orbitals.h:904
void PrepareDimerGuessMixedSpin(const Orbitals &orbitalsA, const Orbitals &orbitalsB)
Dimer guess from two converged monomers of arbitrary charge and spin.
Definition orbitals.cc:1046
void SetupAuxBasis(std::string aux_basis_name)
Definition orbitals.cc:108
std::string qm_package_
Definition orbitals.h:929
std::string excited_forces_state_
Definition orbitals.h:901
Index getLumoAlpha() const
Return the alpha-spin LUMO index inferred from the stored electron counts.
Definition orbitals.h:75
void setNumberOfBetaElectrons(Index electrons)
Store the total number of beta electrons.
Definition orbitals.h:144
tools::EigenSystem BSE_triplet_
Definition orbitals.h:940
void setBSEindices(Index vmin, Index cmax)
Definition orbitals.h:467
const Eigen::MatrixXd & getInactiveDensity() const
Return the inactive-region density matrix used in embedding workflows.
Definition orbitals.h:758
std::vector< Index > SortEnergies()
Definition orbitals.cc:81
Index getHomoBeta() const
Return the beta-spin HOMO index.
Definition orbitals.h:101
std::array< Eigen::MatrixXd, 2 > DensityMatrixExcitedState_AR(const QMState &state) const
Definition orbitals.cc:609
double getExcitedStateEnergy(const QMState &state) const
Return the excitation energy of the requested state in Hartree.
Definition orbitals.cc:703
void setECPName(const std::string &ECP)
Store the effective core potential label.
Definition orbitals.h:170
void setNumberOfOccupiedLevels(Index occupied_levels)
Definition orbitals.h:122
Index occupied_levels_beta_
Definition orbitals.h:867
Orbitals()
Construct an empty orbital container with default metadata.
Definition orbitals.cc:46
tools::EigenSystem mos_
Definition orbitals.h:875
void OrderMOsbyEnergyAlpha()
Definition orbitals.cc:939
tools::EigenSystem QPdiag_
Definition orbitals.h:936
Eigen::VectorXd rpa_inputenergies_beta_
Definition orbitals.h:955
Eigen::MatrixXd DensityMatrixKSstate(const QMState &state) const
Build the AO density matrix for a single KS orbital state.
Definition orbitals.cc:236
Eigen::MatrixXd DensityMatrixQuasiParticle(const QMState &state) const
Build the AO density matrix for a quasiparticle state.
Definition orbitals.cc:284
bool hasExcitedStateForces() const
Definition orbitals.h:328
Index getBasisSetSize() const
Return the number of AO basis functions in the DFT basis.
Definition orbitals.h:72
std::vector< Index > SortEnergiesBeta()
Definition orbitals.cc:929
Eigen::VectorXd BSE_singlet_dynamic_change_
Definition orbitals.h:945
Eigen::MatrixXd QPpert_energies_alpha_
Definition orbitals.h:957
Eigen::MatrixXd BSEOrbitals() const
Definition orbitals.cc:254
Eigen::VectorXd BSE_singlet_energies_dynamic_
Definition orbitals.h:943
Index getGWAmin() const
Return the lower GW orbital index.
Definition orbitals.h:433
const tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
Definition orbitals.h:192
Eigen::MatrixXd DensityMatrixGroundState() const
Build the ground-state AO density matrix from the stored orbitals.
Definition orbitals.cc:224
std::string CalcType_
Definition orbitals.h:873
Index getLumoBeta() const
Definition orbitals.h:87
const QMMolecule & QMAtoms() const
Return read-only access to the molecular geometry.
Definition orbitals.h:262
tools::EigenSystem mos_embedding_
Definition orbitals.h:879
Eigen::VectorXd rpa_inputenergies_alpha_
Definition orbitals.h:954
std::vector< Index > SortEnergiesAlpha()
Definition orbitals.cc:917
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1242
tools::EigenSystem BSE_uks_
Definition orbitals.h:963
void setNumberOfOccupiedLevelsBeta(Index occupied_levels_beta)
Store the number of occupied beta-spin orbitals.
Definition orbitals.h:134
void setChargeAndSpin(Index charge, Index spin)
Definition orbitals.h:246
Eigen::VectorXd QPpert_energies_
Definition orbitals.h:933
void WriteToCpt(const std::string &filename) const
Write the orbital container to a checkpoint file on disk.
Definition orbitals.cc:1119
const std::string & getECPName() const
Return the effective core potential label.
Definition orbitals.h:167
const std::string & getDFTbasisName() const
Return the DFT basis-set name.
Definition orbitals.h:376
void SetupDftBasis(std::string basis_name)
Build and attach the DFT AO basis from the stored molecular geometry.
Definition orbitals.cc:99
std::array< Eigen::MatrixXd, 2 > DensityMatrixExcitedState(const QMState &state) const
Build separate hole and electron AO densities for an excited state.
Definition orbitals.cc:433
std::string ECP_
Definition orbitals.h:870
Index number_alpha_electrons_
Definition orbitals.h:868
Eigen::Vector3d CalcElDipole(const QMState &state) const
Compute the electronic dipole moment associated with a state density.
Definition orbitals.cc:307
Eigen::VectorXd BSE_triplet_dynamic_iterations_
Definition orbitals.h:948
Index getHomoAlpha() const
Return the alpha-spin HOMO index.
Definition orbitals.h:83
const AOBasis & getDftBasis() const
Return the DFT AO basis, throwing if it has not been initialized.
Definition orbitals.h:386
QMMolecule atoms_
Definition orbitals.h:888
Index getLumo() const
Return the default LUMO index used by spin-agnostic callers.
Definition orbitals.h:105
container for QM atoms
Definition qmatom.h:37
std::string ToLongString() const
Definition qmstate.cc:72
bool isKSState() const
Definition qmstate.h:92
bool isPQPState() const
Definition qmstate.h:94
bool isExciton() const
Definition qmstate.h:73
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
std::string ToString() const
Definition qmstate.cc:155
Index StateIdx() const
Definition qmstate.h:157
bool isTransition() const
Definition qmstate.h:156
const QMStateType & Type() const
Definition qmstate.h:154
const std::string & ToolsVersionStr()
Definition version.cc:33
std::recursive_mutex & Hdf5Mutex()
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26