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-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 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:
69  std::vector<SharedMatrix> external_potentials_;
70 
75 
79 
80  // Q: right now, thresholds are removed from Wfn since only appear once, py-side.
81  // should we instead store here the E & D to which SCF was converged?
82 
84  std::map<std::string, double> energies_;
85 
87  std::vector<std::shared_ptr<BasisSet>> sad_basissets_;
88  std::vector<std::shared_ptr<BasisSet>> sad_fitting_basissets_;
89 
91  bool ref_C_;
92 
95 
97  bool converged_;
98 
100  double nuclearrep_;
101 
104 
107 
110 
111  // Initial SAD doubly occupied may be more than ndocc
112  // int sad_nocc_[8];
117  // Reset occupations in SCF iteration?
119  // SAD guess, non-idempotent guess density?
120  bool sad_;
121 
124  int* so2index_;
125 
127  std::string scf_type_;
128 
131 
133  std::shared_ptr<JK> jk_;
134 
141 
144 
148  std::shared_ptr<DIISManager> diis_manager_;
149 
154 
155  // parameters for hard-sphere potentials
156  double radius_; // radius of spherical potential
157  double thickness_; // thickness of spherical barrier
158  int r_points_; // number of radial integration points
159  int theta_points_; // number of colatitude integration points
160  int phi_points_; // number of azimuthal integration points
161 
163  std::shared_ptr<SuperFunctional> functional_;
164  std::shared_ptr<VBase> potential_;
165 
166  // CPHF info
169 
171  virtual void prepare_canonical_orthogonalization() { return; }
172 
174  void print_occupation();
175 
177  void common_init();
178 
180  void MOM();
182  void MOM_start();
183 
185  void frac();
186 
187  void print_stability_analysis(std::vector<std::pair<double, int>>& vec);
188 
190  void compute_fcpi();
191  void compute_fvpi();
192 
194  void print_orbital_pairs(const char* header, std::vector<std::pair<double, std::pair<std::string, int>>> orbs);
195 
199 
202 
204  int charge_;
205 
208 
210  virtual void compute_SAD_guess();
212  virtual void compute_huckel_guess();
213 
215  virtual void diagonalize_F(const SharedMatrix& F, SharedMatrix& C, std::shared_ptr<Vector>& eps);
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  ~HF() override;
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_gtfock_jk();
350 
352  void form_Shalf();
353 
355  virtual void guess();
356 
358  virtual void form_C();
360  virtual void form_initial_C() { form_C(); }
361 
363  virtual void form_D();
364 
366  virtual void form_V();
367 
369  virtual void form_F();
371  virtual void form_initial_F() { form_F(); }
372 
374  virtual void form_G();
375 
377  void rotate_orbitals(SharedMatrix C, const SharedMatrix x);
378 
380  virtual std::vector<SharedMatrix> onel_Hx(std::vector<SharedMatrix> x);
381  virtual std::vector<SharedMatrix> twoel_Hx(std::vector<SharedMatrix> x, bool combine = true,
382  std::string return_basis = "MO");
383  virtual std::vector<SharedMatrix> cphf_Hx(std::vector<SharedMatrix> x);
384  virtual std::vector<SharedMatrix> cphf_solve(std::vector<SharedMatrix> x_vec, double conv_tol = 1.e-4,
385  int max_iter = 10, int print_lvl = 1);
386 
387  // CPHF data
388  bool cphf_converged() { return cphf_converged_; }
390 
391  // Return the DFT potenitals
392  SharedMatrix Va() { return Va_; }
393  SharedMatrix Vb() { return Vb_; }
394 
395  // Set guess occupied orbitals, nalpha and nbeta will be taken from the number of passed in eigenvectors
398 
399  // Expert option to reset the occuption or not at iteration zero
400  bool reset_occ() const { return reset_occ_; }
401  void set_reset_occ(bool reset) { reset_occ_ = reset; }
402  // Expert option to toggle non-idempotent density matrix or not at iteration zero
403  bool sad() const { return sad_; }
404  void set_sad(bool sad) { sad_ = sad; }
405 
406  // SAD information
407  void set_sad_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) { sad_basissets_ = basis_vec; }
408  void set_sad_fitting_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) {
409  sad_fitting_basissets_ = basis_vec;
410  }
411 
412  // Energies data
413  void set_energies(std::string key, double value) { energies_[key] = value; }
414  double get_energies(std::string key) { return energies_[key]; }
415 
416  // External potentials
419 };
420 } // namespace scf
421 } // namespace psi
422 
423 #endif
virtual void form_initial_C()
Definition: hf.h:360
int multiplicity_
The multiplicity of the system (specified as 2 Ms + 1)
Definition: hf.h:207
std::shared_ptr< Vector > occupation_a() const
Returns the occupation vectors.
Definition: hf.cc:1215
int * so2index_
Definition: hf.h:124
Options & options() const
Definition: wavefunction.cc:645
void print_stability_analysis(std::vector< std::pair< double, int >> &vec)
Definition: hf.cc:1325
SharedMatrix T_
The kinetic energy matrix.
Definition: hf.h:51
bool MOM_performed_
MOM performed?
Definition: hf.h:140
void set_iteration(int iter)
Definition: hf.h:234
std::shared_ptr< Vector > occupation_b() const
Definition: hf.cc:1224
SharedMatrix Ca_old_
Old C Alpha matrix (if needed for MOM)
Definition: hf.h:72
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:643
SharedMatrix Cb() const
Returns the beta electrons MO coefficients.
Definition: wavefunction.cc:737
virtual void initialize_gtfock_jk()
Do any needed integral JK setup.
Definition: hf.cc:345
bool reset_occ_
Definition: hf.h:118
int original_nbeta_
Definition: hf.h:116
std::shared_ptr< VBase > potential_
Definition: hf.h:164
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:103
std::map< std::string, double > energies_
Table of energy components.
Definition: hf.h:84
double ** scf
Definition: dx_write.cc:57
virtual void form_V()
Computes the density matrix (V_)
Definition: hf.cc:281
SharedMatrix Vb_
Definition: hf.h:58
std::vector< std::shared_ptr< BasisSet > > sad_fitting_basissets_
Definition: hf.h:88
double integral_threshold_
The value below which integrals are neglected.
Definition: hf.h:130
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:396
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:294
std::shared_ptr< DIISManager > diis_manager_
DIIS manager for all SCF wavefunctions.
Definition: hf.h:148
SharedMatrix Va()
Definition: hf.h:392
virtual void form_initial_F()
Definition: hf.h:371
double thickness_
Definition: hf.h:157
std::shared_ptr< SuperFunctional > functional() const
The DFT Functional object (or null if it has been deleted)
Definition: hf.h:296
SharedMatrix Cb_old_
Old C Beta matrix (if needed for MOM)
Definition: hf.h:74
virtual std::vector< SharedMatrix > onel_Hx(std::vector< SharedMatrix > x)
Hessian-vector computers and solvers.
Definition: hf.cc:285
void check_phases()
Check MO phases.
Definition: hf.cc:1157
double get_energies(std::string key)
Definition: hf.h:414
void print_header()
Prints some opening information.
Definition: hf.cc:472
virtual std::vector< SharedMatrix > twoel_Hx(std::vector< SharedMatrix > x, bool combine=true, std::string return_basis="MO")
Definition: hf.cc:288
void print_occupation()
Prints the orbital occupation.
Definition: hf.cc:1187
virtual void form_G()
Definition: hf.cc:301
virtual void format_guess()
Definition: hf.cc:1153
SharedMatrix diag_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:62
std::vector< SharedMatrix > external_potentials_
Definition: hf.h:69
bool sad_
Definition: hf.h:120
int attempt_number_
Definition: hf.h:198
SharedMatrix guess_Ca_
User defined orbitals.
Definition: hf.h:77
void guess_Cb(SharedMatrix Cb)
Definition: hf.h:397
int diis_enabled_
Are we even using DIIS?
Definition: hf.h:153
virtual void form_D()
Computes the density matrix (D_)
Definition: hf.cc:283
void print_preiterations()
Prints some details about nsopi/nmopi, and initial occupations.
Definition: hf.cc:520
virtual void form_F()
Definition: hf.cc:302
SharedMatrix Ca() const
Returns the alpha electrons MO coefficients.
Definition: wavefunction.cc:726
std::shared_ptr< JK > jk_
The soon to be ubiquitous JK object.
Definition: hf.h:133
void push_back_external_potential(const SharedMatrix &V)
Definition: hf.h:418
virtual void compute_spin_contamination()
Definition: frac.cc:225
bool MOM_enabled_
Are we to do MOM?
Definition: hf.h:136
virtual void finalize()
Definition: hf.cc:361
bool converged_
Did the SCF converge?
Definition: hf.h:97
void set_sad_fitting_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:408
SharedMatrix diag_F_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:64
void print_orbitals()
Prints the orbitals in arbitrary order (works with MOM)
Definition: hf.cc:874
void set_attempt_number(int an)
Definition: hf.h:261
virtual void damping_update(double)
Definition: hf.cc:269
int attempt_number() const
Definition: hf.h:260
void set_MOM_excited(bool tf)
Definition: hf.h:250
bool input_socc_
SOCC vector from input (if found)
Definition: hf.h:106
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:841
bool cphf_converged_
Definition: hf.h:168
void set_energies(std::string key, double value)
Definition: hf.h:413
virtual void save_density_and_energy()
Save the current density and energy.
Definition: hf.cc:298
virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int *noccpi)
Definition: hf.cc:1256
std::string scf_type_
SCF algorithm type.
Definition: hf.h:127
SharedMatrix X_
The orthogonalization matrix (symmetric or canonical)
Definition: hf.h:60
double nuclearrep_
Nuclear repulsion energy.
Definition: hf.h:100
double radius_
Definition: hf.h:156
bool broken_symmetry_
Whether its broken symmetry solution or not.
Definition: hf.h:109
bool MOM_excited_
Are we to do excited-state MOM?
Definition: hf.h:138
SharedMatrix Horig_
A temporary spot for the H matrix.
Definition: hf.h:55
void form_Shalf()
Formation of S^+1/2 and S^-1/2 are the same.
Definition: hf.cc:697
virtual bool diis()
Definition: hf.h:321
std::shared_ptr< SuperFunctional > functional_
DFT variables.
Definition: hf.h:163
void rotate_orbitals(SharedMatrix C, const SharedMatrix x)
Definition: hf.cc:304
bool MOM_performed() const
MOM performed?
Definition: hf.h:253
virtual void compute_huckel_guess()
Huckel guess.
Definition: sad.cc:797
virtual bool stability_analysis()
Check the stability of the wavefunction, and correct (if requested)
Definition: hf.cc:1346
Definition: dimension.h:40
bool initialized_diis_manager_
DIIS manager intiialized?
Definition: hf.h:146
virtual void form_C()
Compute the MO coefficients (C_)
Definition: hf.cc:282
Definition: liboptions.h:352
void set_sad(bool sad)
Definition: hf.h:404
virtual int soscf_update(double soscf_conv, int soscf_min_iter, int soscf_max_iter, int soscf_print)
Definition: hf.cc:275
void set_MOM_performed(bool tf)
Definition: hf.h:254
virtual void semicanonicalize()
Definition: hf.cc:398
virtual double compute_orbital_gradient(bool save_diis, int max_diis_vectors)
Definition: hf.h:324
int cphf_nfock_builds_
Definition: hf.h:167
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:387
virtual double compute_E()
Compute energy for the iteration.
Definition: hf.cc:303
virtual std::vector< SharedMatrix > cphf_Hx(std::vector< SharedMatrix > x)
Definition: hf.cc:291
void MOM_start()
Start the MOM algorithm (requires one iteration worth of setup)
Definition: mom.cc:63
Dimension original_doccpi_
Definition: hf.h:113
int diis_start_
When do we start collecting vectors for DIIS.
Definition: hf.h:151
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_sad_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:407
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:388
bool sad() const
Definition: hf.h:403
int nelectron_
The number of electrons.
Definition: hf.h:201
virtual void prepare_canonical_orthogonalization()
Edit matrices if we are doing canonical orthogonalization.
Definition: hf.h:171
int theta_points_
Definition: hf.h:159
int charge_
The charge of the system.
Definition: hf.h:204
SharedMatrix V_
The 1e potential energy matrix.
Definition: hf.h:53
SharedMatrix Vb()
Definition: hf.h:393
void set_reset_occ(bool reset)
Definition: hf.h:401
int cphf_nfock_builds()
Definition: hf.h:389
bool initialized_diis_manager() const
Definition: hf.h:287
~HF() override
Definition: hf.cc:86
Definition: hf.h:48
int original_nalpha_
Definition: hf.h:115
void common_init()
Common initializer.
Definition: hf.cc:88
std::vector< std::shared_ptr< BasisSet > > sad_basissets_
Basis list for SAD.
Definition: hf.h:87
HF(SharedWavefunction ref_wfn, std::shared_ptr< SuperFunctional > funct, Options &options, std::shared_ptr< PSIO > psio)
Definition: hf.cc:79
void clear_external_potentials()
Definition: hf.h:417
virtual void compute_SAD_guess()
SAD Guess and propagation.
Definition: sad.cc:747
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:1244
bool frac_performed_
Frac started? (Same thing as frac_performed_)
Definition: hf.h:143
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:400
virtual void form_H()
Formation of H is the same regardless of RHF, ROHF, UHF.
Definition: hf.cc:535
Dimension original_soccpi_
Definition: hf.h:114
int r_points_
Definition: hf.h:158
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:864
virtual void diagonalize_F(const SharedMatrix &F, SharedMatrix &C, std::shared_ptr< Vector > &eps)
Definition: hf.cc:1232
int phi_points_
Definition: hf.h:160
virtual SharedMatrix form_FDSmSDF(SharedMatrix Fso, SharedMatrix Dso)
Definition: hf.cc:1302
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
SharedMatrix diag_C_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:66
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:810
int iteration_
Current Iteration.
Definition: hf.h:94
SharedMatrix Va_
The DFT potential matrices (nice naming scheme)
Definition: hf.h:57
bool ref_C_
Definition: hf.h:91
virtual void guess()
Form the guess (guarantees C, D, and E)
Definition: hf.cc:980
int * so2symblk_
Mapping arrays.
Definition: hf.h:123
bool reset_occ() const
Definition: hf.h:400
SharedMatrix guess_Cb_
Definition: hf.h:78