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-2019 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 {
42 namespace mcscf {
43 
45 
46 class SCF : public Wavefunction {
47  public:
48  explicit SCF(SharedWavefunction ref_wfn, Options& options_, std::shared_ptr<PSIO> psio);
49  ~SCF() override;
50  double compute_energy() override;
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;
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  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 } // namespace mcscf
173 } // namespace psi
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:121
double * ci
Definition: scf.h:131
Definition: scf.h:46
double compute_energy() override
Compute energy. Subclasses override this function to compute its energy.
Definition: scf_compute_energy.cc:38
size_t total_symmetric_block_size
Definition: scf.h:78
SBlockMatrix Dc_old
Definition: scf.h:99
int ** pair
Definition: scf.h:86
intvec sopi
Definition: scf.h:60
static const int maxdiis
Definition: scf.h:55
void startup()
Definition: scf.cc:58
int nso
Definition: scf.h:59
std::shared_ptr< PSIO > psio() const
Definition: wavefunction.cc:646
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:51
Definition: scf.h:44
void print_eigenvectors_and_MO()
Definition: scf_print_eigenvectors_and_MO.cc:44
int ** pair_sym
Definition: scf.h:87
int ndiis
Definition: scf.h:65
int tcscf_mos[maxci]
Definition: scf.h:134
size_t batch_size[maxbatches]
Definition: scf.h:77
void PSI_API integrals(psi::OneBodyAOInt &integral, ambit::Tensor *target)
Definition: integrals.cc:48
Definition: scf.h:44
int * pair_offset
Definition: scf.h:88
Definition: sblock_matrix.h:42
SBlockMatrix Dc
Definition: scf.h:98
bool use_diis
Definition: scf.h:67
static const int maxci
Definition: scf.h:54
SBlockMatrix T
Definition: scf.h:116
int turn_on_actv
Definition: scf.h:63
int nbatch
Definition: scf.h:72
int nci
Definition: scf.h:129
void transform(SBlockMatrix &Initial, SBlockMatrix &Final, SBlockMatrix &Transformation)
Definition: scf.cc:242
double diis_ci[maxci][maxdiis]
Definition: scf.h:126
~SCF() override
Definition: scf.cc:52
bool out_of_core
Definition: scf.h:71
ReferenceType reference
Definition: scf.h:53
Definition: scf.h:44
void density_matrix()
Definition: scf_density_matrix.cc:34
SBlockMatrix O
Definition: scf.h:118
void write_Raffanetti(const char *integral_type, double *integrals, int batch)
Definition: scf_G.cc:114
int current_diis
Definition: scf.h:66
static const int maxbatches
Definition: scf.h:56
double * K
Definition: scf.h:91
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:39
void guess_occupation()
Definition: scf_guess_occupation.cc:45
SharedWavefunction mcscf(SharedWavefunction, Options &)
Definition: mcscf.cc:69
SBlockVector epsilon
Definition: scf.h:93
void cleanup()
Definition: scf.cc:188
ReferenceType
Definition: scf.h:44
SBlockMatrix e
Definition: scf.h:123
SBlockMatrix C
Definition: scf.h:95
SBlockMatrix Dtc[maxci]
Definition: scf.h:101
double energy() const
Definition: wavefunction.h:417
intvec actv
Definition: scf.h:62
intvec docc
Definition: scf.h:61
void construct_F()
Definition: scf_F.cc:35
int npairs
Definition: scf.h:83
SBlockMatrix diis_e[maxdiis]
Definition: scf.h:125
Options & options_
Options object.
Definition: wavefunction.h:106
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:122
SBlockMatrix Favg
Definition: scf.h:108
SBlockMatrix diis_F[maxdiis]
Definition: scf.h:124
double * PK
Definition: scf.h:90
SBlockMatrix C_T
Definition: scf.h:97
Definition: scf.h:44
SBlockMatrix Dsum[maxci]
Definition: scf.h:103
Definition: liboptions.h:353
void read_so_tei_form_PK_and_K()
Definition: scf_read_so_tei.cc:197
size_t batch_index_max[maxbatches]
Definition: scf.h:76
SBlockMatrix S_sqrt_inv
Definition: scf.h:120
void construct_Favg()
Definition: scf_F.cc:127
std::vector< int > intvec
Definition: moinfo_base.h:49
SBlockMatrix Fc_t
Definition: scf.h:105
int nirreps
Definition: scf.h:58
Simple wavefunction base class.
Definition: wavefunction.h:85
size_t batch_pq_max[maxbatches]
Definition: scf.h:74
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:45
SBlockMatrix S
Definition: scf.h:119
SCF(SharedWavefunction ref_wfn, Options &options_, std::shared_ptr< PSIO > psio)
Definition: scf.cc:46
Definition: sblock_vector.h:40
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:49
int root
Definition: scf.h:64
void construct_Feff(int cycle)
Definition: scf_Feff.cc:37
int * pairpi
Definition: scf.h:84
void read_Raffanetti(const char *integral_type, double *integrals, int batch)
Definition: scf_G.cc:106
size_t batch_index_min[maxbatches]
Definition: scf.h:75
void save_info()
Definition: scf_save_info.cc:50
int tcscf_sym[maxci]
Definition: scf.h:135
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
void generate_pairs()
Definition: scf_pairs.cc:43
void iterate_scf_equations()
Definition: scf_iterate_scf_equations.cc:43
SBlockMatrix Fc
Definition: scf.h:104
SBlockMatrix Dtc_old[maxci]
Definition: scf.h:102
double total_energy
Definition: scf.h:68
void initial_guess()
Definition: scf_initial_guess.cc:39
SBlockMatrix G
Definition: scf.h:115
int * block_offset
Definition: scf.h:82
void canonicalize_MO()
Definition: scf_canonicalize_MO.cc:36
SBlockMatrix Feff_t
Definition: scf.h:112
int * pairs
Definition: scf.h:85
size_t batch_pq_min[maxbatches]
Definition: scf.h:73
SBlockMatrix Fo
Definition: scf.h:106
size_t nin_core
Definition: scf.h:79
void construct_S_inverse_sqrt()
Definition: scf_S_inverse_sqrt.cc:35