MPQC  3.0.0-alpha
integrals.hpp
1 #ifndef MPQC_CI_INTEGRALS_HPP
2 #define MPQC_CI_INTEGRALS_HPP
3 
4 #include "mpqc/math/matrix.hpp"
5 #include <boost/foreach.hpp>
6 
7 #include <chemistry/qc/basis/tbint.h>
8 
9 namespace mpqc {
10  namespace ci {
11 
12  template<class C, class U, class T>
13  void transform(const range &p, const C &c, const U &u, T &t) {
14  t += u.transpose() * c(range(c.rows()), p).transpose();
15  }
16 
17  void integrals(sc::Ref<sc::GaussianBasisSet> basis, const Matrix &C,
19  size_t no = C.rows();
20  range O(0, no);
21  range shells(basis->nshell());
22 
23  V.resize((no * no + no) / 2, (no * no + no) / 2);
24  V.fill(0);
25 
26  Matrix T1, T2, T3, T4;
27  T4.resize(no * no * no, no);
28  T4.fill(0);
29 
30  BOOST_FOREACH (auto s, shells) {
31  range S = basis->range(s);
32  int ns = S.size();
33  T3.resize(ns*no*no, no);
34  T3.fill(0);
35  BOOST_FOREACH (auto r, shells) {
36  range R = basis->range(r);
37  int nr = R.size();
38  T2.resize(nr*ns*no, no);
39  T2.fill(0);
40  BOOST_FOREACH (auto q, shells) {
41  range Q = basis->range(q);
42  int nq = Q.size();
43  T1.resize(nq*nr*ns, no);
44  T1.fill(0);
45  BOOST_FOREACH (auto p, shells) {
46  range P = basis->range(p);
47  int np = P.size();
48  int2->compute_shell(s, r, q, p);
49  auto G = Matrix::Map(int2->buffer(), np, nq*nr*ns);
50  transform(P, C, G, T1);
51  }
52  T1.resize(nq, nr*ns*no);
53  transform(Q, C, T1, T2);
54  }
55  T2.resize(nr, ns*no*no);
56  transform(R, C, T2, T3);
57  }
58  T3.resize(ns, no*no*no);
59  transform(S, C, T3, T4);
60  }
61 
62  for (size_t l = 0, kl = 0; l < no; ++l) {
63  for (size_t k = 0; k <= l; ++k, ++kl) {
64  for (size_t j = 0, ij = 0; j < no; ++j) {
65  for (size_t i = 0; i <= j; ++i, ++ij) {
66  MPQC_ASSERT(
67  fabs(
68  V(index(j, i), index(k, l)) - V(index(i, j), index(k, l))
69  < 1e-14));
70  auto v = T4(i + j * no + k * no * no, l);
71  if (fabs(v) < 1e-15)
72  v = 0;
73  V(ij, kl) = v;
74  //printf("integral %i %i %e\n", ij, kl, v);
75  }
76  }
77  }
78  }
79 
80  }
81 
82  void integrals(const Matrix &C, const Matrix &h_ao, Vector &h) {
83  size_t no = C.rows();
84  Matrix T1 = C * h_ao;
85  Matrix T2 = T1 * C.transpose();
86  h.resize((no * no + no) / 2);
87  h.fill(0);
88  for (size_t l = 0, kl = 0; l < no; ++l) {
89  for (size_t k = 0; k <= l; ++k, ++kl) {
90  h(kl) = T2(k, l);
91  }
92  }
93  }
94 
95  void integrals(sc::Ref<sc::GaussianBasisSet> basis, const Matrix &C,
97  range shells(basis->nshell());
98  size_t n = C.cols();
99  Matrix h_ao(n, n);
100  h_ao.fill(0);
101  BOOST_FOREACH (auto s, shells) {
102  range S = basis->range(s);
103  int ns = S.size();
104  BOOST_FOREACH (auto r, shells) {
105  range R = basis->range(r);
106  int nr = R.size();
107  int1->compute_shell(s, r);
108  h_ao(R,S) = Matrix::Map(int1->buffer(), nr, ns);
109  }
110  }
111  integrals(C, h_ao, h);
112  }
113 
114  } // namespace ci
115 } // namespace mpqc
116 
117 #endif /* MPQC_CI_INTEGRALS_HPP */
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
sc::GaussianBasisSet::nshell
unsigned int nshell() const
Return the number of shells.
Definition: gaussbas.h:500
sc::Ref< sc::GaussianBasisSet >
mpqc::Matrix
matrix< double > Matrix
Convience double matrix type.
Definition: matrix.hpp:170
sc::TwoBodyInt::compute_shell
virtual void compute_shell(int, int, int, int)=0
Given four shell indices, integrals will be computed and placed in the buffer.
sc::OneBodyInt::buffer
const double * buffer() const
Returns the buffer where the integrals are placed.
sc::OneBodyInt::compute_shell
virtual void compute_shell(int, int)=0
Computes the integrals between basis functions in the given shell pair.
sc::TwoBodyInt::buffer
virtual const double * buffer(TwoBodyOper::type type=TwoBodyOper::eri) const
The computed shell integrals will be put in the buffer returned by this member.
sc::transform
RefSCMatrix transform(const OrbitalSpace &space2, const OrbitalSpace &space1, const Ref< SCMatrixKit > &kit=SCMatrixKit::default_matrixkit())
transform(s2,s1) returns matrix that transforms s1 to s2.
mpqc::Vector
vector< double > Vector
Convience double vector type.
Definition: matrix.hpp:172

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.