CheMPS2
FCI.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 FCI_CHEMPS2_H
21 #define FCI_CHEMPS2_H
22 
23 #include "Hamiltonian.h"
24 
25 namespace CheMPS2{
32  class FCI{
33 
34  public:
35 
37 
43  FCI(CheMPS2::Hamiltonian * Ham, const unsigned int Nel_up, const unsigned int Nel_down, const int TargetIrrep, const double maxMemWorkMB=100.0, const int FCIverbose=2);
44 
46  virtual ~FCI();
47 
48 //==========> Getters of basic information: all these variables are set by the constructor
49 
51 
52  unsigned int getL() const{ return L; }
53 
55 
56  unsigned int getNel_up() const{ return Nel_up; }
57 
59 
60  unsigned int getNel_down() const{ return Nel_down; }
61 
63 
65  unsigned int getVecLength(const int irrep_center) const{ return irrep_center_jumps[ irrep_center ][ num_irreps ]; }
66 
68 
69  int getTargetIrrep() const{ return TargetIrrep; }
70 
72 
74  int getOrb2Irrep(const int orb) const{ return orb2irrep[ orb ]; }
75 
77 
82  double getERI(const int orb1, const int orb2, const int orb3, const int orb4) const{ return ERI[ orb1 + L * ( orb2 + L * ( orb3 + L * orb4 ) ) ]; }
83 
85 
88  double getGmat(const int orb1, const int orb2) const{ return Gmat[ orb1 + L * orb2 ]; }
89 
91 
92  double getEconst() const{ return Econstant; }
93 
94 //==========> The core routines for users
95 
97 
100  double GSDavidson(double * inoutput=NULL, const int DVDSN_NUM_VEC=CheMPS2::DAVIDSON_NUM_VEC) const;
101 
103 
104  unsigned int LowestEnergyDeterminant() const;
105 
107 
110  double Fill2RDM(double * vector, double * TwoRDM) const;
111 
113 
115  void Fill3RDM(double * vector, double * ThreeRDM) const;
116 
118 
120  void Fill4RDM(double * vector, double * FourRDM) const;
121 
123 
127  void Fock4RDM(double * vector, double * ThreeRDM, double * Fock, double * output) const;
128 
130 
134  void Diag4RDM( double * vector, double * three_rdm, const unsigned int orbz, double * output ) const;
135 
137 
139  double CalcSpinSquared(double * vector) const;
140 
142 
144  static void FillRandom(const unsigned int vecLength, double * vec);
145 
147 
149  static void ClearVector(const unsigned int vecLength, double * vec);
150 
151 //==========> Green's functions functionality
152 
154 
164  void RetardedGF(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double * GSvector, CheMPS2::Hamiltonian * Ham, double * RePartGF, double * ImPartGF) const;
165 
167 
180  void RetardedGF_addition(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double * GSvector, CheMPS2::Hamiltonian * Ham, double * RePartGF, double * ImPartGF, double * TwoRDMreal=NULL, double * TwoRDMimag=NULL, double * TwoRDMadd=NULL) const;
181 
183 
198  void GFmatrix_addition(const double alpha, const double beta, const double eta, int * orbsLeft, const unsigned int numLeft, int * orbsRight, const unsigned int numRight, const bool isUp, double * GSvector, CheMPS2::Hamiltonian * Ham, double * RePartsGF, double * ImPartsGF, double ** TwoRDMreal=NULL, double ** TwoRDMimag=NULL, double ** TwoRDMadd=NULL) const;
199 
201 
214  void RetardedGF_removal(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double * GSvector, CheMPS2::Hamiltonian * Ham, double * RePartGF, double * ImPartGF, double * TwoRDMreal=NULL, double * TwoRDMimag=NULL, double * TwoRDMrem=NULL) const;
215 
217 
232  void GFmatrix_removal(const double alpha, const double beta, const double eta, int * orbsLeft, const unsigned int numLeft, int * orbsRight, const unsigned int numRight, const bool isUp, double * GSvector, CheMPS2::Hamiltonian * Ham, double * RePartsGF, double * ImPartsGF, double ** TwoRDMreal=NULL, double ** TwoRDMimag=NULL, double ** TwoRDMrem=NULL) const;
233 
235 
243  void DensityResponseGF(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double * GSvector, double * RePartGF, double * ImPartGF) const;
244 
246 
257  void DensityResponseGF_forward(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double * GSvector, double * RePartGF, double * ImPartGF, double * TwoRDMreal=NULL, double * TwoRDMimag=NULL, double * TwoRDMdens=NULL) const;
258 
260 
271  void DensityResponseGF_backward(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double * GSvector, double * RePartGF, double * ImPartGF, double * TwoRDMreal=NULL, double * TwoRDMimag=NULL, double * TwoRDMdens=NULL) const;
272 
274 
281  void CGSolveSystem(const double alpha, const double beta, const double eta, double * RHS, double * RealSol, double * ImagSol, const bool checkError=true) const;
282 
283  //void CheckHamDEBUG() const;
284 
286 
290  double getFCIcoeff(int * bits_up, int * bits_down, double * vector) const;
291 
292  protected:
293 
294 //==========> Functions involving Hamiltonian matrix elements
295 
297 
298  void DiagHam(double * diag) const;
299 
301 
302  void DiagHamSquared(double * output) const;
303 
305 
307  void matvec( double * input, double * output ) const;
308 
310 
316  double GetMatrixElement(int * bits_bra_up, int * bits_bra_down, int * bits_ket_up, int * bits_ket_down, int * work) const;
317 
318 //==========> Basic conversions between bit string representations
319 
321 
325  void getBitsOfCounter(const int irrep_center, const unsigned int counter, int * bits_up, int * bits_down) const;
326 
328 
331  static void str2bits(const unsigned int Lvalue, const unsigned int bitstring, int * bits);
332 
334 
337  static unsigned int bits2str(const unsigned int Lvalue, int * bits);
338 
340 
343  int getUpIrrepOfCounter(const int irrep_center, const unsigned int counter) const;
344 
345 //==========> Some lapack like routines
346 
348 
352  static double FCIddot(const unsigned int vecLength, double * vec1, double * vec2);
353 
355 
358  static void FCIdcopy(const unsigned int vecLength, double * origin, double * target);
359 
361 
364  static double FCIfrobeniusnorm(const unsigned int vecLength, double * vec);
365 
367 
371  static void FCIdaxpy(const unsigned int vecLength, const double alpha, double * vec_x, double * vec_y);
372 
374 
377  static void FCIdscal(const unsigned int vecLength, const double alpha, double * vec);
378 
379 //==========> Protected functions regarding the Green's functions
380 
382 
388  void ActWithSecondQuantizedOperator(const char whichOperator, const bool isUp, const unsigned int orbIndex, double * thisVector, const FCI * otherFCI, double * otherVector) const;
389 
391 
394  void ActWithNumberOperator(const unsigned int orbIndex, double * resultVector, double * sourceVector) const;
395 
397 
407  void CGCoreSolver(const double alpha, const double beta, const double eta, double * precon, double * Sol, double * RESID, double * PVEC, double * OxPVEC, double * temp, double * temp2) const;
408 
410 
414  void CGAlphaPlusBetaHAM(const double alpha, const double beta, double * in, double * out) const;
415 
417 
423  void CGoperator(const double alpha, const double beta, const double eta, double * in, double * temp, double * out) const;
424 
426 
431  void CGdiagonal(const double alpha, const double beta, const double eta, double * diagonal, double * workspace) const;
432 
433 //==========> Protected functions regarding the higher order RDMs
434 
436 
441  void apply_excitation( double * orig_vector, double * result_vector, const int crea, const int anni, const int orig_target_irrep ) const;
442 
443  private:
444 
446  int FCIverbose;
447 
449  double maxMemWorkMB;
450 
452  double Econstant;
453 
455  double * Gmat;
456 
458  double * ERI;
459 
461  unsigned int num_irreps;
462 
464  int TargetIrrep;
465 
467  int * orb2irrep;
468 
470  unsigned int L;
471 
473  unsigned int Nel_up;
474 
476  unsigned int Nel_down;
477 
479  unsigned int * numPerIrrep_up;
480 
482  unsigned int * numPerIrrep_down;
483 
485  int ** str2cnt_up;
486 
488  int ** str2cnt_down;
489 
491  unsigned int ** cnt2str_up;
492 
494  unsigned int ** cnt2str_down;
495 
497  int *** lookup_cnt_alpha;
498 
500  int *** lookup_cnt_beta;
501 
503  int *** lookup_sign_alpha;
504 
506  int *** lookup_sign_beta;
507 
509  unsigned int * irrep_center_num;
510 
512  unsigned int ** irrep_center_crea_orb;
513 
515  unsigned int ** irrep_center_anni_orb;
516 
518  unsigned int ** irrep_center_jumps;
519 
521  unsigned long long HXVsizeWorkspace;
522 
524  double * HXVworksmall;
525 
527  double * HXVworkbig1;
528 
530  double * HXVworkbig2;
531 
533  void StartupCountersVsBitstrings();
534 
536  void StartupLookupTables();
537 
539  void StartupIrrepCenter();
540 
542  double Driver3RDM(double * vector, double * output, double * three_rdm, double * fock, const unsigned int orbz) const;
543 
545  static void excite_alpha_omp( const unsigned int dim_new_up, const unsigned int dim_old_up, const unsigned int dim_down, double * origin, double * result, int * signmap, int * countmap );
546  static void excite_alpha_first( const unsigned int dim_new_up, const unsigned int dim_old_up, const unsigned int start_down, const unsigned int stop_down, double * origin, double * result, int * signmap, int * countmap );
547  static void excite_alpha_second_omp( const unsigned int dim_new_up, const unsigned int dim_old_up, const unsigned int start_down, const unsigned int stop_down, double * origin, double * result, int * signmap, int * countmap );
548 
550  static void excite_beta_omp( const unsigned int dim_up, const unsigned int dim_new_down, double * origin, double * result, int * signmap, int * countmap );
551  static void excite_beta_first( const unsigned int dim_up, const unsigned int start_down, const unsigned int stop_down, double * origin, double * result, int * signmap, int * countmap );
552  static void excite_beta_second_omp( const unsigned int dim_up, const unsigned int start_down, const unsigned int stop_down, double * origin, double * result, int * signmap, int * countmap );
553 
554  };
555 
556 }
557 
558 #endif
static double FCIddot(const unsigned int vecLength, double *vec1, double *vec2)
Take the inproduct of two vectors.
Definition: FCI.cpp:1876
void Diag4RDM(double *vector, double *three_rdm, const unsigned int orbz, double *output) const
Construct part of the 4-RDM: output(i,j,k,p,q,r) = Gamma^4(i,j,k,z,p,q,r,z)
Definition: FCI.cpp:1176
void apply_excitation(double *orig_vector, double *result_vector, const int crea, const int anni, const int orig_target_irrep) const
Apply E_{crea,anni} to |orig_vector> and store the result in |result_vector>
Definition: FCI.cpp:772
double getEconst() const
Function which returns the nuclear repulsion energy.
Definition: FCI.h:92
void DensityResponseGF(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double *GSvector, double *RePartGF, double *ImPartGF) const
Calculate the density response Green's function (= forward - backward propagating part) ...
Definition: FCI.cpp:2398
void DensityResponseGF_backward(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double *GSvector, double *RePartGF, double *ImPartGF, double *TwoRDMreal=NULL, double *TwoRDMimag=NULL, double *TwoRDMdens=NULL) const
Calculate the backward propagating part of the density response Green&#39;s function: <GSvector| ( n_beta...
Definition: FCI.cpp:2458
double getERI(const int orb1, const int orb2, const int orb3, const int orb4) const
Function which returns the electron repulsion integral (in chemists notation: integral dr1 dr2 orb1(r...
Definition: FCI.h:82
void DiagHam(double *diag) const
Function which returns the diagonal elements of the FCI Hamiltonian (without Econstant!!) = Slater de...
Definition: FCI.cpp:1467
static void FCIdcopy(const unsigned int vecLength, double *origin, double *target)
Copy a vector.
Definition: FCI.cpp:1868
void CGdiagonal(const double alpha, const double beta, const double eta, double *diagonal, double *workspace) const
Calculate (without approximation) diagonal = diag[ (alpha + beta * Hamiltonian)^2 + eta^2 ] (Econstan...
Definition: FCI.cpp:2162
double GSDavidson(double *inoutput=NULL, const int DVDSN_NUM_VEC=CheMPS2::DAVIDSON_NUM_VEC) const
Calculates the FCI ground state with Davidson&#39;s algorithm.
Definition: FCI.cpp:1920
void CGCoreSolver(const double alpha, const double beta, const double eta, double *precon, double *Sol, double *RESID, double *PVEC, double *OxPVEC, double *temp, double *temp2) const
Calculate the solution of the system Operator |Sol> = |RESID> with Operator = precon * [ ( alpha + be...
void ActWithSecondQuantizedOperator(const char whichOperator, const bool isUp, const unsigned int orbIndex, double *thisVector, const FCI *otherFCI, double *otherVector) const
Set thisVector to a creator/annihilator acting on otherVector.
Definition: FCI.cpp:1975
void Fill4RDM(double *vector, double *FourRDM) const
Construct the (spin-summed) 4-RDM of a FCI vector: Gamma^4(i,j,k,l,p,q,r,t) = sum_sigma,tau,s,z < a^+_{i,sigma} a^+_{j,tau} a^+_{k,s} a^+_{l,z} a_{t,z} a_{r,s} a_{q,tau} a_{p,sigma} > = FourRDM[ i + L * ( j + L * ( k + L * ( l + L * ( p + L * ( q + L * ( r + L * t ) ) ) ) ) ) ].
Definition: FCI.cpp:896
Definition: CASPT2.h:42
static void FCIdaxpy(const unsigned int vecLength, const double alpha, double *vec_x, double *vec_y)
Do lapack&#39;s daxpy vec_y += alpha * vec_x.
Definition: FCI.cpp:1890
void DensityResponseGF_forward(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const double GSenergy, double *GSvector, double *RePartGF, double *ImPartGF, double *TwoRDMreal=NULL, double *TwoRDMimag=NULL, double *TwoRDMdens=NULL) const
Calculate the forward propagating part of the density response Green&#39;s function: <GSvector| ( n_alpha...
Definition: FCI.cpp:2422
void GFmatrix_removal(const double alpha, const double beta, const double eta, int *orbsLeft, const unsigned int numLeft, int *orbsRight, const unsigned int numRight, const bool isUp, double *GSvector, CheMPS2::Hamiltonian *Ham, double *RePartsGF, double *ImPartsGF, double **TwoRDMreal=NULL, double **TwoRDMimag=NULL, double **TwoRDMrem=NULL) const
Calculate the removal Green&#39;s function: GF[i+numLeft*j] = <GSvector| a^+_{orbsLeft[i], spin} [ alpha + beta * Ham + I*eta ]^{-1} a_{orbsRight[j], spin} |GSvector>
Definition: FCI.cpp:2306
void DiagHamSquared(double *output) const
Function which returns the diagonal elements of the FCI Hamiltonian squared (without Econstant!!) ...
Definition: FCI.cpp:1504
static void FillRandom(const unsigned int vecLength, double *vec)
Fill a vector with random numbers in the interval [-1,1[; used when output for GSDavidson is desired ...
Definition: FCI.cpp:1914
void RetardedGF_removal(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double *GSvector, CheMPS2::Hamiltonian *Ham, double *RePartGF, double *ImPartGF, double *TwoRDMreal=NULL, double *TwoRDMimag=NULL, double *TwoRDMrem=NULL) const
Calculate the removal part of the retarded Green&#39;s function: <GSvector| a^+_{beta, spin(isUp)} [ omega + Ham - GSenergy + I*eta ]^{-1} a_{alpha, spin(isUp)} |GSvector>
Definition: FCI.cpp:2378
static void FCIdscal(const unsigned int vecLength, const double alpha, double *vec)
Do lapack&#39;s dscal vec *= alpha.
Definition: FCI.cpp:1899
unsigned int LowestEnergyDeterminant() const
Return the global counter of the Slater determinant with the lowest energy.
Definition: FCI.cpp:1700
void CGoperator(const double alpha, const double beta, const double eta, double *in, double *temp, double *out) const
Calculate out = [(alpha + beta * Hamiltonian)^2 + eta^2] * in (Econstant is taken into account!!) ...
Definition: FCI.cpp:2153
unsigned int getNel_down() const
Getter for the number of down or beta electrons.
Definition: FCI.h:60
double getGmat(const int orb1, const int orb2) const
Function which returns the AUGMENTED one-body matrix elements ( G_{ij} = T_{ij} - 0...
Definition: FCI.h:88
void CGSolveSystem(const double alpha, const double beta, const double eta, double *RHS, double *RealSol, double *ImagSol, const bool checkError=true) const
Calculate the solution of the equation ( alpha + beta * Hamiltonian + I * eta ) Solution = RHS with c...
Definition: FCI.cpp:2066
void RetardedGF(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double *GSvector, CheMPS2::Hamiltonian *Ham, double *RePartGF, double *ImPartGF) const
Calculate the retarded Green&#39;s function (= addition + removal amplitude)
Definition: FCI.cpp:2191
double getFCIcoeff(int *bits_up, int *bits_down, double *vector) const
Function which returns a FCI coefficient.
Definition: FCI.cpp:435
void GFmatrix_addition(const double alpha, const double beta, const double eta, int *orbsLeft, const unsigned int numLeft, int *orbsRight, const unsigned int numRight, const bool isUp, double *GSvector, CheMPS2::Hamiltonian *Ham, double *RePartsGF, double *ImPartsGF, double **TwoRDMreal=NULL, double **TwoRDMimag=NULL, double **TwoRDMadd=NULL) const
Calculate the addition Green&#39;s function: GF[i+numLeft*j] = <GSvector| a_{orbsLeft[i], spin} [ alpha + beta * Ham + I*eta ]^{-1} a^+_{orbsRight[j], spin} |GSvector>
Definition: FCI.cpp:2215
virtual ~FCI()
Destructor.
Definition: FCI.cpp:82
unsigned int getVecLength(const int irrep_center) const
Getter for the number of variables in the vector " E_ij | FCI vector > " ; where irrep_center = I_i x...
Definition: FCI.h:65
void Fill3RDM(double *vector, double *ThreeRDM) const
Construct the (spin-summed) 3-RDM of a FCI vector: Gamma^3(i,j,k,l,m,n) = sum_sigma,tau,s < a^+_{i,sigma} a^+_{j,tau} a^+_{k,s} a_{n,s} a_{m,tau} a_{l,sigma} > = ThreeRDM[ i + L * ( j + L * ( k + L * ( l + L * ( m + L * n ) ) ) ) ].
Definition: FCI.cpp:1168
void CGAlphaPlusBetaHAM(const double alpha, const double beta, double *in, double *out) const
Calculate out = (alpha + beta * Hamiltonian) * in (Econstant is taken into account!!) ...
Definition: FCI.cpp:2142
double GetMatrixElement(int *bits_bra_up, int *bits_bra_down, int *bits_ket_up, int *bits_ket_down, int *work) const
Sandwich the Hamiltonian between two Slater determinants (return a specific element) (without Econsta...
Definition: FCI.cpp:1722
static void ClearVector(const unsigned int vecLength, double *vec)
Set the entries of a vector to zero.
Definition: FCI.cpp:1908
void ActWithNumberOperator(const unsigned int orbIndex, double *resultVector, double *sourceVector) const
Set resultVector to the number operator of a specific site acting on sourceVector.
Definition: FCI.cpp:1957
void RetardedGF_addition(const double omega, const double eta, const unsigned int orb_alpha, const unsigned int orb_beta, const bool isUp, const double GSenergy, double *GSvector, CheMPS2::Hamiltonian *Ham, double *RePartGF, double *ImPartGF, double *TwoRDMreal=NULL, double *TwoRDMimag=NULL, double *TwoRDMadd=NULL) const
Calculate the addition part of the retarded Green&#39;s function: <GSvector| a_{alpha, spin(isUp)} [ omega - Ham + GSenergy + I*eta ]^{-1} a^+_{beta, spin(isUp)} |GSvector>
Definition: FCI.cpp:2287
static void str2bits(const unsigned int Lvalue, const unsigned int bitstring, int *bits)
Convertor between two representations of a same spin-projection Slater determinant.
Definition: FCI.cpp:391
static unsigned int bits2str(const unsigned int Lvalue, int *bits)
Convertor between two representations of a same spin-projection Slater determinant.
Definition: FCI.cpp:397
unsigned int getNel_up() const
Getter for the number of up or alpha electrons.
Definition: FCI.h:56
void matvec(double *input, double *output) const
Function which performs the Hamiltonian times Vector product (without Econstant!!) making use of the ...
Definition: FCI.cpp:618
void getBitsOfCounter(const int irrep_center, const unsigned int counter, int *bits_up, int *bits_down) const
Find the bit representation of a global counter corresponding to " E_ij | FCI vector > " ; where irre...
Definition: FCI.cpp:417
double CalcSpinSquared(double *vector) const
Measure S(S+1) (spin squared)
Definition: FCI.cpp:1405
int getUpIrrepOfCounter(const int irrep_center, const unsigned int counter) const
Find the irrep of the up Slater determinant of a global counter corresponding to " E_ij | FCI vector ...
Definition: FCI.cpp:409
unsigned int getL() const
Getter for the number of orbitals.
Definition: FCI.h:52
int getTargetIrrep() const
Get the target irrep.
Definition: FCI.h:69
static double FCIfrobeniusnorm(const unsigned int vecLength, double *vec)
Calculate the 2-norm of a vector.
Definition: FCI.cpp:1884
double Fill2RDM(double *vector, double *TwoRDM) const
Construct the (spin-summed) 2-RDM of a FCI vector: Gamma^2(i,j,k,l) = sum_sigma,tau < a^+_i...
Definition: FCI.cpp:805
void Fock4RDM(double *vector, double *ThreeRDM, double *Fock, double *output) const
Construct the (spin-summed) contraction of the 4-RDM with the Fock operator: output(i,j,k,p,q,r) = sum_{l,t} Fock(l,t) * Gamma^4(i,j,k,l,p,q,r,t)
Definition: FCI.cpp:1160
int getOrb2Irrep(const int orb) const
Get an orbital irrep.
Definition: FCI.h:74
FCI(CheMPS2::Hamiltonian *Ham, const unsigned int Nel_up, const unsigned int Nel_down, const int TargetIrrep, const double maxMemWorkMB=100.0, const int FCIverbose=2)
Constructor.
Definition: FCI.cpp:37