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