35#define LIBINT2_CONSTEXPR_STATICS 0
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-W#warnings"
39#elif defined(__GNUC__)
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Warray-bounds"
42#pragma GCC diagnostic ignored "-Wcpp"
45#include <libint2/statics_definition.h>
47#pragma clang diagnostic pop
48#elif defined(__GNUC__)
49#pragma GCC diagnostic pop
56 double threshold)
const {
63 std::vector<libint2::Engine> engines;
64 engines.reserve(nthreads);
66 for (
Index i = 1; i != nthreads; ++i) {
67 engines.push_back(engines[0]);
70 std::vector<std::vector<Index>> pairs(shells.size());
72#pragma omp parallel for schedule(dynamic)
73 for (
Index s1 = 0; s1 <
Index(shells.size()); ++s1) {
76 libint2::Engine& engine = engines[thread_id];
77 const libint2::Engine::target_ptr_vec& buf = engine.results();
78 Index n1 = shells[s1].size();
80 for (
Index s2 = 0; s2 <= s1; ++s2) {
81 bool on_same_center = (shells[s1].O == shells[s2].O);
82 bool significant = on_same_center;
83 if (!on_same_center) {
84 Index n2 = shells[s2].size();
85 engine.compute(shells[s1], shells[s2]);
86 Eigen::Map<const Eigen::MatrixXd> buf_mat(buf[0], n1, n2);
87 significant = (buf_mat.norm() >= threshold);
90 pairs[s1].push_back(s2);
93 std::sort(pairs[s1].
begin(), pairs[s1].
end());
99 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
101template <libint2::Operator obtype,
102 typename OperatorParams =
103 typename libint2::operator_traits<obtype>::oper_params_type>
104std::array<MatrixLibInt, libint2::operator_traits<obtype>::nopers>
106 OperatorParams oparams = OperatorParams()) {
113 Index nopers =
static_cast<Index>(libint2::operator_traits<obtype>::nopers);
114 std::array<MatrixLibInt, libint2::operator_traits<obtype>::nopers> result;
119 std::vector<libint2::Engine> engines(nthreads);
120 engines[0] = libint2::Engine(obtype, aobasis.
getMaxNprim(),
121 static_cast<int>(aobasis.
getMaxL()), 0);
122 engines[0].set_params(oparams);
123 for (
Index i = 1; i < nthreads; ++i) {
124 engines[i] = engines[0];
129#pragma omp parallel for schedule(dynamic)
132 libint2::Engine& engine = engines[thread_id];
133 const libint2::Engine::target_ptr_vec& buf = engine.results();
135 Index bf1 = shell2bf[s1];
136 Index n1 = shells[s1].size();
138 for (
Index s2 : shellpair_list[s1]) {
140 engine.compute(shells[s1], shells[s2]);
141 if (buf[0] ==
nullptr) {
144 Index bf2 = shell2bf[s2];
145 Index n2 = shells[s2].size();
146 for (
unsigned int op = 0; op != nopers; ++op) {
147 Eigen::Map<const MatrixLibInt> buf_mat(buf[op], n1, n2);
148 result[op].block(bf1, bf2, n1, n2) = buf_mat;
151 result[op].block(bf2, bf1, n2, n1) = buf_mat.transpose();
163 libint2::Shell::do_enforce_unit_normalization(
false);
168 Eigen::MatrixXd result =
171 std::vector<libint2::Engine> engines(nthreads);
172 engines[0] = libint2::Engine(
173 libint2::Operator::overlap,
176 for (
Index i = 1; i < nthreads; ++i) {
177 engines[i] = engines[0];
179#pragma omp parallel for schedule(dynamic)
180 for (
Index s1 = 0; s1 <
Index(sa.size()); ++s1) {
182 const libint2::Engine::target_ptr_vec& buf = engine.results();
184 for (
Index s2 = 0; s2 <
Index(sb.size()); ++s2) {
185 engine.compute(sa[s1], sb[s2]);
186 if (buf[0] ==
nullptr) {
190 Eigen::Map<const MatrixLibInt> m(buf[0], n1, n2);
191 result.block(ba[s1], bb[s2], n1, n2) = m;
212 libint2::Shell::do_enforce_unit_normalization(
false);
213 libint2::Operator obtype = libint2::Operator::overlap;
215 libint2::Engine engine(obtype, shell.
getSize(),
216 static_cast<int>(shell.
getL()), 0);
218 const libint2::Engine::target_ptr_vec& buf = engine.results();
221 engine.compute(s, s);
223 Eigen::Map<const MatrixLibInt> buf_mat(buf[0], shell.
getNumFunc(),
226 }
catch (
const libint2::Engine::lmax_exceeded& error) {
227 std::ostringstream oss;
228 oss <<
"\nA libint error occured:\n"
229 << error.what() <<
"\n"
230 <<
"\nYou requested a computation for a shell with angular momentum "
231 << error.lmax_requested()
232 <<
",\nbut your libint package only supports angular momenta upto "
233 << error.lmax_limit() - 1 <<
".\n"
234 <<
"\nTo fix this error you will need to reinstall libint with "
236 "for higher angular momenta. If you installed your own libint it\n"
237 "should be reconfigured and installed with the option "
238 "--with-max-am=<maxAngularMomentum>.\n"
239 "If you installed libint with your OS package manager, you will\n"
240 "need to setup you own libint installation with the \n"
241 "--with-max-am=<maxAngularMomentum> option set."
243 throw std::runtime_error(oss.str());
252 std::array<libint2::Shell::real_t, 3>>(
255 for (
Index i = 0; i < 3; i++) {
277 std::vector<libint2::Engine> engines(nthreads);
279 libint2::Engine(libint2::Operator::coulomb, aobasis.
getMaxNprim(),
280 static_cast<int>(aobasis.
getMaxL()), 0);
281 engines[0].set(libint2::BraKet::xs_xs);
282 for (
Index i = 1; i != nthreads; ++i) {
283 engines[i] = engines[0];
286#pragma omp parallel for schedule(dynamic)
289 const libint2::Engine::target_ptr_vec& buf = engine.results();
291 Index bf1 = shell2bf[s1];
292 Index n1 = shells[s1].size();
295 for (
Index s2 = 0; s2 <= s1; ++s2) {
297 engine.compute2<libint2::Operator::coulomb, libint2::BraKet::xs_xs, 0>(
298 shells[s1], libint2::Shell::unit(), shells[s2],
299 libint2::Shell::unit());
301 if (buf[0] ==
nullptr) {
304 Index bf2 = shell2bf[s2];
305 Index n2 = shells[s2].size();
307 Eigen::Map<const MatrixLibInt> buf_mat(buf[0], n1, n2);
308 aomatrix_.block(bf1, bf2, n1, n2) = buf_mat;
311 aomatrix_.block(bf2, bf1, n2, n1) = buf_mat.transpose();
321 Eigen::MatrixXd result = Eigen::MatrixXd::Zero(noshells, noshells);
323 std::vector<libint2::Engine> engines(nthreads);
324 double epsilon = 0.0;
325 engines[0] = libint2::Engine(libint2::Operator::coulomb, basis.
getMaxNprim(),
326 static_cast<int>(basis.
getMaxL()), 0, epsilon);
328 for (
Index i = 1; i < nthreads; ++i) {
329 engines[i] = engines[0];
334#pragma omp parallel for schedule(dynamic)
337 libint2::Engine& engine = engines[thread_id];
338 const libint2::Engine::target_ptr_vec& buf = engine.results();
339 Index n1 = shells[s1].size();
341 for (
Index s2 = 0l; s2 <= s1; ++s2) {
342 Index n2 = shells[s2].size();
346 .compute2<libint2::Operator::coulomb, libint2::BraKet::xx_xx, 0>(
347 shells[s1], shells[s2], shells[s1], shells[s2]);
349 Eigen::Map<const MatrixLibInt> buf_mat(buf[0], n12, n12);
351 result(s2, s1) = std::sqrt(buf_mat.cwiseAbs().maxCoeff());
354 return result.selfadjointView<Eigen::Upper>();
357template <
bool with_exchange>
359 double error)
const {
361 "Please call Initialize_4c before running this");
364 Eigen::MatrixXd hartree = Eigen::MatrixXd::Zero(dmat.rows(), dmat.cols());
365 Eigen::MatrixXd exchange;
367 exchange = Eigen::MatrixXd::Zero(dmat.rows(), dmat.cols());
370 double fock_precision = error;
374 double engine_precision = std::min(fock_precision / dnorm_block.maxCoeff(),
375 std::numeric_limits<double>::epsilon()) /
377 std::vector<libint2::Engine> engines(nthreads);
378 engines[0] = libint2::Engine(libint2::Operator::coulomb,
int(
maxnprim_),
380 engines[0].set_precision(engine_precision);
384 for (
Index i = 1; i < nthreads; ++i) {
385 engines[i] = engines[0];
389#pragma omp parallel for schedule(dynamic) reduction(+ : hartree) \
390 reduction(+ : exchange)
391 for (
Index s1 = 0; s1 < nshells; ++s1) {
393 libint2::Engine& engine = engines[thread_id];
394 const auto& buf = engine.results();
396 const libint2::Shell& shell1 =
basis_[s1];
397 Index n1 = shell1.size();
402 const libint2::Shell& shell2 =
basis_[s2];
403 Index n2 = shell2.size();
404 double dnorm_12 = dnorm_block(s1, s2);
405 const libint2::ShellPair* sp12 = &(*sp12_iter);
408 for (
Index s3 = 0; s3 <= s1; ++s3) {
411 const libint2::Shell& shell3 =
basis_[s3];
412 Index n3 = shell3.size();
414 double dnorm_123 = std::max(dnorm_block(s1, s3),
415 std::max(dnorm_block(s2, s3), dnorm_12));
416 Index s4max = (s1 == s3) ? s2 : s3;
423 const libint2::ShellPair* sp34 = &(*sp34_iter);
427 std::max(dnorm_block(s1, s4),
428 std::max(dnorm_block(s2, s4),
429 std::max(dnorm_block(s3, s4), dnorm_123)));
436 const libint2::Shell& shell4 =
basis_[s4];
438 .compute2<libint2::Operator::coulomb, libint2::BraKet::xx_xx, 0>(
439 shell1, shell2, shell3, shell4, sp12, sp34);
440 const auto* buf_1234 = buf[0];
441 if (buf_1234 ==
nullptr) {
445 Index n4 = shell4.size();
446 Index s12_deg = (s1 == s2) ? 1 : 2;
447 Index s34_deg = (s3 == s4) ? 1 : 2;
448 Index s12_34_deg = (s1 == s3) ? (s2 == s4 ? 1 : 2) : 2;
449 Index s1234_deg = s12_deg * s34_deg * s12_34_deg;
451 for (
Index f1 = 0, f1234 = 0; f1 != n1; ++f1) {
452 const Index bf1 = f1 + start_1;
453 for (
Index f2 = 0; f2 != n2; ++f2) {
454 const Index bf2 = f2 + start_2;
455 for (
Index f3 = 0; f3 != n3; ++f3) {
456 const Index bf3 = f3 + start_3;
457 for (
Index f4 = 0; f4 != n4; ++f4, ++f1234) {
458 const Index bf4 = f4 + start_4;
460 const double value = buf_1234[f1234];
462 const double value_scal_by_deg = value * double(s1234_deg);
464 hartree(bf1, bf2) += dmat(bf3, bf4) * value_scal_by_deg;
465 hartree(bf3, bf4) += dmat(bf1, bf2) * value_scal_by_deg;
467 exchange(bf1, bf3) -= dmat(bf2, bf4) * value_scal_by_deg;
468 exchange(bf2, bf3) -= dmat(bf1, bf4) * value_scal_by_deg;
469 exchange(bf2, bf4) -= dmat(bf1, bf3) * value_scal_by_deg;
470 exchange(bf1, bf4) -= dmat(bf2, bf3) * value_scal_by_deg;
480 std::array<Eigen::MatrixXd, 2> result2;
482 result2[0] = 0.25 * (hartree + hartree.transpose());
485 result2[1] = 0.125 * (exchange + exchange.transpose());
491 const Eigen::MatrixXd& dmat,
double error)
const;
493 const Eigen::MatrixXd& dmat,
double error)
const;
496 const AOBasis& dftbasis,
const Eigen::MatrixXd& metric,
497 double pair_threshold)
const {
499 std::vector<std::vector<Index>> kept(nshells);
500 if (pair_threshold <= 0.0) {
501 for (
Index a = 0; a < nshells; ++a) {
502 kept[a].resize(a + 1);
503 std::iota(kept[a].begin(), kept[a].end(),
Index(0));
508 const double max_aux = std::sqrt(metric.diagonal().cwiseAbs().maxCoeff());
510 std::vector<libint2::Engine> engines(nthreads);
512 libint2::Engine(libint2::Operator::coulomb, dftbasis.
getMaxNprim(),
513 static_cast<int>(dftbasis.
getMaxL()), 0, 0.0);
514 for (
Index i = 1; i < nthreads; ++i) {
515 engines[i] = engines[0];
518#pragma omp parallel for schedule(dynamic)
519 for (
Index a = nshells - 1; a >= 0; --a) {
521 const libint2::Engine::target_ptr_vec& buf = engine.results();
522 for (
Index b = 0; b < a; ++b) {
523 engine.compute2<libint2::Operator::coulomb, libint2::BraKet::xx_xx, 0>(
524 shells[a], shells[b], shells[a], shells[b]);
525 if (buf[0] ==
nullptr) {
529 const double schwarz =
530 std::sqrt(Eigen::Map<const Eigen::MatrixXd>(buf[0], n, n)
533 if (max_aux * schwarz >= pair_threshold) {
534 kept[a].push_back(b);
537 kept[a].push_back(a);
543 double pair_threshold,
Index build_columns) {
544 std::vector<std::vector<Index>> kept;
546 auto metric_start = std::chrono::steady_clock::now();
548 auxAOcoulomb.
Fill(auxbasis);
552 std::chrono::steady_clock::now() - metric_start)
576 std::vector<Unit> units;
586 rows + na *
Index(dftshells[kept[a][last]].
size()) <=
588 rows += na *
Index(dftshells[kept[a][last]].
size());
591 max_rows = std::max(max_rows, rows);
592 units.push_back({a, first, last});
598 std::vector<libint2::Engine> engines(nthreads);
599 engines[0] = libint2::Engine(
600 libint2::Operator::coulomb,
602 static_cast<int>(std::max(dftbasis.
getMaxL(), auxbasis.
getMaxL())), 0);
603 engines[0].set(libint2::BraKet::xs_xx);
604 for (
Index i = 1; i < nthreads; ++i) {
605 engines[i] = engines[0];
611 const libint2::Engine::target_ptr_vec& buf = engine.results();
613 Eigen::MatrixXd raw(max_rows, naux);
614 Eigen::MatrixXd transformed(max_rows, naux);
615 std::vector<Index> row_start;
616 std::vector<Index> chunk_pos;
618#pragma omp for schedule(dynamic)
619 for (
Index u = 0; u <
Index(units.size()); ++u) {
620 const Unit& unit = units[u];
621 const libint2::Shell& shell_a = dftshells[unit.a];
623 const Index start_a = shell2bf[unit.a];
624 const bool has_diagonal = kept[unit.a][unit.last - 1] == unit.a;
627 chunk_pos.assign(1, 0);
628 for (
Index k = unit.first; k < unit.last; ++k) {
629 chunk_pos.push_back(chunk_pos.back() +
630 Index(dftshells[kept[unit.a][k]].size()));
632 const Index width = chunk_pos.back();
634 row_start.assign(1, 0);
635 for (
Index i = 0; i < na; ++i) {
636 const Index len = has_diagonal ? width - (na - i - 1) : width;
637 row_start.push_back(row_start.back() + len);
639 const Index rows = row_start.back();
640 raw.topRows(rows).setZero();
642 for (
Index aux = 0; aux <
Index(auxshells.size()); ++aux) {
643 const libint2::Shell& auxshell = auxshells[aux];
644 const Index aux_start = auxshell2bf[aux];
645 for (
Index k = unit.first; k < unit.last; ++k) {
646 const Index b = kept[unit.a][k];
647 const libint2::Shell& shell_b = dftshells[b];
649 .compute2<libint2::Operator::coulomb, libint2::BraKet::xs_xx, 0>(
650 auxshell, libint2::Shell::unit(), shell_a, shell_b);
651 if (buf[0] ==
nullptr) {
655 Eigen::Tensor<const double, 3, Eigen::RowMajor>
const>
656 result(buf[0], auxshell.size(), shell_a.size(), shell_b.size());
658 const Index pos = chunk_pos[k - unit.first];
659 for (
Index i = 0; i < na; ++i) {
661 const Index ncol = (b == unit.a) ? std::min(nb, i + 1) : nb;
662 for (
Index c = 0; c < ncol; ++c) {
663 for (
Index f = 0; f <
Index(auxshell.size()); ++f) {
664 raw(row_start[i] + pos + c, aux_start + f) = result(f, i, c);
672 transformed.topRows(rows).noalias() =
673 raw.topRows(rows) *
inv_sqrt_.transpose();
676 for (
Index k = 0; k < unit.first; ++k) {
677 before +=
Index(dftshells[kept[unit.a][k]].size());
679 for (
Index i = 0; i < na; ++i) {
680 const Index len = row_start[i + 1] - row_start[i];
682 transformed.middleRows(row_start[i], len);
695 libint2::Engine& engine) {
696 std::vector<Eigen::MatrixXd> ao3c = std::vector<Eigen::MatrixXd>(
703 const libint2::Engine::target_ptr_vec& buf = engine.results();
705 for (
Index row = 0; row <
Index(dftshells.size()); row++) {
707 const libint2::Shell& shell_row = dftshells[row];
708 const Index row_start = shell2bf[row];
711 for (
Index col = 0; col <= row; col++) {
712 const libint2::Shell& shell_col = dftshells[col];
713 const Index col_start = shell2bf[col];
715 engine.compute2<libint2::Operator::coulomb, libint2::BraKet::xs_xx, 0>(
716 auxshell, libint2::Shell::unit(), shell_col, shell_row);
718 if (buf[0] ==
nullptr) {
721 Eigen::TensorMap<Eigen::Tensor<const double, 3, Eigen::RowMajor>
const>
722 result(buf[0], auxshell.size(), shell_col.size(), shell_row.size());
724 for (
size_t aux_c = 0; aux_c < auxshell.size(); aux_c++) {
725 for (
size_t col_c = 0; col_c < shell_col.size(); col_c++) {
726 for (
size_t row_c = 0; row_c < shell_row.size(); row_c++) {
728 ao3c[aux_c](row_start + row_c, col_start + col_c) =
729 result(aux_c, col_c, row_c);
737 for (Eigen::MatrixXd& mat : ao3c) {
738 mat.triangularView<Eigen::Upper>() =
739 mat.triangularView<Eigen::Lower>().transpose();
751struct GaussianSiteShells {
756 GaussianSiteShells(
const Eigen::Vector3d& pos,
double width) {
757 const double beta = 1.0 / (width * width);
758 const std::array<double, 3> O = {pos.x(), pos.y(), pos.z()};
759 s = libint2::Shell{{beta}, {{0,
false, {1.0}}}, O};
760 p = libint2::Shell{{beta}, {{1,
false, {1.0}}}, O};
761 const double n_s = std::pow(2.0 * beta / M_PI, 0.75);
762 s_factor = 1.0 / (n_s * std::pow(M_PI / beta, 1.5));
763 const double n_p = n_s * 2.0 * std::sqrt(beta);
764 p_factor = 2.0 * beta * std::pow(beta / M_PI, 1.5) / n_p;
768std::vector<libint2::Engine> GaussianSiteEngines(
const AOBasis& basis) {
770 engines[0] = libint2::Engine(libint2::Operator::coulomb,
771 int(std::max<Index>(basis.getMaxNprim(), 1)),
772 int(std::max<Index>(basis.getMaxL(), 1)), 0);
773 engines[0].set(libint2::BraKet::xs_xx);
774 for (std::size_t i = 1; i < engines.size(); ++i) {
775 engines[i] = engines[0];
782 const std::vector<Source>& sources) {
784 Eigen::MatrixXd
V = Eigen::MatrixXd::Zero(nao, nao);
785 for (
const Source& src : sources) {
786 if (!(src.width > 0.0)) {
787 throw std::runtime_error(
788 "AOGaussianSites: Gaussian sites need a positive width");
791 std::vector<libint2::Engine> engines = GaussianSiteEngines(basis);
792#pragma omp parallel for schedule(dynamic) reduction(+ : V)
793 for (
Index k = 0; k <
Index(sources.size()); ++k) {
794 const Source& src = sources[std::size_t(k)];
795 const GaussianSiteShells sh(src.
pos, src.
width);
801 if (src.
dipole.squaredNorm() > 0.0) {
803 for (
Index c = 0; c < 3; ++c) {
804 V += (src.
dipole(c) * sh.p_factor) * p[std::size_t(c)];
812 const AOBasis& basis,
const Eigen::MatrixXd&
D,
813 const std::vector<Eigen::Vector3d>& points,
814 const std::vector<double>& widths) {
815 if (widths.size() != points.size()) {
816 throw std::runtime_error(
817 "AOGaussianSites: " + std::to_string(widths.size()) +
" widths for " +
818 std::to_string(points.size()) +
" points");
821 for (
double w : widths) {
823 throw std::runtime_error(
824 "AOGaussianSites: Gaussian sites need a positive width");
827 Eigen::MatrixXd result = Eigen::MatrixXd::Zero(n, 4);
828 std::vector<libint2::Engine> engines = GaussianSiteEngines(basis);
829#pragma omp parallel for schedule(dynamic)
830 for (
Index k = 0; k < n; ++k) {
831 const GaussianSiteShells sh(points[std::size_t(k)], widths[std::size_t(k)]);
838 for (
Index c = 0; c < 3; ++c) {
839 result(k, 1 + c) = sh.p_factor * p[std::size_t(c)].cwiseProduct(
D).sum();
850Eigen::MatrixXd MultiplyLeftRight(
const Eigen::MatrixXd&
L,
851 const Eigen::MatrixXd& A,
852 const Eigen::MatrixXd& R) {
853 const double left_first =
854 double(
L.rows()) * double(A.rows()) * double(A.cols()) +
855 double(
L.rows()) * double(A.cols()) * double(R.cols());
856 const double right_first =
857 double(A.rows()) * double(A.cols()) * double(R.cols()) +
858 double(
L.rows()) * double(A.rows()) * double(R.cols());
859 if (right_first < left_first) {
867 const Eigen::MatrixXd& dft_orbitals) {
871 const Eigen::MatrixXd dftm =
873 const Eigen::MatrixXd dftn =
879 std::vector<libint2::Engine> engines(nthreads);
880 engines[0] = libint2::Engine(
881 libint2::Operator::coulomb,
883 static_cast<int>(std::max(dftbasis.
getMaxL(), auxbasis.
getMaxL())), 0);
884 engines[0].set(libint2::BraKet::xs_xx);
885 for (
Index i = 1; i < nthreads; ++i) {
886 engines[i] = engines[0];
893#pragma omp for schedule(dynamic)
894 for (
Index aux = 0; aux <
Index(auxshells.size()); aux++) {
895 const libint2::Shell& auxshell = auxshells[aux];
897 std::vector<Eigen::MatrixXd> ao3c =
903 const Index dim =
static_cast<Index>(ao3c.size());
904 const Index aux0 = auxshell2bf[aux];
905 for (
Index k = 0; k < dim; ++k) {
906 ao3c[k] = MultiplyLeftRight(dftn, ao3c[k], dftm);
907 for (
Index m_level = skip; m_level <
mtotal_; m_level++) {
908 matrix_[m_level].col(aux0 + k) = ao3c[k].col(m_level - skip);
910 ao3c[k].resize(0, 0);
922 const AOBasis& auxbasis,
const std::vector<Eigen::Vector3d>& points,
923 const std::vector<double>& widths) {
924 if (!widths.empty() && widths.size() != points.size()) {
925 throw std::runtime_error(
"EnvironmentScreening::AuxFieldAtPoints: " +
926 std::to_string(widths.size()) +
" widths for " +
927 std::to_string(points.size()) +
" points.");
938 Eigen::MatrixXd::Zero(auxbasis.
AOBasisSize(), 3 * n_points);
939 if (n_points == 0 || shells.empty()) {
944 std::vector<libint2::Engine> engines(nthreads);
946 libint2::Engine(libint2::Operator::nuclear,
int(auxbasis.
getMaxNprim()),
948 for (
Index i = 1; i < nthreads; ++i) {
949 engines[i] = engines[0];
953 std::vector<libint2::Engine> coulomb(nthreads);
955 libint2::Engine(libint2::Operator::coulomb,
int(auxbasis.
getMaxNprim()),
957 coulomb[0].set(libint2::BraKet::xs_xs);
958 for (
Index i = 1; i < nthreads; ++i) {
959 coulomb[i] = coulomb[0];
964 const double h = 1
e-3;
965 const std::array<double, 4> offset = {2.0 * h, h, -h, -2.0 * h};
966 const std::array<double, 4> weight = {-1.0 / (12.0 * h), 8.0 / (12.0 * h),
967 -8.0 / (12.0 * h), 1.0 / (12.0 * h)};
974#pragma omp parallel for schedule(dynamic)
975 for (
Index p = 0; p < n_points; ++p) {
976 const double width = widths.empty() ? 0.0 : widths[std::size_t(p)];
984 const libint2::Engine::target_ptr_vec& buf = engine.results();
985 const double beta = 1.0 / (width * width);
986 const double charge =
987 std::pow(2.0 * beta / M_PI, 0.75) * std::pow(M_PI / beta, 1.5);
988 for (
Index k = 0; k < 3; ++k) {
989 for (std::size_t s = 0; s < offset.size(); ++s) {
990 Eigen::Vector3d C = points[std::size_t(p)];
992 const libint2::Shell g{
993 {beta}, {{0,
false, {1.0}}}, {{C.x(), C.y(), C.z()}}};
994 for (std::size_t sh = 0; sh < shells.size(); ++sh) {
995 engine.compute2<libint2::Operator::coulomb, libint2::BraKet::xs_xs,
996 0>(shells[sh], libint2::Shell::unit(), g,
997 libint2::Shell::unit());
998 if (buf[0] ==
nullptr) {
1001 const Index start = shell2bf[sh];
1002 for (std::size_t f = 0; f < shells[sh].size(); ++f) {
1003 F(start +
Index(f), 3 * p + k) -= weight[s] * buf[0][f] / charge;
1011 const libint2::Engine::target_ptr_vec& buf = engine.results();
1012 for (
Index k = 0; k < 3; ++k) {
1013 for (std::size_t s = 0; s < offset.size(); ++s) {
1014 Eigen::Vector3d C = points[std::size_t(p)];
1016 std::vector<std::pair<double, std::array<double, 3>>> charge{
1017 {1.0, {C.x(), C.y(), C.z()}}};
1018 engine.set_params(charge);
1019 for (std::size_t sh = 0; sh < shells.size(); ++sh) {
1020 engine.compute(shells[sh], libint2::Shell::unit());
1021 if (buf[0] ==
nullptr) {
1024 const Index start = shell2bf[sh];
1025 for (std::size_t f = 0; f < shells[sh].size(); ++f) {
1026 F(start +
Index(f), 3 * p + k) += weight[s] * buf[0][f];
1039 const AOBasis& auxbasis,
const std::vector<Eigen::Vector3d>& points,
1040 const std::vector<double>& widths) {
1041 if (widths.size() != points.size()) {
1042 throw std::runtime_error(
"EnvironmentScreening::AuxPotentialAtPoints: " +
1043 std::to_string(widths.size()) +
" widths for " +
1044 std::to_string(points.size()) +
" points.");
1049 Eigen::MatrixXd
P = Eigen::MatrixXd::Zero(auxbasis.
AOBasisSize(), n_points);
1050 if (n_points == 0 || shells.empty()) {
1054 std::vector<libint2::Engine> engines(nthreads);
1056 libint2::Engine(libint2::Operator::nuclear,
int(auxbasis.
getMaxNprim()),
1058 std::vector<libint2::Engine> coulomb(nthreads);
1060 libint2::Engine(libint2::Operator::coulomb,
int(auxbasis.
getMaxNprim()),
1062 coulomb[0].set(libint2::BraKet::xs_xs);
1063 for (
Index i = 1; i < nthreads; ++i) {
1064 engines[i] = engines[0];
1065 coulomb[i] = coulomb[0];
1071#pragma omp parallel for schedule(dynamic)
1072 for (
Index p = 0; p < n_points; ++p) {
1073 const Eigen::Vector3d& C = points[std::size_t(p)];
1074 const double width = widths[std::size_t(p)];
1077 const libint2::Engine::target_ptr_vec& buf = engine.results();
1078 const double beta = 1.0 / (width * width);
1079 const double charge =
1080 std::pow(2.0 * beta / M_PI, 0.75) * std::pow(M_PI / beta, 1.5);
1081 const libint2::Shell g{
1082 {beta}, {{0,
false, {1.0}}}, {{C.x(), C.y(), C.z()}}};
1083 for (std::size_t sh = 0; sh < shells.size(); ++sh) {
1084 engine.compute2<libint2::Operator::coulomb, libint2::BraKet::xs_xs, 0>(
1085 shells[sh], libint2::Shell::unit(), g, libint2::Shell::unit());
1086 if (buf[0] ==
nullptr) {
1089 for (std::size_t f = 0; f < shells[sh].size(); ++f) {
1090 P(shell2bf[sh] +
Index(f), p) = buf[0][f] / charge;
1096 const libint2::Engine::target_ptr_vec& buf = engine.results();
1097 std::vector<std::pair<double, std::array<double, 3>>> charge{
1098 {1.0, {C.x(), C.y(), C.z()}}};
1099 engine.set_params(charge);
1100 for (std::size_t sh = 0; sh < shells.size(); ++sh) {
1101 engine.compute(shells[sh], libint2::Shell::unit());
1102 if (buf[0] ==
nullptr) {
1105 for (std::size_t f = 0; f < shells[sh].size(); ++f) {
1106 P(shell2bf[sh] +
Index(f), p) = -buf[0][f];
1116 Eigen::VectorXd q = Eigen::VectorXd::Zero(auxbasis.
AOBasisSize());
1117 libint2::Engine engine(libint2::Operator::overlap,
1120 const libint2::Engine::target_ptr_vec& buf = engine.results();
1121 for (std::size_t sh = 0; sh < shells.size(); ++sh) {
1122 engine.compute(shells[sh], libint2::Shell::unit());
1123 if (buf[0] ==
nullptr) {
1126 for (std::size_t f = 0; f < shells[sh].size(); ++f) {
1127 q(shell2bf[sh] +
Index(f)) = buf[0][f];
Container to hold Basisfunctions for all atoms.
AOShellIterator begin() const
Index AOBasisSize() const
AOShellIterator end() const
std::vector< Index > getMapToBasisFunctions() const
Index getNumofShells() const
Index getMaxNprim() const
std::vector< std::vector< Index > > ComputeShellPairs(double threshold=1e-20) const
std::vector< libint2::Shell > GenerateLibintBasis() const
void Fill(const AOBasis &aobasis) final
Eigen::MatrixXd aomatrix_
const Eigen::MatrixXd & Matrix() const
void computeCoulombIntegrals(const AOBasis &aobasis)
Eigen::MatrixXd Pseudo_InvSqrt(double etol)
Index Removedfunctions() const
std::array< Eigen::MatrixXd, 3 > aomatrix_
std::array< libint2::Shell::real_t, 3 > r_
void Fill(const AOBasis &aobasis) final
static Eigen::MatrixXd Potential(const AOBasis &basis, const std::vector< Source > &sources)
static Eigen::MatrixXd PotentialAndGradientAt(const AOBasis &basis, const Eigen::MatrixXd &D, const std::vector< Eigen::Vector3d > &points, const std::vector< double > &widths)
void Fill(const AOBasis &aobasis) final
Eigen::MatrixXd aomatrix_
void Fill(const AOBasis &aobasis) final
Eigen::MatrixXd singleShellOverlap(const AOShell &shell) const
Eigen::MatrixXd aomatrix_
libint2::Shell LibintShell() const
std::vector< std::vector< libint2::ShellPair > > shellpairdata_
std::vector< libint2::Shell > basis_
Eigen::MatrixXd ComputeSchwarzShells(const AOBasis &dftbasis) const
std::vector< std::vector< Index > > shellpairs_
std::array< Eigen::MatrixXd, 2 > Compute4c(const Eigen::MatrixXd &dmat, double error) const
Eigen::MatrixXd schwarzscreen_
Eigen::MatrixXd ComputeShellBlockNorm(const Eigen::MatrixXd &dmat) const
std::vector< Index > starts_
static Eigen::VectorXd AuxCharges(const AOBasis &auxbasis)
static Eigen::MatrixXd AuxPotentialAtPoints(const AOBasis &auxbasis, const std::vector< Eigen::Vector3d > &points, const std::vector< double > &widths)
The electrostatic potential of each auxiliary function (as a charge density) at each point,...
static Eigen::MatrixXd AuxFieldAtPoints(const AOBasis &auxbasis, const std::vector< Eigen::Vector3d > &points, const std::vector< double > &widths={})
F: the electric field at each point produced by each auxiliary basis function, taken as a charge dens...
std::vector< Index > col_offset_
std::vector< std::vector< Index > > SignificantPairs(const AOBasis &dftbasis, const Eigen::MatrixXd &metric, double pair_threshold) const
Index size() const
Number of aux functions.
void Fill(const AOBasis &auxbasis, const AOBasis &dftbasis, double pair_threshold=0.0, Index build_columns=kBuildColumns)
void SetupLayout(const AOBasis &dftbasis, const std::vector< std::vector< Index > > &kept)
void Fill3cMO(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &dft_orbitals)
std::vector< Eigen::MatrixXd > matrix_
Eigen::MatrixXd inv_sqrt_
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixLibInt
Eigen::MatrixXd ComputeMixedOverlap(const AOBasis &row, const AOBasis &col)
std::vector< Eigen::MatrixXd > ComputeAO3cBlock(const libint2::Shell &auxshell, const AOBasis &dftbasis, libint2::Engine &engine)
std::array< MatrixLibInt, libint2::operator_traits< obtype >::nopers > computeOneBodyIntegrals(const AOBasis &aobasis, OperatorParams oparams=OperatorParams())
Provides a means for comparing floating point numbers.