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-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 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 
68 
73 
77 
80 
83 
85  double Eold_;
86  double E_;
87 
89  std::map<std::string, double> energies_;
90 
92  std::vector<std::shared_ptr<BasisSet>> sad_basissets_;
93  std::vector<std::shared_ptr<BasisSet>> sad_fitting_basissets_;
94 
96  double Drms_;
97 
99  int maxiter_;
100 
102  bool ref_C_;
103 
106 
109 
111 
113 
115  double nuclearrep_;
116 
119 
122 
125 
128 
129  //Initial SAD doubly occupied may be more than ndocc
130  // int sad_nocc_[8];
136 
139  int *so2index_;
140 
142  std::string scf_type_;
143 
146  std::string old_scf_type_;
147 
148 
151 
153  std::shared_ptr<JK> jk_;
154 
163 
168 
172  std::shared_ptr<DIISManager> diis_manager_;
173 
182 
192  double soscf_conv_;
194  double soscf_print_;
195 
204 
205  // parameters for hard-sphere potentials
206  double radius_; // radius of spherical potential
207  double thickness_; // thickness of spherical barrier
208  int r_points_; // number of radial integration points
209  int theta_points_; // number of colatitude integration points
210  int phi_points_; // number of azimuthal integration points
211 
213  std::shared_ptr<SuperFunctional> functional_;
214  std::shared_ptr<VBase> potential_;
215 
216 
217  // CPHF info
220 
221 public:
222 
225 
227  std::shared_ptr<JK> jk() const { return jk_; }
228 
230  std::shared_ptr<SuperFunctional> functional() const { return functional_; }
231 
233  std::shared_ptr<VBase> V_potential() const { return potential_; }
234 
236  double rms_density_error() {return Drms_;}
237 
239  std::shared_ptr<Vector> occupation_a() const;
240  std::shared_ptr<Vector> occupation_b() const;
241 
242  // PCM interface
244  std::shared_ptr<PCM> hf_pcm_;
245 
246 protected:
247 
249  // Temporarily converting to virtual function for testing embedding
250  // potentials. TDC, 5/23/12.
251  virtual void form_H();
252 
254  void form_Shalf();
255 
257  virtual void prepare_canonical_orthogonalization() { return; }
258 
260  void print_occupation();
261 
263  void common_init();
264 
266  void find_occupation();
267 
269  void MOM();
271  void MOM_start();
272 
274  void frac();
276  void frac_renormalize();
277 
279  virtual bool stability_analysis();
280  void print_stability_analysis(std::vector<std::pair<double, int> > &vec);
281 
282 
284  void compute_fcpi();
285  void compute_fvpi();
286 
288  void print_orbitals(const char* header, std::vector<std::pair<double,
289  std::pair< std::string, int> > > orbs);
290 
292  void print_orbitals();
293 
295  void print_energies();
296 
298  void print_header();
299 
301  void print_preiterations();
302 
304  virtual void integrals();
305 
311 
314 
316  int charge_;
317 
320 
323 
325  virtual double compute_E() = 0;
326 
328  virtual void save_density_and_energy() = 0;
329 
331  void check_phases();
332 
334  void compute_SAD_guess();
335 
337  void reset_occupation();
338 
340  virtual void guess();
341 
343  virtual void damp_update();
344 
346  virtual int soscf_update();
347 
349  virtual void diagonalize_F(const SharedMatrix& F, SharedMatrix& C, std::shared_ptr<Vector>& eps);
350 
352  virtual void form_initial_C() { form_C(); }
353 
355  virtual double compute_initial_E() { return 0.0; }
356 
358  virtual bool test_convergency() { return false; }
359 
361  virtual void compute_spin_contamination();
362 
364  virtual void save_information() {}
365 
367  virtual void compute_orbital_gradient(bool) {}
368 
370  virtual bool diis() { return false; }
371 
373  virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int* noccpi);
374 
377 
379  virtual void format_guess();
380 
382  // virtual void save_orbitals();
383 
385  // bool do_use_fock_guess();
386 
388  // virtual void load_fock();
389 
391  // virtual void load_orbitals();
392 
393 public:
394  HF(SharedWavefunction ref_wfn, std::shared_ptr<SuperFunctional> funct,
395  Options& options, std::shared_ptr<PSIO> psio);
396 
397  virtual ~HF();
398 
400  virtual void initialize();
401 
403  virtual void iterations();
404 
409  virtual double finalize_E();
410 
414  virtual double compute_energy();
415 
418  virtual void finalize();
419 
425  virtual void semicanonicalize();
426 
428  virtual void form_C();
429 
431  virtual void form_D();
432 
434  virtual void form_V();
435 
437  void rotate_orbitals(SharedMatrix C, const SharedMatrix x);
438 
440  virtual void form_F() = 0;
441 
443  virtual void form_G() = 0;
444 
445 
447  virtual std::vector<SharedMatrix> onel_Hx(std::vector<SharedMatrix> x);
448  virtual std::vector<SharedMatrix> twoel_Hx(std::vector<SharedMatrix> x, bool combine = true,
449  std::string return_basis = "MO");
450  virtual std::vector<SharedMatrix> cphf_Hx(std::vector<SharedMatrix> x);
451  virtual std::vector<SharedMatrix> cphf_solve(std::vector<SharedMatrix> x_vec,
452  double conv_tol = 1.e-4, int max_iter = 10,
453  int print_lvl = 1);
454  bool cphf_converged() { return cphf_converged_; }
456 
457  // Return the DFT potenitals
458  SharedMatrix Va() { return Va_; }
459  SharedMatrix Vb() { return Vb_; }
460 
461  // Set guess occupied orbitals, nalpha and nbeta will be taken from the number of passed in eigenvectors
464 
465  // Expert option to reset the occuption or not at iteration zero
466  void reset_occ(bool reset) { reset_occ_ = reset; }
467 
468  // SAD information
469  void set_sad_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) { sad_basissets_ = basis_vec; }
470  void set_sad_fitting_basissets(std::vector<std::shared_ptr<BasisSet>> basis_vec) { sad_fitting_basissets_ = basis_vec; }
471 };
472 
473 }} // Namespaces
474 
475 #endif
virtual void form_initial_C()
Definition: hf.h:352
int multiplicity_
The multiplicity of the system (specified as 2 Ms + 1)
Definition: hf.h:319
std::shared_ptr< Vector > occupation_a() const
Returns the occupation vectors.
Definition: hf.cc:1897
virtual void save_density_and_energy()=0
Save the current density and energy.
SharedMatrix Ca() const
Returns the alpha electrons MO coefficients.
int * so2index_
Definition: hf.h:139
SharedMatrix T_
The kinetic energy matrix.
Definition: hf.h:52
bool MOM_performed_
MOM performed?
Definition: hf.h:162
std::shared_ptr< Vector > occupation_b() const
Definition: hf.cc:1908
SharedMatrix Ca_old_
Old C Alpha matrix (if needed for MOM)
Definition: hf.h:70
bool reset_occ_
Definition: hf.h:135
int original_nbeta_
Definition: hf.h:134
std::shared_ptr< VBase > potential_
Definition: hf.h:214
virtual void iterations()
Performs the actual SCF iterations.
Definition: hf.cc:1577
bool damping_enabled_
Whether to use SCF damping.
Definition: hf.h:201
bool pcm_enabled_
Definition: hf.h:243
void MOM()
Maximum overlap method for prevention of oscillation/excited state SCF.
Definition: mom.cc:589
bool fail_on_maxiter_
Fail if we don&#39;t converge by maxiter?
Definition: hf.h:105
int max_diis_vectors_
How many max vectors for DIIS.
Definition: hf.h:177
bool input_docc_
DOCC vector from input (if found)
Definition: hf.h:121
std::map< std::string, double > energies_
Table of energy components.
Definition: hf.h:89
double ** scf
Definition: dx_write.cc:57
virtual void form_V()
Computes the density matrix (V_)
Definition: hf.cc:357
SharedMatrix Vb_
Definition: hf.h:59
std::vector< std::shared_ptr< BasisSet > > sad_fitting_basissets_
Definition: hf.h:93
virtual void compute_orbital_gradient(bool)
Definition: hf.h:367
double integral_threshold_
The value below which integrals are neglected.
Definition: hf.h:150
virtual double compute_initial_E()
Definition: hf.h:355
int min_diis_vectors_
How many min vectors for DIIS.
Definition: hf.h:175
void frac()
Fractional occupation UHF/UKS.
Definition: frac.cc:67
void guess_Ca(SharedMatrix Ca)
Definition: hf.h:462
double damping_percentage_
The amount (%) of the previous orbitals to mix in during SCF damping.
Definition: hf.h:197
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:377
std::shared_ptr< DIISManager > diis_manager_
DIIS manager for all SCF wavefunctions.
Definition: hf.h:172
SharedMatrix Va()
Definition: hf.h:458
double thickness_
Definition: hf.h:207
std::shared_ptr< SuperFunctional > functional() const
The DFT Functional object (or null if it has been deleted)
Definition: hf.h:230
double Drms_
The RMS error in the density.
Definition: hf.h:96
SharedMatrix Cb_old_
Old C Beta matrix (if needed for MOM)
Definition: hf.h:72
virtual std::vector< SharedMatrix > onel_Hx(std::vector< SharedMatrix > x)
Hessian-vector computers and solvers.
Definition: hf.cc:367
void check_phases()
Check MO phases.
Definition: hf.cc:1474
void print_header()
Prints some opening information.
Definition: hf.cc:738
virtual std::vector< SharedMatrix > twoel_Hx(std::vector< SharedMatrix > x, bool combine=true, std::string return_basis="MO")
Definition: hf.cc:370
void print_occupation()
Prints the orbital occupation.
Definition: hf.cc:1867
std::shared_ptr< PSIO > psio() const
virtual void format_guess()
Definition: hf.cc:1468
std::string old_scf_type_
Definition: hf.h:146
int soscf_max_iter_
Minimum number of iterations.
Definition: hf.h:190
SharedMatrix diag_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:63
int attempt_number_
Definition: hf.h:308
SharedMatrix guess_Ca_
User defined orbitals.
Definition: hf.h:75
void guess_Cb(SharedMatrix Cb)
Definition: hf.h:463
int diis_enabled_
Are we even using DIIS?
Definition: hf.h:181
virtual void form_D()
Computes the density matrix (D_)
Definition: hf.cc:364
void print_preiterations()
Prints some details about nsopi/nmopi, and initial occupations.
Definition: hf.cc:792
std::shared_ptr< JK > jk_
The soon to be ubiquitous JK object.
Definition: hf.h:153
virtual void initialize()
Specialized initialization, compute integrals and does everything to prepare for iterations.
Definition: hf.cc:1506
virtual double compute_E()=0
Compute energy for the iteration.
virtual void compute_spin_contamination()
Definition: frac.cc:230
bool MOM_enabled_
Are we to do MOM?
Definition: hf.h:156
virtual void finalize()
Definition: hf.cc:627
bool damping_performed_
Whether damping was actually performed this iteration.
Definition: hf.h:203
bool converged_
Did the SCF converge?
Definition: hf.h:112
double Eold_
Previous iteration&#39;s energy and current energy.
Definition: hf.h:85
void set_sad_fitting_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:470
virtual ~HF()
Definition: hf.cc:89
SharedMatrix diag_F_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:65
void print_orbitals()
Prints the orbitals in arbitrary order (works with MOM)
Definition: hf.cc:1184
bool soscf_enabled_
Are we doing second-order convergence acceleration?
Definition: hf.h:184
void print_stability_analysis(std::vector< std::pair< double, int > > &vec)
Definition: hf.cc:2019
bool input_socc_
SOCC vector from input (if found)
Definition: hf.h:124
std::shared_ptr< VBase > V_potential() const
The DFT Potential object (or null if it has been deleted)
Definition: hf.h:233
void compute_fvpi()
Definition: hf.cc:1146
bool cphf_converged_
Definition: hf.h:219
bool diis_performed_
Whether DIIS was performed this iteration, or not.
Definition: hf.h:118
virtual SharedMatrix form_Fia(SharedMatrix Fso, SharedMatrix Cso, int *noccpi)
Definition: hf.cc:1946
std::string scf_type_
SCF algorithm type.
Definition: hf.h:142
virtual double compute_energy()
Definition: hf.cc:472
SharedMatrix X_
The orthogonalization matrix (symmetric or canonical)
Definition: hf.h:61
double nuclearrep_
Nuclear repulsion energy.
Definition: hf.h:115
virtual void form_G()=0
double radius_
Definition: hf.h:206
virtual double finalize_E()
Definition: hf.cc:479
bool broken_symmetry_
Whether its broken symmetry solution or not.
Definition: hf.h:127
bool MOM_excited_
Are we to do excited-state MOM?
Definition: hf.h:158
double energy_threshold_
Energy convergence threshold.
Definition: hf.h:79
SharedMatrix Horig_
A temporary spot for the H matrix.
Definition: hf.h:56
void form_Shalf()
Formation of S^+1/2 and S^-1/2 are the same.
Definition: hf.cc:987
virtual bool diis()
Definition: hf.h:370
double damping_convergence_
The energy convergence at which SCF damping is disabled.
Definition: hf.h:199
std::shared_ptr< SuperFunctional > functional_
DFT variables.
Definition: hf.h:213
virtual void form_F()=0
Options & options() const
void rotate_orbitals(SharedMatrix C, const SharedMatrix x)
Definition: hf.cc:381
int iterations_needed_
The number of iterations need to reach convergence.
Definition: hf.h:322
virtual void save_information()
Definition: hf.h:364
virtual bool stability_analysis()
Check the stability of the wavefunction, and correct (if requested)
Definition: hf.cc:2042
Definition: dimension.h:38
bool initialized_diis_manager_
DIIS manager intiialized?
Definition: hf.h:170
virtual void form_C()
Compute the MO coefficients (C_)
Definition: hf.cc:361
Definition: liboptions.h:355
virtual void semicanonicalize()
Definition: hf.cc:657
double density_threshold_
Density convergence threshold.
Definition: hf.h:82
int cphf_nfock_builds_
Definition: hf.h:218
virtual int soscf_update()
Definition: hf.cc:352
virtual std::vector< SharedMatrix > cphf_Hx(std::vector< SharedMatrix > x)
Definition: hf.cc:374
void MOM_start()
Start the MOM algorithm (requires one iteration worth of setup)
Definition: mom.cc:62
int soscf_min_iter_
Maximum number of iterations.
Definition: hf.h:188
Dimension original_doccpi_
Definition: hf.h:131
int diis_start_
When do we start collecting vectors for DIIS.
Definition: hf.h:179
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_sad_basissets(std::vector< std::shared_ptr< BasisSet >> basis_vec)
Definition: hf.h:469
std::shared_ptr< JK > jk() const
The JK object (or null if it has been deleted)
Definition: hf.h:227
virtual void damp_update()
Definition: hf.cc:346
Simple wavefunction base class.
Definition: wavefunction.h:85
bool frac_enabled_
Are we to fractionally occupy?
Definition: hf.h:165
bool cphf_converged()
Definition: hf.h:454
void reset_occ(bool reset)
Definition: hf.h:466
int nelectron_
The number of electrons.
Definition: hf.h:313
virtual void prepare_canonical_orthogonalization()
Edit matrices if we are doing canonical orthogonalization.
Definition: hf.h:257
int theta_points_
Definition: hf.h:209
int charge_
The charge of the system.
Definition: hf.h:316
SharedMatrix V_
The 1e potential energy matrix.
Definition: hf.h:54
SharedMatrix Vb()
Definition: hf.h:459
int cphf_nfock_builds()
Definition: hf.h:455
Definition: hf.h:48
int original_nalpha_
Definition: hf.h:133
void common_init()
Common initializer.
Definition: hf.cc:93
std::vector< std::shared_ptr< BasisSet > > sad_basissets_
Basis list for SAD.
Definition: hf.h:92
HF(SharedWavefunction ref_wfn, std::shared_ptr< SuperFunctional > funct, Options &options, std::shared_ptr< PSIO > psio)
Definition: hf.cc:79
int max_attempts_
Maximum number of macroiterations to take in e.g. a stability analysis.
Definition: hf.h:310
void compute_SAD_guess()
SAD Guess and propagation.
Definition: sad.cc:618
void reset_occupation()
Reset to regular occupation from the fractional occupation.
Definition: hf.cc:1932
bool frac_performed_
Frac started? (Same thing as frac_performed_)
Definition: hf.h:167
double soscf_r_start_
What is the gradient threshold that we should start?
Definition: hf.h:186
virtual bool test_convergency()
Definition: hf.h:358
int iterations_needed()
The number of iterations needed to reach convergence.
Definition: hf.h:224
int maxiter_
Max number of iterations for HF.
Definition: hf.h:99
virtual void integrals()
Do any needed integral setup.
Definition: hf.cc:424
void find_occupation()
Figure out how to occupy the orbitals in the absence of DOCC and SOCC.
Definition: hf.cc:662
std::shared_ptr< PCM > hf_pcm_
Definition: hf.h:244
double rms_density_error()
The RMS error in the density.
Definition: hf.h:236
virtual void form_H()
Formation of H is the same regardless of RHF, ROHF, UHF.
Definition: hf.cc:811
Dimension original_soccpi_
Definition: hf.h:132
int r_points_
Definition: hf.h:208
virtual void diagonalize_F(const SharedMatrix &F, SharedMatrix &C, std::shared_ptr< Vector > &eps)
Definition: hf.cc:1919
int phi_points_
Definition: hf.h:210
virtual SharedMatrix form_FDSmSDF(SharedMatrix Fso, SharedMatrix Dso)
Definition: hf.cc:1995
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
SharedMatrix diag_C_temp_
Temporary matrix for diagonalize_F.
Definition: hf.h:67
double E_
Definition: hf.h:86
double soscf_conv_
Break if the residual RMS is less than this.
Definition: hf.h:192
void print_energies()
Prints the energy breakdown from this SCF.
Definition: hf.cc:1811
bool MOM_started_
MOM started?
Definition: hf.h:160
void frac_renormalize()
Renormalize orbitals to 1.0 before saving.
Definition: frac.cc:189
void compute_fcpi()
Determine how many core and virtual orbitals to freeze.
Definition: hf.cc:1111
SharedMatrix Cb() const
Returns the beta electrons MO coefficients.
double soscf_print_
Do we print the microiterations?
Definition: hf.h:194
int iteration_
Current Iteration.
Definition: hf.h:108
SharedMatrix Va_
The DFT potential matrices (nice naming scheme)
Definition: hf.h:58
bool ref_C_
Fail if we don&#39;t converge by maxiter?
Definition: hf.h:102
virtual void guess()
Form the guess (gaurantees C, D, and E)
Definition: hf.cc:1311
int * so2symblk_
Mapping arrays.
Definition: hf.h:138
SharedMatrix guess_Cb_
Definition: hf.h:76