MPQC  3.0.0-alpha
scf.h
1 //
2 // scf.h --- definition of the SCF abstract base class
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Edward Seidl <seidl@janed.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _chemistry_qc_scf_scf_h
29 #define _chemistry_qc_scf_scf_h
30 
31 #include <util/group/thread.h>
32 #ifdef MPQC_NEW_THREADS
33 # include <util/misc/xml.h>
34 #endif
35 
36 #include <math/optimize/scextrap.h>
37 
38 #include <chemistry/qc/basis/tbint.h>
39 #include <chemistry/qc/wfn/accum.h>
40 #include <chemistry/qc/wfn/obwfn.h>
41 
42 namespace sc {
43 
44  class SCFIterationLogger;
45  class DensityFittingInfo;
46 
47 // //////////////////////////////////////////////////////////////////////////
48 
51 class SCF: public OneBodyWavefunction {
52  protected:
53  int compute_guess_;
54 
55  RefDiagSCMatrix current_evals_;
56 
57  int keep_guess_wfn_;
58  Ref<OneBodyWavefunction> guess_wfn_;
59 
60  int always_use_guess_wfn_;
61 
63 
64  Ref<AccumH> accumdih_;
65  Ref<AccumH> accumddh_;
66 
67  int maxiter_;
68  int miniter_;
69  int dens_reset_freq_;
70  int reset_occ_;
71  size_t storage_;
72  int print_all_evals_;
73  int print_occ_evals_;
74 
75  // Super expert stuff. Don't mess with this unless you know what you're doing
76  // A subclass can set this to true to make compute_vector() set delta to 0.0 and break after the fock build
77  bool fake_scf_convergence_after_fock_build_;
78  // A subclass can set this to make compute_vector() set delta to 0.0 and break after some number of iterations no matter what
79  int fake_scf_convergence_after_n_iter_;
80 
81  double level_shift_;
82 
83  Ref<MessageGrp> scf_grp_;
84  Ref<ThreadGrp> threadgrp_;
85 
86  // Whether or not the matrix kit creates local matrices (int functioning as a bool)
87  int local_;
88 
89  // Whether or not the density can be stored locally (int functioning as a bool)
90  int local_dens_;
91 
92  Ref<TwoBodyInt>* tbis_; // a two body integral evaluator for each thread
93  virtual void init_threads();
94  virtual void done_threads();
95 
96  // implement the Compute::compute() function
97  virtual void compute();
98 
99  // calculate the scf vector, returning the accuracy
100  virtual double compute_vector(double&, double enuclear);
101 
102  // return the DIIS error matrices
103  virtual Ref<SCExtrapError> extrap_error();
104 
105  // calculate the scf gradient
106  virtual void compute_gradient(const RefSCVector&);
107 
108  // calculate the scf hessian
109  virtual void compute_hessian(const RefSymmSCMatrix&);
110 
111  // saves state and restart information after every checkpoint_freq()
112  // SCF iterations
113  virtual void savestate_iter(int);
114 
115  // saves state to the given filename
116  virtual void savestate_to_file(const std::string &filename);
117  std::string previous_savestate_file_;
118 
119  // returns the log of the max density element in each shell block
120  signed char * init_pmax(double *);
121 
122  // given a matrix, this will convert the matrix to a local matrix if
123  // it isn't one already, and return that local matrix. it will also
124  // set the double* to point to the local matrix's data.
125  enum Access { Read, Write, Accum };
126  RefSymmSCMatrix get_local_data(const RefSymmSCMatrix&, double*&, Access);
127 
128  // create the initial scf vector. either use the eigenvectors in
129  // guess_wfn_, or use a core Hamiltonian guess.
130  virtual void initial_vector();
131 
133  virtual void obsolete_vector();
134 
135  // given the total number of density and fock matrices, figure out
136  // how much memory that will require and then set the local_dens_
137  // variable accordingly
138  void init_mem(int);
139 
140  void so_density(const RefSymmSCMatrix& d, double occ, int alp=1);
141 
142  // Returns a new'ed allocation vector if it is in the input,
143  // otherwise null.
144  int *read_occ(const Ref<KeyVal> &, const char *name, int nirrep);
145 
147  static double guess_acc_ratio() { return 1e4; }
148 
149 #ifdef MPQC_NEW_FEATURES
150  Ref<SCFIterationLogger> iter_log_;
151 #endif
152 
154  static void iter_print(int iter,
155  double energy,
156  double delta,
157  double walltime,
158  std::ostream& os = ExEnv::out0());
159 
160  public:
161  SCF(StateIn&);
239  SCF(const Ref<KeyVal>&);
240  ~SCF();
241 
242  void save_data_state(StateOut&);
243 
244 #ifdef MPQC_NEW_FEATURES
245  boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent, const XMLWriter& writer);
246 #endif
247 
250 
251  int spin_unrestricted(); // return 0
252 
253  // return the number of AO Fock matrices needed
254  virtual int n_fock_matrices() const =0;
255 
256  // returns the n'th AO Fock matrix
257  virtual RefSymmSCMatrix fock(int) =0;
258 
259  // return the effective MO fock matrix
260  virtual RefSymmSCMatrix effective_fock() =0;
261 
264  virtual Ref<DensityFittingInfo> dfinfo() const;
265 
266  virtual double one_body_energy();
267  virtual void two_body_energy(double &ec, double &ex);
268 
269  void symmetry_changed();
270 
271  void obsolete();
272  void purge();
273 
274  void print(std::ostream&o=ExEnv::out0()) const;
275 
276  protected:
277  // the following are scratch and are not checkpointed
278  RefSCMatrix oso_scf_vector_;
279  RefSCMatrix oso_scf_vector_beta_; // only used if !spin_restricted
280  RefSymmSCMatrix hcore_;
281 
282  // //////////////////////////////////////////////////////////////////////
283  // pure virtual member functions follow
284 
285  // tries to automagically guess the MO occupations
286  virtual void set_occupations(const RefDiagSCMatrix&) =0;
287 
288  // //////////////////////////////////////////////////////////////////////
289  // do setup for SCF calculation
290  virtual void init_vector() =0;
291  virtual void done_vector() =0;
292 
293  // calculate new density matrices, returns the rms density difference
294  virtual double new_density() =0;
295 
296  // reset density diff matrix and zero out delta G matrix
297  virtual void reset_density() =0;
298 
299  // return the scf electronic energy
300  virtual double scf_energy() =0;
301 
302  // return the initial extrapolation data. Used when the mixing_fraction
303  // input for DIIS is nonzero. By default null is returned.
304  virtual Ref<SCExtrapData> initial_extrap_data();
305 
306  // return the DIIS data matrices
307  virtual Ref<SCExtrapData> extrap_data() =0;
308 
309  // form the AO basis fock matrices
310  virtual void ao_fock(double accuracy) =0;
311 
312  // //////////////////////////////////////////////////////////////////////
313  // do setup for gradient calculation
314  virtual void init_gradient() =0;
315  virtual void done_gradient() =0;
316 
317  virtual RefSymmSCMatrix lagrangian() =0;
318  virtual RefSymmSCMatrix gradient_density() =0;
319  virtual void two_body_deriv(double*) =0;
320 
321  // //////////////////////////////////////////////////////////////////////
322  // do setup for hessian calculation
323  virtual void init_hessian() =0;
324  virtual void done_hessian() =0;
325 
326  private:
327  // This experimental function does SVD of Coulomb matrix
328  // to be used in low-rank reconstruction
329  void svd_product_basis();
330 };
331 
332 }
333 
334 #endif
335 
336 // Local Variables:
337 // mode: c++
338 // c-file-style: "ETS"
339 // End:
sc::SCF
The SCF class is the base for all classes that use a self-consistent field procedure to solve an effe...
Definition: scf.h:51
sc::SCF::iter_print
static void iter_print(int iter, double energy, double delta, double walltime, std::ostream &os=ExEnv::out0())
prints iteration log
sc::SCF::oso_eigenvectors
RefSCMatrix oso_eigenvectors()
Returns the orthogonal MO (columns) to orthogonal-SO (rows) transformation matrix.
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::OneBodyWavefunction
A OneBodyWavefunction is a MolecularEnergy that solves an effective one-body problem.
Definition: obwfn.h:44
sc::SCF::dfinfo
virtual Ref< DensityFittingInfo > dfinfo() const
return the DensityFittingInfo object used to implement compute() this is important to be able to reco...
sc::RefSCMatrix
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition: matrix.h:135
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::SCF::obsolete_vector
virtual void obsolete_vector()
Obsolete scf vector so that next call to initial_vector() will cause recomputation.
sc::SCF::print
void print(std::ostream &o=ExEnv::out0()) const
Print information about the object.
sc::SCF::guess_acc_ratio
static double guess_acc_ratio()
how much lower is the desired accuracy of the guess?
Definition: scf.h:147
sc::SCF::eigenvalues
RefDiagSCMatrix eigenvalues()
Returns the MO basis eigenvalues.
sc::RefDiagSCMatrix
The RefDiagSCMatrix class is a smart pointer to an DiagSCMatrix specialization.
Definition: matrix.h:389
sc::SCF::obsolete
void obsolete()
Marks all results as being out of date.
sc::StateIn
Definition: statein.h:79
sc::MolecularEnergy::energy
virtual double energy()
A wrapper around value();.
sc::SCF::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::SCF::spin_unrestricted
int spin_unrestricted()
Return 1 if the alpha orbitals are not equal to the beta orbitals.
sc::SCF::purge
void purge()
This function purges any caches of data in MolecularEnergy.
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::StateOut
Definition: stateout.h:71
sc::XMLWriter
Definition: xmlwriter.h:215
sc::SCF::symmetry_changed
void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::SCF::compute
virtual void compute()
Recompute at least the results that have compute true and are not already computed.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.