QMCPACK
ci_configuration2.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_CI_CONFIGURATION2_H
16 #define QMCPLUSPLUS_CI_CONFIGURATION2_H
17 
18 #include <algorithm>
19 #include <iostream>
20 #include <stdexcept>
21 
22 namespace qmcplusplus
23 {
24 // Defines a ci configuration based of the occupied MOs
26 {
27  // occupied orbitals
28  std::vector<size_t> occup;
29 
31 
32  ci_configuration2(std::vector<size_t>& v) : occup(v.begin(), v.end()) {}
34 
36 
37  inline bool operator==(const ci_configuration2& c) const
38  {
39  if (occup.size() != c.occup.size())
40  throw std::runtime_error("ci_configuration2::operator==() - ci_configuration2s are not compatible.");
41 
42  for (int i = 0; i < occup.size(); i++)
43  if (occup[i] != c.occup[i])
44  return false;
45  return true;
46  }
47 
48  /*
49  * The routine determines the number excitations that
50  * transform the given configuration (argument) into (*this).
51  */
53  {
54  if (occup.size() != c.occup.size())
55  throw std::runtime_error("ci_configuration2::operator==() - ci_configuration2s are not compatible.");
56 
57  size_t n = 0;
58  for (size_t i = 0; i < occup.size(); i++)
59  if (std::find(c.occup.begin(), c.occup.end(), occup[i]) == c.occup.end())
60  n++;
61  return n;
62  }
63 
64  /*
65  * The routine determines the excitations that
66  * transform the given configuration (argument) into (*this).
67  * The sign of the permutation is returned.
68  * - n: number of excitations
69  * - pos: positions of MOs in c that need to be changed (not the label of the MO)
70  * - ocp: label of the MO being removed (needed to calculate matrix elements)
71  * - uno: label of the MO that replaces ocp[i] (should be the same as the position in array, as opposed to ocp)
72  *
73  */
75  size_t& n,
76  std::vector<size_t>& pos,
77  std::vector<size_t>& ocp,
78  std::vector<size_t>& uno) const
79  {
80  if (occup.size() != c.occup.size())
81  throw std::runtime_error("ci_configuration2::operator==() - ci_configuration2s are not compatible.");
82 
83  n = 0;
84  for (size_t i = 0; i < occup.size(); i++)
85  if (std::find(c.occup.begin(), c.occup.end(), occup[i]) == c.occup.end())
86  {
87  pos[n] = i;
88  ocp[n++] = occup[i];
89  }
90 
91  if (n == 0)
92  return 1.0;
93 
94  size_t cnt = 0;
95  for (size_t i = 0; i < c.occup.size(); i++)
96  if (std::find(occup.begin(), occup.end(), c.occup[i]) == occup.end())
97  uno[cnt++] = c.occup[i];
98 
99  if (cnt != n)
100  throw std::runtime_error(" Error #1 in ci_configuration2::calculateExcitations() \n");
101 
102  double res = 1.0;
103  // this is needed because ci coefficients are given wrt standard ordering,
104  // but by defining the determinant through excitations from a reference might change
105  // the parity
106  // inefficient but easy, is there a sort routine in STL that gives me the parity too???
107  auto ref0(occup);
108  for (size_t i = 0; i < n; i++)
109  ref0[pos[i]] = uno[i];
110 
111  for (size_t i = 0; i < ref0.size(); i++)
112  for (size_t k = i + 1; k < ref0.size(); k++)
113  if (ref0[i] > ref0[k])
114  {
115  size_t q = ref0[i];
116  ref0[i] = ref0[k];
117  ref0[k] = q;
118  res *= -1.0;
119  }
120  else if (ref0[i] == ref0[k])
121  throw std::runtime_error(" Error #2 in ci_configuration2::calculateExcitations() \n");
122 
123  return res;
124  }
125 };
126 
127 inline std::ostream& operator<<(std::ostream& out, const ci_configuration2& c)
128 {
129  out << "ci ci_configuration2: ";
130  for (size_t i = 0; i < c.occup.size(); i++)
131  out << c.occup[i] << " ";
132  out << std::endl;
133  return out;
134 };
135 
136 } // namespace qmcplusplus
137 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
if(c->rank()==0)
ci_configuration2(const ci_configuration2 &c)
size_t calculateNumOfExcitations(const ci_configuration2 &c) const
bool operator==(const ci_configuration2 &c) const
std::ostream & operator<<(std::ostream &out, const AntiSymTensor< T, D > &rhs)
ci_configuration2(std::vector< size_t > &v)
double calculateExcitations(const ci_configuration2 &c, size_t &n, std::vector< size_t > &pos, std::vector< size_t > &ocp, std::vector< size_t > &uno) const