22#include <boost/format.hpp>
59void CanonicalizeOrbitalPhases(Eigen::MatrixXd& coeffs) {
60 constexpr double tol = 1
e-14;
62 for (
Index col = 0; col < coeffs.cols(); ++col) {
63 Eigen::Index pivot = 0;
64 const double maxabs = coeffs.col(col).cwiseAbs().maxCoeff(&pivot);
70 if (coeffs(pivot, col) < 0.0) {
71 coeffs.col(col) *= -1.0;
76void CanonicalizeOrbitalPhases(tools::EigenSystem& mos) {
77 CanonicalizeOrbitalPhases(mos.eigenvectors());
101 const std::string key_xtpdft =
"xtpdft";
104 if (options.
exists(
".auxbasisset")) {
111 options.
get(key_xtpdft +
".fock_matrix_reset").
as<
Index>();
113 if (options.
exists(
".ecp")) {
117 if (options.
exists(key_xtpdft +
".force_uks_path")) {
121 if (options.
exists(key_xtpdft +
".polarizability")) {
123 options.
get(key_xtpdft +
".polarizability").
as<
bool>();
126 if (options.
exists(key_xtpdft +
".compute_forces")) {
131 throw std::runtime_error(
132 "compute_forces=true was requested, but libint2 was built without "
133 "derivative integrals for one or more of the required operator "
134 "categories (one-body, two-center Coulomb metric, three-center RI). "
135 "Many packaged libint2 builds (Homebrew, Ubuntu apt, etc.) lack "
136 "them; rebuild libint2 with --enable-1body/--enable-eri2/"
137 "--enable-eri3 to use this feature.");
142 throw std::runtime_error(
143 "compute_forces=true was requested together with an ECP ('" +
145 "'), but the analytic nuclear forces do not include the ECP "
146 "term d(V_ECP)/dR. Either drop the ECP or do not request "
150 if (options.
exists(key_xtpdft +
".cdft.enabled")) {
156 std::string indices_str =
157 options.
get(key_xtpdft +
".cdft.indices").
as<std::string>();
158 if (indices_str.empty()) {
159 throw std::runtime_error(
160 "cdft.enabled=true was requested, but cdft.indices is empty; "
161 "specify the atoms of the constrained fragment (0-based, e.g. "
162 "'1 3 13:17', same syntax as the fragment indices in "
163 "diabatization.xml).");
168 options.
get(key_xtpdft +
".cdft.charge").
as<
double>();
170 options.
get(key_xtpdft +
".cdft.initial_lambda").
as<
double>();
172 options.
get(key_xtpdft +
".cdft.max_iterations").
as<
Index>();
174 options.
get(key_xtpdft +
".cdft.population_tolerance").
as<
double>();
176 options.
get(key_xtpdft +
".cdft.guess_strategy").
as<std::string>();
187 throw std::runtime_error(
188 "initial_guess=dimer_guess requires both dimer_guess_orbA and "
189 "dimer_guess_orbB to be set to real monomer .orb file paths.");
193 grid_name_ = options.
get(key_xtpdft +
".integration_grid").
as<std::string>();
196 if (options.
exists(key_xtpdft +
".externaldensity")) {
199 options.
get(key_xtpdft +
".externaldensity.orbfile").
as<std::string>();
200 gridquality_ = options.
get(key_xtpdft +
".externaldensity.gridquality")
203 options.
get(key_xtpdft +
".externaldensity.state").
as<std::string>();
206 if (options.
exists(
".externalfield")) {
212 options.
get(key_xtpdft +
".convergence.energy").
as<
double>();
214 options.
get(key_xtpdft +
".convergence.error").
as<
double>();
216 options.
get(key_xtpdft +
".convergence.max_iterations").
as<
Index>();
219 options.
get(key_xtpdft +
".convergence.method").
as<std::string>();
220 if (method ==
"DIIS") {
222 }
else if (method ==
"mixing") {
230 options.
get(key_xtpdft +
".convergence.mixing").
as<
double>();
233 options.
get(key_xtpdft +
".convergence.mixing_max").
as<
double>();
235 options.
get(key_xtpdft +
".convergence.levelshift").
as<
double>();
237 options.
get(key_xtpdft +
".convergence.levelshift_end").
as<
double>();
241 options.
get(key_xtpdft +
".convergence.mixing_end").
as<
double>();
243 options.
get(key_xtpdft +
".convergence.DIIS_maxout").
as<
bool>();
245 options.
get(key_xtpdft +
".convergence.DIIS_length").
as<
Index>();
247 options.
get(key_xtpdft +
".convergence.DIIS_start").
as<
double>();
249 options.
get(key_xtpdft +
".convergence.ADIIS_start").
as<
double>();
251 options.
get(key_xtpdft +
".convergence.davidson_max_iter").
as<
Index>();
253 key_xtpdft +
".convergence.energy_reset", 1.0);
255 key_xtpdft +
".convergence.second_order",
"auto");
258 throw std::runtime_error(
259 "xtpdft.convergence.second_order must be auto, always or off, not " +
263 key_xtpdft +
".overlap_tolerance", 1
e-8);
265 key_xtpdft +
".ri_pair_threshold", 1
e-10);
267 if (options.
exists(key_xtpdft +
".dft_in_dft.activeatoms")) {
269 options.
get(key_xtpdft +
".dft_in_dft.activeatoms").
as<std::string>();
271 options.
get(key_xtpdft +
".dft_in_dft.threshold").
as<
double>();
273 options.
get(key_xtpdft +
".dft_in_dft.levelshift").
as<
double>();
275 options.
get(key_xtpdft +
".dft_in_dft.truncate_basis").
as<
bool>();
277 key_xtpdft +
".dft_in_dft.grow",
false);
279 key_xtpdft +
".dft_in_dft.grow_window", 0.1) *
282 key_xtpdft +
".dft_in_dft.grow_threshold", 0.0025);
287 options.
get(key_xtpdft +
".dft_in_dft.truncation_threshold")
294 XTP_LOG(level, *
pLog_) <<
" Orbital energies: " << std::flush;
295 XTP_LOG(level, *
pLog_) <<
" index occupation energy(Hartree) " << std::flush;
297 for (
Index i = 0; i < MOEnergies.size(); ++i) {
305 XTP_LOG(level, *
pLog_) << (boost::format(
" %1$5d %2$1d %3$+1.10f") %
306 i % occupancy % MOEnergies(i))
314 const Eigen::VectorXd& beta_energies,
316 XTP_LOG(level, *
pLog_) <<
" UKS orbital energies:" << std::flush;
317 XTP_LOG(level, *
pLog_) <<
" index occ eps_a(Ha) eps_b(Ha)"
321 std::max<Index>(alpha_energies.size(), beta_energies.size());
323 for (
Index i = 0; i < nrows; ++i) {
327 std::string occ =
"0";
328 if (occ_a && occ_b) {
336 std::string eps_a =
" -";
337 std::string eps_b =
" -";
339 if (i < alpha_energies.size()) {
340 eps_a = (boost::format(
"%+1.10f") % alpha_energies(i)).str();
342 if (i < beta_energies.size()) {
343 eps_b = (boost::format(
"%+1.10f") % beta_energies(i)).str();
347 " %1$5d %2$1s %3$15s %4$15s") %
348 i % occ % eps_a % eps_b)
356 " alpha HOMO-LUMO gap: %+1.10f Ha") %
365 " beta HOMO-LUMO gap: %+1.10f Ha") %
377 <<
TimeStamp() <<
" Electric Dipole is[e*bohr]:\n\t\t dx=" << result[0]
378 <<
"\n\t\t dy=" << result[1] <<
"\n\t\t dz=" << result[2] << std::flush;
398 Orbitals& orb,
const Eigen::MatrixXd& Dmat,
403 <<
" Skipping force calculation: RI-J gradient (DFTGradient::"
404 "RIJGradient) only implements the RI path, but this SCF ran "
405 "without an auxiliary basis (conventional 4-center ERIs)."
413 <<
" Skipping force calculation: the libint2 this was built "
414 "against lacks derivative integrals for one or more required "
415 "operator categories; rebuild libint2 with "
416 "--enable-1body/--enable-eri2/--enable-eri3 to use analytic "
427 <<
"') was used for this SCF, but analytic nuclear forces do "
428 "not include the ECP term d(V_ECP)/dR."
437 << natoms <<
" atoms)" << std::flush;
443 <<
" Computing one-electron (kinetic + nuclear "
444 "attraction) derivatives"
447 std::vector<AOMatrixDerivative> dVne =
449 Eigen::MatrixXd eone_grad = Eigen::MatrixXd::Zero(natoms, 3);
450 for (
Index a = 0; a < natoms; ++a) {
451 for (
Index xyz = 0; xyz < 3; ++xyz) {
452 eone_grad(a, xyz) = Dmat.cwiseProduct(dT[a][xyz] + dVne[a][xyz]).sum();
456 <<
TimeStamp() <<
" One-electron derivatives done" << std::flush;
468 Eigen::MatrixXd W = 2.0 * C_occ * eps_occ.asDiagonal() * C_occ.transpose();
471 <<
TimeStamp() <<
" Computing overlap (Pulay) derivatives"
474 Eigen::MatrixXd overlap_pulay_grad = Eigen::MatrixXd::Zero(natoms, 3);
475 for (
Index a = 0; a < natoms; ++a) {
476 for (
Index xyz = 0; xyz < 3; ++xyz) {
477 overlap_pulay_grad(a, xyz) = -W.cwiseProduct(dS[a][xyz]).sum();
481 <<
TimeStamp() <<
" Overlap derivatives done" << std::flush;
484 <<
TimeStamp() <<
" Computing RI-J (Coulomb) gradient" << std::flush;
485 Eigen::MatrixXd rij_term =
488 <<
TimeStamp() <<
" RI-J gradient done" << std::flush;
491 <<
TimeStamp() <<
" Computing XC grid (Pulay + weight) gradient terms"
497 <<
TimeStamp() <<
" XC grid gradient terms done" << std::flush;
499 Eigen::MatrixXd grad = nucrep_term + eone_grad + overlap_pulay_grad +
500 rij_term + pulay_term + weight_term;
509 <<
TimeStamp() <<
" Computing RI-K (exact exchange) gradient"
513 <<
TimeStamp() <<
" RI-K gradient done" << std::flush;
518 Eigen::Vector3d sum = grad.colwise().sum();
519 if (sum.cwiseAbs().maxCoeff() > 1
e-4) {
522 <<
" WARNING: computed forces do not sum to zero across atoms "
523 "(translational invariance check failed, max component="
524 << sum.cwiseAbs().maxCoeff()
525 <<
") -- treat these forces with "
532 Eigen::MatrixXd force = -grad;
536 <<
TimeStamp() <<
" Computed and stored ground-state nuclear forces."
540 for (
Index a = 0; a < natoms; ++a) {
542 (boost::format(
" %1$s"
543 " %2$+1.6f %3$+1.6f %4$+1.6f") %
544 mol[a].getElement() % force(a, 0) % force(a, 1) % force(a, 2))
564 Eigen::MatrixXd C_alpha_occ = MOs_alpha.
eigenvectors().leftCols(n_occ_alpha);
565 Eigen::MatrixXd C_beta_occ = MOs_beta.
eigenvectors().leftCols(n_occ_beta);
566 Eigen::VectorXd eps_alpha_occ = MOs_alpha.
eigenvalues().head(n_occ_alpha);
567 Eigen::VectorXd eps_beta_occ = MOs_beta.
eigenvalues().head(n_occ_beta);
569 C_alpha_occ * eps_alpha_occ.asDiagonal() * C_alpha_occ.transpose() +
570 C_beta_occ * eps_beta_occ.asDiagonal() * C_beta_occ.transpose();
574 Eigen::MatrixXd overlap_pulay_grad = Eigen::MatrixXd::Zero(natoms, 3);
575 for (
Index a = 0; a < natoms; ++a) {
576 for (
Index xyz = 0; xyz < 3; ++xyz) {
577 overlap_pulay_grad(a, xyz) = -W.cwiseProduct(dS[a][xyz]).sum();
580 return overlap_pulay_grad;
588 const Eigen::MatrixXd D_total = Dspin.
total();
593 std::vector<AOMatrixDerivative> dVne =
595 Eigen::MatrixXd eone_grad = Eigen::MatrixXd::Zero(natoms, 3);
596 for (
Index a = 0; a < natoms; ++a) {
597 for (
Index xyz = 0; xyz < 3; ++xyz) {
598 eone_grad(a, xyz) = D_total.cwiseProduct(dT[a][xyz] + dVne[a][xyz]).sum();
602 Eigen::MatrixXd overlap_pulay_grad =
605 Eigen::MatrixXd grad =
615 Eigen::MatrixXd C_alpha_occ =
617 Eigen::MatrixXd C_beta_occ =
633 <<
" Skipping UKS force calculation: RI-J gradient only "
634 "implements the RI path, but this SCF ran without an "
643 <<
" Skipping UKS force calculation: the libint2 this was "
644 "built against lacks derivative integrals for one or more "
645 "required operator categories; rebuild libint2 with "
646 "--enable-1body/--enable-eri2/--enable-eri3 to use "
655 <<
TimeStamp() <<
" Skipping UKS force calculation: an ECP ('"
657 <<
"') was used for this SCF, but analytic nuclear forces do "
658 "not include the ECP term d(V_ECP)/dR."
663 Eigen::MatrixXd grad =
672 Eigen::Vector3d sum = grad.colwise().sum();
673 if (sum.cwiseAbs().maxCoeff() > 1
e-4) {
676 <<
" WARNING: computed UKS forces do not sum to zero across "
677 "atoms (translational invariance check failed, max "
679 << sum.cwiseAbs().maxCoeff()
680 <<
") -- treat these forces with "
686 Eigen::MatrixXd force = -grad;
690 <<
TimeStamp() <<
" Computed and stored ground-state UKS nuclear forces."
695 for (
Index a = 0; a < force.rows(); ++a) {
696 std::string output = (boost::format(
" %1$s"
697 " %2$+1.6f %3$+1.6f %4$+1.6f") %
698 mol_for_print[a].getElement() % force(a, 0) %
699 force(a, 1) % force(a, 2))
714 const Eigen::MatrixXd& MOCoeff,
const Eigen::MatrixXd& Dmat,
715 double error)
const {
717 std::array<Eigen::MatrixXd, 2> result;
719 auto t =
timings_.Measure(
"J (RI)");
720 result[0] =
ERIs_.CalculateERIs_3c(Dmat);
723 auto t =
timings_.Measure(
"K (RI, from density matrix)");
724 result[1] =
ERIs_.CalculateEXX_3c(Eigen::MatrixXd::Zero(0, 0), Dmat);
726 auto t =
timings_.Measure(
"K (RI, from occupied MOs)");
728 result[1] =
ERIs_.CalculateEXX_3c(occblock, Dmat);
732 auto t =
timings_.Measure(
"J+K (4c)");
733 return ERIs_.CalculateERIs_EXX_4c(Dmat, error);
740 double error)
const {
742 auto t =
timings_.Measure(
"J (RI)");
743 return ERIs_.CalculateERIs_3c(Dmat);
745 auto t =
timings_.Measure(
"J (4c)");
746 return ERIs_.CalculateERIs_4c(Dmat, error);
751 const double gb = 1024.0 * 1024.0 * 1024.0;
752 const double n = double(
dftbasis_.AOBasisSize());
759 const double naux = double(
ERIs_.AuxSize());
761 const double tensor =
762 naux * double(
ERIs_.StoredPairs()) *
sizeof(double) / gb;
763 const double kept = double(
ERIs_.StoredPairs()) /
764 double(std::max<Index>(1,
ERIs_.AllPairs()));
767 const double scratch = threads * 4 * n * n *
sizeof(double) / gb;
769 <<
TimeStamp() <<
" RI: " <<
ERIs_.AuxSize() <<
" aux functions ("
770 <<
ERIs_.Removedfunctions()
771 <<
" removed from the metric); stored 3c tensor "
772 << std::setprecision(3) << tensor <<
" GB (" << 100.0 * kept
774 <<
"); J/K scratch up to about " << scratch <<
" GB" << std::flush;
780 <<
" Resident memory after setup: " << std::setprecision(3) << rss
781 <<
" GB" << std::flush;
799 Eigen::MatrixXd Dmat = [&]() {
800 auto t =
timings_.Measure(
"guess: atomic densities");
808 <<
TimeStamp() <<
" Filled DFT Vxc matrix " << std::flush;
813 std::array<Eigen::MatrixXd, 2> both =
838 <<
TimeStamp() <<
" Peak resident memory of this process so far: "
839 << std::setprecision(3) << peak <<
" GB" << std::flush;
846 throw std::runtime_error(
847 "xtpdft polarizability: closed-shell ground states only");
851 <<
" Static polarizability (coupled-perturbed KS, 3 uniform fields)"
856 const std::vector<Eigen::MatrixXd> h(dipole.
Matrix().begin(),
859 Eigen::Matrix3d alpha;
860 for (
Index a = 0; a < 3; ++a) {
861 for (
Index c = 0; c < 3; ++c) {
862 alpha(a, c) = -dipole.
Matrix()[std::size_t(a)]
863 .cwiseProduct(dP[std::size_t(c)])
867 alpha = 0.5 * (alpha + alpha.transpose()).eval();
871 <<
TimeStamp() <<
" Polarizability [a.u.]:\n"
872 << alpha <<
"\n isotropic " << alpha.trace() / 3
873 <<
" a.u. = " << alpha.trace() / 3 * A3 <<
" A^3" << std::flush;
886 bool converged =
RunCDFT(orb, constraint);
889 if (converged && original_compute_forces) {
896 <<
" CDFT converged -- computing the ordinary DFT force once, "
897 "for the final, converged density only"
912 std::map<std::string, Eigen::MatrixXd> reference_densities =
922 std::vector<HirshfeldPartition::AtomicReference> atoms =
926 std::array<Eigen::MatrixXd, 2> Dspin =
930 Eigen::MatrixXd density_total = Dspin[0] + Dspin[1];
932 Eigen::MatrixXd cdft_gradient_correction =
935 cdft_gradient_correction +=
937 atoms, atom_index, density_total, orb.
QMAtoms(), full_dftbasis,
943 constraint.
lambda * cdft_gradient_correction);
949 const std::string previous_basis =
963 <<
" Starting from the orbitals of the previous QM/MM iteration"
967 <<
TimeStamp() <<
" Previous orbitals not usable as guess (" << reason
974 auto t =
timings_.Measure(
"setup: XC grid");
979 bool success =
false;
984 <<
" Forcing closed-shell singlet through UKS development path."
997 const std::string& previous_basis,
998 std::string& reason)
const {
1006 reason =
"basis size differs";
1009 if (!previous_basis.empty() && previous_basis != orb.
getDFTbasisName()) {
1010 reason =
"basis set differs";
1015 reason =
"electron count differs";
1038 double lambda_lo = constraint.
lambda - 0.1;
1039 double lambda_hi = constraint.
lambda + 0.1;
1041 auto EvaluateMismatch = [&](
double lambda) ->
double {
1044 <<
TimeStamp() <<
" CDFT: starting inner SCF at lambda=" << lambda
1046 bool scf_converged =
EvaluateUKS(orb, H0, vxcpotential);
1047 if (!scf_converged) {
1048 throw std::runtime_error(
1049 "RunCDFT: inner SCF did not converge at lambda=" +
1050 std::to_string(lambda));
1057 std::array<Eigen::MatrixXd, 2> Dspin =
1068 double mismatch_lo = EvaluateMismatch(lambda_lo);
1069 double mismatch_hi = EvaluateMismatch(lambda_hi);
1071 Index bracket_attempts = 0;
1072 constexpr Index kMaxBracketAttempts = 10;
1073 while (mismatch_lo * mismatch_hi > 0.0 &&
1074 bracket_attempts < kMaxBracketAttempts) {
1075 double width = lambda_hi - lambda_lo;
1076 lambda_lo -= 0.5 * width;
1077 lambda_hi += 0.5 * width;
1078 mismatch_lo = EvaluateMismatch(lambda_lo);
1079 mismatch_hi = EvaluateMismatch(lambda_hi);
1082 if (mismatch_lo * mismatch_hi > 0.0) {
1085 <<
" RunCDFT: could not bracket a root for the population "
1087 << kMaxBracketAttempts
1088 <<
" bracket-expansion attempts -- the target population may "
1089 "be unreachable for this system, or the initial "
1090 "lambda guess may be far from the actual root."
1099 double lambda_mid = 0.5 * (lambda_lo + lambda_hi);
1100 double mismatch_mid = EvaluateMismatch(lambda_mid);
1103 <<
TimeStamp() <<
" CDFT outer iteration " << outer_iter + 1 <<
" of "
1105 <<
" population mismatch=" << mismatch_mid << std::flush;
1108 constraint.
lambda = lambda_mid;
1111 <<
TimeStamp() <<
" CDFT converged after " << outer_iter + 1
1112 <<
" outer iterations, lambda=" << lambda_mid << std::flush;
1116 if (mismatch_mid * mismatch_lo < 0.0) {
1117 lambda_hi = lambda_mid;
1118 mismatch_hi = mismatch_mid;
1120 lambda_lo = lambda_mid;
1121 mismatch_lo = mismatch_mid;
1124 }
catch (
const std::runtime_error&) {
1132 <<
" RunCDFT: outer bisection loop did not converge "
1135 constraint.
lambda = 0.5 * (lambda_lo + lambda_hi);
1156 <<
TimeStamp() <<
" Reading guess from orbitals object/file"
1181 throw std::runtime_error(
1182 "initial_guess=dimer_guess: this is a restricted (closed-shell) "
1183 "calculation, but at least one monomer .orb file is open-shell "
1184 "or unrestricted. Use force_uks_path to run the dimer "
1185 "unrestricted with this guess.");
1188 throw std::runtime_error(
1189 "initial_guess=dimer_guess: the monomers have " +
1191 " electrons in total, but this calculation has " +
1193 ". Check the monomer charges against the dimer charge.");
1195 MOs = dimer_guess_orb.
MOs();
1198 throw std::runtime_error(
"Initial guess method not known/implemented");
1204 Eigen::MatrixXd Dmat = spin_dmat.
total();
1207 <<
TimeStamp() <<
" Guess Matrix gives N=" << std::setprecision(9)
1208 << Dmat.cwiseProduct(
dftAOoverlap_.Matrix()).sum() <<
" electrons."
1218 const Eigen::MatrixXd&
F,
1219 const Eigen::MatrixXd& X) {
1225 <<
TimeStamp() <<
" STARTING SCF cycle" << std::flush;
1227 <<
" ----------------------------------------------"
1228 "----------------------------"
1231 Eigen::MatrixXd J = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols());
1234 K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols());
1237 double start_incremental_F_threshold = 1
e-4;
1239 start_incremental_F_threshold = 0.0;
1256 <<
TimeStamp() <<
" Filled DFT Vxc matrix " << std::flush;
1259 double Eone = Dmat.cwiseProduct(H0.
matrix()).sum();
1260 double Etwo = e_vxc.
energy();
1268 double integral_error =
1276 Etwo += 0.5 * Dmat.cwiseProduct(J).sum();
1279 exx = 0.25 *
ScaHFX_ * Dmat.cwiseProduct(K).sum();
1281 <<
TimeStamp() <<
" Filled F+K matrix " << std::flush;
1285 <<
TimeStamp() <<
" Filled F matrix " << std::flush;
1287 Etwo += 0.5 * Dmat.cwiseProduct(J).sum();
1291 double totenergy = Eone + H0.
energy() + Etwo;
1294 << std::setprecision(12) << Eone << std::flush;
1296 << std::setprecision(12) << Etwo << std::flush;
1298 <<
TimeStamp() << std::setprecision(12) <<
" Local Exc contribution "
1299 << e_vxc.
energy() << std::flush;
1303 <<
" Non local Ex contribution " << exx << std::flush;
1306 <<
TimeStamp() <<
" Total Energy " << std::setprecision(12) << totenergy
1310 auto t =
timings_.Measure(
"DIIS/ADIIS + diagonalisation");
1329 <<
TimeStamp() <<
" Total Energy has converged to "
1331 <<
"[Ha] after " << this_iter + 1
1332 <<
" iterations. DIIS error is converged up to "
1335 <<
TimeStamp() <<
" Final Single Point Energy "
1336 << std::setprecision(12) << totenergy <<
" Ha" << std::flush;
1338 <<
" Final Local Exc contribution "
1339 << e_vxc.
energy() <<
" Ha" << std::flush;
1342 <<
" Final Non Local Ex contribution "
1343 << exx <<
" Ha" << std::flush;
1348 Index nuclear_charge = 0;
1350 nuclear_charge += atom.getNuccharge();
1363 auto t =
timings_.Measure(
"forces");
1369 }
else if (this_iter ==
max_iter_ - 1) {
1371 <<
TimeStamp() <<
" DFT calculation has not converged after "
1373 <<
" iterations. Use more iterations or another convergence "
1374 "acceleration scheme."
1411 conv_uks.
Configure(opt_alpha, opt_beta);
1417 <<
TimeStamp() <<
" Reading UKS guess from orbitals object/file"
1420 MOs_alpha = orb.
MOs();
1429 <<
" Orbital file has no beta MOs, using alpha guess for beta."
1431 MOs_beta = MOs_alpha;
1436 <<
" Building UKS guess from two monomer .orb files (dimer_guess)"
1439 MOs_alpha = dimer_guess_orb.
MOs();
1441 MOs_beta = dimer_guess_orb.
MOs_beta();
1458 throw std::runtime_error(
"Initial guess method not known/implemented");
1471 <<
TimeStamp() <<
" UKS guess gives Nalpha="
1478 <<
TimeStamp() <<
" STARTING UKS SCF cycle" << std::flush;
1480 <<
" ------------------------------------------------------------"
1488 Eigen::MatrixXd H_alpha = H0.
matrix();
1489 Eigen::MatrixXd H_beta = H0.
matrix();
1493 const Eigen::MatrixXd D_total = Dspin.
total();
1495 double E_one = Dspin.
alpha.cwiseProduct(H0.
matrix()).sum() +
1498 double E_coul = 0.0;
1502 double integral_error = std::min(conv_uks.
getDIIsError() * 1
e-5, 1
e-5);
1505 std::array<Eigen::MatrixXd, 2> both_alpha =
CalcERIs_EXX(
1506 Eigen::MatrixXd::Zero(0, 0), Dspin.
alpha, integral_error);
1507 std::array<Eigen::MatrixXd, 2> both_beta =
1510 Eigen::MatrixXd J = both_alpha[0] + both_beta[0];
1511 Eigen::MatrixXd K_alpha = both_alpha[1];
1512 Eigen::MatrixXd K_beta = both_beta[1];
1514 H_alpha += J +
ScaHFX_ * K_alpha;
1515 H_beta += J +
ScaHFX_ * K_beta;
1517 E_coul = 0.5 * D_total.cwiseProduct(J).sum();
1519 (Dspin.
alpha.cwiseProduct(K_alpha).sum() +
1520 Dspin.
beta.cwiseProduct(K_beta).sum());
1522 Eigen::MatrixXd J =
CalcERIs(D_total, integral_error);
1525 E_coul = 0.5 * D_total.cwiseProduct(J).sum();
1532 H_alpha += vxc.vxc_alpha;
1533 H_beta += vxc.vxc_beta;
1536 double totenergy = H0.
energy() + E_one + E_coul + E_xc + E_exx;
1545 H_alpha += (c.lambda * c.spin_alpha_coefficient) * c.weight_matrix;
1546 H_beta += (c.lambda * c.spin_beta_coefficient) * c.weight_matrix;
1548 c.spin_alpha_coefficient *
1549 Dspin.
alpha.cwiseProduct(c.weight_matrix).sum() +
1550 c.spin_beta_coefficient *
1551 Dspin.
beta.cwiseProduct(c.weight_matrix).sum();
1552 totenergy += c.lambda * (population - c.target_population);
1557 << std::setprecision(12) << E_one << std::flush;
1559 << std::setprecision(12) << E_coul << std::flush;
1561 << std::setprecision(12) << E_xc << std::flush;
1564 <<
TimeStamp() <<
" EXX contribution " << std::setprecision(12)
1565 << E_exx << std::flush;
1568 <<
TimeStamp() <<
" Total Energy " << std::setprecision(12) << totenergy
1579 [
this, &H0, &vxcpotential](
const Eigen::MatrixXd& alpha_new,
1580 const Eigen::MatrixXd& beta_new) {
1587 [
this, &vxcpotential](
1590 const Eigen::MatrixXd& F_beta,
const Eigen::MatrixXd& X) {
1596 auto t =
timings_.Measure(
"DIIS/ADIIS + diagonalisation");
1597 Dspin = conv_uks.
Iterate(Dspin, Hspin, MOs_alpha, MOs_beta, totenergy);
1600 MOs_beta = MOs_alpha;
1618 Index nuclear_charge = 0;
1620 nuclear_charge += atom.getNuccharge();
1623 CanonicalizeOrbitalPhases(MOs_alpha);
1624 CanonicalizeOrbitalPhases(MOs_beta);
1627 orb.
MOs() = MOs_alpha;
1638 <<
TimeStamp() <<
" UKS converged after " << this_iter + 1
1639 <<
" iterations. Delta E=" << conv_uks.
getDeltaE()
1640 <<
" DIIS error=" << conv_uks.
getDIIsError() << std::flush;
1643 <<
TimeStamp() <<
" Final Single Point Energy "
1644 << std::setprecision(12) << totenergy <<
" Ha" << std::flush;
1646 <<
TimeStamp() << std::setprecision(12) <<
" Final XC contribution "
1647 << E_xc <<
" Ha" << std::flush;
1651 <<
" Final EXX contribution " << E_exx <<
" Ha" << std::flush;
1662 auto t =
timings_.Measure(
"forces");
1672 <<
TimeStamp() <<
" UKS calculation has not converged after "
1673 <<
max_iter_ <<
" iterations." << std::flush;
1691 std::make_unique<DFTTimings::Scope>(
timings_,
"setup: one-electron H0");
1697 <<
TimeStamp() <<
" Filled DFT Kinetic energy matrix ." << std::flush;
1702 <<
TimeStamp() <<
" Filled DFT nuclear potential matrix." << std::flush;
1704 Eigen::MatrixXd H0 = dftAOkinetic.
Matrix() + dftAOESP.
Matrix();
1706 <<
TimeStamp() <<
" Constructed independent particle hamiltonian "
1710 << std::setprecision(9) << E0 << std::flush;
1717 <<
TimeStamp() <<
" Filled DFT ECP matrix" << std::flush;
1723 <<
" External sites" << std::flush;
1724 bool has_quadrupoles = std::any_of(
1726 [](
const std::unique_ptr<StaticSite>& s) { return s->getRank() == 2; });
1727 std::string header =
1728 " Name Coordinates[a0] charge[e] dipole[e*a0] ";
1729 if (has_quadrupoles) {
1730 header +=
" quadrupole[e*a0^2]";
1735 for (
const std::unique_ptr<StaticSite>& site : *
externalsites_) {
1736 if (counter == limit) {
1739 std::string output =
1740 (boost::format(
" %1$s"
1741 " %2$+1.4f %3$+1.4f %4$+1.4f"
1743 site->getElement() % site->getPos()[0] % site->getPos()[1] %
1744 site->getPos()[2] % site->getCharge())
1746 const Eigen::Vector3d& dipole = site->getDipole();
1747 output += (boost::format(
" %1$+1.4f %2$+1.4f %3$+1.4f") % dipole[0] %
1748 dipole[1] % dipole[2])
1750 if (site->getRank() > 1) {
1751 Eigen::VectorXd quadrupole = site->Q().tail<5>();
1753 (boost::format(
" %1$+1.4f %2$+1.4f %3$+1.4f %4$+1.4f %5$+1.4f") %
1754 quadrupole[0] % quadrupole[1] % quadrupole[2] % quadrupole[3] %
1761 if (counter == limit) {
1764 <<
" sites not displayed)\n"
1768 auto t =
timings_.Measure(
"setup: external multipoles");
1772 <<
TimeStamp() <<
" Nuclei-external site interaction energy "
1773 << std::setprecision(9) << ext_multipoles.
energy() << std::flush;
1774 E0 += ext_multipoles.
energy();
1775 H0 += ext_multipoles.
matrix();
1782 E0 += extdensity_result.
energy();
1784 <<
TimeStamp() <<
" Nuclei-external density interaction energy "
1785 << std::setprecision(9) << extdensity_result.
energy() << std::flush;
1786 H0 += extdensity_result.
matrix();
1792 throw std::runtime_error(
1793 "DFTEngine: the external potential matrix does not match the DFT "
1802 <<
TimeStamp() <<
" Integrating external electric field with F[Hrt]="
1809 <<
TimeStamp() <<
" Integrating external Ewald Potential" << std::flush;
1810 auto t =
timings_.Measure(
"setup: Ewald potential on grid");
1822 throw std::runtime_error(
1823 "DFTEngine: the external Ewald potential grid has " +
1825 " boxes but this molecule's own grid has " +
1827 ". The potential was evaluated on a different grid than the one "
1828 "being integrated over.");
1834 const std::vector<double>& source =
1836 if (
Index(source.size()) != box.
size()) {
1837 throw std::runtime_error(
"DFTEngine: box " + std::to_string(i) +
1838 " of the external Ewald "
1839 "potential grid holds " +
1840 std::to_string(source.size()) +
1841 " values for " + std::to_string(box.
size()) +
1849 std::string ewald_key;
1855 for (
double v : ewaldgrid[i].getPotentialValues()) {
1861 std::ostringstream key;
1863 << points <<
"|" << sum <<
"|" << sum2;
1864 ewald_key = key.str();
1871 <<
" Reusing the Ewald potential matrix of the previous run"
1875 const Eigen::MatrixXd ewald_matrix =
1888 <<
TimeStamp() <<
" Nuclei-external Ewald potential energy "
1897 std::ostringstream key;
1902 for (
const AOShell& shell : *basis) {
1903 key << static_cast<int>(shell.getL()) <<
"," << shell.getSize() <<
","
1904 << shell.getPos().x() <<
"," << shell.getPos().y() <<
","
1905 << shell.getPos().z() <<
";";
1918 <<
TimeStamp() <<
" SCF thresholds for this run: Delta E "
1920 <<
" (set by the caller)" << std::flush;
1925 ERIs_.AuxSize() == 0) {
1937 auto overlap_timer =
1938 std::make_unique<DFTTimings::Scope>(
timings_,
"setup: overlap, S^-1/2");
1941 <<
TimeStamp() <<
" Filled DFT Overlap matrix." << std::flush;
1953 overlap_timer.reset();
1963 <<
" Reusing the RI integrals of the previous run (same basis sets "
1968 auto ri_start = DFTTimings::Clock::now();
1976 std::chrono::duration<double>(DFTTimings::Clock::now() - ri_start)
1978 timings_.Add(
"setup: RI metric V^-1/2",
ERIs_.MetricSeconds());
1979 timings_.Add(
"setup: RI 3c integrals", ri_seconds -
ERIs_.MetricSeconds());
1981 <<
TimeStamp() <<
" Inverted AUX Coulomb matrix, removed "
1982 <<
ERIs_.Removedfunctions() <<
" functions from aux basis"
1986 <<
" Setup invariant parts of Electron Repulsion integrals "
1990 <<
TimeStamp() <<
" Calculating 4c diagonals. " << std::flush;
1991 auto t =
timings_.Measure(
"setup: 4c Schwarz screening");
1994 <<
TimeStamp() <<
" Calculated 4c diagonals. " << std::flush;
2014class SphericalAtomSCF {
2016 explicit SphericalAtomSCF(
const AOBasis& basis) : n_(basis.AOBasisSize()) {
2017 for (
const AOShell& shell : basis) {
2018 const Index l =
static_cast<Index>(shell.getL());
2020 while (g <
Index(l_.size()) && l_[g] != l) {
2023 if (g ==
Index(l_.size())) {
2025 starts_.emplace_back();
2027 starts_[g].push_back(shell.getStartIndex());
2031 Index Groups()
const {
return Index(l_.size()); }
2034 Eigen::MatrixXd Reduce(
const Eigen::MatrixXd& full,
Index g)
const {
2035 const std::vector<Index>& st = starts_[g];
2036 const Index size = 2 * l_[g] + 1;
2037 Eigen::MatrixXd red(st.size(), st.size());
2038 for (
Index i = 0; i <
Index(st.size()); ++i) {
2039 for (
Index j = 0; j <
Index(st.size()); ++j) {
2040 red(i, j) = full.block(st[i], st[j], size, size).trace() / double(size);
2048 Eigen::MatrixXd Expand(
const std::vector<Eigen::MatrixXd>& red)
const {
2049 Eigen::MatrixXd full = Eigen::MatrixXd::Zero(n_, n_);
2050 for (
Index g = 0; g < Groups(); ++g) {
2051 const std::vector<Index>& st = starts_[g];
2052 const Index size = 2 * l_[g] + 1;
2053 for (
Index i = 0; i <
Index(st.size()); ++i) {
2054 for (
Index j = 0; j <
Index(st.size()); ++j) {
2055 full.block(st[i], st[j], size, size)
2057 .setConstant(red[g](i, j));
2066 std::vector<Eigen::MatrixXd> Density(
2067 const std::vector<Eigen::MatrixXd>& fock,
2068 const std::vector<Eigen::MatrixXd>& overlap,
2069 const std::vector<Eigen::VectorXd>& occupation)
const {
2070 std::vector<Eigen::MatrixXd> dens(Groups());
2071 for (
Index g = 0; g < Groups(); ++g) {
2072 Eigen::GeneralizedSelfAdjointEigenSolver<Eigen::MatrixXd> es(fock[g],
2074 const Index nocc = occupation[g].size();
2075 const Eigen::MatrixXd c = es.eigenvectors().leftCols(nocc);
2076 dens[g] = c * (occupation[g] / double(2 * l_[g] + 1)).asDiagonal() *
2084 std::vector<Eigen::VectorXd> AufbauOccupation(
2085 const std::vector<Eigen::MatrixXd>& fock,
2086 const std::vector<Eigen::MatrixXd>& overlap,
double nelectrons)
const {
2092 std::vector<Level> levels;
2093 std::vector<Eigen::VectorXd> occ(Groups());
2094 for (
Index g = 0; g < Groups(); ++g) {
2095 Eigen::GeneralizedSelfAdjointEigenSolver<Eigen::MatrixXd> es(
2096 fock[g], overlap[g], Eigen::EigenvaluesOnly);
2097 occ[g] = Eigen::VectorXd::Zero(es.eigenvalues().size());
2098 for (
Index k = 0; k < es.eigenvalues().size(); ++k) {
2099 levels.push_back({es.eigenvalues()(k), g, k});
2103 levels.begin(), levels.end(),
2104 [](
const Level& a,
const Level& b) { return a.energy < b.energy; });
2105 double left = nelectrons;
2106 for (
const Level& lev : levels) {
2107 const double take = std::clamp(left, 0.0,
double(2 * l_[lev.group] + 1));
2108 occ[lev.group](lev.index) = take;
2117 bool OccupationFromSubshells(
2118 const std::vector<std::array<double, 3>>& subshells,
2119 const std::vector<Eigen::MatrixXd>& overlap,
2120 std::vector<Eigen::VectorXd>& occ)
const {
2121 occ.assign(Groups(), Eigen::VectorXd());
2122 for (
Index g = 0; g < Groups(); ++g) {
2123 occ[g] = Eigen::VectorXd::Zero(overlap[g].rows());
2125 for (
const auto& sub : subshells) {
2129 while (g < Groups() && l_[g] != l) {
2132 if (g == Groups() || k >= occ[g].size()) {
2135 occ[g](k) += sub[2];
2142 std::vector<Index> l_;
2143 std::vector<std::vector<Index>> starts_;
2149 explicit SimpleDIIS(
Index maxhist) : maxhist_(maxhist) {}
2151 Eigen::VectorXd Extrapolate(
const Eigen::VectorXd& fock,
2152 const Eigen::VectorXd& error) {
2153 focks_.push_back(fock);
2154 errors_.push_back(error);
2155 if (
Index(focks_.size()) > maxhist_) {
2156 focks_.erase(focks_.begin());
2157 errors_.erase(errors_.begin());
2163 Eigen::MatrixXd b = Eigen::MatrixXd::Zero(m + 1, m + 1);
2164 for (
Index i = 0; i < m; ++i) {
2165 for (
Index j = 0; j <= i; ++j) {
2166 b(i, j) = b(j, i) = errors_[i].dot(errors_[j]);
2168 b(i, m) = b(m, i) = -1.0;
2174 const double scale = b.topLeftCorner(m, m).diagonal().maxCoeff();
2176 b.topLeftCorner(m, m) /= scale;
2178 Eigen::VectorXd rhs = Eigen::VectorXd::Zero(m + 1);
2180 const Eigen::VectorXd
x = b.colPivHouseholderQr().solve(rhs);
2181 if (!
x.allFinite()) {
2184 Eigen::VectorXd result = Eigen::VectorXd::Zero(fock.size());
2185 for (
Index i = 0; i < m; ++i) {
2186 result +=
x(i) * focks_[i];
2193 std::vector<Eigen::VectorXd> focks_;
2194 std::vector<Eigen::VectorXd> errors_;
2206std::vector<std::array<double, 4>> ValenceConfiguration(
Index z,
Index ncore,
2214 std::vector<Sub> subs;
2216 for (
Index sum = 1; left > 0; ++sum) {
2217 for (
Index l = (sum - 1) / 2; l >= 0 && left > 0; --l) {
2218 const Index take = std::min(left, 2 * (2 * l + 1));
2219 subs.push_back({sum - l, l, double(take)});
2223 std::stable_sort(subs.begin(), subs.end(), [](
const Sub& a,
const Sub& b) {
2224 return a.n < b.n || (a.n == b.n && a.l < b.l);
2227 std::size_t first = 0;
2228 while (first < subs.size() && removed < ncore) {
2229 removed +=
Index(subs[first].electrons);
2232 if (removed != ncore) {
2235 std::vector<std::array<double, 4>> result;
2236 for (std::size_t i = first; i < subs.size(); ++i) {
2238 for (std::size_t j = first; j < i; ++j) {
2239 k += (subs[j].l == subs[i].l) ? 1 : 0;
2241 result.push_back({double(subs[i].l), double(k), 0.5 * subs[i].electrons,
2242 0.5 * subs[i].electrons});
2245 double excess = 0.5 * double(nalpha - nbeta);
2246 for (
auto it = result.rbegin(); it != result.rend() && excess > 0.0; ++it) {
2247 const double capacity = double(2 *
Index((*it)[0]) + 1);
2248 const double move = std::min(excess, capacity - (*it)[2]);
2249 if (move > 0.0 && (*it)[3] >= move) {
2255 if (excess > 1
e-12) {
2270std::optional<std::pair<Index, Index>> HundsRuleAlphaBetaElectrons(
2271 Index nuclear_charge) {
2272 switch (nuclear_charge) {
2274 return std::make_pair(1, 0);
2276 return std::make_pair(1, 1);
2278 return std::make_pair(2, 1);
2280 return std::make_pair(2, 2);
2282 return std::make_pair(3, 2);
2284 return std::make_pair(4, 2);
2286 return std::make_pair(5, 2);
2288 return std::make_pair(5, 3);
2290 return std::make_pair(5, 4);
2292 return std::make_pair(5, 5);
2294 return std::make_pair(6, 5);
2296 return std::make_pair(6, 6);
2298 return std::make_pair(7, 6);
2300 return std::make_pair(8, 6);
2302 return std::make_pair(9, 6);
2304 return std::make_pair(9, 7);
2306 return std::make_pair(9, 8);
2308 return std::make_pair(9, 9);
2310 return std::make_pair(10, 9);
2312 return std::make_pair(10, 10);
2315 return std::make_pair(16, 15);
2317 return std::make_pair(17, 15);
2319 return std::make_pair(18, 15);
2321 return std::make_pair(18, 16);
2323 return std::make_pair(18, 17);
2325 return std::make_pair(18, 18);
2328 return std::make_pair(25, 24);
2330 return std::make_pair(26, 24);
2332 return std::make_pair(27, 24);
2334 return std::make_pair(27, 25);
2336 return std::make_pair(27, 26);
2338 return std::make_pair(27, 27);
2340 return std::nullopt;
2346 const QMAtom& uniqueAtom,
bool use_hunds_rule_occupation)
const {
2358 dftbasis.
Fill(basisset, atom);
2368 ecp.
Fill(ecps, atom);
2375 const Index ncore = z - atom[0].getNuccharge();
2376 const Index numofelectrons = atom[0].getNuccharge();
2384 if (use_hunds_rule_occupation) {
2385 auto hunds_rule = HundsRuleAlphaBetaElectrons(z);
2386 if (hunds_rule.has_value()) {
2388 alpha_e = hunds_rule->first - ncore / 2;
2389 beta_e = hunds_rule->second - ncore / 2;
2393 <<
" No Hund's-rule ground-state occupation table "
2394 "entry for nuclear charge "
2396 <<
" (d/f-block elements are not covered); "
2397 "falling back to the parity-based alpha/beta split."
2399 use_hunds_rule_occupation =
false;
2402 if (!use_hunds_rule_occupation) {
2403 if ((numofelectrons % 2) != 0) {
2404 alpha_e = numofelectrons / 2 + numofelectrons % 2;
2405 beta_e = numofelectrons / 2;
2407 alpha_e = numofelectrons / 2;
2418 dftAOoverlap.
Fill(dftbasis);
2419 dftAOkinetic.
Fill(dftbasis);
2424 Eigen::MatrixXd H0 = dftAOkinetic.
Matrix() + dftAOESP.
Matrix();
2432 Eigen::GeneralizedSelfAdjointEigenSolver<Eigen::MatrixXd> es(
2433 H0, dftAOoverlap.
Matrix());
2434 const Eigen::VectorXd c = es.eigenvectors().col(0);
2435 return c * c.transpose();
2440 const SphericalAtomSCF sph(dftbasis);
2441 const Index ngroups = sph.Groups();
2442 using Radial = std::vector<Eigen::MatrixXd>;
2443 Radial S_red(ngroups);
2444 Radial H0_red(ngroups);
2446 Radial X_red(ngroups);
2447 for (
Index g = 0; g < ngroups; ++g) {
2448 S_red[g] = sph.Reduce(dftAOoverlap.
Matrix(), g);
2449 H0_red[g] = sph.Reduce(H0, g);
2450 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(S_red[g]);
2451 X_red[g] = es.eigenvectors() *
2452 es.eigenvalues().cwiseInverse().cwiseSqrt().asDiagonal() *
2453 es.eigenvectors().transpose();
2458 Radial Da, Db, Fa, Fb;
2459 double energy = 0.0;
2463 const double scahfx =
2465 auto Build = [&](
const Radial& Da,
const Radial& Db) {
2466 const Eigen::MatrixXd D_alpha = sph.Expand(Da);
2467 const Eigen::MatrixXd D_beta = sph.Expand(Db);
2468 const Eigen::MatrixXd D_total = D_alpha + D_beta;
2469 Eigen::MatrixXd H_alpha = H0;
2470 Eigen::MatrixXd H_beta = H0;
2473 std::array<Eigen::MatrixXd, 2> both_alpha =
2475 std::array<Eigen::MatrixXd, 2> both_beta =
2477 const Eigen::MatrixXd hartree = both_alpha[0] + both_beta[0];
2478 H_alpha += hartree + scahfx * both_alpha[1];
2479 H_beta += hartree + scahfx * both_beta[1];
2480 e_two = 0.5 * D_total.cwiseProduct(hartree).sum() +
2482 (both_alpha[1].cwiseProduct(D_alpha).sum() +
2483 both_beta[1].cwiseProduct(D_beta).sum());
2485 const Eigen::MatrixXd hartree =
2489 e_two = 0.5 * D_total.cwiseProduct(hartree).sum();
2493 H_beta += vxc.vxc_beta;
2497 st.energy = D_total.cwiseProduct(H0).sum() + e_two + vxc.energy;
2498 st.Fa.resize(ngroups);
2499 st.Fb.resize(ngroups);
2500 for (
Index g = 0; g < ngroups; ++g) {
2501 st.Fa[g] = sph.Reduce(H_alpha, g);
2502 st.Fb[g] = sph.Reduce(H_beta, g);
2509 std::vector<Eigen::VectorXd> occ_alpha;
2510 std::vector<Eigen::VectorXd> occ_beta;
2511 bool fixed_occupation =
false;
2513 const std::vector<std::array<double, 4>> config =
2514 ValenceConfiguration(z, ncore, alpha_e, beta_e);
2515 std::vector<std::array<double, 3>> alpha_subshells;
2516 std::vector<std::array<double, 3>> beta_subshells;
2517 for (
const auto& sub : config) {
2518 alpha_subshells.push_back({sub[0], sub[1], sub[2]});
2519 beta_subshells.push_back({sub[0], sub[1], sub[3]});
2523 sph.OccupationFromSubshells(alpha_subshells, S_red, occ_alpha) &&
2524 sph.OccupationFromSubshells(beta_subshells, S_red, occ_beta);
2525 if (!fixed_occupation) {
2527 <<
TimeStamp() <<
" No subshell configuration for "
2529 <<
" in this basis/ECP; atomic SCF uses aufbau occupation"
2533 auto Occupy = [&](
const Radial&
F,
bool alpha) {
2534 if (fixed_occupation) {
2535 return sph.Density(
F, S_red, alpha ? occ_alpha : occ_beta);
2539 sph.AufbauOccupation(
F, S_red,
double(alpha ? alpha_e : beta_e)));
2542 auto Flatten = [&](
const State& st, Eigen::VectorXd& fock,
2543 Eigen::VectorXd& error) {
2545 for (
Index g = 0; g < ngroups; ++g) {
2546 total += 2 * st.Fa[g].size();
2549 error.resize(total);
2551 for (
Index spin = 0; spin < 2; ++spin) {
2552 const Radial&
F = (spin == 0) ? st.Fa : st.Fb;
2553 const Radial&
D = (spin == 0) ? st.Da : st.Db;
2554 for (
Index g = 0; g < ngroups; ++g) {
2555 const Eigen::MatrixXd fds =
F[g] *
D[g] * S_red[g];
2556 const Eigen::MatrixXd err =
2557 X_red[g] * (fds - fds.transpose()) * X_red[g];
2558 const Index size =
F[g].size();
2559 fock.segment(pos, size) =
2560 Eigen::Map<const Eigen::VectorXd>(
F[g].data(), size);
2561 error.segment(pos, size) =
2562 Eigen::Map<const Eigen::VectorXd>(err.data(), size);
2567 auto Unflatten = [&](
const Eigen::VectorXd& fock, Radial& Fa, Radial& Fb) {
2569 for (
Index spin = 0; spin < 2; ++spin) {
2570 Radial&
F = (spin == 0) ? Fa : Fb;
2571 for (
Index g = 0; g < ngroups; ++g) {
2572 const Index rows = S_red[g].rows();
2573 F[g] = Eigen::Map<const Eigen::MatrixXd>(fock.data() + pos, rows, rows);
2583 State cur = Build(Occupy(H0_red,
true), Occupy(H0_red,
false));
2585 const Index maxiter = 100;
2589 const double error_tolerance = std::max(
conv_opt_.error_converged, 1
e-6);
2590 const double energy_tolerance = std::max(
conv_opt_.Econverged, 1
e-8);
2591 double energy_old = cur.energy;
2592 bool converged =
false;
2593 Index this_iter = 0;
2594 for (; this_iter < maxiter; this_iter++) {
2595 Eigen::VectorXd fock;
2596 Eigen::VectorXd error;
2597 Flatten(cur, fock, error);
2598 const double max_error = error.cwiseAbs().maxCoeff();
2600 <<
TimeStamp() <<
" Iter " << this_iter <<
" of " << maxiter <<
" Etot "
2601 << std::setprecision(12) << cur.energy <<
" error " << max_error
2603 if (this_iter > 0 && max_error < error_tolerance &&
2604 std::abs(cur.energy - energy_old) < energy_tolerance) {
2608 energy_old = cur.energy;
2611 Unflatten(diis.Extrapolate(fock, error), Fa, Fb);
2612 cur = Build(Occupy(Fa,
true), Occupy(Fb,
false));
2616 <<
TimeStamp() <<
" Converged after " << this_iter + 1
2617 <<
" iterations, Etot=" << std::setprecision(12) << cur.energy
2621 <<
TimeStamp() <<
" Not converged after " << maxiter
2622 <<
" iterations. Unconverged density." << std::flush;
2624 const Radial& Da = cur.Da;
2625 const Radial& Db = cur.Db;
2627 const Eigen::MatrixXd density = sph.Expand(Da) + sph.Expand(Db);
2630 <<
" gives N=" << std::setprecision(9)
2631 << density.cwiseProduct(dftAOoverlap.
Matrix()).sum() <<
" electrons."
2640 <<
TimeStamp() <<
" Scanning molecule of size " << mol.
size()
2641 <<
" for unique elements" << std::flush;
2643 for (
auto element : elements) {
2644 uniqueelements.
push_back(
QMAtom(0, element, Eigen::Vector3d::Zero()));
2648 <<
" unique elements found" << std::flush;
2649 std::vector<Eigen::MatrixXd> uniqueatom_guesses;
2650 for (
QMAtom& unique_atom : uniqueelements) {
2652 <<
TimeStamp() <<
" Calculating atom density for "
2653 << unique_atom.getElement() << std::flush;
2655 uniqueatom_guesses.push_back(dmat_unrestricted);
2658 Eigen::MatrixXd guess =
2661 for (
const QMAtom& atom : mol) {
2663 for (; index < uniqueelements.
size(); index++) {
2664 if (atom.getElement() == uniqueelements[index].getElement()) {
2668 Eigen::MatrixXd& dmat_unrestricted = uniqueatom_guesses[index];
2669 guess.block(start, start, dmat_unrestricted.rows(),
2670 dmat_unrestricted.cols()) = dmat_unrestricted;
2671 start += dmat_unrestricted.rows();
2677std::map<std::string, Eigen::MatrixXd>
2681 <<
TimeStamp() <<
" Scanning molecule of size " << mol.
size()
2682 <<
" for unique elements (Hirshfeld reference densities)" << std::flush;
2684 std::map<std::string, Eigen::MatrixXd> reference_densities;
2685 for (
const std::string& element : elements) {
2686 QMAtom unique_atom(0, element, Eigen::Vector3d::Zero());
2688 <<
TimeStamp() <<
" Calculating Hirshfeld reference density for "
2689 << element << std::flush;
2694 return reference_densities;
2702 const Eigen::MatrixXd& alpha_new,
const Eigen::MatrixXd& beta_new) {
2706 constexpr double kIntegralError = 1
e-8;
2708 std::array<Eigen::MatrixXd, 2> both_alpha_new =
2709 CalcERIs_EXX(Eigen::MatrixXd::Zero(0, 0), alpha_new, kIntegralError);
2710 std::array<Eigen::MatrixXd, 2> both_beta_new =
2711 CalcERIs_EXX(Eigen::MatrixXd::Zero(0, 0), beta_new, kIntegralError);
2712 Eigen::MatrixXd J_new = both_alpha_new[0] + both_beta_new[0];
2716 Eigen::MatrixXd J_new =
CalcERIs(alpha_new + beta_new, kIntegralError);
2717 H_new.
alpha += J_new;
2718 H_new.
beta += J_new;
2720 auto vxc_new = [&]() {
2724 H_new.
alpha += vxc_new.vxc_alpha;
2725 H_new.
beta += vxc_new.vxc_beta;
2727 H_new.
alpha += (c.lambda * c.spin_alpha_coefficient) * c.weight_matrix;
2728 H_new.
beta += (c.lambda * c.spin_beta_coefficient) * c.weight_matrix;
2740 const Eigen::MatrixXd&
F,
2741 const Eigen::MatrixXd& X) {
2744 const Index nvirt = C.cols() - nocc;
2745 const Eigen::MatrixXd C_occ = C.leftCols(nocc);
2746 const Eigen::MatrixXd C_virt = C.rightCols(nvirt);
2747 const Eigen::MatrixXd F_oo = C_occ.transpose() *
F * C_occ;
2748 const Eigen::MatrixXd F_vv = C_virt.transpose() *
F * C_virt;
2749 const Eigen::MatrixXd P0 = 2.0 * C_occ * C_occ.transpose();
2751 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
2752 std::vector<Eigen::MatrixXd> U;
2753 for (
Index k = 0; k < X.cols(); ++k) {
2754 const Eigen::VectorXd x = X.col(k);
2755 U.push_back(Eigen::Map<const RowMajor>(x.data(), nocc, nvirt).transpose());
2757 const std::vector<Eigen::MatrixXd>
G =
2759 Eigen::MatrixXd HX(X.rows(), X.cols());
2760 for (
Index k = 0; k < X.cols(); ++k) {
2761 const RowMajor R = 4.0 * (F_vv * U[std::size_t(k)] -
2762 U[std::size_t(k)] * F_oo +
G[std::size_t(k)])
2764 HX.col(k) = Eigen::Map<const Eigen::VectorXd>(R.data(), R.size());
2779 const Eigen::MatrixXd& F_beta,
const Eigen::MatrixXd& X) {
2781 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
2785 Eigen::MatrixXd C_occ;
2786 Eigen::MatrixXd C_virt;
2787 Eigen::MatrixXd F_oo;
2788 Eigen::MatrixXd F_vv;
2796 c.nvirt = C.cols() - nocc;
2797 c.C_occ = C.leftCols(nocc);
2798 c.C_virt = C.rightCols(c.nvirt);
2799 c.F_oo = c.C_occ.transpose() *
F * c.C_occ;
2800 c.F_vv = c.C_virt.transpose() *
F * c.C_virt;
2801 c.P = c.C_occ * c.C_occ.transpose();
2804 const std::array<Channel, 2> ch = {
2807 const std::array<Index, 2> offset = {0, ch[0].nocc * ch[0].nvirt};
2809 const Index ncols = X.cols();
2810 std::vector<std::array<Eigen::MatrixXd, 2>> U(
2811 static_cast<std::size_t
>(ncols));
2812 std::vector<std::array<Eigen::MatrixXd, 2>> dP(
2813 static_cast<std::size_t
>(ncols));
2814 for (
Index k = 0; k < ncols; ++k) {
2815 for (std::size_t s = 0; s < 2; ++s) {
2816 const Channel& c = ch[s];
2817 const Eigen::VectorXd x = X.col(k).segment(offset[s], c.nocc * c.nvirt);
2818 U[std::size_t(k)][s] =
2819 Eigen::Map<const RowMajor>(x.data(), c.nocc, c.nvirt).transpose();
2820 const Eigen::MatrixXd half =
2821 c.C_virt * U[std::size_t(k)][s] * c.C_occ.transpose();
2822 dP[std::size_t(k)][s] = half + half.transpose();
2825 std::vector<std::array<Eigen::MatrixXd, 2>>
G;
2827 auto t =
timings_.Measure(
"second order: f_xc (spin)");
2830 Eigen::MatrixXd HX(X.rows(), ncols);
2831 for (
Index k = 0; k < ncols; ++k) {
2832 std::array<Eigen::MatrixXd, 2>& g =
G[std::size_t(k)];
2833 const std::array<Eigen::MatrixXd, 2>& d = dP[std::size_t(k)];
2836 auto t =
timings_.Measure(
"second order: J (RI)");
2837 const Eigen::MatrixXd J =
ERIs_.CalculateERIs_3c(d[0] + d[1]);
2842 auto t =
timings_.Measure(
"second order: K (RI)");
2843 for (std::size_t s = 0; s < 2; ++s) {
2845 const Eigen::MatrixXd A = ch[s].C_virt * U[std::size_t(k)][s];
2847 ERIs_.CalculateEXX_factors(A + ch[s].C_occ, A - ch[s].C_occ);
2851 auto t =
timings_.Measure(
"second order: J+K (4c)");
2852 const std::array<Eigen::MatrixXd, 2> jk_a =
2853 ERIs_.CalculateERIs_EXX_4c(d[0], 1
e-12);
2854 const std::array<Eigen::MatrixXd, 2> jk_b =
2855 ERIs_.CalculateERIs_EXX_4c(d[1], 1
e-12);
2856 g[0] += jk_a[0] + jk_b[0];
2857 g[1] += jk_a[0] + jk_b[0];
2863 for (std::size_t s = 0; s < 2; ++s) {
2864 const Channel& c = ch[s];
2865 const Eigen::MatrixXd& u = U[std::size_t(k)][s];
2866 const RowMajor R = 2.0 * (c.F_vv * u - u * c.F_oo +
2867 c.C_virt.transpose() * g[s] * c.C_occ)
2869 HX.col(k).segment(offset[s], c.nocc * c.nvirt) =
2870 Eigen::Map<const Eigen::VectorXd>(R.data(), R.size());
2878 const Eigen::MatrixXd& C_occ,
const Eigen::MatrixXd& C_virt,
2879 const std::vector<Eigen::MatrixXd>& U,
2881 auto density = [&](
const Eigen::MatrixXd& u) {
2882 const Eigen::MatrixXd half = (C_virt * u) * C_occ.transpose();
2883 return Eigen::MatrixXd(2.0 * (half + half.transpose()));
2885 std::vector<Eigen::MatrixXd> dP;
2886 for (
const Eigen::MatrixXd& u : U) {
2887 dP.push_back(density(u));
2889 std::vector<Eigen::MatrixXd>
G;
2891 auto t =
timings_.Measure(
"response: f_xc");
2892 G = (fxc_kernel !=
nullptr) ? vxc.
ApplyFXC(*fxc_kernel, dP)
2895 std::vector<Eigen::MatrixXd> result;
2896 for (std::size_t k = 0; k < U.size(); ++k) {
2899 auto t =
timings_.Measure(
"response: J (RI)");
2900 G[k] +=
ERIs_.CalculateERIs_3c(dP[k]);
2903 auto t =
timings_.Measure(
"response: K (RI)");
2904 const Eigen::MatrixXd A = C_virt * U[k];
2906 0.5 *
ScaHFX_ *
ERIs_.CalculateEXX_factors(A + C_occ, A - C_occ);
2909 auto t =
timings_.Measure(
"response: J+K (4c)");
2910 const std::array<Eigen::MatrixXd, 2> jk =
2911 ERIs_.CalculateERIs_EXX_4c(dP[k], 1
e-12);
2917 result.push_back(C_virt.transpose() *
G[k] * C_occ);
2923 const Orbitals& orb,
const std::vector<Eigen::MatrixXd>& perturbations,
2924 double tolerance,
Index max_iterations) {
2929 throw std::runtime_error(
2930 "DFTEngine::StaticResponse: closed-shell ground states only");
2934 throw std::runtime_error(
2935 "DFTEngine::StaticResponse: the orbitals do not belong to this basis");
2941 const Index n_virt = n_mo - n_occ;
2942 const Eigen::MatrixXd C_occ = orb.
MOs().
eigenvectors().leftCols(n_occ);
2943 const Eigen::MatrixXd C_virt = orb.
MOs().
eigenvectors().rightCols(n_virt);
2946 Eigen::MatrixXd diag(n_virt, n_occ);
2947 for (
Index i = 0; i < n_occ; ++i) {
2948 diag.col(i) =
e.tail(n_virt).array() -
e(i);
2950 if (diag.minCoeff() <= 0.0) {
2951 throw std::runtime_error(
2952 "DFTEngine::StaticResponse: no gap between occupied and virtual "
2955 const Eigen::MatrixXd P0 = 2.0 * C_occ * C_occ.transpose();
2957 const Index n_rhs =
Index(perturbations.size());
2958 std::vector<Eigen::MatrixXd> b(
static_cast<std::size_t
>(n_rhs));
2959 for (
Index k = 0; k < n_rhs; ++k) {
2960 const Eigen::MatrixXd& h = perturbations[std::size_t(k)];
2961 if (h.rows() != n_ao || h.cols() != n_ao) {
2962 throw std::runtime_error(
2963 "DFTEngine::StaticResponse: perturbation does not match the basis");
2965 b[std::size_t(k)] = -(C_virt.transpose() * h * C_occ);
2968 auto density = [&](
const Eigen::MatrixXd& U) {
2969 const Eigen::MatrixXd half = (C_virt * U) * C_occ.transpose();
2970 return Eigen::MatrixXd(2.0 * (half + half.transpose()));
2976 auto t =
timings_.Measure(
"response: f_xc kernel");
2979 auto apply = [&](
const std::vector<Eigen::MatrixXd>& U) {
2980 std::vector<Eigen::MatrixXd> result =
2982 for (std::size_t k = 0; k < U.size(); ++k) {
2983 result[k] += diag.cwiseProduct(U[k]);
2992 const double kDropNorm = 1
e-10;
2993 std::vector<Eigen::MatrixXd>
V;
2994 std::vector<Eigen::MatrixXd> AV;
2995 std::vector<Eigen::MatrixXd> x(
static_cast<std::size_t
>(n_rhs));
2996 std::vector<Eigen::MatrixXd> r(
static_cast<std::size_t
>(n_rhs));
2997 std::vector<double> bnorm(
static_cast<std::size_t
>(n_rhs), 0.0);
2998 std::vector<Index> active;
2999 for (
Index k = 0; k < n_rhs; ++k) {
3000 const std::size_t kk = std::size_t(k);
3001 bnorm[kk] = b[kk].norm();
3002 x[kk] = Eigen::MatrixXd::Zero(n_virt, n_occ);
3004 if (bnorm[kk] > 0.0) {
3005 active.push_back(k);
3008 Index iteration = 0;
3009 while (!active.empty()) {
3010 if (iteration == max_iterations) {
3011 throw std::runtime_error(
3012 "DFTEngine::StaticResponse: CPKS did not converge in " +
3013 std::to_string(max_iterations) +
" iterations");
3018 std::vector<Eigen::MatrixXd> fresh;
3019 for (
Index k : active) {
3020 Eigen::MatrixXd v = r[std::size_t(k)].cwiseQuotient(diag);
3021 const double norm0 = v.norm();
3022 for (
Index pass = 0; pass < 2; ++pass) {
3023 for (
const Eigen::MatrixXd& u :
V) {
3024 v -= u.cwiseProduct(v).sum() * u;
3026 for (
const Eigen::MatrixXd& u : fresh) {
3027 v -= u.cwiseProduct(v).sum() * u;
3030 const double norm = v.norm();
3031 if (norm > kDropNorm * norm0) {
3032 fresh.push_back(v / norm);
3035 if (fresh.empty()) {
3036 throw std::runtime_error(
3037 "DFTEngine::StaticResponse: CPKS subspace stopped growing");
3039 const std::vector<Eigen::MatrixXd> Afresh = apply(fresh);
3040 V.insert(
V.end(), fresh.begin(), fresh.end());
3041 AV.insert(AV.end(), Afresh.begin(), Afresh.end());
3043 Eigen::MatrixXd M(m, m);
3044 for (
Index i = 0; i < m; ++i) {
3045 for (
Index j = 0; j <= i; ++j) {
3047 0.5 * (
V[std::size_t(i)].cwiseProduct(AV[std::size_t(j)]).sum() +
3048 V[std::size_t(j)].cwiseProduct(AV[std::size_t(i)]).sum());
3052 const Eigen::LDLT<Eigen::MatrixXd> solver(M);
3053 std::vector<Index> still;
3055 for (
Index k : active) {
3056 const std::size_t kk = std::size_t(k);
3057 Eigen::VectorXd proj(m);
3058 for (
Index i = 0; i < m; ++i) {
3059 proj(i) =
V[std::size_t(i)].cwiseProduct(b[kk]).sum();
3061 const Eigen::VectorXd y = solver.solve(proj);
3064 for (
Index i = 0; i < m; ++i) {
3065 x[kk] += y(i) *
V[std::size_t(i)];
3066 r[kk] -= y(i) * AV[std::size_t(i)];
3068 const double rel = r[kk].norm() / bnorm[kk];
3069 worst = std::max(worst, rel);
3070 if (rel >= tolerance) {
3075 <<
TimeStamp() <<
" CPKS iteration " << iteration <<
": "
3076 << fresh.size() <<
" new directions, subspace " << m
3077 <<
", largest relative residual " << worst << std::flush;
3081 std::vector<Eigen::MatrixXd> dP;
3082 for (
const Eigen::MatrixXd& u : x) {
3083 dP.push_back(density(u));
3097 std::map<std::string, Eigen::MatrixXd> reference_densities =
3104 full_dftbasis.
Fill(basisset, mol);
3110 std::vector<HirshfeldPartition::AtomicReference> atoms =
3112 reference_densities);
3117 double neutral_reference_population = 0.0;
3119 if (atom_index < 0 || atom_index >=
static_cast<Index>(mol.
size())) {
3120 throw std::runtime_error(
3121 "BuildCDFTConstraint: cdft.indices contains atom index " +
3122 std::to_string(atom_index) +
", but this molecule only has " +
3123 std::to_string(mol.
size()) +
3124 " atoms (0-based indexing -- valid range is 0.." +
3125 std::to_string(mol.
size() - 1) +
").");
3131 atoms, atom_index, full_dftbasis, grid);
3132 neutral_reference_population +=
3133 static_cast<double>(mol[atom_index].getNuccharge());
3144 <<
" atom(s), neutral reference population="
3145 << neutral_reference_population
3160 throw std::runtime_error(
3161 (boost::format(
"Basisset Name in guess orb file "
3162 "and in dftengine option file differ %1% vs %2%") %
3170 "Orbital file has no basisset information,"
3171 "using it as a guess might work or not for calculation with "
3196 throw std::runtime_error(
3197 (boost::format(
"ECPs in orb file: %1% and options %2% differ") %
3204 throw std::runtime_error(
3205 (boost::format(
"Number of electrons in guess orb file "
3206 "and in dftengine differ: "
3207 "alpha %1% vs %2%, beta %3% vs %4%.") %
3213 throw std::runtime_error(
3214 (boost::format(
"Number of levels in guess orb file: "
3215 "%1% and in dftengine: %2% differ.") %
3237 for (
const QMAtom& atom : mol) {
3239 std::string output = (boost::format(
" %1$s"
3240 " %2$+1.4f %3$+1.4f %4$+1.4f") %
3241 atom.getElement() % pos[0] % pos[1] % pos[2])
3252 <<
dftbasis_.AOBasisSize() <<
" functions" << std::flush;
3260 <<
auxbasis_.AOBasisSize() <<
" functions" << std::flush;
3268 std::vector<std::string> results =
ecp_.Fill(ecpbasisset, mol);
3270 <<
TimeStamp() <<
" Filled ECP Basis" << std::flush;
3271 if (results.size() > 0) {
3272 std::string message =
"";
3273 for (
const std::string& element : results) {
3274 message +=
" " + element;
3277 <<
TimeStamp() <<
" Found no ECPs for elements" << message
3288 Index nuclear_charge = 0;
3289 for (
const QMAtom& atom : mol) {
3290 nuclear_charge += atom.getNuccharge();
3296 if (multiplicity < 1) {
3297 throw std::runtime_error(
"Spin multiplicity must be >= 1.");
3300 if (numofelectrons >= 0) {
3306 Index spin_excess = multiplicity - 1;
3309 throw std::runtime_error(
"Computed a negative number of electrons.");
3313 throw std::runtime_error(
3314 "Spin multiplicity incompatible with total number of electrons.");
3318 throw std::runtime_error(
3319 "Charge and spin multiplicity imply non-integer alpha/beta "
3331 <<
" (charge=" << target_charge <<
", multiplicity=" << multiplicity
3355 <<
"\t\t " <<
" with " << grid.
getGridSize() <<
" points"
3356 <<
" divided into " << grid.
getBoxesSize() <<
" boxes" << std::flush;
3361 double E_nucnuc = 0.0;
3363 for (
Index i = 0; i < mol.
size(); i++) {
3364 const Eigen::Vector3d& r1 = mol[i].
getPos();
3365 double charge1 = double(mol[i].getNuccharge());
3366 for (
Index j = 0; j < i; j++) {
3367 const Eigen::Vector3d& r2 = mol[j].
getPos();
3368 double charge2 = double(mol[j].getNuccharge());
3369 E_nucnuc += charge1 * charge2 / (r1 - r2).norm();
3386 const Eigen::MatrixXd& dmat,
const AOBasis& dftbasis)
const {
3387 Eigen::MatrixXd avdmat = Eigen::MatrixXd::Zero(dmat.rows(), dmat.cols());
3388 for (
const AOShell& shellrow : dftbasis) {
3389 for (
const AOShell& shellcol : dftbasis) {
3390 if (shellrow.getL() != shellcol.getL()) {
3393 const Index size = shellrow.getNumFunc();
3394 const double diagavg = dmat.block(shellrow.getStartIndex(),
3395 shellcol.getStartIndex(), size, size)
3399 .block(shellrow.getStartIndex(), shellcol.getStartIndex(), size, size)
3401 .setConstant(diagavg);
3418 const std::vector<std::unique_ptr<StaticSite>>& multipoles)
const {
3420 if (multipoles.size() == 0) {
3426 for (
const QMAtom& atom : mol) {
3428 for (
const std::unique_ptr<StaticSite>& site : multipoles) {
3429 if ((site->getPos() - nucleus.
getPos()).norm() < 1
e-7) {
3431 <<
" External site sits on nucleus, "
3432 "interaction between them is ignored."
3446 if (
const PolarSite* p = AsChargeResponseSite(*site)) {
3449 const Eigen::Vector3d r = nucleus.
getPos() - p->getPos();
3451 E_ext += nucleus.
getCharge() * (p->Induced_Charge() * k.
B0 +
3452 k.
B1 * p->getInducedDipole().dot(r));
3454 Q.segment<3>(1) += site->getInducedDipole();
3456 Index rank = site->getRank();
3457 if (rank < 1 && Q.segment<3>(1).norm() > 1
e-12) {
3460 StaticSite effective(site->getId(), site->getElement(), site->getPos());
3474 Eigen::MatrixXd result =
3476 for (
Index i = 0; i < 3; i++) {
3484 const std::vector<std::unique_ptr<StaticSite>>& multipoles)
const {
3491 std::vector<AOGaussianSites::Source> gaussian;
3492 for (
const std::unique_ptr<StaticSite>& site : multipoles) {
3493 if (
const PolarSite* p = AsChargeResponseSite(*site)) {
3494 gaussian.push_back({p->getPos(), p->CRWidth(), p->Induced_Charge(),
3495 p->getInducedDipole()});
3498 if (!gaussian.empty()) {
3500 std::vector<std::unique_ptr<StaticSite>> point_sites;
3501 for (
const std::unique_ptr<StaticSite>& site : multipoles) {
3502 if (AsChargeResponseSite(*site) !=
nullptr) {
3507 point_sites.push_back(std::make_unique<PolarSite>(*p));
3509 point_sites.push_back(std::make_unique<StaticSite>(*site));
3521 <<
TimeStamp() <<
" Filled DFT external multipole potential matrix ("
3522 << gaussian.size() <<
" charge-response sites as Gaussians)"
3531 <<
TimeStamp() <<
" Filled DFT external multipole potential matrix"
3541 Eigen::MatrixXd sites(
Index(multipoles.size()), 13);
3542 for (
Index i = 0; i <
Index(multipoles.size()); ++i) {
3544 sites.block<1, 3>(i, 0) = site.
getPos().transpose();
3545 sites(i, 3) = double(site.
getRank());
3546 sites.block<1, 9>(i, 4) = site.
Q().transpose();
3551 setup_cache_->multipole_sites.rows() == sites.rows() &&
3556 <<
" Reusing the permanent multipole potential matrix of the previous "
3568 <<
TimeStamp() <<
" Filled DFT permanent multipole potential matrix"
3572 const bool has_induced =
3573 std::any_of(multipoles.begin(), multipoles.end(),
3574 [](
const std::unique_ptr<StaticSite>& site) {
3575 return site->getInducedDipole().norm() > 1e-12;
3582 <<
TimeStamp() <<
" Filled DFT induced dipole potential matrix"
3602 <<
TimeStamp() <<
" Calculated external density" << std::flush;
3605 <<
TimeStamp() <<
" Calculated potential from electron density"
3610 double nuc_energy = 0.0;
3611 for (
const QMAtom& atom : mol) {
3615 const double dist = (atom.getPos() - extatom.getPos()).norm();
3617 double(atom.getNuccharge()) * double(extatom.getNuccharge()) / dist;
3621 <<
TimeStamp() <<
" Calculated potential from nuclei" << std::flush;
3623 <<
TimeStamp() <<
" Electrostatic: " << nuc_energy << std::flush;
3628 const Eigen::MatrixXd& GuessMOs)
const {
3629 Eigen::MatrixXd nonortho =
3631 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(nonortho);
3632 Eigen::MatrixXd result = GuessMOs * es.operatorInverseSqrt();
3645 Eigen::VectorXd eps = Eigen::VectorXd::Zero(nao);
3649 int l =
static_cast<int>(shell.getL());
3650 Index start = shell.getStartIndex();
3651 Index nfunc = shell.getNumFunc();
3653 const QMAtom& atom = mol[shell.getAtomIndex()];
3654 const std::string& element = atom.
getElement();
3659 for (
Index i = 0; i < nfunc; ++i) {
3670 const Index nao =
S.rows();
3672 Eigen::MatrixXd
H = Eigen::MatrixXd::Zero(nao, nao);
3673 constexpr double K = 1.75;
3675 for (
Index mu = 0; mu < nao; ++mu) {
3676 H(mu, mu) = eps(mu);
3677 for (
Index nu = 0; nu < mu; ++nu) {
3678 double hij = K *
S(mu, nu) * 0.5 * (eps(mu) + eps(nu));
3690 <<
TimeStamp() <<
" Building Extended Huckel guess" << std::flush;
3695 <<
TimeStamp() <<
" Solving EHT generalized eigenproblem" << std::flush;
3713 std::array<Eigen::MatrixXd, 2> both =
3738 if (nA + nB != dimer_mol.
size()) {
3739 throw std::runtime_error(
3740 "BuildDimerGuessFromMonomerFiles: monomer A (" + std::to_string(nA) +
3741 " atoms) + monomer B (" + std::to_string(nB) +
3742 " atoms) does not equal this calculation's molecule (" +
3743 std::to_string(dimer_mol.
size()) +
3744 " atoms): wrong monomer file(s), or the molecule is not the "
3745 "concatenation of the two monomers.");
3747 for (
Index i = 0; i < nA; ++i) {
3748 if (atomsA[i].getElement() != dimer_mol[i].getElement()) {
3749 throw std::runtime_error(
3750 "BuildDimerGuessFromMonomerFiles: monomer A atom " +
3751 std::to_string(i) +
" (" + atomsA[i].getElement() +
3752 ") does not match this calculation's atom " + std::to_string(i) +
3753 " (" + dimer_mol[i].getElement() +
3754 "); dimer_guess requires monomer A to be the first N_A atoms of "
3755 "the molecule, in the same order.");
3758 for (
Index i = 0; i < nB; ++i) {
3759 if (atomsB[i].getElement() != dimer_mol[nA + i].getElement()) {
3760 throw std::runtime_error(
3761 "BuildDimerGuessFromMonomerFiles: monomer B atom " +
3762 std::to_string(i) +
" (" + atomsB[i].getElement() +
3763 ") does not match this calculation's atom " + std::to_string(nA + i) +
3764 " (" + dimer_mol[nA + i].getElement() +
3765 "); dimer_guess requires monomer B to be the remaining atoms of "
3766 "the molecule (after monomer A), in the same order.");
3772 constexpr double kGeometryToleranceBohr = 1
e-3;
3773 auto CheckInternalGeometry = [&](
const QMMolecule& monomer_atoms,
3774 Index offset_in_dimer,
3775 const std::string& label) {
3777 for (
Index i = 0; i < n; ++i) {
3778 for (
Index j = i + 1; j < n; ++j) {
3779 double monomer_distance =
3780 (monomer_atoms[i].
getPos() - monomer_atoms[j].getPos()).norm();
3781 double dimer_distance = (dimer_mol[offset_in_dimer + i].
getPos() -
3782 dimer_mol[offset_in_dimer + j].getPos())
3784 double diff = std::abs(monomer_distance - dimer_distance);
3785 if (diff > kGeometryToleranceBohr) {
3786 throw std::runtime_error(
3787 "BuildDimerGuessFromMonomerFiles: " + label +
3788 "'s internal geometry does not match this calculation's "
3789 "molecule: distance between its atoms " +
3790 std::to_string(i) +
" and " + std::to_string(j) +
" is " +
3791 std::to_string(monomer_distance) +
3792 " Bohr in the monomer file, but " +
3793 std::to_string(dimer_distance) +
3794 " Bohr in this calculation's molecule (difference " +
3795 std::to_string(diff) +
" Bohr, tolerance " +
3796 std::to_string(kGeometryToleranceBohr) +
" Bohr).");
3801 CheckInternalGeometry(atomsA, 0,
"Monomer A");
3802 CheckInternalGeometry(atomsB, nA,
"Monomer B");
3806 auto MaxDeviationFromTranslation = [&](
const QMMolecule& monomer_atoms,
3807 Index offset_in_dimer) {
3808 Eigen::Vector3d shift =
3809 dimer_mol[offset_in_dimer].
getPos() - monomer_atoms[0].
getPos();
3810 double max_dev = 0.0;
3811 for (
Index i = 0; i < monomer_atoms.
size(); ++i) {
3812 double dev = (dimer_mol[offset_in_dimer + i].
getPos() -
3813 monomer_atoms[i].getPos() - shift)
3815 max_dev = std::max(max_dev, dev);
3819 auto WarnIfRotated = [&](
const QMMolecule& monomer_atoms,
3820 Index offset_in_dimer,
const std::string& label) {
3821 double dev = MaxDeviationFromTranslation(monomer_atoms, offset_in_dimer);
3822 if (dev > kGeometryToleranceBohr) {
3825 <<
" is rotated with respect to its .orb file (max deviation " << dev
3826 <<
" bohr after translation). Its MO coefficients are not "
3827 "rotated, so the dimer guess will be poor."
3831 WarnIfRotated(atomsA, 0,
"Monomer A");
3832 WarnIfRotated(atomsB, nA,
"Monomer B");
3837 dimer_guess.
QMAtoms() = dimer_mol;
Container to hold Basisfunctions for all atoms.
Index AOBasisSize() const
void Fill(const BasisSet &bs, const QMMolecule &atoms)
void setCenter(const Eigen::Vector3d &r)
const std::array< Eigen::MatrixXd, 3 > & Matrix() const
void Fill(const AOBasis &aobasis) final
void FillPotential(const AOBasis &aobasis, const ECPAOBasis &ecp)
static Eigen::MatrixXd Potential(const AOBasis &basis, const std::vector< Source > &sources)
void Fill(const AOBasis &aobasis) final
const Eigen::MatrixXd & Matrix() const
void FillPotential(const AOBasis &aobasis, const QMMolecule &atoms)
@ Permanent
permanent moments only (charge, dipole, quadrupole)
@ Induced
induced dipoles only; sites without one are skipped
void Fill(const AOBasis &aobasis) final
const Eigen::MatrixXd & Matrix() const
const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix() const
void push_back(const T &atom)
std::vector< std::string > FindUniqueElements() const
const Eigen::Vector3d & getPos() const
void Load(const std::string &name)
Eigen::MatrixXd CalcERIs(const Eigen::MatrixXd &Dmat, double error) const
Build the Coulomb matrix contribution from the current density matrix.
Eigen::MatrixXd ComputeOverlapPulayGradientUKS(const QMMolecule &mol, const tools::EigenSystem &MOs_alpha, const tools::EigenSystem &MOs_beta) const
ActiveRegion::Options active_growth_
std::string auxbasis_name_
Index num_alpha_electrons_
tools::EigenSystem ModelPotentialGuess(const Mat_p_Energy &H0, const QMMolecule &mol, const Vxc_Potential< Vxc_Grid > &vxcpotential) const
Mat_p_Energy IntegrateExternalMultipoles(const QMMolecule &mol, const std::vector< std::unique_ptr< StaticSite > > &multipoles) const
tools::EigenSystem IndependentElectronGuess(const Mat_p_Energy &H0) const
Generate an initial guess by diagonalizing the core Hamiltonian only.
void setSCFToleranceFloor(double energy, double error)
Index num_beta_electrons_
Orbitals BuildDimerGuessFromMonomerFiles(const QMMolecule &dimer_mol) const
void ComputePolarizability(Orbitals &orb)
double cdft_population_tolerance_
Eigen::MatrixXd ext_potential_matrix_
void ComputeAndStoreForces(Orbitals &orb, const Eigen::MatrixXd &Dmat, const Vxc_Potential< Vxc_Grid > &vxcpotential) const
bool EvaluateClosedShell(Orbitals &orb, const Mat_p_Energy &H0, const Vxc_Potential< Vxc_Grid > &vxcpotential)
Run the restricted closed-shell SCF loop and store the converged result.
void PrintMOsUKS(const Eigen::VectorXd &alpha_energies, const Eigen::VectorXd &beta_energies, Log::Level level) const
Print separate alpha and beta orbital energies for a UKS calculation.
void ReportDimensionsAndMemory() const
Basis dimensions and the memory of the large intermediates.
std::string dftbasis_name_
DFTSetupCache * setup_cache_
bool EvaluateUKS(Orbitals &orb, const Mat_p_Energy &H0, const Vxc_Potential< Vxc_Grid > &vxcpotential)
double truncation_threshold_
Eigen::MatrixXd RunAtomicDFT_unrestricted(const QMAtom &uniqueAtom, bool use_hunds_rule_occupation=false) const
Mat_p_Energy IntegrateExternalDensity(const QMMolecule &mol, const Orbitals &extdensity) const
std::vector< Eigen::MatrixXd > CoupledResponse(const Vxc_Potential< Vxc_Grid > &vxc, const Eigen::MatrixXd &P0, const Eigen::MatrixXd &C_occ, const Eigen::MatrixXd &C_virt, const std::vector< Eigen::MatrixXd > &U, const Vxc_Potential< Vxc_Grid >::FXCKernel *fxc_kernel=nullptr)
bool compute_polarizability_
void Prepare(Orbitals &orb, Index numofelectrons=-1)
Vxc_Grid external_ewaldgrid_
std::string initial_guess_
UKSConvergenceAcc::SpinFock BuildUKSFock(const Eigen::MatrixXd &H0, const Vxc_Potential< Vxc_Grid > &vxcpotential, const Eigen::MatrixXd &alpha_new, const Eigen::MatrixXd &beta_new)
Eigen::MatrixXd AtomicGuess(const QMMolecule &mol) const
Build an atomic-density based initial guess in the AO basis.
bool EvaluateAndTime(Orbitals &orb)
Evaluate() without the timing report.
std::vector< HirshfeldPartition::AtomicReference > HirshfeldReferences(const QMMolecule &mol) const
Eigen::MatrixXd BuildEHTHamiltonian(const QMMolecule &mol) const
Build the extended-Hückel Hamiltonian for the current molecule.
Eigen::MatrixXd IntegrateExternalField(const QMMolecule &mol) const
Integrate a homogeneous external electric field into the AO basis.
double ri_pair_threshold_
Eigen::Vector3d extfield_
double overlap_tolerance_
std::array< Eigen::MatrixXd, 2 > CalcERIs_EXX(const Eigen::MatrixXd &MOCoeff, const Eigen::MatrixXd &Dmat, double error) const
Eigen::MatrixXd UKSOrbitalHessian(const Vxc_Potential< Vxc_Grid > &vxc, const tools::EigenSystem &mos_alpha, const tools::EigenSystem &mos_beta, const Eigen::MatrixXd &F_alpha, const Eigen::MatrixXd &F_beta, const Eigen::MatrixXd &X)
HirshfeldPartition::Constraint BuildCDFTConstraint(const QMMolecule &mol, const CDFTConstraintSpec &spec) const
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
std::string xc_functional_name_
void CalcElDipole(const Orbitals &orb) const
Evaluate and print the electronic dipole moment from the final density.
double ExternalRepulsion(const QMMolecule &mol, const std::vector< std::unique_ptr< StaticSite > > &multipoles) const
ConvergenceAcc::options conv_opt_
void SetupInvariantMatrices()
Precompute AO matrices that remain unchanged throughout the SCF procedure.
tools::EigenSystem ExtendedHuckelDFTGuess(const Mat_p_Energy &H0, const QMMolecule &mol, const Vxc_Potential< Vxc_Grid > &vxcpotential) const
std::map< std::string, Eigen::MatrixXd > ComputeHirshfeldReferenceDensities(const QMMolecule &mol) const
Index max_cdft_iterations_
std::string active_atoms_as_string_
void ComputeAndStoreForcesUKS(Orbitals &orb, const UKSConvergenceAcc::SpinDensity &Dspin, const tools::EigenSystem &MOs_alpha, const tools::EigenSystem &MOs_beta, const Vxc_Potential< Vxc_Grid > &vxcpotential) const
double ewald_nuclear_energy_
void ConfigOrbfile(Orbitals &orb)
Propagate basis-set, XC, and metadata settings into the orbital container.
Eigen::VectorXd BuildEHTOrbitalEnergies(const QMMolecule &mol) const
Build orbital energies used in the extended-Hückel starting guess.
bool integrate_ext_density_
std::vector< Eigen::MatrixXd > StaticResponse(const Orbitals &orb, const std::vector< Eigen::MatrixXd > &perturbations, double tolerance=1e-7, Index max_iterations=100)
std::vector< HirshfeldPartition::Constraint > constraints_
bool UsableAsWarmStart(const Orbitals &orb, const std::string &previous_basis, std::string &reason) const
void PrintMOs(const Eigen::VectorXd &MOEnergies, Log::Level level)
Print a one-spin list of orbital energies and occupations to the logger.
Eigen::MatrixXd RKSOrbitalHessian(const Vxc_Potential< Vxc_Grid > &vxc, const tools::EigenSystem &mos, const Eigen::MatrixXd &F, const Eigen::MatrixXd &X)
Mat_p_Energy SetupH0(const QMMolecule &mol) const
Assemble the one-electron core Hamiltonian for the current molecule.
tools::EigenSystem ExtendedHuckelGuess(const QMMolecule &mol) const
Eigen::MatrixXd OrthogonalizeGuess(const Eigen::MatrixXd &GuessMOs) const
Orthonormalize an initial MO guess with respect to the AO overlap matrix.
Eigen::MatrixXd SphericalAverageShells(const Eigen::MatrixXd &dmat, const AOBasis &dftbasis) const
bool Evaluate(Orbitals &orb)
CDFTConstraintSpec cdft_constraint_spec_
Eigen::MatrixXd ComputeNonXCGradientUKS(const QMMolecule &mol, const UKSConvergenceAcc::SpinDensity &Dspin, const tools::EigenSystem &MOs_alpha, const tools::EigenSystem &MOs_beta) const
bool RunCDFT(Orbitals &orb, HirshfeldPartition::Constraint &constraint)
std::string dimer_guess_orbB_name_
std::vector< std::unique_ptr< StaticSite > > * externalsites_
Vxc_Potential< Vxc_Grid > SetupVxc(const QMMolecule &mol)
std::string RISetupKey() const
bool integrate_ext_field_
double NuclearRepulsion(const QMMolecule &mol) const
Compute the classical nucleus-nucleus repulsion energy.
ConvergenceAcc conv_accelerator_
std::string dimer_guess_orbA_name_
static Eigen::MatrixXd RIKGradient(const Eigen::MatrixXd &occ_mo_coeffs, const AOBasis &auxbasis, const AOBasis &dftbasis)
static Eigen::MatrixXd NuclearRepulsionDerivative(const QMMolecule &mol)
static Eigen::MatrixXd RIJGradient(const Eigen::MatrixXd &density, const AOBasis &auxbasis, const AOBasis &dftbasis)
static double ResidentMemoryGB(bool peak)
double IntegratePotential(const Eigen::Vector3d &rvector) const
double IntegrateDensity(const Eigen::MatrixXd &density_matrix)
Container to hold ECPs for all atoms.
std::vector< std::string > Fill(const ECPBasisSet &bs, QMMolecule &atoms)
void Load(const std::string &name)
Takes a density matrix and and an auxiliary basis set and calculates the electron repulsion integrals...
std::array< Eigen::MatrixXd, 2 > CalculateERIs_EXX_4c(const Eigen::MatrixXd &DMAT, double error) const
void Initialize_4c(const AOBasis &dftbasis)
Eigen::MatrixXd CalculateERIs_4c(const Eigen::MatrixXd &DMAT, double error) const
Mat_p_Energy IntegrateEwald(Index basissize) const
double GetWithFallback(const std::string &element, int l, int *used_l=nullptr) const
std::vector< double > & getPotentialValues()
static std::vector< AtomicReference > BuildAtomicReferences(const QMMolecule &mol, const std::string &basisset_name, const std::map< std::string, Eigen::MatrixXd > &reference_densities)
static Eigen::MatrixXd BuildWeightMatrix(const std::vector< AtomicReference > &atoms, Index target_atom_index, const AOBasis &full_dftbasis, const Vxc_Grid &grid)
static Eigen::MatrixXd ComputeCDFTForceContribution(const std::vector< AtomicReference > &atoms, Index target_atom_index, const Eigen::MatrixXd &density_matrix, const QMMolecule &mol, const AOBasis &full_dftbasis, const Vxc_Grid &grid)
void UpdateDmats(const Eigen::MatrixXd &dmat, double DiisError, Index Iteration)
void Configure(const Eigen::MatrixXd &dmat)
void resetMatrices(Eigen::MatrixXd &J, Eigen::MatrixXd &K, const Eigen::MatrixXd &dmat)
void Start(Index iteration, double DiisError)
void UpdateCriteria(double DiisError, Index Iteration)
const Eigen::MatrixXd & getDmat_diff() const
std::vector< Index > CreateIndexVector(const std::string &Ids) const
Eigen::MatrixXd & matrix()
Container for molecular orbitals and derived one-particle data.
void setScaHFX(double ScaHFX)
Store the fraction of exact exchange associated with the functional.
Index getCharge() const
Return the stored total charge.
void clearPolarizability()
Index getSpin() const
Return the stored spin multiplicity.
bool hasForces() const
Report whether nuclear forces have been stored.
const tools::EigenSystem & MOs_beta() const
Return read-only access to beta-spin molecular orbitals.
bool hasMOs() const
Report whether alpha/restricted molecular orbitals are available.
std::array< Eigen::MatrixXd, 2 > DensityMatrixGroundStateSpinResolved() const
Index getNumberOfAlphaElectrons() const
Return the stored number of alpha electrons.
void setNumberOfAlphaElectrons(Index electrons)
Store the total number of alpha electrons.
Eigen::MatrixXd DensityMatrixFull(const QMState &state) const
void PrepareDimerGuessMixedSpin(const Orbitals &orbitalsA, const Orbitals &orbitalsB)
Dimer guess from two converged monomers of arbitrary charge and spin.
void SetupAuxBasis(std::string aux_basis_name)
void setNumberOfBetaElectrons(Index electrons)
Store the total number of beta electrons.
void setForces(const Eigen::MatrixXd &forces)
void setECPName(const std::string &ECP)
Store the effective core potential label.
void setXCGrid(std::string grid)
Store the numerical XC grid quality label.
void setNumberOfOccupiedLevels(Index occupied_levels)
Index getBasisSetSize() const
Return the number of AO basis functions in the DFT basis.
void setQMEnergy(double qmenergy)
Store the total DFT energy.
bool hasECPName() const
Report whether an effective core potential label has been stored.
const tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
const QMMolecule & QMAtoms() const
Return read-only access to the molecular geometry.
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
void setNumberOfOccupiedLevelsBeta(Index occupied_levels_beta)
Store the number of occupied beta-spin orbitals.
void setChargeAndSpin(Index charge, Index spin)
bool hasDFTbasisName() const
Report whether a DFT basis-set name has been stored.
const std::string & getECPName() const
Return the effective core potential label.
const std::string & getDFTbasisName() const
Return the DFT basis-set name.
bool hasBetaMOs() const
Report whether beta-spin molecular orbitals are available.
void SetupDftBasis(std::string basis_name)
Build and attach the DFT AO basis from the stored molecular geometry.
void setPolarizability(const Eigen::Matrix3d &alpha)
const Eigen::MatrixXd & getForces() const
Return the stored nuclear forces (Natoms x 3, Hartree/Bohr).
Eigen::Vector3d CalcElDipole(const QMState &state) const
Compute the electronic dipole moment associated with a state density.
Index getNumberOfBetaElectrons() const
Return the stored number of beta electrons.
const AOBasis & getDftBasis() const
Return the DFT AO basis, throwing if it has not been initialized.
void setXCFunctionalName(std::string functionalname)
Class to represent Atom/Site in electrostatic+polarization.
bool isChargeResponse() const
Index getElementNumber() const
const std::string & getElement() const
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Class to represent Atom/Site in electrostatic.
void setMultipole(const Vector9d &multipole, Index rank)
const Eigen::Vector3d & getPos() const
const Vector9d & Q() const
Timestamp returns the current time as a string Example: cout << TimeStamp().
SpinDensity DensityMatrix(const tools::EigenSystem &MOs_alpha, const tools::EigenSystem &MOs_beta) const
void setOverlap(AOOverlap &S, double etol)
void setLogger(Logger *log)
void Configure(const options &opt_alpha, const options &opt_beta)
SpinDensity Iterate(const SpinDensity &dmat, SpinFock &H, tools::EigenSystem &MOs_alpha, tools::EigenSystem &MOs_beta, double totE)
double getDIIsError() const
void setOrbitalHessian(const OrbitalHessian &hessian)
void setCoupledFockBuilder(const CoupledFockBuilder &builder)
Index getGridSize() const
void GridSetup(const std::string &type, const QMMolecule &atoms, const AOBasis &basis)
Index getBoxesSize() const
Eigen::MatrixXd GridWeightGradient(const Eigen::MatrixXd &density_matrix, const QMMolecule &atoms) const
Eigen::MatrixXd PulayGradient(const Eigen::MatrixXd &density_matrix, const AOBasis &dftbasis) const
FXCKernel PrepareFXC(const Eigen::MatrixXd &density_matrix) const
std::vector< Eigen::MatrixXd > ApplyFXC(const FXCKernel &kernel, const std::vector< Eigen::MatrixXd > &response_matrices) const
IntegrateFXC with a prepared kernel (the same results).
Eigen::MatrixXd PulayGradientUKS(const Eigen::MatrixXd &dmat_alpha, const Eigen::MatrixXd &dmat_beta, const AOBasis &dftbasis) const
Mat_p_Energy IntegrateVXC(const Eigen::MatrixXd &density_matrix) const
void setXCfunctional(const std::string &functional)
std::vector< std::array< Eigen::MatrixXd, 2 > > IntegrateFXCSpin(const Eigen::MatrixXd &dmat_alpha, const Eigen::MatrixXd &dmat_beta, const std::vector< std::array< Eigen::MatrixXd, 2 > > &response) const
static double getExactExchange(const std::string &functional)
std::vector< Eigen::MatrixXd > IntegrateFXC(const Eigen::MatrixXd &density_matrix, const std::vector< Eigen::MatrixXd > &response_matrices) const
Eigen::MatrixXd GridWeightGradientUKS(const Eigen::MatrixXd &dmat_alpha, const Eigen::MatrixXd &dmat_beta, const QMMolecule &atoms) const
SpinResult IntegrateVXCSpin(const Eigen::MatrixXd &dmat_alpha, const Eigen::MatrixXd &dmat_beta) const
Mediates interaction between polar and static sites.
double CalcStaticEnergy_site(const StaticSite &site1, const StaticSite &site2) const
#define XTP_LOG(level, log)
void Cite(const std::string &key)
marks a reference as used (thread safe; unknown keys are printed as such)
Charge transport classes.
std::vector< AOMatrixDerivative > ComputeNuclearAttractionDerivatives(const AOBasis &aobasis, const QMMolecule &mol)
std::vector< AOMatrixDerivative > ComputeKineticDerivatives(const AOBasis &aobasis)
std::vector< AOMatrixDerivative > ComputeOverlapDerivatives(const AOBasis &aobasis)
std::string EigenBackendDescription()
std::array< Eigen::MatrixXd, 3 > AOMatrixDerivative
bool HasLibint2DerivativeSupport()
Provides a means for comparing floating point numbers.
Spin-resolved density matrices returned for open-shell SCF updates.
Eigen::MatrixXd total() const
Return the total density P = P^alpha + P^beta.
std::vector< Index > atom_indices
Interaction of two normalized Gaussian charge distributions exp(-r^2/s_i^2) and exp(-r^2/s_j^2): erf(...
Eigen::MatrixXd weight_matrix
double spin_alpha_coefficient
double spin_beta_coefficient
Eigen::MatrixXd total() const
Eigen::MatrixXd vxc_alpha
Eigen::Matrix< double, 9, 1 > Vector9d