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  protected:
58  int debug_;
60  int print_;
64  int nbf_;
72  std::shared_ptr<BasisSet> primary_;
74  std::shared_ptr<SuperFunctional> functional_;
76  std::vector<std::shared_ptr<SuperFunctional>> functional_workers_;
78  std::vector<std::shared_ptr<PointFunctions>> point_workers_;
80  std::shared_ptr<DFTGrid> grid_;
82  std::map<std::string, double> quad_values_;
83  // Caches collocation grids
84  std::unordered_map<size_t, std::map<std::string, SharedMatrix>> cache_map_;
86 
90 
92  std::vector<SharedMatrix> D_AO_;
93 
94  // GRAC data
96 
97  // VV10 dispersion, return vv10_nlc energy
98  void prepare_vv10_cache(DFTGrid& nlgrid, SharedMatrix D,
99  std::vector<std::map<std::string, SharedVector>>& vv10_cache,
100  std::vector<std::shared_ptr<PointFunctions>>& nl_point_workers, int ansatz = 1);
101  double vv10_nlc(SharedMatrix D, SharedMatrix ret);
102  SharedMatrix vv10_nlc_gradient(SharedMatrix D);
103 
105  void common_init();
106 
107  public:
108  VBase(std::shared_ptr<SuperFunctional> functional, std::shared_ptr<BasisSet> primary, Options& options);
109  virtual ~VBase();
110 
111  static std::shared_ptr<VBase> build_V(std::shared_ptr<BasisSet> primary,
112  std::shared_ptr<SuperFunctional> functional, Options& options,
113  const std::string& type = "RV");
114 
115  std::shared_ptr<BasisSet> basis() const { return primary_; }
116  std::shared_ptr<SuperFunctional> functional() const { return functional_; }
117  std::vector<std::shared_ptr<PointFunctions>> properties() const { return point_workers_; }
118  std::shared_ptr<DFTGrid> grid() const { return grid_; }
119  std::shared_ptr<BlockOPoints> get_block(int block);
120  size_t nblocks();
121  std::map<std::string, double>& quadrature_values() { return quad_values_; }
122 
123  // Creates a collocation cache map based on stride
124  void build_collocation_cache(size_t memory);
125  void clear_collocation_cache() { cache_map_.clear(); }
126 
127  // Set the D matrix, get it back if needed
128  void set_D(std::vector<SharedMatrix> Dvec);
129  const std::vector<SharedMatrix>& Dao() const { return D_AO_; }
130 
131  // Set the site of the grac shift
132  void set_grac_shift(double value);
133 
135  virtual void compute_V(std::vector<SharedMatrix> ret);
136  virtual void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret);
137  virtual SharedMatrix compute_gradient();
138  virtual SharedMatrix compute_hessian();
139 
140  void set_print(int print) { print_ = print; }
141  void set_debug(int debug) { debug_ = debug; }
142 
143  virtual void initialize();
144  virtual void finalize();
145 
146  virtual void print_header() const;
147 };
148 
149 // => Derived Classes <= //
150 
151 class RV : public VBase {
152  protected:
153  public:
154  RV(std::shared_ptr<SuperFunctional> functional, std::shared_ptr<BasisSet> primary, Options& options);
155  ~RV() override;
156 
157  void initialize() override;
158  void finalize() override;
159 
160  void compute_V(std::vector<SharedMatrix> ret) override;
161  void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret) override;
162  SharedMatrix compute_gradient() override;
163  SharedMatrix compute_hessian() override;
164 
165  void print_header() const override;
166 };
167 
168 class UV : public VBase {
169  protected:
170  public:
171  UV(std::shared_ptr<SuperFunctional> functional, std::shared_ptr<BasisSet> primary, Options& options);
172  ~UV() override;
173 
174  void initialize() override;
175  void finalize() override;
176 
177  void compute_V(std::vector<SharedMatrix> ret) override;
178  void compute_Vx(std::vector<SharedMatrix> Dx, std::vector<SharedMatrix> ret) override;
179  SharedMatrix compute_gradient() override;
180 
181  void print_header() const override;
182 };
183 }
184 #endif
void compute_Vx(std::vector< SharedMatrix > Dx, std::vector< SharedMatrix > ret) override
Definition: v.cc:716
void set_debug(int debug)
Definition: v.h:141
void finalize() override
Definition: v.cc:1376
std::shared_ptr< DFTGrid > grid_
Integration grid, built by KSPotential.
Definition: v.h:80
std::vector< std::shared_ptr< PointFunctions > > properties() const
Definition: v.h:117
~UV() override
Definition: v.cc:1363
void initialize() override
Definition: v.cc:565
int debug_
Debug flag.
Definition: v.h:58
std::map< std::string, double > & quadrature_values()
Definition: v.h:121
double vv10_rho_cutoff_
VV10 interior kernel threshold.
Definition: v.h:68
std::shared_ptr< DFTGrid > grid() const
Definition: v.h:118
SharedMatrix compute_gradient() override
Definition: v.cc:981
void clear_collocation_cache()
Definition: v.h:125
Options & options_
Options object, used to build grid.
Definition: v.h:70
double v2_rho_cutoff_
Rho threshold for the second derivative;.
Definition: v.h:66
void set_print(int print)
Definition: v.h:140
std::shared_ptr< BasisSet > primary_
Basis set used in the integration.
Definition: v.h:72
std::vector< std::shared_ptr< SuperFunctional > > functional_workers_
Desired superfunctional kernal.
Definition: v.h:76
void compute_Vx(std::vector< SharedMatrix > Dx, std::vector< SharedMatrix > ret) override
Definition: v.cc:1660
void print_header() const override
Definition: v.cc:578
SharedMatrix USO2AO_
Definition: v.h:89
void initialize() override
Definition: v.cc:1364
void finalize() override
Definition: v.cc:577
SharedMatrix compute_gradient() override
Definition: v.cc:2134
Definition: v.h:55
bool grac_initialized_
Definition: v.h:95
std::map< std::string, double > quad_values_
Quadrature values obtained during integration.
Definition: v.h:82
std::unordered_map< size_t, std::map< std::string, SharedMatrix > > cache_map_
Definition: v.h:84
Definition: v.h:168
SharedMatrix AO2USO_
AO2USO matrix (if not C1)
Definition: v.h:88
int print_
Print flag.
Definition: v.h:60
std::vector< SharedMatrix > D_AO_
Vector of C1 D matrices (built by USO2AO)
Definition: v.h:92
UV(std::shared_ptr< SuperFunctional > functional, std::shared_ptr< BasisSet > primary, Options &options)
Definition: v.cc:1361
Definition: cubature.h:201
int cache_map_deriv_
Definition: v.h:85
void print_header() const override
Definition: v.cc:1377
Definition: liboptions.h:352
std::shared_ptr< BasisSet > basis() const
Definition: v.h:115
RV(std::shared_ptr< SuperFunctional > functional, std::shared_ptr< BasisSet > primary, Options &options)
Definition: v.cc:562
int num_threads_
Number of threads.
Definition: v.h:62
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
int nbf_
Number of basis functions;.
Definition: v.h:64
void compute_V(std::vector< SharedMatrix > ret) override
Throws by default.
Definition: v.cc:1378
#define PSI_API
Definition: pragma.h:155
std::shared_ptr< SuperFunctional > functional() const
Definition: v.h:116
SharedMatrix compute_hessian() override
Definition: v.cc:1100
void compute_V(std::vector< SharedMatrix > ret) override
Throws by default.
Definition: v.cc:579
Definition: v.h:151
std::vector< std::shared_ptr< PointFunctions > > point_workers_
Point function computer (densities, gammas, basis values)
Definition: v.h:78
const std::vector< SharedMatrix > & Dao() const
Definition: v.h:129
std::shared_ptr< SuperFunctional > functional_
Desired superfunctional kernal.
Definition: v.h:74
~RV() override
Definition: v.cc:564