Psi4
hf.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-2018 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 HF_H
30 #define HF_H
31 
32 #include <vector>
34 #include "psi4/libmints/vector3.h"
35 #include "psi4/psi4-dec.h"
36 
37 namespace psi {
38 class Vector;
39 class JK;
40 class PCM;
41 class SuperFunctional;
42 class VBase;
43 class BasisSet;
44 class DIISManager;
45 class PSIO;
46 namespace scf {
47 
48 class HF : public Wavefunction {
49  protected:
50  double Drms_;
51 
71  std::vector<SharedMatrix> external_potentials_;
72 
77 
81 
82  // Q: right now, thresholds are removed from Wfn since only appear once, py-side.
83  // should we instead store here the E & D to which SCF was converged?
84 
86  std::map<std::string, double> energies_;
87 
89  std::vector<std::shared_ptr<BasisSet>> sad_basissets_;
90  std::vector<std::shared_ptr<BasisSet>> sad_fitting_basissets_;
91 
93  bool ref_C_;
94 
97 
99  bool converged_;
100 
102  double nuclearrep_;
103 
106 
109 
112 
113  // Initial SAD doubly occupied may be more than ndocc
114  // int sad_nocc_[8];
120 
123  int* so2index_;
124 
126  std::string scf_type_;
127 
130 
132  std::shared_ptr<JK> jk_;
133 
140 
143 
147  std::shared_ptr<DIISManager> diis_manager_;
148 
153 
154  // parameters for hard-sphere potentials
155  double radius_; // radius of spherical potential
156  double thickness_; // thickness of spherical barrier
157  int r_points_; // number of radial integration points
158  int theta_points_; // number of colatitude integration points
159  int phi_points_; // number of azimuthal integration points
160 
162  std::shared_ptr<SuperFunctional> functional_;
163  std::shared_ptr<VBase> potential_;
164 
165  // CPHF info
168 
170  virtual void prepare_canonical_orthogonalization() { return; }
171 
173  void print_occupation();
174 
176  void common_init();
177 
179  void MOM();
181  void MOM_start();
182 
184  void frac();
185 
186  void print_stability_analysis(std::vector<std::pair<double, int>>& vec);
187 
189  void compute_fcpi();
190  void compute_fvpi();
191 
193  void print_orbital_pairs(const char* header, std::vector<std::pair<double, std::pair<std::string, int>>> orbs);
194 
198 
201 
203  int charge_;
204 
207 
209  void compute_SAD_guess();
210 
212  virtual void diagonalize_F(const SharedMatrix& F, SharedMatrix& C, std::shared_ptr<Vector>& eps);
213 
215  virtual void form_initial_C() { form_C(); }
216 
218  virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int* noccpi);
219 
222 
224  virtual void format_guess();
225 
226  public:
227  HF(SharedWavefunction ref_wfn, std::shared_ptr<SuperFunctional> funct, Options& options,
228  std::shared_ptr<PSIO> psio);
229 
230  virtual ~HF();
231 
233  int iteration() const { return iteration_; }
234  void set_iteration(int iter) { iteration_ = iter; }
235 
237  bool diis_enabled() const { return bool(diis_enabled_); }
238  void set_diis_enabled(bool tf) { diis_enabled_ = int(tf); }
239 
241  int diis_start() const { return diis_start_; }
242  void set_diis_start(int iter) { diis_start_ = iter; }
243 
245  bool frac_performed() const { return frac_performed_; }
246  void set_frac_performed(bool tf) { frac_performed_ = tf; }
247 
249  bool MOM_excited() const { return MOM_excited_; }
250  void set_MOM_excited(bool tf) { MOM_excited_ = tf; }
251 
253  bool MOM_performed() const { return MOM_performed_; }
254  void set_MOM_performed(bool tf) { MOM_performed_ = tf; }
255 
256  // Q: MOM_started_ was ditched b/c same info as MOM_performed_
257 
260  int attempt_number() const { return attempt_number_; }
261  void set_attempt_number(int an) { attempt_number_ = an; }
262 
264  virtual bool stability_analysis();
265 
267  virtual double compute_initial_E() { return 0.0; }
268 
270  void check_phases();
271 
273  void print_orbitals();
274 
276  void print_header();
277 
279  void print_preiterations();
280 
282  virtual void compute_spin_contamination();
283 
285  std::shared_ptr<DIISManager> diis_manager() const { return diis_manager_; }
288 
290  std::shared_ptr<JK> jk() const { return jk_; }
291 
293  void set_jk(std::shared_ptr<JK> jk);
294 
296  std::shared_ptr<SuperFunctional> functional() const { return functional_; }
297 
299  std::shared_ptr<VBase> V_potential() const { return potential_; }
300 
302  std::shared_ptr<Vector> occupation_a() const;
303  std::shared_ptr<Vector> occupation_b() const;
304 
306  virtual void save_density_and_energy();
307 
309  void reset_occupation();
310 
312  virtual double compute_E();
313 
315  virtual int soscf_update(double soscf_conv, int soscf_min_iter, int soscf_max_iter, int soscf_print);
316 
318  void find_occupation();
319 
321  virtual bool diis() { return false; }
322 
324  virtual double compute_orbital_gradient(bool save_diis, int max_diis_vectors) { return 0.0; }
325 
327  virtual void damping_update(double);
328 
331  virtual void finalize();
332 
338  virtual void semicanonicalize();
339 
341  void frac_renormalize();
342 
344  // Temporarily converting to virtual function for testing embedding
345  // potentials. TDC, 5/23/12.
346  virtual void form_H();
347 
349  virtual void initialize_jk(size_t effective_memory_doubles);
350 
352  void form_Shalf();
353 
355  virtual void guess();
356 
358  virtual void form_C();
359 
361  virtual void form_D();
362 
364  virtual void form_V();
365 
367  virtual void form_F();
368 
370  virtual void form_G();
371 
373  void rotate_orbitals(SharedMatrix C, const SharedMatrix x);
374 
376  virtual std::vector<SharedMatrix> onel_Hx(std::vector<SharedMatrix> x);
377  virtual std::vector<SharedMatrix> twoel_Hx(std::vector<SharedMatrix> x, bool combine = true,
378  std::string return_basis = "MO");
379  virtual std::vector<SharedMatrix> cphf_Hx(std::vector<SharedMatrix> x);
380  virtual std::vector<SharedMatrix> cphf_solve(std::vector<SharedMatrix> x_vec, double conv_tol = 1.e-4,
381  int max_iter = 10, int print_lvl = 1);
382 
383  // CPHF data
384  bool cphf_converged() { return cphf_converged_; }
386 
387  // Return the DFT potenitals
388  SharedMatrix Va() { return Va_; }
389  SharedMatrix Vb() { return Vb_; }
390 
391  // Set guess occupied orbitals, nalpha and nbeta will be taken from the number of passed in eigenvectors
394 
395  // Expert option to reset the occuption or not at iteration zero
396  bool reset_occ() const { return reset_occ_; }
397  void set_reset_occ(bool reset) { reset_occ_ = reset; }
398 
399  // SAD information
400  void set_sad_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) { sad_basissets_ = basis_vec; }
401  void set_sad_fitting_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) {
402  sad_fitting_basissets_ = basis_vec;
403  }
404 
405  // Energies data
406  void set_energies(std::string key, double value) { energies_[key] = value; }
407  double get_energies(std::string key) { return energies_[key]; }
408 
409  // External potentials
412 };
413 } // namespace scf
414 } // namespace psi
415 
416 #endif
virtual void form_initial_C()
Definition: hf.h:215
int multiplicity_
The multiplicity of the system (specified as 2 Ms + 1)
Definition: hf.h:206
std::shared_ptr< Vector > occupation_a() const
Returns the occupation vectors.
Definition: hf.cc:1222
int * so2index_
Definition: hf.h:123
Options & options() const
Definition: wavefunction.cc:572
void print_stability_analysis(std::vector< std::pair< double, int >> &vec)
Definition: hf.cc:1332
SharedMatrix T_
The kinetic energy matrix.
Definition: hf.h:53
bool MOM_performed_
MOM performed?
Definition: hf.h:139
void set_iteration(int iter)
Definition: hf.h:234
std::shared_ptr< Vector > occupation_b() const
Definition: hf.cc:1231
SharedMatrix Ca_old_
Old C Alpha matrix (if needed for MOM)
Definition: hf.h:74
int diis_start() const
When do we start collecting vectors for DIIS.
Definition: hf.h:241
std::shared_ptr< PSIO > psio() const
Definition: wavefunction.cc:570
SharedMatrix Cb() const
Returns the beta electrons MO coefficients.
Definition: wavefunction.cc:664
bool reset_occ_
Definition: hf.h:119
int original_nbeta_
Definition: hf.h:118
std::shared_ptr< VBase > potential_
Definition: hf.h:163
void MOM()
Maximum overlap method for prevention of oscillation/excited state SCF.
Definition: mom.cc:593
int iteration() const
Get and set current iteration.
Definition: hf.h:233
std::shared_ptr< DIISManager > diis_manager() const
The DIIS object.
Definition: hf.h:285
bool diis_enabled() const
Are we even using DIIS?
Definition: hf.h:237
bool input_docc_
DOCC vector from input (if found)
Definition: hf.h:105
std::map< std::string, double > energies_
Table of energy components.
Definition: hf.h:86
double ** scf
Definition: dx_write.cc:57
virtual void form_V()
Computes the density matrix (V_)
Definition: hf.cc:288
SharedMatrix Vb_
Definition: hf.h:60
std::vector< std::shared_ptr< BasisSet > > sad_fitting_basissets_
Definition: hf.h:90
double integral_threshold_
The value below which integrals are neglected.
Definition: hf.h:129
virtual double compute_initial_E()
Definition: hf.h:267
void frac()
Fractional occupation UHF/UKS.
Definition: frac.cc:67
void guess_Ca(SharedMatrix Ca)
Definition: hf.h:392
virtual std::vector< SharedMatrix > cphf_solve(std::vector< SharedMatrix > x_vec, double conv_tol=1.e-4, int max_iter=10, int print_lvl=1)
Definition: hf.cc:301
std::shared_ptr< DIISManager > diis_manager_
DIIS manager for all SCF wavefunctions.
Definition: hf.h:147
SharedMatrix Va()
Definition: hf.h:388
double thickness_
Definition: hf.h:156
std::shared_ptr< SuperFunctional > functional() const
The DFT Functional object (or null if it has been deleted)
Definition: hf.h:296
double Drms_
Definition: hf.h:50
SharedMatrix Cb_old_
Old C Beta matrix (if needed for MOM)
Definition: hf.h:76
virtual std::vector< SharedMatrix > onel_Hx(std::vector< SharedMatrix > x)
Hessian-vector computers and solvers.
Definition: hf.cc:292
void check_phases()
Check MO phases.
Definition: hf.cc:1164
double get_energies(std::string key)
Definition: hf.h:407
void print_header()
Prints some opening information.
Definition: hf.cc:504
virtual std::vector< SharedMatrix > twoel_Hx(std::vector< SharedMatrix > x, bool combine=true, std::string return_basis="MO")
Definition: hf.cc:295
void print_occupation()
Prints the orbital occupation.
Definition: hf.cc:1194
virtual void form_G()
Definition: hf.cc:308
virtual void format_guess()
Definition: hf.cc:1160
SharedMatrix diag_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:64
std::vector< SharedMatrix > external_potentials_
Definition: hf.h:71
int attempt_number_
Definition: hf.h:197
SharedMatrix guess_Ca_
User defined orbitals.
Definition: hf.h:79
void guess_Cb(SharedMatrix Cb)
Definition: hf.h:393
int diis_enabled_
Are we even using DIIS?
Definition: hf.h:152
virtual void form_D()
Computes the density matrix (D_)
Definition: hf.cc:290
void print_preiterations()
Prints some details about nsopi/nmopi, and initial occupations.
Definition: hf.cc:552
virtual void form_F()
Definition: hf.cc:309
SharedMatrix Ca() const
Returns the alpha electrons MO coefficients.
Definition: wavefunction.cc:653
std::shared_ptr< JK > jk_
The soon to be ubiquitous JK object.
Definition: hf.h:132
void push_back_external_potential(const SharedMatrix &V)
Definition: hf.h:411
virtual void compute_spin_contamination()
Definition: frac.cc:225
bool MOM_enabled_
Are we to do MOM?
Definition: hf.h:135
virtual void finalize()
Definition: hf.cc:393
bool converged_
Did the SCF converge?
Definition: hf.h:99
void set_sad_fitting_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:401
virtual ~HF()
Definition: hf.cc:87
SharedMatrix diag_F_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:66
void print_orbitals()
Prints the orbitals in arbitrary order (works with MOM)
Definition: hf.cc:906
void set_attempt_number(int an)
Definition: hf.h:261
virtual void damping_update(double)
Definition: hf.cc:276
int attempt_number() const
Definition: hf.h:260
virtual void initialize_jk(size_t effective_memory_doubles)
Do any needed integral JK setup.
Definition: hf.cc:352
void set_MOM_excited(bool tf)
Definition: hf.h:250
bool input_socc_
SOCC vector from input (if found)
Definition: hf.h:108
std::shared_ptr< VBase > V_potential() const
The DFT Potential object (or null if it has been deleted)
Definition: hf.h:299
void compute_fvpi()
Definition: hf.cc:873
bool cphf_converged_
Definition: hf.h:167
void set_energies(std::string key, double value)
Definition: hf.h:406
virtual void save_density_and_energy()
Save the current density and energy.
Definition: hf.cc:305
virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int *noccpi)
Definition: hf.cc:1263
std::string scf_type_
SCF algorithm type.
Definition: hf.h:126
SharedMatrix X_
The orthogonalization matrix (symmetric or canonical)
Definition: hf.h:62
double nuclearrep_
Nuclear repulsion energy.
Definition: hf.h:102
double radius_
Definition: hf.h:155
bool broken_symmetry_
Whether its broken symmetry solution or not.
Definition: hf.h:111
bool MOM_excited_
Are we to do excited-state MOM?
Definition: hf.h:137
SharedMatrix Horig_
A temporary spot for the H matrix.
Definition: hf.h:57
void form_Shalf()
Formation of S^+1/2 and S^-1/2 are the same.
Definition: hf.cc:729
virtual bool diis()
Definition: hf.h:321
std::shared_ptr< SuperFunctional > functional_
DFT variables.
Definition: hf.h:162
void rotate_orbitals(SharedMatrix C, const SharedMatrix x)
Definition: hf.cc:311
bool MOM_performed() const
MOM performed?
Definition: hf.h:253
virtual bool stability_analysis()
Check the stability of the wavefunction, and correct (if requested)
Definition: hf.cc:1353
Definition: dimension.h:40
bool initialized_diis_manager_
DIIS manager intiialized?
Definition: hf.h:145
virtual void form_C()
Compute the MO coefficients (C_)
Definition: hf.cc:289
Definition: liboptions.h:353
virtual int soscf_update(double soscf_conv, int soscf_min_iter, int soscf_max_iter, int soscf_print)
Definition: hf.cc:282
void set_MOM_performed(bool tf)
Definition: hf.h:254
virtual void semicanonicalize()
Definition: hf.cc:430
virtual double compute_orbital_gradient(bool save_diis, int max_diis_vectors)
Definition: hf.h:324
int cphf_nfock_builds_
Definition: hf.h:166
void set_diis_enabled(bool tf)
Definition: hf.h:238
void set_jk(std::shared_ptr< JK > jk)
Sets the internal JK object (expert)
Definition: hf.cc:419
virtual double compute_E()
Compute energy for the iteration.
Definition: hf.cc:310
virtual std::vector< SharedMatrix > cphf_Hx(std::vector< SharedMatrix > x)
Definition: hf.cc:298
void MOM_start()
Start the MOM algorithm (requires one iteration worth of setup)
Definition: mom.cc:63
Dimension original_doccpi_
Definition: hf.h:115
int diis_start_
When do we start collecting vectors for DIIS.
Definition: hf.h:150
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_sad_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:400
std::shared_ptr< JK > jk() const
The JK object (or null if it has been deleted)
Definition: hf.h:290
Simple wavefunction base class.
Definition: wavefunction.h:85
bool cphf_converged()
Definition: hf.h:384
int nelectron_
The number of electrons.
Definition: hf.h:200
virtual void prepare_canonical_orthogonalization()
Edit matrices if we are doing canonical orthogonalization.
Definition: hf.h:170
int theta_points_
Definition: hf.h:158
int charge_
The charge of the system.
Definition: hf.h:203
SharedMatrix V_
The 1e potential energy matrix.
Definition: hf.h:55
SharedMatrix Vb()
Definition: hf.h:389
void set_reset_occ(bool reset)
Definition: hf.h:397
int cphf_nfock_builds()
Definition: hf.h:385
bool initialized_diis_manager() const
Definition: hf.h:287
Definition: hf.h:48
int original_nalpha_
Definition: hf.h:117
void common_init()
Common initializer.
Definition: hf.cc:89
std::vector< std::shared_ptr< BasisSet > > sad_basissets_
Basis list for SAD.
Definition: hf.h:89
HF(SharedWavefunction ref_wfn, std::shared_ptr< SuperFunctional > funct, Options &options, std::shared_ptr< PSIO > psio)
Definition: hf.cc:80
void clear_external_potentials()
Definition: hf.h:410
void compute_SAD_guess()
SAD Guess and propagation.
Definition: sad.cc:620
bool frac_performed() const
Frac performed current iteration?
Definition: hf.h:245
void reset_occupation()
Reset to regular occupation from the fractional occupation.
Definition: hf.cc:1251
bool frac_performed_
Frac started? (Same thing as frac_performed_)
Definition: hf.h:142
bool MOM_excited() const
Are we to do excited-state MOM?
Definition: hf.h:249
void set_frac_performed(bool tf)
Definition: hf.h:246
void set_diis_start(int iter)
Definition: hf.h:242
void set_initialized_diis_manager(bool tf)
Definition: hf.h:286
void find_occupation()
Figure out how to occupy the orbitals in the absence of DOCC and SOCC.
Definition: hf.cc:432
virtual void form_H()
Formation of H is the same regardless of RHF, ROHF, UHF.
Definition: hf.cc:567
Dimension original_soccpi_
Definition: hf.h:116
int r_points_
Definition: hf.h:157
void print_orbital_pairs(const char *header, std::vector< std::pair< double, std::pair< std::string, int >>> orbs)
Prints the orbitals energies and symmetries (helper method)
Definition: hf.cc:896
virtual void diagonalize_F(const SharedMatrix &F, SharedMatrix &C, std::shared_ptr< Vector > &eps)
Definition: hf.cc:1239
int phi_points_
Definition: hf.h:159
virtual SharedMatrix form_FDSmSDF(SharedMatrix Fso, SharedMatrix Dso)
Definition: hf.cc:1309
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
SharedMatrix diag_C_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:68
void frac_renormalize()
Renormalize orbitals to 1.0 before saving.
Definition: frac.cc:184
void compute_fcpi()
Determine how many core and virtual orbitals to freeze.
Definition: hf.cc:842
int iteration_
Current Iteration.
Definition: hf.h:96
SharedMatrix Va_
The DFT potential matrices (nice naming scheme)
Definition: hf.h:59
bool ref_C_
Definition: hf.h:93
virtual void guess()
Form the guess (guarantees C, D, and E)
Definition: hf.cc:1012
int * so2symblk_
Mapping arrays.
Definition: hf.h:122
bool reset_occ() const
Definition: hf.h:396
SharedMatrix guess_Cb_
Definition: hf.h:80