27#include <boost/algorithm/string.hpp>
28#include <boost/format.hpp>
57 Index ignored_corelevels = 0;
60 if (
orbitals_.getActiveCoreLevels() >= 0 &&
61 2 *
orbitals_.getNumberOfAlphaElectrons() ==
67 basis.
Load(
"corelevels");
68 Index coreElectrons = 0;
69 for (
const auto& atom :
orbitals_.QMAtoms()) {
72 ignored_corelevels = coreElectrons / 2;
74 return ignored_corelevels;
87 const bool is_uks =
orbitals_.hasUnrestrictedOrbitals();
95 num_of_occlevels = std::max(
orbitals_.getNumberOfAlphaElectrons(),
99 std::string ranges = options.
get(
".ranges").
as<std::string>();
103 if (ranges ==
"factor") {
105 double rpamaxfactor = options.
get(
".rpamax").
as<
double>();
106 rpamax =
Index(rpamaxfactor *
double(num_of_levels)) -
109 double qpminfactor = options.
get(
".qpmin").
as<
double>();
111 num_of_occlevels -
Index(qpminfactor *
double(num_of_occlevels)) - 1;
113 double qpmaxfactor = options.
get(
".qpmax").
as<
double>();
115 num_of_occlevels +
Index(qpmaxfactor *
double(num_of_occlevels)) - 1;
117 double bseminfactor = options.
get(
".bsemin").
as<
double>();
119 num_of_occlevels -
Index(bseminfactor *
double(num_of_occlevels)) - 1;
121 double bsemaxfactor = options.
get(
".bsemax").
as<
double>();
123 num_of_occlevels +
Index(bsemaxfactor *
double(num_of_occlevels)) - 1;
125 }
else if (ranges ==
"explicit") {
130 bse_vmin = options.
get(
".bsemin").
as<
Index>();
131 bse_cmax = options.
get(
".bsemax").
as<
Index>();
132 }
else if (ranges ==
"default") {
133 rpamax = num_of_levels - 1;
135 qpmax = 3 * homo + 1;
137 bse_cmax = 3 * homo + 1;
138 }
else if (ranges ==
"full") {
139 rpamax = num_of_levels - 1;
141 qpmax = num_of_levels - 1;
143 bse_cmax = num_of_levels - 1;
145 std::string ignore_corelevels =
146 options.
get(
".ignore_corelevels").
as<std::string>();
150 ".inactive_screening",
"none"));
153 ".inactive_screening_memory", 0.0);
157 ".inactive_screening_virtual_cutoff", 0.0) *
160 ignore_corelevels !=
"none") {
163 throw std::runtime_error(
164 "inactive_screening is not implemented together with "
165 "ignore_corelevels.");
168 if (ignore_corelevels ==
"RPA" || ignore_corelevels ==
"GW" ||
169 ignore_corelevels ==
"BSE") {
171 if (ignore_corelevels ==
"RPA") {
172 rpamin = ignored_corelevels;
174 if (ignore_corelevels ==
"GW" || ignore_corelevels ==
"RPA") {
175 if (qpmin < ignored_corelevels) {
176 qpmin = ignored_corelevels;
179 if (ignore_corelevels ==
"GW" || ignore_corelevels ==
"RPA" ||
180 ignore_corelevels ==
"BSE") {
181 if (bse_vmin < ignored_corelevels) {
182 bse_vmin = ignored_corelevels;
187 <<
TimeStamp() <<
" Ignoring " << ignored_corelevels
188 <<
" core levels for " << ignore_corelevels <<
" and beyond." << flush;
192 if (rpamax >= num_of_levels) {
193 rpamax = num_of_levels - 1;
195 if (qpmax >= num_of_levels) {
196 qpmax = num_of_levels - 1;
198 if (bse_cmax >= num_of_levels) {
199 bse_cmax = num_of_levels - 1;
208 Index bse_vmax = homo;
209 Index bse_cmin = homo + 1;
215 const double qp_emax =
217 const double qp_emin =
219 const double bse_emax =
221 const double bse_emin =
223 std::vector<const Eigen::VectorXd*> spins{&
orbitals_.MOs().eigenvalues()};
224 std::vector<Index> homos{is_uks ?
orbitals_.getHomoAlpha() : homo};
226 spins.push_back(&
orbitals_.MOs_beta().eigenvalues());
227 homos.push_back(
orbitals_.getHomoBeta());
230 constexpr double degenerate = 5
e-4;
232 auto upper = [&](
double cap_ev) {
233 Index last = homo + 1;
234 for (std::size_t s = 0; s < spins.size(); ++s) {
235 const Eigen::VectorXd&
e = *spins[s];
237 Index i = homos[s] + 1;
238 while (i + 1 <
e.size() &&
e(i + 1) <= limit) {
241 const double edge =
e(i);
242 while (i + 1 <
e.size() &&
e(i + 1) - edge < degenerate) {
245 last = std::max(last, i);
250 auto lower = [&](
double cap_ev) {
252 for (std::size_t s = 0; s < spins.size(); ++s) {
253 const Eigen::VectorXd&
e = *spins[s];
256 while (i - 1 >= 0 &&
e(i - 1) >= limit) {
259 const double edge =
e(i);
260 while (i - 1 >= 0 && edge -
e(i - 1) < degenerate) {
263 first = std::min(first, i);
267 auto report = [&](
const std::string& what,
const std::string& option,
270 <<
TimeStamp() <<
" " << what <<
" capped by " << option <<
" = "
271 << cap <<
" eV: " << before <<
" -> " << after <<
" ("
272 << std::abs(before - after) <<
" levels removed)" << flush;
275 const Index cap = std::min(qpmax, upper(qp_emax));
276 report(
"GW window top",
"qp_emax", qp_emax, qpmax, cap);
280 const Index cap = std::max(qpmin, lower(qp_emin));
281 report(
"GW window bottom",
"qp_emin", qp_emin, qpmin, cap);
284 if (bse_emax > 0.0) {
285 const Index cap = std::min(bse_cmax, upper(bse_emax));
286 report(
"BSE window top",
"bse_emax", bse_emax, bse_cmax, cap);
289 if (bse_emin > 0.0) {
290 const Index cap = std::max(bse_vmin, lower(bse_emin));
291 report(
"BSE window bottom",
"bse_emin", bse_emin, bse_vmin, cap);
301 throw std::runtime_error(
302 "inactive_screening_complete_g needs all levels in the RPA range "
305 qpmin = std::max(qpmin, nB);
306 bse_vmin = std::max(bse_vmin, nB);
308 <<
" Complete G: GW and BSE windows start at level " << nB
309 <<
" (the first active occupied level)" << flush;
312 if (rpamin < 0 || rpamax < 0 || rpamin > rpamax) {
313 throw std::runtime_error(
"Invalid RPA level range after setup/clamping.");
315 if (qpmin < 0 || qpmax < 0 || qpmin > qpmax) {
316 throw std::runtime_error(
"Invalid GW level range after setup/clamping.");
318 if (bse_vmin < 0 || bse_vmax < 0 || bse_vmin > bse_vmax) {
319 throw std::runtime_error(
320 "Invalid BSE occupied level range after setup/clamping.");
322 if (bse_cmin < 0 || bse_cmax < 0 || bse_cmin > bse_cmax) {
323 throw std::runtime_error(
324 "Invalid BSE virtual level range after setup/clamping.");
326 if (bse_vmax >= num_of_levels || bse_cmax >= num_of_levels) {
327 throw std::runtime_error(
328 "BSE level range exceeds available orbital indices.");
330 if (bse_vmax >= bse_cmin) {
331 throw std::runtime_error(
"BSE occupied and virtual level ranges overlap.");
350 orbitals_.setBSEindices(bse_vmin, bse_cmax);
354 Index bse_vtotal = bse_vmax - bse_vmin + 1;
355 Index bse_ctotal = bse_cmax - bse_cmin + 1;
356 Index bse_size = bse_vtotal * bse_ctotal;
359 <<
":" << rpamax <<
"]" << flush;
361 <<
":" << qpmax <<
"]" << flush;
363 <<
TimeStamp() <<
" BSE level range occ[" << bse_vmin <<
":" << bse_vmax
364 <<
"] virt[" << bse_cmin <<
":" << bse_cmax <<
"]" << flush;
374 options.
get(
"bse.davidson.correction").
as<std::string>();
377 options.
get(
"bse.davidson.tolerance").
as<std::string>();
380 options.
get(
"bse.davidson.update").
as<std::string>();
392 Index full_bse_size = (
bseopt_.useTDA) ? bse_size : 2 * bse_size;
394 << full_bse_size <<
"x" << full_bse_size << flush;
396 bseopt_.use_Hqp_offdiag = options.
get(
"bse.use_Hqp_offdiag").
as<
bool>();
399 if (!
bseopt_.use_Hqp_offdiag) {
401 <<
" BSE without Hqp offdiagonal elements" << flush;
404 <<
" BSE with Hqp offdiagonal elements" << flush;
408 bseopt_.dyn_tolerance = options.
get(
"bse.dyn_screen_tol").
as<
double>();
409 if (
bseopt_.max_dyn_iter > 0) {
419 }
else if (options.
exists(
".auxbasisset")) {
426 }
catch (std::runtime_error&) {
427 throw std::runtime_error(
428 "There is no auxbasis from the dftcalculation nor did you specify an "
429 "auxbasisset for the gwbse calculation. Also no auxiliary basisset "
437 std::string mode = options.
get(
"gw.mode").
as<std::string>();
438 if (mode ==
"G0W0") {
439 gwopt_.gw_sc_max_iterations = 1;
445 gwopt_.shift = options.
get(
"gw.scissor_shift").
as<
double>();
447 options.
get(
"gw.qp_sc_limit").
as<
double>();
450 gwopt_.g_sc_max_iterations =
456 if (mode ==
"evGW") {
461 options.
get(
"gw.sc_limit").
as<
double>();
464 <<
" qp_sc_limit [Hartree]: " <<
gwopt_.g_sc_limit << flush;
465 if (
gwopt_.gw_sc_max_iterations > 1) {
467 <<
" gw_sc_limit [Hartree]: " <<
gwopt_.gw_sc_limit << flush;
469 bseopt_.min_print_weight = options.
get(
"bse.print_weight").
as<
double>();
473 std::string tasks_string = options.
get(
".tasks").
as<std::string>();
474 boost::algorithm::to_lower(tasks_string);
476 if (tasks_string.find(
"gw") != std::string::npos) {
481 if (tasks_string.find(
"excitons") != std::string::npos ||
482 tasks_string.find(
"exciton_uks") != std::string::npos) {
487 if (tasks_string.find(
"singlets") != std::string::npos ||
488 tasks_string.find(
"triplets") != std::string::npos) {
489 throw std::runtime_error(
490 "Invalid gwbse task for UKS reference: 'singlets' and 'triplets' "
491 "are not defined for open-shell systems.\n"
492 "Use 'exciton_uks' (or 'excitons') instead.");
495 if (tasks_string.find(
"all") != std::string::npos) {
505 if (tasks_string.find(
"singlets") != std::string::npos) {
508 if (tasks_string.find(
"triplets") != std::string::npos) {
527 if (options.
exists(
"bse.fragments")) {
528 std::vector<tools::Property*> prop_region =
529 options.
Select(
"bse.fragments.fragment");
532 std::string indices = prop->get(
"indices").as<std::string>();
538 gwopt_.sigma_integration =
539 options.
get(
"gw.sigma_integrator").
as<std::string>();
541 <<
" Sigma integration: " <<
gwopt_.sigma_integration << flush;
544 if (
gwopt_.sigma_integration ==
"exact") {
546 <<
" RPA Hamiltonian size: " << (homo + 1 - rpamin) * (rpamax - homo)
549 if (
gwopt_.sigma_integration ==
"cda") {
552 <<
" Quadrature integration order : " <<
gwopt_.order << flush;
553 gwopt_.quadrature_scheme =
554 options.
get(
"gw.quadrature_scheme").
as<std::string>();
556 <<
" Quadrature integration scheme : " <<
gwopt_.quadrature_scheme
558 gwopt_.alpha = options.
get(
"gw.alpha").
as<
double>();
560 <<
" Alpha smoothing parameter : " <<
gwopt_.alpha << flush;
562 gwopt_.qp_solver = options.
get(
"gw.qp_solver").
as<std::string>();
565 if (
gwopt_.qp_solver ==
"grid") {
574 if (options.
exists(
"gw.qp_full_window_half_width")) {
575 gwopt_.qp_full_window_half_width =
576 options.
get(
"gw.qp_full_window_half_width").
as<
double>();
578 if (options.
exists(
"gw.qp_dense_spacing")) {
579 gwopt_.qp_dense_spacing = options.
get(
"gw.qp_dense_spacing").
as<
double>();
581 if (options.
exists(
"gw.qp_adaptive_shell_width")) {
582 gwopt_.qp_adaptive_shell_width =
583 options.
get(
"gw.qp_adaptive_shell_width").
as<
double>();
585 if (options.
exists(
"gw.qp_adaptive_shell_count")) {
586 gwopt_.qp_adaptive_shell_count =
587 options.
get(
"gw.qp_adaptive_shell_count").
as<
Index>();
592 const bool has_legacy_steps = options.
exists(
"gw.qp_grid_steps");
593 const bool has_legacy_spacing = options.
exists(
"gw.qp_grid_spacing");
595 if (has_legacy_steps != has_legacy_spacing) {
596 throw std::runtime_error(
597 "Deprecated gw.qp_grid_steps and gw.qp_grid_spacing must be given "
598 "together if either is used.");
601 if (has_legacy_steps && has_legacy_spacing) {
603 gwopt_.qp_grid_spacing = options.
get(
"gw.qp_grid_spacing").
as<
double>();
605 const double legacy_half_width =
607 const double legacy_shell_width =
610 if (
gwopt_.qp_full_window_half_width <= 0.0) {
611 gwopt_.qp_full_window_half_width = legacy_half_width;
613 if (
gwopt_.qp_dense_spacing <= 0.0) {
616 if (
gwopt_.qp_adaptive_shell_count <= 0 &&
617 gwopt_.qp_adaptive_shell_width <= 0.0) {
618 gwopt_.qp_adaptive_shell_width = legacy_shell_width;
622 <<
" Deprecated GW QP options detected: " <<
"qp_grid_steps="
624 <<
" qp_grid_spacing=" <<
gwopt_.qp_grid_spacing
625 <<
" -> mapped to qp_full_window_half_width="
626 <<
gwopt_.qp_full_window_half_width
627 <<
" qp_dense_spacing=" <<
gwopt_.qp_dense_spacing
628 <<
" qp_adaptive_shell_width=" <<
gwopt_.qp_adaptive_shell_width
637 <<
" QP full window half-width: " <<
gwopt_.qp_full_window_half_width
640 <<
" QP dense spacing: " <<
gwopt_.qp_dense_spacing << flush;
642 <<
" QP adaptive shell width: " <<
gwopt_.qp_adaptive_shell_width
645 <<
" QP adaptive shell count: " <<
gwopt_.qp_adaptive_shell_count
648 gwopt_.qp_root_finder = options.
get(
"gw.qp_root_finder").
as<std::string>();
650 <<
" QP root finder: " <<
gwopt_.qp_root_finder << flush;
658 gwopt_.gw_mixing_alpha = options.
get(
"gw.mixing_alpha").
as<
double>();
659 gwopt_.qp_grid_search_mode =
660 options.
get(
"gw.qp_grid_search_mode").
as<std::string>();
661 gwopt_.qp_restrict_search = options.
get(
"gw.qp_restrict_search").
as<
bool>();
663 "gw.qp_root_continuity",
true);
665 "gw.qp_root_tracking",
false);
670 "gw.screening_update",
"adaptive");
672 gwopt_.screening_update_ratio =
674 "gw.screening_update_ratio", 0.1);
675 gwopt_.screening_update_max_inner =
677 "gw.screening_update_max_inner", 10);
678 gwopt_.qp_zero_margin = options.
get(
"gw.qp_zero_margin").
as<
double>();
679 gwopt_.qp_virtual_min_energy =
680 options.
get(
"gw.qp_virtual_min_energy").
as<
double>();
686 "gw.qsgw_max_iterations", 50);
689 gwopt_.qsgw_max_virt_correction =
691 "gw.qsgw_max_virt_correction", 0.5);
693 "gw.qsgw_hartree_update",
true);
695 "gw.qsgw_hartree_screened",
true);
696 gwopt_.qsgw_regularization =
698 "gw.qsgw_regularization",
"eta");
699 if (
gwopt_.qsgw_regularization !=
"eta" &&
700 gwopt_.qsgw_regularization !=
"srg") {
701 throw std::runtime_error(
"gw.qsgw_regularization must be eta or srg, got " +
702 gwopt_.qsgw_regularization);
706 if (!(
gwopt_.qsgw_srg_s > 0.0)) {
707 throw std::runtime_error(
"gw.qsgw_srg_s must be positive");
711 "gw.out_of_window_shift",
"max"));
712 gwopt_.out_of_window_shift.fit_fraction =
714 "gw.out_of_window_fit_fraction", 0.3);
717 <<
" Levels outside the GW window shifted by: "
720 ?
" (fit fraction " +
721 std::to_string(
gwopt_.out_of_window_shift.fit_fraction) +
728 <<
" QSGW enabled: max_iter=" <<
gwopt_.qsgw_max_iterations
729 <<
" sc_limit=" <<
gwopt_.qsgw_sc_limit <<
" Ha"
730 <<
" max_virt_correction=" <<
gwopt_.qsgw_max_virt_correction <<
" Ha ("
731 <<
gwopt_.qsgw_max_virt_correction * 27.2114 <<
" eV)" << std::flush;
734 if (mode ==
"evGW") {
735 if (
gwopt_.gw_mixing_order == 0) {
737 }
else if (
gwopt_.gw_mixing_order == 1) {
739 <<
gwopt_.gw_mixing_alpha << std::flush;
742 <<
gwopt_.gw_mixing_order <<
" using alpha "
743 <<
gwopt_.gw_mixing_alpha << std::flush;
745 if (
gwopt_.screening_update ==
"adaptive") {
747 <<
" evGW screening update: adaptive (ratio "
748 <<
gwopt_.screening_update_ratio <<
", at most "
749 <<
gwopt_.screening_update_max_inner <<
" iterations per W)"
753 <<
" evGW screening update: every iteration" << std::flush;
757 if (options.
exists(
"gw.sigma_plot")) {
762 options.
get(
"gw.sigma_plot.filename").
as<std::string>();
774 if (options.
exists(
"gw.sigma_dump")) {
776 throw std::runtime_error(
"gw.sigma_dump is not implemented for UKS");
778 if (
gwopt_.sigma_integration !=
"ppm" &&
779 gwopt_.sigma_integration !=
"exact") {
780 throw std::runtime_error(
781 "gw.sigma_dump needs sigma_integrator ppm or exact");
784 throw std::runtime_error(
"gw.sigma_dump is not implemented for QSGW");
788 options.
get(
"gw.sigma_dump.filename").
as<std::string>();
790 options.
get(
"gw.sigma_dump.levels_emax").
as<
double>();
792 options.
get(
"gw.sigma_dump.imag_points").
as<
Index>();
794 options.
get(
"gw.sigma_dump.imag_scale").
as<
double>();
796 options.
get(
"gw.sigma_dump.spectral_min").
as<
double>();
798 options.
get(
"gw.sigma_dump.spectral_max").
as<
double>();
800 options.
get(
"gw.sigma_dump.spectral_binwidth").
as<
double>();
802 options.
get(
"gw.sigma_dump.plot_steps").
as<
Index>();
804 options.
get(
"gw.sigma_dump.plot_spacing").
as<
double>();
818 (boost::format(
"%1$+1.6f ") % (
orbitals_.getDFTTotalEnergy() * hrt2ev))
821 if (
orbitals_.hasUnrestrictedOrbitals()) {
822 gwbse_summary.
add(
"dft_alpha",
"");
823 gwbse_summary.
add(
"dft_beta",
"");
837 (boost::format(
"%1$+1.6f ") %
840 level_alpha.
add(
"gw_energy",
841 (boost::format(
"%1$+1.6f ") %
842 (
orbitals_.QPpertEnergiesAlpha()(state) * hrt2ev))
846 (boost::format(
"%1$+1.6f ") %
847 (
orbitals_.QPdiagAlpha().eigenvalues()(state) * hrt2ev))
854 (boost::format(
"%1$+1.6f ") %
858 level_beta.
add(
"gw_energy",
859 (boost::format(
"%1$+1.6f ") %
860 (
orbitals_.QPpertEnergiesBeta()(state) * hrt2ev))
862 level_beta.
add(
"qp_energy",
863 (boost::format(
"%1$+1.6f ") %
864 (
orbitals_.QPdiagBeta().eigenvalues()(state) * hrt2ev))
877 (boost::format(
"%1$+1.6f ") %
880 level_summary.
add(
"gw_energy",
881 (boost::format(
"%1$+1.6f ") %
882 (
orbitals_.QPpertEnergies()(state) * hrt2ev))
884 level_summary.
add(
"qp_energy",
885 (boost::format(
"%1$+1.6f ") %
886 (
orbitals_.QPdiag().eigenvalues()(state) * hrt2ev))
897 "omega", (boost::format(
"%1$+1.6f ") %
898 (
orbitals_.BSESinglets().eigenvalues()(state) * hrt2ev))
902 const Eigen::Vector3d& dipoles = (
orbitals_.TransitionDipoles())[state];
903 double f = 2 * dipoles.squaredNorm() *
904 orbitals_.BSESinglets().eigenvalues()(state) / 3.0;
906 level_summary.
add(
"f", (boost::format(
"%1$+1.6f ") % f).str());
908 "Trdipole", (boost::format(
"%1$+1.4f %2$+1.4f %3$+1.4f") %
909 dipoles.x() % dipoles.y() % dipoles.z())
922 "omega", (boost::format(
"%1$+1.6f ") %
923 (
orbitals_.BSETriplets().eigenvalues()(state) * hrt2ev))
930 const bool has_dipoles =
orbitals_.hasTransitionDipoles();
931 Eigen::VectorXd oscs = Eigen::VectorXd::Zero(0);
937 for (
Index state = 0;
943 level_summary.
add(
"omega",
944 (boost::format(
"%1$+1.6f ") %
945 (
orbitals_.BSEUKS().eigenvalues()(state) * hrt2ev))
949 const Index nosc =
static_cast<Index>(oscs.size());
951 if (has_dipoles && state < ndip && state < nosc) {
952 const Eigen::Vector3d& dipoles =
orbitals_.TransitionDipoles()[state];
954 level_summary.
add(
"f",
955 (boost::format(
"%1$+1.6f ") % oscs(state)).str());
958 "Trdipole", (boost::format(
"%1$+1.4f %2$+1.4f %3$+1.4f") %
959 dipoles.x() % dipoles.y() % dipoles.z())
981 if (
orbitals_.getXCFunctionalName().empty()) {
985 throw std::runtime_error(
"Functionals from DFT " +
986 orbitals_.getXCFunctionalName() +
" GWBSE " +
994 <<
TimeStamp() <<
" Setup grid for integration with gridsize: " <<
grid_
995 <<
" with " << grid.
getGridSize() <<
" points, divided into "
1002 Eigen::MatrixXd DMAT =
orbitals_.DensityMatrixGroundState();
1009 Eigen::MatrixXd mos =
1012 Eigen::MatrixXd vxc = mos.transpose() * e_vxc_ao.
matrix() * mos;
1014 <<
TimeStamp() <<
" Calculated exchange-correlation expectation values "
1022 if (
orbitals_.getXCFunctionalName().empty()) {
1025 throw std::runtime_error(
"Functionals from DFT " +
1026 orbitals_.getXCFunctionalName() +
" GWBSE " +
1035 auto dmats =
orbitals_.DensityMatrixGroundStateSpinResolved();
1039 Eigen::MatrixXd mos_alpha =
1041 Eigen::MatrixXd mos_beta =
1042 orbitals_.MOs_beta().eigenvectors().middleCols(
gwopt_.qpmin, qptotal);
1044 Eigen::MatrixXd vxc_alpha =
1045 mos_alpha.transpose() * e_vxc_ao.vxc_alpha * mos_alpha;
1046 Eigen::MatrixXd vxc_beta =
1047 mos_beta.transpose() * e_vxc_ao.vxc_beta * mos_beta;
1049 return std::make_pair(vxc_alpha, vxc_beta);
1067 <<
" Screening eigensolvers and inverses call "
1068 "Accelerate LAPACK directly"
1072 <<
TimeStamp() <<
" Molecule Coordinates [A] " << flush;
1074 std::string output = (boost::format(
"%5d"
1076 " %1.4f %1.4f %1.4f") %
1077 atom.getId() % atom.getElement() %
1086 std::string dft_package =
orbitals_.getQMpackage();
1088 <<
TimeStamp() <<
" DFT data was created by " << dft_package << flush;
1111 <<
" size:" << frag.size() << flush;
1119 throw std::runtime_error(
1120 "You want no GW calculation but the orb file has no matching QP "
1124 const bool is_uks =
orbitals_.hasUnrestrictedOrbitals();
1135 <<
TimeStamp() <<
" Calculating alpha spin Mmn " << flush;
1138 <<
TimeStamp() <<
" Calculating beta spin Mmn " << flush;
1147 <<
" inactive occupied levels enter the self-energy (and Vxc), "
1148 <<
"not the RPA; their own slices are not stored" << flush;
1153 throw std::runtime_error(
1154 "GWBSE: stream_rpa is implemented for G0W0 and evGW with "
1155 "sigma_integrator ppm, without QSGW and inactive_screening.");
1160 first_needed = std::min(first_needed,
bseopt_.vmin);
1167 <<
" occupied levels below the windows are not stored; their "
1168 <<
"response is streamed" << flush;
1173 <<
TimeStamp() <<
" Calculating Mmn (3-center-repulsion x orbitals) "
1175 Mmn.
Fill(auxbasis, dftbasis,
orbitals_.MOs().eigenvectors());
1178 <<
" functions from Aux Coulomb matrix to avoid near linear "
1182 <<
TimeStamp() <<
" Calculated Mmn (3-center-repulsion x orbitals) "
1187 <<
TimeStamp() <<
" After Mmn: " << usage << flush;
1193 Eigen::MatrixXd reaction_field;
1196 throw std::runtime_error(
1197 "GWBSE: environment screening is implemented for closed-shell "
1200 std::chrono::time_point<std::chrono::system_clock> start =
1201 std::chrono::system_clock::now();
1202 Index n_explicit = 0;
1204 n_explicit += seg.
size();
1208 n_shell += seg.
size();
1211 <<
TimeStamp() <<
" Environment screening: " << n_explicit
1212 <<
" explicit Thole sites (exp_damp " <<
environment_.exp_damp <<
"), "
1213 << n_shell <<
" shell sites (epsilon " <<
environment_.shell_dielectric
1215 const Eigen::MatrixXd B =
1219 std::chrono::duration<double> elapsed_time =
1220 std::chrono::system_clock::now() - start;
1222 <<
TimeStamp() <<
" Built environment reaction field in "
1223 << elapsed_time.count() <<
" seconds." << flush;
1232 Eigen::MatrixXd inactive_static_bse;
1235 throw std::runtime_error(
1236 "GWBSE: inactive_screening is not implemented for QSGW.");
1239 throw std::runtime_error(
1240 "GWBSE: dynamical screening in the BSE is not implemented with "
1241 "inactive_screening (the BSE has the inactive response only at "
1242 "zero frequency).");
1245 throw std::runtime_error(
1246 "GWBSE: inactive_screening is implemented for closed-shell "
1250 throw std::runtime_error(
1251 "GWBSE: inactive_screening=" +
1253 " needs the inactive region of a projection-based embedding "
1254 "(dft_in_dft) prepared by the caller.");
1258 <<
TimeStamp() <<
" Warning: the inactive region holds no occupied "
1259 <<
"orbitals; inactive_screening has nothing to add" << flush;
1261 std::chrono::time_point<std::chrono::system_clock> start =
1262 std::chrono::system_clock::now();
1264 <<
TimeStamp() <<
" Inactive-region screening ("
1267 <<
" inactive occupied orbitals, response over "
1268 <<
inactive_.occupied.cols() <<
" occupied"
1270 ?
" (" + std::to_string(
inactive_.n_far) +
1271 " inactive orbitals beyond " +
1273 " Angstrom left out)"
1275 <<
" x " <<
inactive_.virtuals.cols() <<
" virtual levels; projector "
1276 <<
"idempotency error " <<
inactive_.idempotency_error << flush;
1281 const std::vector<double> frequencies{
RPA(*
pLog_, Mmn).
getEta(), w_i};
1283 if (chunk_bytes <= 0.0) {
1297 <<
TimeStamp() <<
" Inactive response: " << nv
1298 <<
" virtual levels up to "
1300 <<
" eV above the LUMO" << flush;
1302 const double nvirt = double(nv);
1303 const double total = 8.0 * double(
inactive_.occupied.cols()) * nvirt *
1306 <<
TimeStamp() <<
" Inactive response integrals: " << total / 1e9
1307 <<
" GB in chunks of at most " << chunk_bytes / 1e9 <<
" GB ("
1308 <<
Index(std::ceil(total / chunk_bytes))
1309 <<
" pass(es) over the AO integrals)" << flush;
1317 const Eigen::MatrixXd& Y = Ys.front();
1319 std::chrono::duration<double> t =
1320 std::chrono::system_clock::now() - start;
1322 <<
TimeStamp() <<
" Inactive response at " << frequencies.size()
1323 <<
" frequencies in " << t.count() <<
" seconds" << flush;
1326 if (y.minCoeff() < -1
e-6 * std::max(1.0, y.maxCoeff())) {
1328 <<
TimeStamp() <<
" Warning: the inactive response has a negative "
1329 <<
"eigenvalue " << y.minCoeff() <<
" (max " << y.maxCoeff()
1330 <<
"); is the embedding converged?" << flush;
1333 const Eigen::MatrixXd& Y_i = Ys[1];
1337 inactive_static_bse = Y;
1338 if (
gwopt_.sigma_integration ==
"ppm") {
1343 <<
TimeStamp() <<
" Inactive region enters the plasmon-pole "
1344 <<
"model of W (responses at 0 and " << w_i
1345 <<
"i Ha); GW keeps only the environment's reaction field" << flush;
1353 <<
" poles fitted at 0 and " << w_i <<
"i Ha (energies "
1357 <<
" modes clipped); they enter the RPA of "
1358 <<
gwopt_.sigma_integration <<
" Sigma as pseudo-transitions"
1363 <<
" inactive modes have no real pole frequency (expected "
1364 <<
"only for inactive_screening exact); the fit is then not "
1365 <<
"exact at the two points" << flush;
1370 std::chrono::duration<double> elapsed_time =
1371 std::chrono::system_clock::now() - start;
1373 <<
TimeStamp() <<
" Built inactive-region response in "
1374 << elapsed_time.count() <<
" seconds; eigenvalues of the static Y in ["
1375 << y.minCoeff() <<
", " << y.maxCoeff() <<
"]" << flush;
1378 Eigen::MatrixXd Hqp;
1379 Eigen::MatrixXd Hqp_alpha;
1380 Eigen::MatrixXd Hqp_beta;
1383 std::chrono::time_point<std::chrono::system_clock> start =
1384 std::chrono::system_clock::now();
1387 throw std::runtime_error(
1388 "QSGW (gw.do_qsgw) is not implemented for open-shell (UKS) "
1444 auxbasis, dftbasis,
orbitals_.MOs().eigenvectors(),
1447 auxbasis, dftbasis,
orbitals_.MOs_beta().eigenvectors(),
1450 <<
TimeStamp() <<
" Sigma_x includes the exchange with the "
1451 <<
gwopt_.rpamin <<
" frozen core levels" << flush;
1461 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es_alpha =
1463 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es_beta =
1465 orbitals_.QPdiagAlpha().eigenvectors() = es_alpha.eigenvectors();
1466 orbitals_.QPdiagAlpha().eigenvalues() = es_alpha.eigenvalues();
1467 orbitals_.QPdiagBeta().eigenvectors() = es_beta.eigenvectors();
1468 orbitals_.QPdiagBeta().eigenvalues() = es_beta.eigenvalues();
1469 std::chrono::duration<double> elapsed_time =
1470 std::chrono::system_clock::now() - start;
1472 <<
TimeStamp() <<
" UKS GW calculation took " << elapsed_time.count()
1473 <<
" seconds." << flush;
1487 std::vector<Eigen::MatrixXd> Y;
1499 <<
TimeStamp() <<
" Sigma_x includes the exchange with the "
1500 <<
gwopt_.rpamin <<
" frozen core levels" << flush;
1514 <<
TimeStamp() <<
" Calculating offdiagonal part of Sigma " << flush;
1521 const std::string seed_label =
1522 (
gwopt_.gw_sc_max_iterations == 1) ?
"G0W0" :
"evGW";
1534 orbitals_.QPdiag().eigenvalues() = qsgw_energies;
1543 <<
TimeStamp() <<
" Rebuilding Mmn in QSGW QP wavefunction basis"
1547 <<
TimeStamp() <<
" Rebuilt Mmn (3-center-repulsion x QP orbitals)"
1549 Hqp = qsgw_energies.asDiagonal();
1554 <<
TimeStamp() <<
" Calculated offdiagonal part of Sigma "
1561 (
gwopt_.gw_sc_max_iterations > 1) ?
"evGW" :
"G0W0",
1565 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es =
1567 if (es.info() == Eigen::ComputationInfo::Success) {
1569 <<
TimeStamp() <<
" Diagonalized QP Hamiltonian " << flush;
1572 orbitals_.QPdiag().eigenvectors() = es.eigenvectors();
1573 orbitals_.QPdiag().eigenvalues() = es.eigenvalues();
1575 std::chrono::duration<double> elapsed_time =
1576 std::chrono::system_clock::now() - start;
1578 <<
TimeStamp() <<
" GW calculation took " << elapsed_time.count()
1579 <<
" seconds." << flush;
1587 throw std::runtime_error(
1588 "The ranges for GW and RPA do not agree with the ranges from the "
1589 ".orb file, rerun your GW calculation");
1593 const Eigen::MatrixXd& qpcoeff_alpha =
1595 const Eigen::MatrixXd& qpcoeff_beta =
1598 Hqp_alpha = qpcoeff_alpha *
1599 orbitals_.QPdiagAlpha().eigenvalues().asDiagonal() *
1600 qpcoeff_alpha.transpose();
1601 Hqp_beta = qpcoeff_beta *
1602 orbitals_.QPdiagBeta().eigenvalues().asDiagonal() *
1603 qpcoeff_beta.transpose();
1609 <<
" Rebuilding Mmn in QSGW QP wavefunction basis (BSE-only)"
1613 <<
TimeStamp() <<
" Rebuilt Mmn (3-center-repulsion x QP orbitals)"
1615 Hqp =
orbitals_.QPdiag().eigenvalues().asDiagonal();
1617 const Eigen::MatrixXd& qpcoeff =
orbitals_.QPdiag().eigenvectors();
1619 Hqp = qpcoeff *
orbitals_.QPdiag().eigenvalues().asDiagonal() *
1620 qpcoeff.transpose();
1627 std::chrono::time_point<std::chrono::system_clock> start =
1628 std::chrono::system_clock::now();
1643 Eigen::VectorXd epsilon_0_inv_bse =
1644 Eigen::VectorXd::Zero(es_bse.
values.size());
1645 for (
Index i = 0; i < es_bse.
values.size(); ++i) {
1646 if (es_bse.
values(i) > 1
e-8) {
1647 epsilon_0_inv_bse(i) = 1.0 / es_bse.
values(i);
1674 Hqp_alpha, Hqp_beta, epsilon_0_inv_bse, es_bse.
vectors);
1678 <<
TimeStamp() <<
" Solved combined UKS BSE exciton problem "
1693 std::vector<Eigen::MatrixXd> Y;
1695 {RPA(*pLog_, Mmn).getEta()}, Y);
1696 inactive_static_bse = Y[0];
1699 if (inactive_static_bse.size() > 0) {
1710 <<
TimeStamp() <<
" Solved BSE for triplets " << flush;
1717 <<
TimeStamp() <<
" Solved BSE for singlets " << flush;
1734 std::chrono::duration<double> elapsed_time =
1735 std::chrono::system_clock::now() - start;
1737 << elapsed_time.count() <<
" seconds." << flush;
1741 <<
TimeStamp() <<
" End of GWBSE: " << usage << flush;
1744 <<
TimeStamp() <<
" GWBSE calculation finished " << flush;
1751 const Eigen::VectorXd& rpa_energies,
1752 const std::vector<double>& frequencies,
1753 std::vector<Eigen::MatrixXd>& Y)
const {
1754 std::chrono::time_point<std::chrono::system_clock> start =
1755 std::chrono::system_clock::now();
1756 const Eigen::MatrixXd& C =
orbitals_.MOs().eigenvectors();
1761 if (chunk_bytes <= 0.0) {
1765 auxbasis, dftbasis, C.middleCols(
gwopt_.rpamin, nh),
1766 rpa_energies.head(nh), C.middleCols(
gwopt_.homo + 1, nv),
1767 rpa_energies.segment(lumo, nv), chunk_bytes, frequencies, Mmn.
InvSqrt());
1768 for (Eigen::MatrixXd& y : Y) {
1769 y = 0.5 * (y + y.transpose()).eval();
1771 const double total =
1772 8.0 * double(nh) * double(nv) * double(auxbasis.
AOBasisSize());
1773 std::chrono::duration<double> t = std::chrono::system_clock::now() - start;
1775 <<
TimeStamp() <<
" Streamed the response of " << nh
1776 <<
" occupied levels at " << frequencies.size() <<
" frequencies ("
1777 << total / 1e9 <<
" GB of integrals in "
1778 <<
Index(std::ceil(total / chunk_bytes)) <<
" pass(es)) in " << t.count()
1779 <<
" seconds" << flush;
Container to hold Basisfunctions for all atoms.
Index AOBasisSize() const
void configure_with_precomputed_screening(const options &opt, Index homo_alpha, Index homo_beta, const Eigen::VectorXd &RPAInputEnergiesAlpha, const Eigen::VectorXd &RPAInputEnergiesBeta, const Eigen::MatrixXd &Hqp_alpha_in, const Eigen::MatrixXd &Hqp_beta_in, const Eigen::VectorXd &epsilon_0_inv, const Eigen::MatrixXd &epsilon_eigenvectors)
void Perturbative_DynamicalScreening(Orbitals &orb)
void Solve_excitons_uks(Orbitals &orb) const
void Analyze_excitons_uks(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
void setReactionField(const Eigen::MatrixXd &R, bool include_kreac)
Screen by a static polarizable environment (embedded BSE).
void Solve_singlets(Orbitals &orb) const
void Analyze_singlets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
void Perturbative_DynamicalScreening(const QMStateType &type, Orbitals &orb)
void Analyze_triplets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
void configure(const options &opt, const Eigen::VectorXd &RPAEnergies, const Eigen::MatrixXd &Hqp_in)
void Solve_triplets(Orbitals &orb) const
void Load(const std::string &name)
void Load(const std::string &name)
const ECPElement & getElement(std::string element_type) const
static Eigen::MatrixXd Kernel(const AOBasis &auxbasis, const ScreeningEnvironment &env)
B for a whole environment: ReactionFieldKernel of the explicit segments plus ShellKernel of the shell...
static Eigen::MatrixXd SymmetrizedReactionField(const Eigen::MatrixXd &B, const Eigen::MatrixXd &T)
R = T^T B T, the reaction field in the metric of the stored three-centre integrals,...
InactiveScreeningInput::Mode inactive_mode_
Eigen::MatrixXd StreamedResponse(const AOBasis &auxbasis, const AOBasis &dftbasis, const TCMatrix_gwbse &Mmn, const Eigen::VectorXd &rpa_energies, const std::vector< double > &frequencies, std::vector< Eigen::MatrixXd > &Y) const
InactiveScreeningInput inactive_
std::pair< Eigen::MatrixXd, Eigen::MatrixXd > CalculateVXCSpinResolved(const AOBasis &dftbasis)
std::vector< QMFragment< BSE_Population > > fragments_
std::string sigma_plot_states_
ScreeningEnvironment environment_
double inactive_virtual_cutoff_
void addoutput(tools::Property &summary)
GW::sigma_dump_options sigma_dump_opt_
std::string auxbasis_name_
Eigen::MatrixXd CalculateVXC(const AOBasis &dftbasis)
std::string dftbasis_name_
double inactive_chunk_bytes_
void Initialize(tools::Property &options)
double sigma_plot_spacing_
std::string sigma_plot_filename_
bool do_dynamical_screening_bse_
Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > DiagonalizeQPHamiltonianAlpha() const
Eigen::VectorXd getGWAResultsAlpha() const
const Eigen::VectorXd & RPAInputEnergiesAlpha() const
const Eigen::VectorXd & RPAInputEnergiesBeta() const
Eigen::MatrixXd getHQPBeta() const
Eigen::VectorXd getGWAResultsBeta() const
Eigen::MatrixXd getHQPAlpha() const
void setCoreExchange(const Eigen::MatrixXd &alpha, const Eigen::MatrixXd &beta)
Frozen-core exchange per spin, see GW::setCoreExchange.
Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > DiagonalizeQPHamiltonianBeta() const
void configure(const options &opt)
void CalculateGWPerturbation()
const Eigen::VectorXd & getQSGWSeedEnergies() const
Return the seed (G0W0/evGW) energies that QSGW started from.
void setReactionField(const Eigen::MatrixXd &R)
Screen by a static polarizable environment (embedded GW).
Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > DiagonalizeQPHamiltonian() const
void DumpSigma(const sigma_dump_options &dopt, const std::string &gw_mode, const std::string &version)
Write the self-energy and screening data of the finished GW (G0W0 or evGW, ppm or exact) to a separat...
void setCoreExchange(const Eigen::MatrixXd &X)
void PrintQSGW_Energies(const std::string &seed_label, const Eigen::VectorXd &seed_energies, const Eigen::VectorXd &qsgw_energies) const
Print a two-column comparison of seed (G0W0 or evGW) vs converged QSGW quasiparticle energies.
void CalculateQSGW()
Run quasiparticle self-consistent GW (QSGW).
void configure(const options &opt)
Eigen::MatrixXd getHQP() const
void setKeepScreeningData(bool keep)
Call after configure and before CalculateGWPerturbation.
void PrintQSGW_Composition(double threshold=0.01) const
Print the dominant DFT-KS orbital contributions to each converged QSGW quasiparticle state.
Eigen::VectorXd getGWAResults() const
Eigen::VectorXd RPAInputEnergies() const
void setScreeningHook(ScreeningHook hook)
const Eigen::MatrixXd & getQSGWRotation() const
void PlotSigma(std::string filename, Index steps, double spacing, std::string states)
void CalculateGWPerturbation()
static PoleFit FitPoles(const Eigen::MatrixXd &Y0, const Eigen::MatrixXd &Yi, double w_i, double tolerance=1e-10)
static std::vector< Eigen::MatrixXd > Kernels(const AOBasis &auxbasis, const AOBasis &dftbasis, const InactiveScreeningInput &input, const TCMatrix_gwbse &active, const Eigen::VectorXd &rpa_energies, Index homo, Index rpamin, Index rpamax, double chunk_bytes, const std::vector< double > &imaginary_frequencies, double virtual_cutoff=0.0)
Y at several imaginary frequencies, as GWBSE uses it: one integral pass for the full (exact) or inact...
static std::vector< Eigen::MatrixXd > Responses(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &occupied, const Eigen::VectorXd &occupied_energies, const Eigen::MatrixXd &virtuals, const Eigen::VectorXd &virtual_energies, double chunk_bytes, const std::vector< double > &imaginary_frequencies, const Eigen::MatrixXd &inv_sqrt=Eigen::MatrixXd())
Eigen::MatrixXd & matrix()
static std::string Usage()
static double AvailableBytes()
double ImaginaryFittingFrequency() const
double RealFittingFrequency() const
Unrestricted RPA helper for spin-resolved GW screening.
void setRPAInputEnergies(const Eigen::VectorXd &rpaenergies_alpha, const Eigen::VectorXd &rpaenergies_beta)
Set alpha and beta RPA input energies directly.
void configure(Index homo_alpha, Index homo_beta, Index rpamin, Index rpamax)
Eigen::MatrixXd calculate_epsilon_r(double frequency) const
Dielectric matrix on the real frequency axis.
static Mode Parse(const std::string &name)
void Fill(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &dft_orbitals)
void setAdditionalPoles(Eigen::VectorXd energies, Eigen::MatrixXd vectors)
A response given as poles, in the form of transitions: Y(i w) = sum_k 4 W_k/(W_k^2 + w^2) c_k c_k^T,...
void Initialize(Index basissize, Index mmin, Index mmax, Index nmin, Index nmax)
void setAdditionalResponse(std::vector< ResponsePoint > points)
void setExcludedHoles(Index k)
The first k occupied slices (levels rpamin .. rpamin+k-1) are left out of the RPA response sums,...
static Eigen::MatrixXd CoreExchange(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &mos, Index ncore, Index qpmin, Index qpmax)
const Eigen::MatrixXd & InvSqrt() const
Index Removedfunctions() const
Timestamp returns the current time as a string Example: cout << TimeStamp().
Index getGridSize() const
void GridSetup(const std::string &type, const QMMolecule &atoms, const AOBasis &basis)
Index getBoxesSize() const
Mat_p_Energy IntegrateVXC(const Eigen::MatrixXd &density_matrix) const
void setXCfunctional(const std::string &functional)
SpinResult IntegrateVXCSpin(const Eigen::MatrixXd &dmat_alpha, const Eigen::MatrixXd &dmat_beta) const
#define XTP_LOG(level, log)
bool LapackAvailable()
Whether the routines below can run here (Accelerate build, macOS 13.3+).
void Cite(const std::string &key)
marks a reference as used (thread safe; unknown keys are printed as such)
double LegacyAdaptiveShellWidth(const Opt &opt)
void NormalizeGridSearchOptions(Opt &opt)
double LegacyFullWindowHalfWidth(const Opt &opt)
Charge transport classes.
SymmetricEigenSystem SymmetricEigen(const Eigen::MatrixXd &A, bool vectors=true)
With vectors = false only the eigenvalues are computed.
ClassicalSegment< PolarSite > PolarSegment
std::string EigenBackendDescription()
Provides a means for comparing floating point numbers.
std::string davidson_update
std::string davidson_tolerance
std::string davidson_correction
Index qp_adaptive_shell_count
std::string screening_update
double qp_virtual_min_energy
double screening_update_ratio
std::string quadrature_scheme
OutOfWindowShift out_of_window_shift
Index screening_update_max_inner
double qp_full_window_half_width
std::string qp_grid_search_mode
std::string sigma_integration
Index g_sc_max_iterations
std::string qp_root_finder
Index gw_sc_max_iterations
double qp_adaptive_shell_width
Poles in the form of transitions that reproduce a response at zero and at one imaginary frequency: Y(...
static Mode Parse(const std::string &name)
static std::string Name(Mode mode)