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 
92 
94  bool converged_;
95 
97  double nuclearrep_;
98 
101 
104 
107 
108  // Initial SAD doubly occupied may be more than ndocc
109  // int sad_nocc_[8];
114  // Reset occupations in SCF iteration?
116  // SAD guess, non-idempotent guess density?
117  bool sad_;
118 
121  int* so2index_;
122 
124  std::string scf_type_;
125 
128 
130  std::shared_ptr<JK> jk_;
131 
138 
141 
145  std::shared_ptr<DIISManager> diis_manager_;
146 
151 
152  // parameters for hard-sphere potentials
153  double radius_; // radius of spherical potential
154  double thickness_; // thickness of spherical barrier
155  int r_points_; // number of radial integration points
156  int theta_points_; // number of colatitude integration points
157  int phi_points_; // number of azimuthal integration points
158 
160  std::shared_ptr<SuperFunctional> functional_;
161  std::shared_ptr<VBase> potential_;
162 
163  // CPHF info
166 
168  virtual void prepare_canonical_orthogonalization() { return; }
169 
171  void print_occupation();
172 
174  void common_init();
175 
177  void MOM();
179  void MOM_start();
180 
182  void frac();
183 
184  void print_stability_analysis(std::vector<std::pair<double, int>>& vec);
185 
187  void compute_fcpi();
188  void compute_fvpi();
189 
191  void print_orbital_pairs(const char* header, std::vector<std::pair<double, std::pair<std::string, int>>> orbs);
192 
196 
199 
201  int charge_;
202 
205 
207  virtual void compute_SAD_guess(bool natorb);
209  virtual void compute_huckel_guess();
210 
212  virtual void diagonalize_F(const SharedMatrix& F, SharedMatrix& C, std::shared_ptr<Vector>& eps);
213 
215  virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int* noccpi);
216 
219 
221  virtual void format_guess();
222 
223  public:
224  HF(SharedWavefunction ref_wfn, std::shared_ptr<SuperFunctional> funct, Options& options,
225  std::shared_ptr<PSIO> psio);
226 
227  ~HF() override;
228 
230  int iteration() const { return iteration_; }
231  void set_iteration(int iter) { iteration_ = iter; }
232 
234  bool diis_enabled() const { return bool(diis_enabled_); }
235  void set_diis_enabled(bool tf) { diis_enabled_ = int(tf); }
236 
238  int diis_start() const { return diis_start_; }
239  void set_diis_start(int iter) { diis_start_ = iter; }
240 
242  bool frac_performed() const { return frac_performed_; }
243  void set_frac_performed(bool tf) { frac_performed_ = tf; }
244 
246  bool MOM_excited() const { return MOM_excited_; }
247  void set_MOM_excited(bool tf) { MOM_excited_ = tf; }
248 
250  bool MOM_performed() const { return MOM_performed_; }
251  void set_MOM_performed(bool tf) { MOM_performed_ = tf; }
252 
253  // Q: MOM_started_ was ditched b/c same info as MOM_performed_
254 
257  int attempt_number() const { return attempt_number_; }
258  void set_attempt_number(int an) { attempt_number_ = an; }
259 
261  virtual bool stability_analysis();
262 
264  virtual double compute_initial_E() { return 0.0; }
265 
267  void check_phases();
268 
270  void print_orbitals();
271 
273  void print_header();
274 
276  virtual void compute_spin_contamination();
277 
279  std::shared_ptr<DIISManager> diis_manager() const { return diis_manager_; }
282 
284  std::shared_ptr<JK> jk() const { return jk_; }
285 
287  void set_jk(std::shared_ptr<JK> jk);
288 
290  std::shared_ptr<SuperFunctional> functional() const { return functional_; }
291 
293  std::shared_ptr<VBase> V_potential() const { return potential_; }
294 
296  std::shared_ptr<Vector> occupation_a() const;
297  std::shared_ptr<Vector> occupation_b() const;
298 
300  virtual void save_density_and_energy();
301 
303  void reset_occupation();
304 
306  virtual double compute_E();
307 
309  virtual int soscf_update(double soscf_conv, int soscf_min_iter, int soscf_max_iter, int soscf_print);
310 
312  void find_occupation();
313 
315  virtual bool diis() { return false; }
316 
318  virtual double compute_orbital_gradient(bool save_diis, int max_diis_vectors) { return 0.0; }
319 
321  virtual void damping_update(double);
322 
325  virtual void finalize();
326 
332  virtual void semicanonicalize();
333 
335  void frac_renormalize();
336 
338  // Temporarily converting to virtual function for testing embedding
339  // potentials. TDC, 5/23/12.
340  virtual void form_H();
341 
343  virtual void initialize_gtfock_jk();
344 
346  void form_Shalf();
347 
349  virtual void guess();
350 
352  virtual void form_C();
354  virtual void form_initial_C() { form_C(); }
355 
357  virtual void form_D();
358 
360  virtual void form_V();
361 
363  virtual void form_F();
365  virtual void form_initial_F() { form_F(); }
366 
368  virtual void form_G();
369 
371  void rotate_orbitals(SharedMatrix C, const SharedMatrix x);
372 
374  virtual std::vector<SharedMatrix> onel_Hx(std::vector<SharedMatrix> x);
375  virtual std::vector<SharedMatrix> twoel_Hx(std::vector<SharedMatrix> x, bool combine = true,
376  std::string return_basis = "MO");
377  virtual std::vector<SharedMatrix> cphf_Hx(std::vector<SharedMatrix> x);
378  virtual std::vector<SharedMatrix> cphf_solve(std::vector<SharedMatrix> x_vec, double conv_tol = 1.e-4,
379  int max_iter = 10, int print_lvl = 1);
380 
381  // CPHF data
382  bool cphf_converged() { return cphf_converged_; }
384 
385  // Return the DFT potenitals
386  SharedMatrix Va() { return Va_; }
387  SharedMatrix Vb() { return Vb_; }
388 
389  // Set guess occupied orbitals, nalpha and nbeta will be taken from the number of passed in eigenvectors
392 
393  // Expert option to reset the occuption or not at iteration zero
394  bool reset_occ() const { return reset_occ_; }
395  void set_reset_occ(bool reset) { reset_occ_ = reset; }
396  // Expert option to toggle non-idempotent density matrix or not at iteration zero
397  bool sad() const { return sad_; }
398  void set_sad(bool sad) { sad_ = sad; }
399 
400  // SAD information
401  void set_sad_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) { sad_basissets_ = basis_vec; }
402  void set_sad_fitting_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) {
403  sad_fitting_basissets_ = basis_vec;
404  }
405 
406  // Energies data
407  void set_energies(std::string key, double value) { energies_[key] = value; }
408  double get_energies(std::string key) { return energies_[key]; }
409 
410  // External potentials
413 };
414 } // namespace scf
415 } // namespace psi
416 
417 #endif
virtual void form_initial_C()
Definition: hf.h:354
int multiplicity_
The multiplicity of the system (specified as 2 Ms + 1)
Definition: hf.h:204
std::shared_ptr< Vector > occupation_a() const
Returns the occupation vectors.
Definition: hf.cc:1250
int * so2index_
Definition: hf.h:121
Options & options() const
Definition: wavefunction.cc:648
void print_stability_analysis(std::vector< std::pair< double, int >> &vec)
Definition: hf.cc:1360
SharedMatrix T_
The kinetic energy matrix.
Definition: hf.h:51
bool MOM_performed_
MOM performed?
Definition: hf.h:137
void set_iteration(int iter)
Definition: hf.h:231
std::shared_ptr< Vector > occupation_b() const
Definition: hf.cc:1259
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:238
std::shared_ptr< PSIO > psio() const
Definition: wavefunction.cc:646
SharedMatrix Cb() const
Returns the beta electrons MO coefficients.
Definition: wavefunction.cc:740
virtual void initialize_gtfock_jk()
Do any needed integral JK setup.
Definition: hf.cc:352
bool reset_occ_
Definition: hf.h:115
int original_nbeta_
Definition: hf.h:113
std::shared_ptr< VBase > potential_
Definition: hf.h:161
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:230
std::shared_ptr< DIISManager > diis_manager() const
The DIIS object.
Definition: hf.h:279
bool diis_enabled() const
Are we even using DIIS?
Definition: hf.h:234
bool input_docc_
DOCC vector from input (if found)
Definition: hf.h:100
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:288
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:127
virtual double compute_initial_E()
Definition: hf.h:264
void frac()
Fractional occupation UHF/UKS.
Definition: frac.cc:67
void guess_Ca(SharedMatrix Ca)
Definition: hf.h:390
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:145
SharedMatrix Va()
Definition: hf.h:386
virtual void form_initial_F()
Definition: hf.h:365
double thickness_
Definition: hf.h:154
std::shared_ptr< SuperFunctional > functional() const
The DFT Functional object (or null if it has been deleted)
Definition: hf.h:290
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:292
void check_phases()
Check MO phases.
Definition: hf.cc:1192
double get_energies(std::string key)
Definition: hf.h:408
void print_header()
Prints some opening information.
Definition: hf.cc:479
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:1222
virtual void form_G()
Definition: hf.cc:308
virtual void format_guess()
Definition: hf.cc:1188
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:117
int attempt_number_
Definition: hf.h:195
SharedMatrix guess_Ca_
User defined orbitals.
Definition: hf.h:77
void guess_Cb(SharedMatrix Cb)
Definition: hf.h:391
int diis_enabled_
Are we even using DIIS?
Definition: hf.h:150
virtual void form_D()
Computes the density matrix (D_)
Definition: hf.cc:290
virtual void form_F()
Definition: hf.cc:309
SharedMatrix Ca() const
Returns the alpha electrons MO coefficients.
Definition: wavefunction.cc:729
std::shared_ptr< JK > jk_
The soon to be ubiquitous JK object.
Definition: hf.h:130
void push_back_external_potential(const SharedMatrix &V)
Definition: hf.h:412
virtual void compute_spin_contamination()
Definition: frac.cc:225
bool MOM_enabled_
Are we to do MOM?
Definition: hf.h:133
virtual void finalize()
Definition: hf.cc:368
bool converged_
Did the SCF converge?
Definition: hf.h:94
void set_sad_fitting_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:402
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:865
void set_attempt_number(int an)
Definition: hf.h:258
virtual void damping_update(double)
Definition: hf.cc:276
int attempt_number() const
Definition: hf.h:257
void set_MOM_excited(bool tf)
Definition: hf.h:247
bool input_socc_
SOCC vector from input (if found)
Definition: hf.h:103
std::shared_ptr< VBase > V_potential() const
The DFT Potential object (or null if it has been deleted)
Definition: hf.h:293
void compute_fvpi()
Definition: hf.cc:832
bool cphf_converged_
Definition: hf.h:165
void set_energies(std::string key, double value)
Definition: hf.h:407
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:1291
std::string scf_type_
SCF algorithm type.
Definition: hf.h:124
SharedMatrix X_
The orthogonalization matrix (symmetric or canonical)
Definition: hf.h:60
double nuclearrep_
Nuclear repulsion energy.
Definition: hf.h:97
double radius_
Definition: hf.h:153
bool broken_symmetry_
Whether its broken symmetry solution or not.
Definition: hf.h:106
bool MOM_excited_
Are we to do excited-state MOM?
Definition: hf.h:135
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:689
virtual bool diis()
Definition: hf.h:315
std::shared_ptr< SuperFunctional > functional_
DFT variables.
Definition: hf.h:160
void rotate_orbitals(SharedMatrix C, const SharedMatrix x)
Definition: hf.cc:311
bool MOM_performed() const
MOM performed?
Definition: hf.h:250
virtual void compute_huckel_guess()
Huckel guess.
Definition: sad.cc:837
virtual bool stability_analysis()
Check the stability of the wavefunction, and correct (if requested)
Definition: hf.cc:1381
Definition: dimension.h:40
bool initialized_diis_manager_
DIIS manager intiialized?
Definition: hf.h:143
virtual void form_C()
Compute the MO coefficients (C_)
Definition: hf.cc:289
Definition: liboptions.h:353
void set_sad(bool sad)
Definition: hf.h:398
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:251
virtual void semicanonicalize()
Definition: hf.cc:405
virtual double compute_orbital_gradient(bool save_diis, int max_diis_vectors)
Definition: hf.h:318
int cphf_nfock_builds_
Definition: hf.h:164
void set_diis_enabled(bool tf)
Definition: hf.h:235
void set_jk(std::shared_ptr< JK > jk)
Sets the internal JK object (expert)
Definition: hf.cc:394
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
virtual void compute_SAD_guess(bool natorb)
SAD Guess and propagation.
Definition: sad.cc:755
Dimension original_doccpi_
Definition: hf.h:110
int diis_start_
When do we start collecting vectors for DIIS.
Definition: hf.h:148
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_sad_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:401
std::shared_ptr< JK > jk() const
The JK object (or null if it has been deleted)
Definition: hf.h:284
Simple wavefunction base class.
Definition: wavefunction.h:85
bool cphf_converged()
Definition: hf.h:382
bool sad() const
Definition: hf.h:397
int nelectron_
The number of electrons.
Definition: hf.h:198
virtual void prepare_canonical_orthogonalization()
Edit matrices if we are doing canonical orthogonalization.
Definition: hf.h:168
int theta_points_
Definition: hf.h:156
int charge_
The charge of the system.
Definition: hf.h:201
SharedMatrix V_
The 1e potential energy matrix.
Definition: hf.h:53
SharedMatrix Vb()
Definition: hf.h:387
void set_reset_occ(bool reset)
Definition: hf.h:395
int cphf_nfock_builds()
Definition: hf.h:383
bool initialized_diis_manager() const
Definition: hf.h:281
~HF() override
Definition: hf.cc:86
Definition: hf.h:48
int original_nalpha_
Definition: hf.h:112
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:411
bool frac_performed() const
Frac performed current iteration?
Definition: hf.h:242
void reset_occupation()
Reset to regular occupation from the fractional occupation.
Definition: hf.cc:1279
bool frac_performed_
Frac started? (Same thing as frac_performed_)
Definition: hf.h:140
bool MOM_excited() const
Are we to do excited-state MOM?
Definition: hf.h:246
void set_frac_performed(bool tf)
Definition: hf.h:243
void set_diis_start(int iter)
Definition: hf.h:239
void set_initialized_diis_manager(bool tf)
Definition: hf.h:280
void find_occupation()
Figure out how to occupy the orbitals in the absence of DOCC and SOCC.
Definition: hf.cc:407
virtual void form_H()
Formation of H is the same regardless of RHF, ROHF, UHF.
Definition: hf.cc:527
Dimension original_soccpi_
Definition: hf.h:111
int r_points_
Definition: hf.h:155
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:855
virtual void diagonalize_F(const SharedMatrix &F, SharedMatrix &C, std::shared_ptr< Vector > &eps)
Definition: hf.cc:1267
int phi_points_
Definition: hf.h:157
virtual SharedMatrix form_FDSmSDF(SharedMatrix Fso, SharedMatrix Dso)
Definition: hf.cc:1337
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:801
int iteration_
Current Iteration.
Definition: hf.h:91
SharedMatrix Va_
The DFT potential matrices (nice naming scheme)
Definition: hf.h:57
virtual void guess()
Form the guess (guarantees C, D, and E)
Definition: hf.cc:971
int * so2symblk_
Mapping arrays.
Definition: hf.h:120
bool reset_occ() const
Definition: hf.h:394
SharedMatrix guess_Cb_
Definition: hf.h:78