CheMPS2
CASSCF.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 CASSCF_CHEMPS2_H
21 #define CASSCF_CHEMPS2_H
22 
23 #include <string>
24 
25 #include "Hamiltonian.h"
26 #include "Irreps.h"
27 #include "TwoDM.h"
28 #include "ThreeDM.h"
29 #include "DMRG.h"
30 #include "Problem.h"
31 #include "Options.h"
32 #include "ConvergenceScheme.h"
33 #include "DMRGSCFindices.h"
34 #include "DMRGSCFunitary.h"
35 #include "DMRGSCFoptions.h"
36 #include "DMRGSCFwtilde.h"
37 #include "DMRGSCFmatrix.h"
38 #include "DMRGSCFintegrals.h"
39 
40 namespace CheMPS2{
164  class CASSCF{
165 
166  public:
167 
169 
176  CASSCF( Hamiltonian * ham_in, int * docc, int * socc, int * nocc, int * ndmrg, int * nvirt, const string tmp_folder=CheMPS2::defaultTMPpath );
177 
179  virtual ~CASSCF();
180 
182 
183  int get_num_irreps();
184 
186 
193  double solve( const int Nelectrons, const int TwoS, const int Irrep, ConvergenceScheme * OptScheme, const int rootNum, DMRGSCFoptions * scf_options );
194 
196 
208  double caspt2( const int Nelectrons, const int TwoS, const int Irrep, ConvergenceScheme * OptScheme, const int rootNum, DMRGSCFoptions * scf_options, const double IPEA, const double IMAG, const bool PSEUDOCANONICAL, const bool CHECKPOINT = false, const bool CUMULANT = false );
209 
211  /* \param filename File to delete */
212  static void deleteStoredUnitary( const string filename=CheMPS2::DMRGSCF_unitary_storage_name ){ delete_file( filename ); }
213 
215  /* \param filename File to delete */
216  static void deleteStoredDIIS( const string filename=CheMPS2::DMRGSCF_diis_storage_name ){ delete_file( filename ); }
217 
219 
227  static void buildFmat( DMRGSCFmatrix * localFmat, const DMRGSCFmatrix * localTmat, const DMRGSCFmatrix * localJKocc, const DMRGSCFmatrix * localJKact, const DMRGSCFindices * localIdx, const DMRGSCFintegrals * theInts, double * local2DM, double * local1DM );
228 
230 
238  static void buildWtilde( DMRGSCFwtilde * localwtilde, const DMRGSCFmatrix * localTmat, const DMRGSCFmatrix * localJKocc, const DMRGSCFmatrix * localJKact, const DMRGSCFindices * localIdx, const DMRGSCFintegrals * theInts, double * local2DM, double * local1DM );
239 
241 
248  static void augmentedHessianNR( DMRGSCFmatrix * localFmat, DMRGSCFwtilde * localwtilde, const DMRGSCFindices * localIdx, const DMRGSCFunitary * localUmat, double * theupdate, double * updateNorm, double * gradNorm );
249 
251 
254  static void copy2DMover( TwoDM * theDMRG2DM, const int LAS, double * two_dm );
255 
257 
261  static void setDMRG1DM( const int num_elec, const int LAS, double * one_dm, double * two_dm );
262 
264 
268  static void copy_active( double * origin, DMRGSCFmatrix * result, const DMRGSCFindices * idx, const bool one_rdm );
269 
271 
274  static void copy_active( const DMRGSCFmatrix * origin, double * result, const DMRGSCFindices * idx );
275 
277 
280  static void fillLocalizedOrbitalRotations( DMRGSCFunitary * umat, DMRGSCFindices * idx, double * eigenvecs );
281 
283 
293  static void block_diagonalize( const char space, const DMRGSCFmatrix * Mat, DMRGSCFunitary * Umat, double * work1, double * work2, const DMRGSCFindices * idx, const bool invert, double * two_dm, double * three_dm, double * contract );
294 
296 
301  static void construct_fock( DMRGSCFmatrix * Fock, const DMRGSCFmatrix * Tmat, const DMRGSCFmatrix * Qocc, const DMRGSCFmatrix * Qact, const DMRGSCFindices * idx );
302 
304 
307  static double deviation_from_blockdiag( DMRGSCFmatrix * matrix, const DMRGSCFindices * idx );
308 
310 
315  static void write_f4rdm_checkpoint( const string f4rdm_file, int * hamorb1, int * hamorb2, const int tot_dmrg_power6, double * contract );
316 
318 
324  static bool read_f4rdm_checkpoint( const string f4rdm_file, int * hamorb1, int * hamorb2, const int tot_dmrg_power6, double * contract );
325 
327 
336  static void fock_dot_4rdm( double * fockmx, CheMPS2::DMRG * dmrgsolver, CheMPS2::Hamiltonian * ham, int next_orb1, int next_orb2, double * work, double * result, const bool CHECKPOINT, const bool PSEUDOCANONICAL );
337 
338  private:
339 
340  // CASSCF tmp folder
341  string tmp_folder;
342 
343  // Index convention handler
344  DMRGSCFindices * iHandler;
345 
346  // Unitary matrix storage and manipulator
347  DMRGSCFunitary * unitary;
348 
349  // Whether CheMPS2::CASSCF::solve has been successfully terminated
350  bool successful_solve;
351 
352  // The original Hamiltonian
353  double NUCL_ORIG;
354  const TwoIndex * TMAT_ORIG;
355  const FourIndex * VMAT_ORIG;
356 
357  // Irreps controller
358  Irreps SymmInfo;
359 
360  // The number of orbitals
361  int L;
362 
363  // The number of irreps
364  int num_irreps;
365 
366  // Number of DMRG orbitals
367  int nOrbDMRG;
368 
369  // Space for the DMRG 1DM
370  double * DMRG1DM;
371 
372  // Space for the DMRG 2DM
373  double * DMRG2DM;
374 
375  // Helper function to check HF
376  void checkHF( int * docc, int * socc );
377 
378  // Fill Econst and Tmat of HamDMRG
379  void fillConstAndTmatDMRG( Hamiltonian * HamDMRG ) const;
380 
381  // Calculate the gradient, return function is the gradient 2-norm
382  static double construct_gradient( DMRGSCFmatrix * Fmatrix, const DMRGSCFindices * idx, double * gradient );
383 
384  // Add hessian * origin to target
385  static void add_hessian( DMRGSCFmatrix * Fmatrix, DMRGSCFwtilde * Wtilde, const DMRGSCFindices * idx, double * origin, double * target );
386 
387  // Construct the diagonal of the hessian
388  static void diag_hessian( DMRGSCFmatrix * Fmatrix, const DMRGSCFwtilde * Wtilde, const DMRGSCFindices * idx, double * diagonal );
389 
390  // Apply augmented hessian
391  static void DGEMM_WRAP( double prefactor, char transA, char transB, double * A, double * B, double * C, int m, int n, int k, int lda, int ldb, int ldc );
392  static void DGEMV_WRAP( double prefactor, double * matrix, double * result, double * vector, int rowdim, int coldim, int ldmat, int incres, int incvec );
393  static void augmented_hessian( DMRGSCFmatrix * Fmatrix, DMRGSCFwtilde * Wtilde, const DMRGSCFindices * idx, double * origin, double * target, double * gradient, const int linsize );
394 
395  // Rotate an active space object
396  static void rotate_active_space_object( const int num_indices, double * object, double * work, double * rotation, const int LAS, const int NJUMP, const int NROTATE );
397 
398  // Fmat function as defined by Eq. (11) in the Siegbahn paper.
399  DMRGSCFmatrix * theFmatrix;
400 
401  // The Coulomb and exchange interaction with the occupied and active electrons respectively
402  DMRGSCFmatrix * theQmatOCC;
403  DMRGSCFmatrix * theQmatACT;
404  DMRGSCFmatrix * theQmatWORK;
405  DMRGSCFmatrix * theTmatrix;
406  void rotateOldToNew(DMRGSCFmatrix * myMatrix);
407  void buildTmatrix();
408  void constructCoulombAndExchangeMatrixInOrigIndices( DMRGSCFmatrix * density, DMRGSCFmatrix * result );
409  void buildQmatOCC();
410  void buildQmatACT();
411 
412  // Function to get coefficients of certain Slater determinants for Fe2. Important to figure out diatomic D(inf)h symmetries when calculating them in D2h symmetry.
413  void coeff_fe2( DMRG * theDMRG );
414 
415  static void delete_file( const string filename );
416 
417  };
418 }
419 
420 #endif
static void write_f4rdm_checkpoint(const string f4rdm_file, int *hamorb1, int *hamorb2, const int tot_dmrg_power6, double *contract)
Write the checkpoint file for the contraction of the generalized Fock operator with the 4-RDM to disk...
Definition: CASSCFpt2.cpp:44
static void buildWtilde(DMRGSCFwtilde *localwtilde, const DMRGSCFmatrix *localTmat, const DMRGSCFmatrix *localJKocc, const DMRGSCFmatrix *localJKact, const DMRGSCFindices *localIdx, const DMRGSCFintegrals *theInts, double *local2DM, double *local1DM)
Build the Wtilde-matrix (Eq. (20b) in the Siegbahn paper [CAS3])
static void copy_active(double *origin, DMRGSCFmatrix *result, const DMRGSCFindices *idx, const bool one_rdm)
Copy a one-orbital quantity from array format to DMRGSCFmatrix format.
Definition: CASSCF.cpp:375
Definition: CASPT2.h:42
static void construct_fock(DMRGSCFmatrix *Fock, const DMRGSCFmatrix *Tmat, const DMRGSCFmatrix *Qocc, const DMRGSCFmatrix *Qact, const DMRGSCFindices *idx)
Construct the Fock matrix.
Definition: CASSCFpt2.cpp:395
static void augmentedHessianNR(DMRGSCFmatrix *localFmat, DMRGSCFwtilde *localwtilde, const DMRGSCFindices *localIdx, const DMRGSCFunitary *localUmat, double *theupdate, double *updateNorm, double *gradNorm)
Calculate the augmented Hessian Newton-Raphson update for the orthogonal orbital rotation matrix...
static void copy2DMover(TwoDM *theDMRG2DM, const int LAS, double *two_dm)
Copy over the DMRG 2-RDM.
Definition: CASSCF.cpp:119
double caspt2(const int Nelectrons, const int TwoS, const int Irrep, ConvergenceScheme *OptScheme, const int rootNum, DMRGSCFoptions *scf_options, const double IPEA, const double IMAG, const bool PSEUDOCANONICAL, const bool CHECKPOINT=false, const bool CUMULANT=false)
Calculate the caspt2 correction energy for a converged casscf wavefunction.
Definition: CASSCFpt2.cpp:189
static void block_diagonalize(const char space, const DMRGSCFmatrix *Mat, DMRGSCFunitary *Umat, double *work1, double *work2, const DMRGSCFindices *idx, const bool invert, double *two_dm, double *three_dm, double *contract)
Block-diagonalize Mat.
Definition: CASSCF.cpp:433
static void fillLocalizedOrbitalRotations(DMRGSCFunitary *umat, DMRGSCFindices *idx, double *eigenvecs)
From an Edmiston-Ruedenberg active space rotation, fetch the eigenvectors and store them in eigenvecs...
Definition: CASSCF.cpp:160
static void fock_dot_4rdm(double *fockmx, CheMPS2::DMRG *dmrgsolver, CheMPS2::Hamiltonian *ham, int next_orb1, int next_orb2, double *work, double *result, const bool CHECKPOINT, const bool PSEUDOCANONICAL)
Build the contraction of the fock matrix with the 4-RDM.
Definition: CASSCFpt2.cpp:140
double solve(const int Nelectrons, const int TwoS, const int Irrep, ConvergenceScheme *OptScheme, const int rootNum, DMRGSCFoptions *scf_options)
Do the CASSCF cycles with the augmented Hessian Newton-Raphson method.
int get_num_irreps()
Get the number of irreps.
Definition: CASSCF.cpp:117
static void setDMRG1DM(const int num_elec, const int LAS, double *one_dm, double *two_dm)
Construct the 1-RDM from the 2-RDM.
Definition: CASSCF.cpp:134
static void deleteStoredDIIS(const string filename=CheMPS2::DMRGSCF_diis_storage_name)
CASSCF DIIS vectors remove call.
Definition: CASSCF.h:216
static void deleteStoredUnitary(const string filename=CheMPS2::DMRGSCF_unitary_storage_name)
CASSCF unitary rotation remove call.
Definition: CASSCF.h:212
virtual ~CASSCF()
Destructor.
Definition: CASSCF.cpp:100
static bool read_f4rdm_checkpoint(const string f4rdm_file, int *hamorb1, int *hamorb2, const int tot_dmrg_power6, double *contract)
Read the checkpoint file for the contraction of the generalized Fock operator with the 4-RDM from dis...
Definition: CASSCFpt2.cpp:87
static double deviation_from_blockdiag(DMRGSCFmatrix *matrix, const DMRGSCFindices *idx)
Return the RMS deviation from block-diagonal.
Definition: CASSCFpt2.cpp:411
CASSCF(Hamiltonian *ham_in, int *docc, int *socc, int *nocc, int *ndmrg, int *nvirt, const string tmp_folder=CheMPS2::defaultTMPpath)
Constructor.
Definition: CASSCF.cpp:39
static void buildFmat(DMRGSCFmatrix *localFmat, const DMRGSCFmatrix *localTmat, const DMRGSCFmatrix *localJKocc, const DMRGSCFmatrix *localJKact, const DMRGSCFindices *localIdx, const DMRGSCFintegrals *theInts, double *local2DM, double *local1DM)
Build the F-matrix (Eq. (11) in the Siegbahn paper [CAS3])