CheMPS2
TwoDM.h
1 /*
2  CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
3  Copyright (C) 2013-2016 Sebastian Wouters
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef TWODM_CHEMPS2_H
21 #define TWODM_CHEMPS2_H
22 
23 #include "TensorT.h"
24 #include "TensorL.h"
25 #include "TensorF0.h"
26 #include "TensorF1.h"
27 #include "TensorS0.h"
28 #include "TensorS1.h"
29 #include "SyBookkeeper.h"
30 
31 namespace CheMPS2{
50  class TwoDM{
51 
52  public:
53 
55 
57  TwoDM(const SyBookkeeper * denBKIn, const Problem * ProbIn);
58 
60  virtual ~TwoDM();
61 
63 
68  double getTwoDMA_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const;
69 
71 
76  double getTwoDMB_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const;
77 
79 
82  double get1RDM_DMRG(const int cnt1, const int cnt2) const;
83 
85 
88  double spin_density_dmrg( const int cnt1, const int cnt2 ) const;
89 
91 
96  double getTwoDMA_HAM(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const;
97 
99 
104  double getTwoDMB_HAM(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const;
105 
107 
110  double get1RDM_HAM(const int cnt1, const int cnt2) const;
111 
113 
116  double spin_density_ham( const int cnt1, const int cnt2 ) const;
117 
119 
125  void FillSite(TensorT * denT, TensorL *** Ltens, TensorF0 **** F0tens, TensorF1 **** F1tens, TensorS0 **** S0tens, TensorS1 **** S1tens);
126 
129 
131 
132  double trace() const;
133 
135 
136  double energy() const;
137 
139  void print_noon() const;
140 
142  void save() const;
143 
145  void read();
146 
148 
149  void save_HAM( const string filename ) const;
150 
152 
153  void write2DMAfile(const string filename) const;
154 
156  void mpi_allreduce();
157 
158  private:
159 
160  //The BK containing all the irrep information
161  const SyBookkeeper * denBK;
162 
163  //The problem containing orbital reshuffling and symmetry information
164  const Problem * Prob;
165 
166  //The chain length
167  int L;
168 
169  //Two 2DM^{A,B} objects
170  double * two_rdm_A;
171  double * two_rdm_B;
172 
173  // Set 2DM terms, using the DMRG indices
174  void set_2rdm_A_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4, const double value);
175  void set_2rdm_B_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4, const double value);
176 
177  //Helper functions
178  double doD1(TensorT * denT);
179  double doD2(TensorT * denT, TensorL * Lright, double * workmem);
180  double doD3(TensorT * denT, TensorS0 * S0right, double * workmem);
181  double doD4(TensorT * denT, TensorF0 * F0right, double * workmem);
182  double doD5(TensorT * denT, TensorF0 * F0right, double * workmem);
183  double doD6(TensorT * denT, TensorF1 * F1right, double * workmem);
184  double doD7(TensorT * denT, TensorL * Lleft, double * workmem);
185  double doD8(TensorT * denT, TensorL * Lleft, TensorL * Lright, double * workmem, double * workmem2, int Irrep_g);
186  void doD9andD10andD11(TensorT * denT, TensorL * Lleft, TensorL * Lright, double * workmem, double * workmem2, double * d9, double * d10, double * d11, int Irrep_g);
187  double doD12(TensorT * denT, TensorL * Lleft, TensorL * Lright, double * workmem, double * workmem2, int Irrep_g);
188  double doD13(TensorT * denT, TensorL * Lleft, TensorS0 * S0right, double * workmem, double * workmem2, int Irrep_g);
189  double doD14(TensorT * denT, TensorL * Lleft, TensorS0 * S0right, double * workmem, double * workmem2, int Irrep_g);
190  double doD15(TensorT * denT, TensorL * Lleft, TensorS1 * S1right, double * workmem, double * workmem2, int Irrep_g);
191  double doD16(TensorT * denT, TensorL * Lleft, TensorS1 * S1right, double * workmem, double * workmem2, int Irrep_g);
192  double doD17orD21(TensorT * denT, TensorL * Lleft, TensorF0 * F0right, double * workmem, double * workmem2, int Irrep_g, bool shouldIdoD17);
193  double doD18orD22(TensorT * denT, TensorL * Lleft, TensorF0 * F0right, double * workmem, double * workmem2, int Irrep_g, bool shouldIdoD18);
194  double doD19orD23(TensorT * denT, TensorL * Lleft, TensorF1 * F1right, double * workmem, double * workmem2, int Irrep_g, bool shouldIdoD19);
195  double doD20orD24(TensorT * denT, TensorL * Lleft, TensorF1 * F1right, double * workmem, double * workmem2, int Irrep_g, bool shouldIdoD20);
196 
197  };
198 }
199 
200 #endif
void FillSite(TensorT *denT, TensorL ***Ltens, TensorF0 ****F0tens, TensorF1 ****F1tens, TensorS0 ****S0tens, TensorS1 ****S1tens)
Fill the 2DM terms with as second site index denT->gIndex()
Definition: TwoDM.cpp:444
virtual ~TwoDM()
Destructor.
Definition: TwoDM.cpp:56
double get1RDM_HAM(const int cnt1, const int cnt2) const
Get a 1-RDM term, using the HAM indices.
Definition: TwoDM.cpp:184
void save() const
Save the TwoDMs to disk.
Definition: TwoDM.cpp:314
Definition: CASPT2.h:42
double getTwoDMB_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const
Get a 2DM_B term, using the DMRG indices.
Definition: TwoDM.cpp:112
double energy() const
Calculate the energy based on the 2DM-A.
Definition: TwoDM.cpp:216
double spin_density_dmrg(const int cnt1, const int cnt2) const
Get a spin-density term, using the DMRG indices.
Definition: TwoDM.cpp:143
void correct_higher_multiplicities()
After the whole 2-RDM is filled, a prefactor for higher multiplicities should be applied.
Definition: TwoDM.cpp:629
double getTwoDMA_HAM(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const
Get a 2DM_A term, using the HAM indices.
Definition: TwoDM.cpp:164
double get1RDM_DMRG(const int cnt1, const int cnt2) const
Get a 1-RDM term, using the DMRG indices.
Definition: TwoDM.cpp:127
double getTwoDMA_DMRG(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const
Get a 2DM_A term, using the DMRG indices.
Definition: TwoDM.cpp:97
double trace() const
Return the double trace of 2DM-A (should be N(N-1))
Definition: TwoDM.cpp:204
double spin_density_ham(const int cnt1, const int cnt2) const
Get a spin-density term, using the HAM indices.
Definition: TwoDM.cpp:194
void mpi_allreduce()
Add the 2-RDM elements of all MPI processes.
double getTwoDMB_HAM(const int cnt1, const int cnt2, const int cnt3, const int cnt4) const
Get a 2DM_B term, using the HAM indices.
Definition: TwoDM.cpp:174
void print_noon() const
Print the natural orbital occupation numbers.
Definition: TwoDM.cpp:233
void read()
Load the TwoDMs from disk.
Definition: TwoDM.cpp:345
void save_HAM(const string filename) const
Save the 2-RDM-A to disk in Hamiltonian indices.
Definition: TwoDM.cpp:278
TwoDM(const SyBookkeeper *denBKIn, const Problem *ProbIn)
Constructor.
Definition: TwoDM.cpp:39
void write2DMAfile(const string filename) const
Write the 2-RDM-A to a file.
Definition: TwoDM.cpp:372