votca 2026-dev
Loading...
Searching...
No Matches
ERIs.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_ERIS_H
22#define VOTCA_XTP_ERIS_H
23
24// Local VOTCA includes
25#include "threecenter.h"
26
27namespace votca {
28namespace xtp {
29
35class ERIs {
36
37 public:
40 void Initialize(const AOBasis& dftbasis, const AOBasis& auxbasis,
41 double pair_threshold = 0.0);
42 void Initialize_4c(const AOBasis& dftbasis);
43
44 Eigen::MatrixXd CalculateERIs_3c(const Eigen::MatrixXd& DMAT) const;
45
46 std::array<Eigen::MatrixXd, 2> CalculateERIs_EXX_3c(
47 const Eigen::MatrixXd& occMos, const Eigen::MatrixXd& DMAT) const {
48 std::array<Eigen::MatrixXd, 2> result;
49 result[0] = CalculateERIs_3c(DMAT);
50 result[1] = CalculateEXX_3c(occMos, DMAT);
51 return result;
52 }
53
56 Eigen::MatrixXd CalculateEXX_3c(const Eigen::MatrixXd& occMos,
57 const Eigen::MatrixXd& DMAT) const {
58 if (occMos.rows() > 0 && occMos.cols() > 0) {
59 assert(occMos.rows() == DMAT.rows() && "occMos.rows()==DMAT.rows()");
60 return CalculateEXX_mos(occMos);
61 }
62 return CalculateEXX_dmat(DMAT);
63 }
64
69 Eigen::MatrixXd CalculateEXX_factors(const Eigen::MatrixXd& X,
70 const Eigen::MatrixXd& Y) const {
71 assert(threecenter_.size() > 0 &&
72 "Please call Initialize before running this");
73 Eigen::MatrixXd factors(X.rows(), X.cols() + Y.cols());
74 factors << X, Y;
75 return ExchangeFromFactors(factors, X.cols());
76 }
77
78 Index AuxSize() const { return threecenter_.size(); }
80 Index StoredPairs() const { return threecenter_.StoredPairs(); }
81 Index AllPairs() const { return threecenter_.AllPairs(); }
83 double MetricSeconds() const { return threecenter_.MetricSeconds(); }
84
85 Eigen::MatrixXd CalculateERIs_4c(const Eigen::MatrixXd& DMAT,
86 double error) const {
87 return Compute4c<false>(DMAT, error)[0];
88 }
89
90 std::array<Eigen::MatrixXd, 2> CalculateERIs_EXX_4c(
91 const Eigen::MatrixXd& DMAT, double error) const {
92 return Compute4c<true>(DMAT, error);
93 }
94
95 Index Removedfunctions() const { return threecenter_.Removedfunctions(); }
96
97 static double CalculateEnergy(const Eigen::MatrixXd& DMAT,
98 const Eigen::MatrixXd& matrix_operator) {
99 return matrix_operator.cwiseProduct(DMAT).sum();
100 }
101
102 private:
103 std::vector<libint2::Shell> basis_;
104 std::vector<Index> starts_;
105
106 std::vector<std::vector<Index>> shellpairs_;
107 std::vector<std::vector<libint2::ShellPair>> shellpairdata_;
110
113 static constexpr double kDensityRankCutoff = 1e-12;
114 Eigen::MatrixXd CalculateEXX_dmat(const Eigen::MatrixXd& DMAT) const;
115 Eigen::MatrixXd CalculateEXX_mos(const Eigen::MatrixXd& occMos) const;
118 Eigen::MatrixXd ExchangeFromFactors(const Eigen::MatrixXd& factors,
119 Index npos) const;
121 static constexpr Index kExchangeBatchRows = 1024;
122
123 std::vector<std::vector<libint2::ShellPair>> ComputeShellPairData(
124 const std::vector<libint2::Shell>& basis,
125 const std::vector<std::vector<Index>>& shellpairs) const;
126
127 Eigen::MatrixXd ComputeSchwarzShells(const AOBasis& dftbasis) const;
128 Eigen::MatrixXd ComputeShellBlockNorm(const Eigen::MatrixXd& dmat) const;
129
130 template <bool with_exchange>
131 std::array<Eigen::MatrixXd, 2> Compute4c(const Eigen::MatrixXd& dmat,
132 double error) const;
133
135
136 Eigen::MatrixXd schwarzscreen_; // Square matrix containing <ab|ab> for all
137 // shells
138}; // namespace xtp
139
140} // namespace xtp
141} // namespace votca
142
143#endif // VOTCA_XTP_ERIS_H
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
Takes a density matrix and and an auxiliary basis set and calculates the electron repulsion integrals...
Definition ERIs.h:35
Eigen::MatrixXd CalculateERIs_3c(const Eigen::MatrixXd &DMAT) const
Definition ERIs.cc:89
void Initialize(const AOBasis &dftbasis, const AOBasis &auxbasis, double pair_threshold=0.0)
Definition ERIs.cc:33
Index Removedfunctions() const
Definition ERIs.h:95
std::vector< std::vector< libint2::ShellPair > > shellpairdata_
Definition ERIs.h:107
std::vector< libint2::Shell > basis_
Definition ERIs.h:103
Eigen::MatrixXd ComputeSchwarzShells(const AOBasis &dftbasis) const
double MetricSeconds() const
Wall time spent on the aux Coulomb metric and its inverse square root.
Definition ERIs.h:83
static constexpr double kDensityRankCutoff
Definition ERIs.h:113
std::vector< std::vector< Index > > shellpairs_
Definition ERIs.h:106
std::array< Eigen::MatrixXd, 2 > CalculateERIs_EXX_4c(const Eigen::MatrixXd &DMAT, double error) const
Definition ERIs.h:90
Index StoredPairs() const
Stored basis-function pairs of the 3c tensor and all N(N+1)/2 pairs.
Definition ERIs.h:80
static constexpr Index kExchangeBatchRows
Rows of B_P X collected per thread before one rank update.
Definition ERIs.h:121
void Initialize_4c(const AOBasis &dftbasis)
Definition ERIs.cc:39
Eigen::MatrixXd CalculateEXX_3c(const Eigen::MatrixXd &occMos, const Eigen::MatrixXd &DMAT) const
Definition ERIs.h:56
Index AllPairs() const
Definition ERIs.h:81
static double CalculateEnergy(const Eigen::MatrixXd &DMAT, const Eigen::MatrixXd &matrix_operator)
Definition ERIs.h:97
std::array< Eigen::MatrixXd, 2 > Compute4c(const Eigen::MatrixXd &dmat, double error) const
std::array< Eigen::MatrixXd, 2 > CalculateERIs_EXX_3c(const Eigen::MatrixXd &occMos, const Eigen::MatrixXd &DMAT) const
Definition ERIs.h:46
Eigen::MatrixXd CalculateEXX_factors(const Eigen::MatrixXd &X, const Eigen::MatrixXd &Y) const
Definition ERIs.h:69
Index maxL_
Definition ERIs.h:109
std::vector< std::vector< libint2::ShellPair > > ComputeShellPairData(const std::vector< libint2::Shell > &basis, const std::vector< std::vector< Index > > &shellpairs) const
Definition ERIs.cc:53
Eigen::MatrixXd CalculateERIs_4c(const Eigen::MatrixXd &DMAT, double error) const
Definition ERIs.h:85
Eigen::MatrixXd ExchangeFromFactors(const Eigen::MatrixXd &factors, Index npos) const
Definition ERIs.cc:174
Eigen::MatrixXd schwarzscreen_
Definition ERIs.h:136
Eigen::MatrixXd ComputeShellBlockNorm(const Eigen::MatrixXd &dmat) const
Definition ERIs.cc:70
std::vector< Index > starts_
Definition ERIs.h:104
Eigen::MatrixXd CalculateEXX_dmat(const Eigen::MatrixXd &DMAT) const
Definition ERIs.cc:122
TCMatrix_dft threecenter_
Definition ERIs.h:134
Index AuxSize() const
Definition ERIs.h:78
Index maxnprim_
Definition ERIs.h:108
Eigen::MatrixXd CalculateEXX_mos(const Eigen::MatrixXd &occMos) const
Definition ERIs.cc:162
RI three-centre tensor of the DFT code, B_P,mu nu = sum_Q V^-1/2_PQ (Q|mu nu).
Definition threecenter.h:74
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26