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 
35 namespace psi {
36 
37 class ERISieve;
38 
39 namespace scfgrad {
40 
41 class JKGrad {
42 
43 protected:
45  int print_;
47  int debug_;
49  int bench_;
51  unsigned long int memory_;
55  double cutoff_;
57  int deriv_;
58 
59  std::shared_ptr<BasisSet> primary_;
60 
62  std::shared_ptr<ERISieve> sieve_;
63 
66 
70 
71  bool do_J_;
72  bool do_K_;
73  bool do_wK_;
74 
75  double omega_;
76 
77  std::map<std::string, SharedMatrix> gradients_;
78  std::map<std::string, SharedMatrix> hessians_;
79 
80  void common_init();
81 
82 public:
83  JKGrad(int deriv, std::shared_ptr<BasisSet> primary);
84  virtual ~JKGrad();
85 
92  static std::shared_ptr<JKGrad> build_JKGrad(int deriv, std::shared_ptr<BasisSet> primary,
93  std::shared_ptr<BasisSet> auxiliary);
94 
95  void set_Ca(SharedMatrix Ca) { Ca_ = Ca; }
96  void set_Cb(SharedMatrix Cb) { Cb_ = Cb; }
97  void set_Da(SharedMatrix Da) { Da_ = Da; }
98  void set_Db(SharedMatrix Db) { Db_ = Db; }
99  void set_Dt(SharedMatrix Dt) { Dt_ = Dt; }
100 
108  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
114  void set_memory(unsigned long int memory) { memory_ = memory; }
124  void set_omp_num_threads(int omp_nthread) { omp_num_threads_ = omp_nthread; }
126  void set_print(int print) { print_ = print; }
128  void set_debug(int debug) { debug_ = debug; }
130  void set_bench(int bench) { bench_ = bench; }
136  void set_do_J(bool do_J) { do_J_ = do_J; }
142  void set_do_K(bool do_K) { do_K_ = do_K; }
148  void set_do_wK(bool do_wK) { do_wK_ = do_wK; }
153  void set_omega(double omega) { omega_ = omega; }
154 
155  std::map<std::string, SharedMatrix>& gradients() { return gradients_; }
156  std::map<std::string, SharedMatrix>& hessians() { return hessians_; }
157 
158  virtual void compute_gradient() = 0;
159  virtual void compute_hessian() = 0;
160 
161  virtual void print_header() const = 0;
162 };
163 
164 class DFJKGrad : public JKGrad {
165 
166 protected:
167  std::shared_ptr<BasisSet> auxiliary_;
168 
169  std::shared_ptr<PSIO> psio_;
170 
174  double condition_;
175 
176  void common_init();
177 
178  void build_Amn_terms();
179  void build_Amn_lr_terms();
180  void build_AB_inv_terms();
181  void build_UV_terms();
182  void build_AB_x_terms();
183  void build_Amn_x_terms();
184  void build_Amn_x_lr_terms();
185 
187  unsigned int unit_a_;
189  unsigned int unit_b_;
191  unsigned int unit_c_;
192 
193 public:
194  DFJKGrad(int deriv, std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
195  virtual ~DFJKGrad();
196 
197  void compute_gradient();
198  void compute_hessian();
199 
200  void print_header() const;
201 
209  void set_condition(double condition) { condition_ = condition; }
214  void set_unit_a(unsigned int unit) { unit_a_ = unit; }
219  void set_unit_b(unsigned int unit) { unit_b_ = unit; }
224  void set_unit_c(unsigned int unit) { unit_c_ = unit; }
225 
231 };
232 
233 class DirectJKGrad : public JKGrad {
234 
235 protected:
236  // Number of threads to use
238 
239  void common_init();
240 
241  std::map<std::string, std::shared_ptr<Matrix> > compute1(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
242  std::map<std::string, std::shared_ptr<Matrix> > compute2(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints);
243 public:
244  DirectJKGrad(int deriv, std::shared_ptr<BasisSet> primary);
245  virtual ~DirectJKGrad();
246 
247  void compute_gradient();
248  void compute_hessian();
249 
250  void print_header() const;
251 
256  void set_ints_num_threads(int val) { ints_num_threads_ = val; }
257 
258 
259 };
260 
261 }} // Namespaces
262 #endif
void set_Cb(SharedMatrix Cb)
Definition: jk_grad.h:96
std::map< std::string, std::shared_ptr< Matrix > > compute2(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2662
void build_Amn_x_terms()
Definition: jk_grad.cc:1019
void set_memory(unsigned long int memory)
Definition: jk_grad.h:114
void set_omp_num_threads(int omp_nthread)
Definition: jk_grad.h:124
virtual ~DFJKGrad()
Definition: jk_grad.cc:126
void compute_gradient()
Definition: jk_grad.cc:2365
virtual ~JKGrad()
Definition: jk_grad.cc:55
int print_
Print flag, defaults to 1.
Definition: jk_grad.h:45
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: jk_grad.h:55
void print_header() const
Definition: jk_grad.cc:2349
Definition: jk_grad.h:233
virtual void print_header() const =0
std::map< std::string, SharedMatrix > & hessians()
Definition: jk_grad.h:156
void set_unit_a(unsigned int unit)
Definition: jk_grad.h:214
std::shared_ptr< BasisSet > primary_
Definition: jk_grad.h:59
void set_unit_b(unsigned int unit)
Definition: jk_grad.h:219
void set_omega(double omega)
Definition: jk_grad.h:153
void set_ints_num_threads(int val)
Definition: jk_grad.h:256
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: jk_grad.h:62
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: jk_grad.h:130
virtual void compute_gradient()=0
int deriv_
Maximum derivative level.
Definition: jk_grad.h:57
JKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:50
bool do_wK_
Definition: jk_grad.h:73
std::map< std::string, SharedMatrix > hessians_
Definition: jk_grad.h:78
int bench_
Bench flag, defaults to 0.
Definition: jk_grad.h:49
void compute_gradient()
Definition: jk_grad.cc:162
unsigned int unit_a_
File number for Alpha (Q|mn) tensor.
Definition: jk_grad.h:187
void set_cutoff(double cutoff)
Definition: jk_grad.h:108
SharedMatrix Dt_
Definition: jk_grad.h:69
std::map< std::string, std::shared_ptr< Matrix > > compute1(std::vector< std::shared_ptr< TwoBodyAOInt > > &ints)
Definition: jk_grad.cc:2413
DFJKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:121
void build_Amn_x_lr_terms()
Definition: jk_grad.cc:1369
std::map< std::string, SharedMatrix > & gradients()
Definition: jk_grad.h:155
void set_unit_c(unsigned int unit)
Definition: jk_grad.h:224
void set_print(int print)
Print flag (defaults to 1)
Definition: jk_grad.h:126
SharedMatrix Da_
Definition: jk_grad.h:67
int omp_num_threads_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: jk_grad.h:53
virtual ~DirectJKGrad()
Definition: jk_grad.cc:2339
Definition: jk_grad.h:164
void build_AB_x_terms()
Definition: jk_grad.cc:835
void compute_hessian()
Definition: jk_grad.cc:1593
void set_df_ints_num_threads(int val)
Definition: jk_grad.h:230
void set_do_J(bool do_J)
Definition: jk_grad.h:136
void set_Db(SharedMatrix Db)
Definition: jk_grad.h:98
SharedMatrix Ca_
Definition: jk_grad.h:64
SharedMatrix scfgrad(SharedWavefunction, Options &)
Definition: scfgrad/wrapper.cc:38
void build_Amn_lr_terms()
Definition: jk_grad.cc:412
void build_Amn_terms()
Definition: jk_grad.cc:227
void set_do_wK(bool do_wK)
Definition: jk_grad.h:148
void set_Da(SharedMatrix Da)
Definition: jk_grad.h:97
void set_do_K(bool do_K)
Definition: jk_grad.h:142
void build_UV_terms()
Definition: jk_grad.cc:727
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk_grad.h:172
void set_Ca(SharedMatrix Ca)
Definition: jk_grad.h:95
void set_condition(double condition)
Definition: jk_grad.h:209
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
SharedMatrix Db_
Definition: jk_grad.h:68
static std::shared_ptr< JKGrad > build_JKGrad(int deriv, std::shared_ptr< BasisSet > primary, std::shared_ptr< BasisSet > auxiliary)
Definition: jk_grad.cc:58
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk_grad.h:174
int ints_num_threads_
Definition: jk_grad.h:237
void build_AB_inv_terms()
Definition: jk_grad.cc:576
void common_init()
Definition: jk_grad.cc:129
bool do_K_
Definition: jk_grad.h:72
unsigned long int memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: jk_grad.h:51
unsigned int unit_c_
File number for J tensors.
Definition: jk_grad.h:191
unsigned int unit_b_
File number for Beta (Q|mn) tensor.
Definition: jk_grad.h:189
std::map< std::string, SharedMatrix > gradients_
Definition: jk_grad.h:77
double omega_
Definition: jk_grad.h:75
void common_init()
Definition: jk_grad.cc:102
SharedMatrix Cb_
Definition: jk_grad.h:65
std::shared_ptr< BasisSet > auxiliary_
Definition: jk_grad.h:167
virtual void compute_hessian()=0
void compute_hessian()
Definition: jk_grad.cc:2614
void print_header() const
Definition: jk_grad.cc:141
void common_init()
Definition: jk_grad.cc:2342
bool do_J_
Definition: jk_grad.h:71
DirectJKGrad(int deriv, std::shared_ptr< BasisSet > primary)
Definition: jk_grad.cc:2334
void set_Dt(SharedMatrix Dt)
Definition: jk_grad.h:99
std::shared_ptr< PSIO > psio_
Definition: jk_grad.h:169
Definition: jk_grad.h:41
int debug_
Debug flag, defaults to 0.
Definition: jk_grad.h:47
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: jk_grad.h:128