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"
37 
38 #define STORE_TEI 0
39 
40 namespace psi{ namespace mcscf{
41 
43 
44 class SCF : public Wavefunction
45 {
46 public:
47  explicit SCF(SharedWavefunction ref_wfn, Options& options_, std::shared_ptr<PSIO> psio);
48  ~SCF();
49  double compute_energy();
50 
51 private:
53  static const int maxci = 8;
54  static const int maxdiis = 10;
55  static const int maxbatches = 50;
56 
57  int nirreps;
58  int nso;
59  size_t* ioff;
64  int root;
65  int ndiis;
67  bool use_diis;
68  double total_energy;
69 
70  // Out-of-core algorithm
72  int nbatch;
79  size_t nin_core; // Number of matrix elements of the PK and K matrices held in of core
80 
81  // Addressing routines
83  int npairs; // Total number of pairs
84  int* pairpi; // Number of pairs per irrep
85  int* pairs; // The pairs stored as [ p1 q1 p2 q2 ... ]
86  int** pair; // Maps absolute p and q to the pair index
87  int** pair_sym; // Maps absolute p and q to the pair symmetry
88  int* pair_offset; // Offset for first pair of a given irrep
89 
90  double* PK; // PK(pq|rs)
91  double* K; // K(pq|rs)
92 
93  SBlockVector epsilon; // Effective Fock matrix eigenvalues
94 
95 
96  SBlockMatrix C; // MO coefficients matrix
97  SBlockMatrix C_t; // transformed C matrix
98  SBlockMatrix C_T; // MO coefficients matrix transposed
99  SBlockMatrix Dc; // The density matrix (closed)
100  SBlockMatrix Dc_old; // The density matrix (closed)
101  SBlockMatrix Do; // The density matrix (open)
102  SBlockMatrix Dtc[maxci]; // The density matrix (tcscf)
103  SBlockMatrix Dtc_old[maxci]; // The density matrix (tcscf)
104  SBlockMatrix Dsum[maxci]; // The density matrix (closed + tcscf)
105  SBlockMatrix Fc; // The Fock matrix (closed)
106  SBlockMatrix Fc_t; // The transformed Fock matrix (closed)
107  SBlockMatrix Fo; // The Fock matrix (open)
108  SBlockMatrix Fo_t; // The transformed Fock matrix (open)
109  SBlockMatrix Favg; // The Fock matrix (average)
110  SBlockMatrix Favg_t; // The transformed Fock matrix (average)
111  SBlockMatrix Ftc[maxci]; // The Fock matrix (tcscf)
112  SBlockMatrix Ftc_t[maxci];// The transformed Fock matrix (tcscf)
113  SBlockMatrix Feff_t; // The transformed effective Fock matrix
114  SBlockMatrix Feff_t_old; // The transformed effective Fock matrix
115  SBlockMatrix Feff_oAO; // The effective Fock matrix in the orthogonal AO basis
116  SBlockMatrix G; // The G matrix
117  SBlockMatrix T; // a temp matrix
118  SBlockMatrix H; // one electron integrals
119  SBlockMatrix O; // The occupation matrix
120  SBlockMatrix S; // overlap integrals
123 
124  SBlockMatrix e; // MO coefficients error matrix
125  SBlockMatrix diis_F[maxdiis]; // The Fock matrices saved for DIIS
126  SBlockMatrix diis_e[maxdiis]; // The error matrices saved for DIIS
127  double diis_ci[maxci][maxdiis]; // The ci vector saved for DIIS
128 
129  // TWOCON Specific
130  int nci; // Number of references
131  double norm_ci_grad; // Norm of the CI gradient (sum_I |C_I|)
132  double* ci; // TWOCON CI coefficients
133  double* ci_grad; // TWOCON CI coefficients gradient
134  double** H_tcscf; // TWOCON Hamiltonian
135  int tcscf_mos[maxci]; // Number of the TWOCON mos (relative to the irrep)
136  int tcscf_sym[maxci]; // Symmetry of the TWOCON mos
137 
138  // Private functions
139  void startup();
140  void cleanup();
141 
142  void generate_pairs();
143  void read_so_oei();
144  void read_so_tei();
145  void read_so_tei_form_PK();
147  void read_Raffanetti(const char* integral_type, double* integrals, int batch);
148  void write_Raffanetti(const char* integral_type, double* integrals, int batch);
149 
151  void iterate_scf_equations();
152  void guess_occupation();
153  void canonicalize_MO();
154  void save_info();
155  void check_orthonormality();
157 
158  void initial_guess();
159  void density_matrix();
160  void construct_G(SBlockMatrix& density,SBlockMatrix& G,double* integrals,int batch, double factor);
161  void construct_G(SBlockMatrix& density,SBlockMatrix& G,double* integrals,int batch);
162  void construct_F();
163  void construct_Favg();
164  void construct_Feff(int cycle);
165  double energy(int cycle,double old_energy);
166 
167  void diis(int cycle);
168 
169  // Auxiliary functions
170  void transform(SBlockMatrix& Initial, SBlockMatrix& Final, SBlockMatrix& Transformation);
171 };
172 
173 }} /* End Namespaces */
174 
175 #endif // _psi_src_bin_mcscf_scf_h_
176 
177 /*
178 // void read_C();
179 
180 
181 
182  int* so_sym;
183 
184  // TWOCON
185 
186 
187 
188  // DIIS
189  int maxdiis;
190  int current_diis;
191 
192  double* epsilon; // Eigenvalues
193  SBlockMatrix* C; // MO coefficients matrix
194  SBlockMatrix* C_T; // Transpose coefficients matrix
195  SBlockMatrix* C_t; // transformed C matrix
196  SBlockMatrix* D; // density matrix
197  SBlockMatrix* Dc; // closed-shell density matrix
198  SBlockMatrix* Do; // open-shell density matrix
199  SBlockMatrix* Dtc[2]; // tcscf density matrices
200  SBlockMatrix* Ex; // tcscf exchange matrix
201  SBlockMatrix* F; // Fock matrix
202  SBlockMatrix* F_t; // transformed Fock matrix
203  SBlockMatrix* Fc; // closed-shell Fock matrix
204  SBlockMatrix* Fo; // open-shell Fock matrix
205 
206  SBlockMatrix* Fc_t; // transformed closed-shell Fock matrix
207  SBlockMatrix* Fo_t; // transformed open-shell Fock matrix
208  SBlockMatrix* Feff_t; // transformed effective Fock matrix
209  SBlockMatrix* G; // two electron contribution to F
210 
211  SBlockMatrix* SDF; // SDF: used to compute the diis error
212  SBlockMatrix* FDS; // FDS: used to compute the diis error
213  SBlockMatrix* CSC; // CSC = 1 for orthornormal MOs
214 
215 
216  SBlockMatrix* Temp; // A temporary matrix
217 
218 
219 
220 */
SBlockMatrix S_sqrt
Definition: scf.h:122
double * ci
Definition: scf.h:132
Definition: scf.h:44
size_t total_symmetric_block_size
Definition: scf.h:78
SBlockMatrix Dc_old
Definition: scf.h:100
int ** pair
Definition: scf.h:86
intvec sopi
Definition: scf.h:60
static const int maxdiis
Definition: scf.h:54
void startup()
Definition: scf.cc:63
int nso
Definition: scf.h:58
std::shared_ptr< PSIO > psio() const
Definition: wavefunction.cc:391
SBlockMatrix Ftc_t[maxci]
Definition: scf.h:112
SBlockMatrix C_t
Definition: scf.h:97
void read_so_oei()
Definition: scf_read_so_oei.cc:51
Definition: scf.h:42
void print_eigenvectors_and_MO()
Definition: scf_print_eigenvectors_and_MO.cc:45
int ** pair_sym
Definition: scf.h:87
int ndiis
Definition: scf.h:65
int tcscf_mos[maxci]
Definition: scf.h:135
size_t batch_size[maxbatches]
Definition: scf.h:77
void integrals(psi::OneBodyAOInt &integral, ambit::Tensor *target)
Definition: integrals.cc:51
Definition: scf.h:42
int * pair_offset
Definition: scf.h:88
Definition: sblock_matrix.h:41
SBlockMatrix Dc
Definition: scf.h:99
bool use_diis
Definition: scf.h:67
static const int maxci
Definition: scf.h:53
SBlockMatrix T
Definition: scf.h:117
int turn_on_actv
Definition: scf.h:63
int nbatch
Definition: scf.h:72
int nci
Definition: scf.h:130
void transform(SBlockMatrix &Initial, SBlockMatrix &Final, SBlockMatrix &Transformation)
Definition: scf.cc:254
double diis_ci[maxci][maxdiis]
Definition: scf.h:127
bool out_of_core
Definition: scf.h:71
ReferenceType reference
Definition: scf.h:52
Definition: scf.h:42
void density_matrix()
Definition: scf_density_matrix.cc:33
SBlockMatrix O
Definition: scf.h:119
void write_Raffanetti(const char *integral_type, double *integrals, int batch)
Definition: scf_G.cc:126
int current_diis
Definition: scf.h:66
static const int maxbatches
Definition: scf.h:55
double * K
Definition: scf.h:91
SBlockMatrix Feff_t_old
Definition: scf.h:114
SBlockMatrix Ftc[maxci]
Definition: scf.h:111
double * ci_grad
Definition: scf.h:133
double norm_ci_grad
Definition: scf.h:131
SBlockMatrix Favg_t
Definition: scf.h:110
void check_orthonormality()
Definition: scf_check_orthonormality.cc:38
void guess_occupation()
Definition: scf_guess_occupation.cc:46
SharedWavefunction mcscf(SharedWavefunction, Options &)
Definition: mcscf.cc:73
SBlockVector epsilon
Definition: scf.h:93
void cleanup()
Definition: scf.cc:199
ReferenceType
Definition: scf.h:42
SBlockMatrix e
Definition: scf.h:124
SBlockMatrix C
Definition: scf.h:96
SBlockMatrix Dtc[maxci]
Definition: scf.h:102
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:59
intvec actv
Definition: scf.h:62
intvec docc
Definition: scf.h:61
void construct_F()
Definition: scf_F.cc:34
int npairs
Definition: scf.h:83
SBlockMatrix diis_e[maxdiis]
Definition: scf.h:126
Options & options_
Options object.
Definition: wavefunction.h:106
SBlockMatrix Feff_oAO
Definition: scf.h:115
double ** H_tcscf
Definition: scf.h:134
void read_so_tei_form_PK()
Definition: scf_read_so_tei.cc:132
SBlockMatrix Favg
Definition: scf.h:109
SBlockMatrix diis_F[maxdiis]
Definition: scf.h:125
double * PK
Definition: scf.h:90
SBlockMatrix C_T
Definition: scf.h:98
Definition: scf.h:42
SBlockMatrix Dsum[maxci]
Definition: scf.h:104
Definition: liboptions.h:360
void read_so_tei_form_PK_and_K()
Definition: scf_read_so_tei.cc:215
size_t batch_index_max[maxbatches]
Definition: scf.h:76
SBlockMatrix S_sqrt_inv
Definition: scf.h:121
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:106
int nirreps
Definition: scf.h:57
Simple wavefunction base class.
Definition: wavefunction.h:84
size_t batch_pq_max[maxbatches]
Definition: scf.h:74
SBlockMatrix H
Definition: scf.h:118
SBlockMatrix Fo_t
Definition: scf.h:108
SBlockMatrix Do
Definition: scf.h:101
void diis(int cycle)
Definition: scf_diis.cc:44
SBlockMatrix S
Definition: scf.h:120
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:52
void construct_G(SBlockMatrix &density, SBlockMatrix &G, double *integrals, int batch, double factor)
Definition: scf_G.cc:53
int root
Definition: scf.h:64
void construct_Feff(int cycle)
Definition: scf_Feff.cc:36
int * pairpi
Definition: scf.h:84
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:75
void save_info()
Definition: scf_save_info.cc:51
~SCF()
Definition: scf.cc:56
int tcscf_sym[maxci]
Definition: scf.h:136
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:52
void generate_pairs()
Definition: scf_pairs.cc:42
void iterate_scf_equations()
Definition: scf_iterate_scf_equations.cc:42
SBlockMatrix Fc
Definition: scf.h:105
SBlockMatrix Dtc_old[maxci]
Definition: scf.h:103
double total_energy
Definition: scf.h:68
void initial_guess()
Definition: scf_initial_guess.cc:38
SBlockMatrix G
Definition: scf.h:116
int * block_offset
Definition: scf.h:82
void canonicalize_MO()
Definition: scf_canonicalize_MO.cc:35
SBlockMatrix Feff_t
Definition: scf.h:113
int * pairs
Definition: scf.h:85
size_t batch_pq_min[maxbatches]
Definition: scf.h:73
SBlockMatrix Fo
Definition: scf.h:107
size_t nin_core
Definition: scf.h:79
void construct_S_inverse_sqrt()
Definition: scf_S_inverse_sqrt.cc:34