Psi4
scf.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_bin_mcscf_scf_h_
30 #define _psi_src_bin_mcscf_scf_h_
31 
32 #include "sblock_vector.h"
33 #include "sblock_matrix.h"
38 
39 #define STORE_TEI 0
40 
41 namespace psi{ namespace mcscf{
42 
44 
45 class SCF : public Wavefunction
46 {
47 public:
48  explicit SCF(SharedWavefunction ref_wfn, Options& options_, std::shared_ptr<PSIO> psio);
49  ~SCF();
50  double compute_energy();
51 
52 private:
54  static const int maxci = 8;
55  static const int maxdiis = 10;
56  static const int maxbatches = 50;
57 
58  int nirreps;
59  int nso;
60  size_t* ioff;
65  int root;
66  int ndiis;
68  bool use_diis;
69  double total_energy;
70 
71  // Out-of-core algorithm
73  int nbatch;
80  size_t nin_core; // Number of matrix elements of the PK and K matrices held in of core
81 
82  // Addressing routines
84  int npairs; // Total number of pairs
85  int* pairpi; // Number of pairs per irrep
86  int* pairs; // The pairs stored as [ p1 q1 p2 q2 ... ]
87  int** pair; // Maps absolute p and q to the pair index
88  int** pair_sym; // Maps absolute p and q to the pair symmetry
89  int* pair_offset; // Offset for first pair of a given irrep
90 
91  double* PK; // PK(pq|rs)
92  double* K; // K(pq|rs)
93 
94  SBlockVector epsilon; // Effective Fock matrix eigenvalues
95 
96 
97  SBlockMatrix C; // MO coefficients matrix
98  SBlockMatrix C_t; // transformed C matrix
99  SBlockMatrix C_T; // MO coefficients matrix transposed
100  SBlockMatrix Dc; // The density matrix (closed)
101  SBlockMatrix Dc_old; // The density matrix (closed)
102  SBlockMatrix Do; // The density matrix (open)
103  SBlockMatrix Dtc[maxci]; // The density matrix (tcscf)
104  SBlockMatrix Dtc_old[maxci]; // The density matrix (tcscf)
105  SBlockMatrix Dsum[maxci]; // The density matrix (closed + tcscf)
106  SBlockMatrix Fc; // The Fock matrix (closed)
107  SBlockMatrix Fc_t; // The transformed Fock matrix (closed)
108  SBlockMatrix Fo; // The Fock matrix (open)
109  SBlockMatrix Fo_t; // The transformed Fock matrix (open)
110  SBlockMatrix Favg; // The Fock matrix (average)
111  SBlockMatrix Favg_t; // The transformed Fock matrix (average)
112  SBlockMatrix Ftc[maxci]; // The Fock matrix (tcscf)
113  SBlockMatrix Ftc_t[maxci];// The transformed Fock matrix (tcscf)
114  SBlockMatrix Feff_t; // The transformed effective Fock matrix
115  SBlockMatrix Feff_t_old; // The transformed effective Fock matrix
116  SBlockMatrix Feff_oAO; // The effective Fock matrix in the orthogonal AO basis
117  SBlockMatrix G; // The G matrix
118  SBlockMatrix T; // a temp matrix
119  SBlockMatrix H; // one electron integrals
120  SBlockMatrix O; // The occupation matrix
121  SBlockMatrix S; // overlap integrals
124 
125  SBlockMatrix e; // MO coefficients error matrix
126  SBlockMatrix diis_F[maxdiis]; // The Fock matrices saved for DIIS
127  SBlockMatrix diis_e[maxdiis]; // The error matrices saved for DIIS
128  double diis_ci[maxci][maxdiis]; // The ci vector saved for DIIS
129 
130  // TWOCON Specific
131  int nci; // Number of references
132  double norm_ci_grad; // Norm of the CI gradient (sum_I |C_I|)
133  double* ci; // TWOCON CI coefficients
134  double* ci_grad; // TWOCON CI coefficients gradient
135  double** H_tcscf; // TWOCON Hamiltonian
136  int tcscf_mos[maxci]; // Number of the TWOCON mos (relative to the irrep)
137  int tcscf_sym[maxci]; // Symmetry of the TWOCON mos
138 
139  // Private functions
140  void startup();
141  void cleanup();
142 
143  void generate_pairs();
144  void read_so_oei();
145  void read_so_tei();
146  void read_so_tei_form_PK();
148  void read_Raffanetti(const char* integral_type, double* integrals, int batch);
149  void write_Raffanetti(const char* integral_type, double* integrals, int batch);
150 
152  void iterate_scf_equations();
153  void guess_occupation();
154  void canonicalize_MO();
155  void save_info();
156  void check_orthonormality();
158 
159  void initial_guess();
160  void density_matrix();
161  void construct_G(SBlockMatrix& density,SBlockMatrix& G,double* integrals,int batch, double factor);
162  void construct_G(SBlockMatrix& density,SBlockMatrix& G,double* integrals,int batch);
163  void construct_F();
164  void construct_Favg();
165  void construct_Feff(int cycle);
166  double energy(int cycle,double old_energy);
167 
168  void diis(int cycle);
169 
170  // Auxiliary functions
171  void transform(SBlockMatrix& Initial, SBlockMatrix& Final, SBlockMatrix& Transformation);
172 };
173 
174 }} /* End Namespaces */
175 
176 #endif // _psi_src_bin_mcscf_scf_h_
177 
178 /*
179 // void read_C();
180 
181 
182 
183  int* so_sym;
184 
185  // TWOCON
186 
187 
188 
189  // DIIS
190  int maxdiis;
191  int current_diis;
192 
193  double* epsilon; // Eigenvalues
194  SBlockMatrix* C; // MO coefficients matrix
195  SBlockMatrix* C_T; // Transpose coefficients matrix
196  SBlockMatrix* C_t; // transformed C matrix
197  SBlockMatrix* D; // density matrix
198  SBlockMatrix* Dc; // closed-shell density matrix
199  SBlockMatrix* Do; // open-shell density matrix
200  SBlockMatrix* Dtc[2]; // tcscf density matrices
201  SBlockMatrix* Ex; // tcscf exchange matrix
202  SBlockMatrix* F; // Fock matrix
203  SBlockMatrix* F_t; // transformed Fock matrix
204  SBlockMatrix* Fc; // closed-shell Fock matrix
205  SBlockMatrix* Fo; // open-shell Fock matrix
206 
207  SBlockMatrix* Fc_t; // transformed closed-shell Fock matrix
208  SBlockMatrix* Fo_t; // transformed open-shell Fock matrix
209  SBlockMatrix* Feff_t; // transformed effective Fock matrix
210  SBlockMatrix* G; // two electron contribution to F
211 
212  SBlockMatrix* SDF; // SDF: used to compute the diis error
213  SBlockMatrix* FDS; // FDS: used to compute the diis error
214  SBlockMatrix* CSC; // CSC = 1 for orthornormal MOs
215 
216 
217  SBlockMatrix* Temp; // A temporary matrix
218 
219 
220 
221 */
SBlockMatrix S_sqrt
Definition: scf.h:123
double * ci
Definition: scf.h:133
Definition: scf.h:45
size_t total_symmetric_block_size
Definition: scf.h:79
SBlockMatrix Dc_old
Definition: scf.h:101
int ** pair
Definition: scf.h:87
intvec sopi
Definition: scf.h:61
static const int maxdiis
Definition: scf.h:55
void startup()
Definition: scf.cc:63
int nso
Definition: scf.h:59
std::shared_ptr< PSIO > psio() const
Definition: wavefunction.cc:407
SBlockMatrix Ftc_t[maxci]
Definition: scf.h:113
SBlockMatrix C_t
Definition: scf.h:98
void read_so_oei()
Definition: scf_read_so_oei.cc:51
Definition: scf.h:43
void print_eigenvectors_and_MO()
Definition: scf_print_eigenvectors_and_MO.cc:43
int ** pair_sym
Definition: scf.h:88
int ndiis
Definition: scf.h:66
int tcscf_mos[maxci]
Definition: scf.h:136
size_t batch_size[maxbatches]
Definition: scf.h:78
void integrals(psi::OneBodyAOInt &integral, ambit::Tensor *target)
Definition: integrals.cc:51
Definition: scf.h:43
int * pair_offset
Definition: scf.h:89
Definition: sblock_matrix.h:41
SBlockMatrix Dc
Definition: scf.h:100
bool use_diis
Definition: scf.h:68
static const int maxci
Definition: scf.h:54
SBlockMatrix T
Definition: scf.h:118
int turn_on_actv
Definition: scf.h:64
int nbatch
Definition: scf.h:73
int nci
Definition: scf.h:131
void transform(SBlockMatrix &Initial, SBlockMatrix &Final, SBlockMatrix &Transformation)
Definition: scf.cc:254
double diis_ci[maxci][maxdiis]
Definition: scf.h:128
bool out_of_core
Definition: scf.h:72
ReferenceType reference
Definition: scf.h:53
Definition: scf.h:43
void density_matrix()
Definition: scf_density_matrix.cc:33
SBlockMatrix O
Definition: scf.h:120
void write_Raffanetti(const char *integral_type, double *integrals, int batch)
Definition: scf_G.cc:126
int current_diis
Definition: scf.h:67
static const int maxbatches
Definition: scf.h:56
double * K
Definition: scf.h:92
SBlockMatrix Feff_t_old
Definition: scf.h:115
SBlockMatrix Ftc[maxci]
Definition: scf.h:112
double * ci_grad
Definition: scf.h:134
double norm_ci_grad
Definition: scf.h:132
SBlockMatrix Favg_t
Definition: scf.h:111
void check_orthonormality()
Definition: scf_check_orthonormality.cc:38
void guess_occupation()
Definition: scf_guess_occupation.cc:44
SharedWavefunction mcscf(SharedWavefunction, Options &)
Definition: mcscf.cc:71
SBlockVector epsilon
Definition: scf.h:94
void cleanup()
Definition: scf.cc:199
ReferenceType
Definition: scf.h:43
SBlockMatrix e
Definition: scf.h:125
SBlockMatrix C
Definition: scf.h:97
SBlockMatrix Dtc[maxci]
Definition: scf.h:103
double compute_energy()
Compute energy. Subclasses override this function to compute its energy.
Definition: scf_compute_energy.cc:37
size_t * ioff
Definition: scf.h:60
intvec actv
Definition: scf.h:63
intvec docc
Definition: scf.h:62
void construct_F()
Definition: scf_F.cc:34
int npairs
Definition: scf.h:84
SBlockMatrix diis_e[maxdiis]
Definition: scf.h:127
Options & options_
Options object.
Definition: wavefunction.h:106
SBlockMatrix Feff_oAO
Definition: scf.h:116
double ** H_tcscf
Definition: scf.h:135
void read_so_tei_form_PK()
Definition: scf_read_so_tei.cc:130
SBlockMatrix Favg
Definition: scf.h:110
SBlockMatrix diis_F[maxdiis]
Definition: scf.h:126
double * PK
Definition: scf.h:91
SBlockMatrix C_T
Definition: scf.h:99
Definition: scf.h:43
SBlockMatrix Dsum[maxci]
Definition: scf.h:105
Definition: liboptions.h:355
void read_so_tei_form_PK_and_K()
Definition: scf_read_so_tei.cc:213
size_t batch_index_max[maxbatches]
Definition: scf.h:77
SBlockMatrix S_sqrt_inv
Definition: scf.h:122
void construct_Favg()
Definition: scf_F.cc:129
double energy(int cycle, double old_energy)
Definition: scf_energy.cc:45
std::vector< int > intvec
Definition: moinfo_base.h:46
SBlockMatrix Fc_t
Definition: scf.h:107
int nirreps
Definition: scf.h:58
Simple wavefunction base class.
Definition: wavefunction.h:84
size_t batch_pq_max[maxbatches]
Definition: scf.h:75
SBlockMatrix H
Definition: scf.h:119
SBlockMatrix Fo_t
Definition: scf.h:109
SBlockMatrix Do
Definition: scf.h:102
void diis(int cycle)
Definition: scf_diis.cc:44
SBlockMatrix S
Definition: scf.h:121
SCF(SharedWavefunction ref_wfn, Options &options_, std::shared_ptr< PSIO > psio)
Definition: scf.cc:48
Definition: sblock_vector.h:39
void read_so_tei()
Definition: scf_read_so_tei.cc:50
void construct_G(SBlockMatrix &density, SBlockMatrix &G, double *integrals, int batch, double factor)
Definition: scf_G.cc:53
int root
Definition: scf.h:65
void construct_Feff(int cycle)
Definition: scf_Feff.cc:36
int * pairpi
Definition: scf.h:85
void read_Raffanetti(const char *integral_type, double *integrals, int batch)
Definition: scf_G.cc:117
size_t batch_index_min[maxbatches]
Definition: scf.h:76
void save_info()
Definition: scf_save_info.cc:49
~SCF()
Definition: scf.cc:56
int tcscf_sym[maxci]
Definition: scf.h:137
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
void generate_pairs()
Definition: scf_pairs.cc:42
void iterate_scf_equations()
Definition: scf_iterate_scf_equations.cc:42
SBlockMatrix Fc
Definition: scf.h:106
SBlockMatrix Dtc_old[maxci]
Definition: scf.h:104
double total_energy
Definition: scf.h:69
void initial_guess()
Definition: scf_initial_guess.cc:38
SBlockMatrix G
Definition: scf.h:117
int * block_offset
Definition: scf.h:83
void canonicalize_MO()
Definition: scf_canonicalize_MO.cc:35
SBlockMatrix Feff_t
Definition: scf.h:114
int * pairs
Definition: scf.h:86
size_t batch_pq_min[maxbatches]
Definition: scf.h:74
SBlockMatrix Fo
Definition: scf.h:108
size_t nin_core
Definition: scf.h:80
void construct_S_inverse_sqrt()
Definition: scf_S_inverse_sqrt.cc:34