Psi4
jk_grad.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 JK_GRAD_H
30 #define JK_GRAD_H
31 
32 #include "psi4/libmints/typedefs.h"
33 #include <map>
34 #include <vector>
35 
36 namespace psi {
37 
38 class ERISieve;
39 class BasisSet;
40 class PSIO;
41 class TwoBodyAOInt;
42 
43 namespace scfgrad {
44 
45 class JKGrad {
46 
47 protected:
49  int print_;
51  int debug_;
53  int bench_;
55  size_t memory_;
59  double cutoff_;
61  int deriv_;
62 
63  std::shared_ptr<BasisSet> primary_;
64 
66  std::shared_ptr<ERISieve> sieve_;
67 
70 
74 
75  bool do_J_;
76  bool do_K_;
77  bool do_wK_;
78 
79  double omega_;
80 
81  std::map<std::string, SharedMatrix> gradients_;
82  std::map<std::string, SharedMatrix> hessians_;
83 
84  void common_init();
85 
86 public:
87  JKGrad(int deriv, std::shared_ptr<BasisSet> primary);
88  virtual ~JKGrad();
89 
96  static std::shared_ptr<JKGrad> build_JKGrad(int deriv, std::shared_ptr<BasisSet> primary,
97  std::shared_ptr<BasisSet> auxiliary);
98 
99  void set_Ca(SharedMatrix Ca) { Ca_ = Ca; }
100  void set_Cb(SharedMatrix Cb) { Cb_ = Cb; }
101  void set_Da(SharedMatrix Da) { Da_ = Da; }
102  void set_Db(SharedMatrix Db) { Db_ = Db; }
103  void set_Dt(SharedMatrix Dt) { Dt_ = Dt; }
104 
112  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
118  void set_memory(size_t memory) { memory_ = memory; }
128  void set_omp_num_threads(int omp_nthread) { omp_num_threads_ = omp_nthread; }
130  void set_print(int print) { print_ = print; }
132  void set_debug(int debug) { debug_ = debug; }
134  void set_bench(int bench) { bench_ = bench; }
140  void set_do_J(bool do_J) { do_J_ = do_J; }
146  void set_do_K(bool do_K) { do_K_ = do_K; }
152  void set_do_wK(bool do_wK) { do_wK_ = do_wK; }
157  void set_omega(double omega) { omega_ = omega; }
158 
159  std::map<std::string, SharedMatrix>& gradients() { return gradients_; }
160  std::map<std::string, SharedMatrix>& hessians() { return hessians_; }
161 
162  virtual void compute_gradient() = 0;
163  virtual void compute_hessian() = 0;
164 
165  virtual void print_header() const = 0;
166 };
167 
168 class DFJKGrad : public JKGrad {
169 
170 protected:
171  std::shared_ptr<BasisSet> auxiliary_;
172 
173  std::shared_ptr<PSIO> psio_;
174 
178  double condition_;
179 
180  void common_init();
181 
182  void build_Amn_terms();
183  void build_Amn_lr_terms();
184  void build_AB_inv_terms();
185  void build_UV_terms();
186  void build_AB_x_terms();
187  void build_Amn_x_terms();
188  void build_Amn_x_lr_terms();
189 
191  size_t unit_a_;
193  size_t unit_b_;
195  size_t unit_c_;
196 
197 public:
198  DFJKGrad(int deriv, std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
199  virtual ~DFJKGrad();
200 
201  void compute_gradient();
202  void compute_hessian();
203 
204  void print_header() const;
205 
213  void set_condition(double condition) { condition_ = condition; }
218  void set_unit_a(size_t unit) { unit_a_ = unit; }
223  void set_unit_b(size_t unit) { unit_b_ = unit; }
228  void set_unit_c(size_t unit) { unit_c_ = unit; }
229 
235 };
236 
237 class DirectJKGrad : public JKGrad {
238 
239 protected:
240  // Number of threads to use
242 
243  void common_init();
244 
245  std::map<std::string, std::shared_ptr<Matrix> > compute1(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
246  std::map<std::string, std::shared_ptr<Matrix> > compute2(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
247 public:
248  DirectJKGrad(int deriv, std::shared_ptr<BasisSet> primary);
249  virtual ~DirectJKGrad();
250 
251  void compute_gradient();
252  void compute_hessian();
253 
254  void print_header() const;
255 
260  void set_ints_num_threads(int val) { ints_num_threads_ = val; }
261 
262 
263 };
264 
265 }} // Namespaces
266 #endif
void set_Cb(SharedMatrix Cb)
Definition: jk_grad.h:100
std::map< std::string, std::shared_ptr< Matrix > > compute2(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2667
void set_unit_b(size_t unit)
Definition: jk_grad.h:223
void build_Amn_x_terms()
Definition: jk_grad.cc:1024
void set_omp_num_threads(int omp_nthread)
Definition: jk_grad.h:128
virtual ~DFJKGrad()
Definition: jk_grad.cc:131
void compute_gradient()
Definition: jk_grad.cc:2370
virtual ~JKGrad()
Definition: jk_grad.cc:60
int print_
Print flag, defaults to 1.
Definition: jk_grad.h:49
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: jk_grad.h:59
void print_header() const
Definition: jk_grad.cc:2354
Definition: jk_grad.h:237
virtual void print_header() const =0
std::map< std::string, SharedMatrix > & hessians()
Definition: jk_grad.h:160
std::shared_ptr< BasisSet > primary_
Definition: jk_grad.h:63
void set_omega(double omega)
Definition: jk_grad.h:157
void set_memory(size_t memory)
Definition: jk_grad.h:118
void set_ints_num_threads(int val)
Definition: jk_grad.h:260
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: jk_grad.h:66
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: jk_grad.h:134
virtual void compute_gradient()=0
int deriv_
Maximum derivative level.
Definition: jk_grad.h:61
JKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:55
bool do_wK_
Definition: jk_grad.h:77
std::map< std::string, SharedMatrix > hessians_
Definition: jk_grad.h:82
int bench_
Bench flag, defaults to 0.
Definition: jk_grad.h:53
void compute_gradient()
Definition: jk_grad.cc:167
void set_cutoff(double cutoff)
Definition: jk_grad.h:112
SharedMatrix Dt_
Definition: jk_grad.h:73
std::map< std::string, std::shared_ptr< Matrix > > compute1(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2418
DFJKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:126
void build_Amn_x_lr_terms()
Definition: jk_grad.cc:1374
std::map< std::string, SharedMatrix > & gradients()
Definition: jk_grad.h:159
void set_print(int print)
Print flag (defaults to 1)
Definition: jk_grad.h:130
size_t unit_a_
File number for Alpha (Q|mn) tensor.
Definition: jk_grad.h:191
SharedMatrix Da_
Definition: jk_grad.h:71
int omp_num_threads_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: jk_grad.h:57
virtual ~DirectJKGrad()
Definition: jk_grad.cc:2344
Definition: jk_grad.h:168
void build_AB_x_terms()
Definition: jk_grad.cc:840
void compute_hessian()
Definition: jk_grad.cc:1598
size_t unit_b_
File number for Beta (Q|mn) tensor.
Definition: jk_grad.h:193
void set_df_ints_num_threads(int val)
Definition: jk_grad.h:234
void set_do_J(bool do_J)
Definition: jk_grad.h:140
void set_Db(SharedMatrix Db)
Definition: jk_grad.h:102
void set_unit_c(size_t unit)
Definition: jk_grad.h:228
SharedMatrix Ca_
Definition: jk_grad.h:68
SharedMatrix scfgrad(SharedWavefunction, Options &)
Definition: scfgrad/wrapper.cc:39
void build_Amn_lr_terms()
Definition: jk_grad.cc:417
void build_Amn_terms()
Definition: jk_grad.cc:232
void set_do_wK(bool do_wK)
Definition: jk_grad.h:152
void set_Da(SharedMatrix Da)
Definition: jk_grad.h:101
void set_do_K(bool do_K)
Definition: jk_grad.h:146
void build_UV_terms()
Definition: jk_grad.cc:732
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk_grad.h:176
void set_Ca(SharedMatrix Ca)
Definition: jk_grad.h:99
void set_condition(double condition)
Definition: jk_grad.h:213
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
size_t memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: jk_grad.h:55
SharedMatrix Db_
Definition: jk_grad.h:72
static std::shared_ptr< JKGrad > build_JKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:63
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk_grad.h:178
int ints_num_threads_
Definition: jk_grad.h:241
void build_AB_inv_terms()
Definition: jk_grad.cc:581
void common_init()
Definition: jk_grad.cc:134
bool do_K_
Definition: jk_grad.h:76
std::map< std::string, SharedMatrix > gradients_
Definition: jk_grad.h:81
double omega_
Definition: jk_grad.h:79
void common_init()
Definition: jk_grad.cc:107
SharedMatrix Cb_
Definition: jk_grad.h:69
std::shared_ptr< BasisSet > auxiliary_
Definition: jk_grad.h:171
size_t unit_c_
File number for J tensors.
Definition: jk_grad.h:195
virtual void compute_hessian()=0
void compute_hessian()
Definition: jk_grad.cc:2619
void print_header() const
Definition: jk_grad.cc:146
void common_init()
Definition: jk_grad.cc:2347
bool do_J_
Definition: jk_grad.h:75
DirectJKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:2339
void set_Dt(SharedMatrix Dt)
Definition: jk_grad.h:103
std::shared_ptr< PSIO > psio_
Definition: jk_grad.h:173
Definition: jk_grad.h:45
int debug_
Debug flag, defaults to 0.
Definition: jk_grad.h:51
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: jk_grad.h:132
void set_unit_a(size_t unit)
Definition: jk_grad.h:218