Psi4
v.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-2018 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 LIBFOCK_DFT_H
30 #define LIBFOCK_DFT_H
31 #include "psi4/libmints/typedefs.h"
32 #include "psi4/pragma.h"
33 #include <vector>
34 #include <map>
35 #include <unordered_map>
36 #include <string>
37 
38 namespace psi {
39 class BasisSet;
40 class Options;
41 class DFTGrid;
42 class PointFunctions;
43 class SuperFunctional;
44 class BlockOPoints;
45 
46 // => BASE CLASS <= //
47 
55 class PSI_API VBase {
56 
57 protected:
59  int debug_;
61  int print_;
65  int nbf_;
73  std::shared_ptr<BasisSet> primary_;
75  std::shared_ptr<SuperFunctional> functional_;
77  std::vector<std::shared_ptr<SuperFunctional>> functional_workers_;
79  std::vector<std::shared_ptr<PointFunctions>> point_workers_;
81  std::shared_ptr<DFTGrid> grid_;
83  std::map<std::string, double> quad_values_;
84  // Caches collocation grids
85  std::unordered_map<size_t, std::map<std::string, SharedMatrix>> cache_map_;
87 
91 
93  std::vector<SharedMatrix> D_AO_;
94 
95  // GRAC data
97 
98  // VV10 dispersion, return vv10_nlc energy
99  void prepare_vv10_cache(
100  DFTGrid& nlgrid,
101  SharedMatrix D,
102  std::vector<std::map<std::string, SharedVector>>& vv10_cache,
103  std::vector<std::shared_ptr<PointFunctions>>& nl_point_workers,
104  int ansatz=1);
105  double vv10_nlc(SharedMatrix D, SharedMatrix ret);
106  SharedMatrix vv10_nlc_gradient(SharedMatrix D);
107 
109  void common_init();
110 
111 
112 public:
113  VBase(std::shared_ptr<SuperFunctional> functional,
114  std::shared_ptr<BasisSet> primary, Options& options);
115  virtual ~VBase();
116 
117  static std::shared_ptr<VBase> build_V(std::shared_ptr<BasisSet> primary,
118  std::shared_ptr<SuperFunctional> functional,
119  Options& options,
120  const std::string& type = "RV");
121 
122  std::shared_ptr<BasisSet> basis() const { return primary_; }
123  std::shared_ptr<SuperFunctional> functional() const { return functional_; }
124  std::vector<std::shared_ptr<PointFunctions>> properties() const { return point_workers_; }
125  std::shared_ptr<DFTGrid> grid() const { return grid_; }
126  std::shared_ptr<BlockOPoints> get_block(int block);
127  size_t nblocks();
128  std::map<std::string, double>& quadrature_values() { return quad_values_; }
129 
130  // Creates a collocation cache map based on stride
131  void build_collocation_cache(size_t memory);
132  void clear_collocation_cache() { cache_map_.clear(); }
133 
134  // Set the D matrix, get it back if needed
135  void set_D(std::vector<SharedMatrix> Dvec);
136  const std::vector<SharedMatrix>& Dao() const { return D_AO_; }
137 
138  // Set the site of the grac shift
139  void set_grac_shift(double value);
140 
142  virtual void compute_V(std::vector<SharedMatrix> ret);
143  virtual void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret);
144  virtual SharedMatrix compute_gradient();
145  virtual SharedMatrix compute_hessian();
146 
147  void set_print(int print) { print_ = print; }
148  void set_debug(int debug) { debug_ = debug; }
149 
150  virtual void initialize();
151  virtual void finalize();
152 
153  virtual void print_header() const;
154 };
155 
156 // => Derived Classes <= //
157 
158 class RV : public VBase {
159 
160 protected:
161 
162 public:
163  RV(std::shared_ptr<SuperFunctional> functional,
164  std::shared_ptr<BasisSet> primary,
165  Options& options);
166  virtual ~RV();
167 
168  virtual void initialize();
169  virtual void finalize();
170 
171  virtual void compute_V(std::vector<SharedMatrix> ret);
172  virtual void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret);
173  virtual SharedMatrix compute_gradient();
174  virtual SharedMatrix compute_hessian();
175 
176  virtual void print_header() const;
177 };
178 
179 class UV : public VBase {
180 
181 protected:
182 
183 public:
184  UV(std::shared_ptr<SuperFunctional> functional,
185  std::shared_ptr<BasisSet> primary,
186  Options& options);
187  virtual ~UV();
188 
189  virtual void initialize();
190  virtual void finalize();
191 
192  virtual void compute_V(std::vector<SharedMatrix> ret);
193  virtual void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret);
194  virtual SharedMatrix compute_gradient();
195 
196  virtual void print_header() const;
197 };
198 
199 
200 }
201 #endif
void set_debug(int debug)
Definition: v.h:148
virtual void print_header() const
Definition: v.cc:572
std::shared_ptr< DFTGrid > grid_
Integration grid, built by KSPotential.
Definition: v.h:81
std::vector< std::shared_ptr< PointFunctions > > properties() const
Definition: v.h:124
int debug_
Debug flag.
Definition: v.h:59
std::map< std::string, double > & quadrature_values()
Definition: v.h:128
double vv10_rho_cutoff_
VV10 interior kernel threshold.
Definition: v.h:69
virtual void compute_Vx(std::vector< SharedMatrix > Dx, std::vector< SharedMatrix > ret)
Definition: v.cc:710
std::shared_ptr< DFTGrid > grid() const
Definition: v.h:125
void clear_collocation_cache()
Definition: v.h:132
Options & options_
Options object, used to build grid.
Definition: v.h:71
double v2_rho_cutoff_
Rho threshold for the second derivative;.
Definition: v.h:67
virtual void compute_Vx(std::vector< SharedMatrix > Dx, std::vector< SharedMatrix > ret)
Definition: v.cc:1655
virtual void compute_V(std::vector< SharedMatrix > ret)
Throws by default.
Definition: v.cc:573
virtual void compute_V(std::vector< SharedMatrix > ret)
Throws by default.
Definition: v.cc:1373
void set_print(int print)
Definition: v.h:147
std::shared_ptr< BasisSet > primary_
Basis set used in the integration.
Definition: v.h:73
std::vector< std::shared_ptr< SuperFunctional > > functional_workers_
Desired superfunctional kernal.
Definition: v.h:77
virtual ~RV()
Definition: v.cc:557
SharedMatrix USO2AO_
Definition: v.h:90
virtual void finalize()
Definition: v.cc:1371
virtual void print_header() const
Definition: v.cc:1372
Definition: v.h:55
bool grac_initialized_
Definition: v.h:96
std::map< std::string, double > quad_values_
Quadrature values obtained during integration.
Definition: v.h:83
std::unordered_map< size_t, std::map< std::string, SharedMatrix > > cache_map_
Definition: v.h:85
Definition: v.h:179
SharedMatrix AO2USO_
AO2USO matrix (if not C1)
Definition: v.h:89
int print_
Print flag.
Definition: v.h:61
std::vector< SharedMatrix > D_AO_
Vector of C1 D matrices (built by USO2AO)
Definition: v.h:93
UV(std::shared_ptr< SuperFunctional > functional, std::shared_ptr< BasisSet > primary, Options &options)
Definition: v.cc:1355
virtual void initialize()
Definition: v.cc:558
Definition: cubature.h:203
int cache_map_deriv_
Definition: v.h:86
Definition: liboptions.h:353
std::shared_ptr< BasisSet > basis() const
Definition: v.h:122
RV(std::shared_ptr< SuperFunctional > functional, std::shared_ptr< BasisSet > primary, Options &options)
Definition: v.cc:555
virtual SharedMatrix compute_gradient()
Definition: v.cc:975
int num_threads_
Number of threads.
Definition: v.h:63
virtual ~UV()
Definition: v.cc:1357
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
int nbf_
Number of basis functions;.
Definition: v.h:65
virtual void finalize()
Definition: v.cc:571
#define PSI_API
Definition: pragma.h:155
std::shared_ptr< SuperFunctional > functional() const
Definition: v.h:123
Definition: v.h:158
std::vector< std::shared_ptr< PointFunctions > > point_workers_
Point function computer (densities, gammas, basis values)
Definition: v.h:79
const std::vector< SharedMatrix > & Dao() const
Definition: v.h:136
std::shared_ptr< SuperFunctional > functional_
Desired superfunctional kernal.
Definition: v.h:75
virtual void initialize()
Definition: v.cc:1358
virtual SharedMatrix compute_gradient()
Definition: v.cc:2129
virtual SharedMatrix compute_hessian()
Definition: v.cc:1094