Psi4
superfunctional.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-2019 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 SUPERFUNCTIONAL_H
30 #define SUPERFUNCTIONAL_H
31 
32 #include "psi4/libmints/typedefs.h"
33 #include "psi4/pragma.h"
34 #include <map>
35 #include <vector>
36 #include <cstdlib>
37 #include <string>
38 namespace psi {
39 
40 class Functional;
41 class BlockOPoints;
42 
63  protected:
64  // => Meta-Data <= //
65  std::string name_;
66  std::string description_;
67  std::string citation_;
68  bool locked_;
69 
70  // => Exchange-side DFA functionals <= //
71  std::vector<std::shared_ptr<Functional>> x_functionals_;
72  double x_alpha_;
73  double x_beta_;
74  double x_omega_;
75 
76  // => Correlation-side DFA functionals <= //
77  std::vector<std::shared_ptr<Functional>> c_functionals_;
78  double c_alpha_;
79  double c_ss_alpha_;
80  double c_os_alpha_;
81  double c_omega_;
82 
83  // => Asymptotic corrections <= //
85  std::shared_ptr<Functional> grac_x_functional_;
86  std::shared_ptr<Functional> grac_c_functional_;
87  double grac_shift_;
88  double grac_alpha_;
89  double grac_beta_;
90 
91  // => VV10 parameters corrections <= //
93  double vv10_b_;
94  double vv10_c_;
95  double vv10_beta_;
96 
97  // => Functional values and partials <= //
100  int deriv_;
101  std::map<std::string, SharedVector> values_;
102  std::map<std::string, SharedVector> ac_values_;
103  std::map<std::string, SharedVector> vv_values_;
104 
105  // Set up a null Superfunctional
106  void common_init();
107 
108  // Check if we can edit this Superfunctional
109  void can_edit();
110 
111  public:
112  // => Constructors (Use the factory constructor, or really know what's up) <= //
113 
114  SuperFunctional();
115  virtual ~SuperFunctional();
116 
117  // Build a blank superfunctional
118  static std::shared_ptr<SuperFunctional> blank();
119  static std::shared_ptr<SuperFunctional> XC_build(std::string name, bool unpolarized);
120 
121  // Builds a worker version of the superfunctional
122  std::shared_ptr<SuperFunctional> build_worker();
123 
124  // Allocate values (MUST be called after adding new functionals to the superfunctional)
125  void allocate();
126 
127  // => Computers <= //
128 
129  std::map<std::string, SharedVector>& compute_functional(const std::map<std::string, SharedVector>& vals,
130  int npoints = -1);
131  void test_functional(SharedVector rho_a, SharedVector rho_b, SharedVector gamma_aa, SharedVector gamma_ab,
132  SharedVector gamma_bb, SharedVector tau_a, SharedVector tau_b);
133 
134  // Compute the cache data for VV10 dispersion
135  std::map<std::string, SharedVector> compute_vv10_cache(const std::map<std::string, SharedVector>& vals,
136  std::shared_ptr<BlockOPoints> block, double rho_thresh,
137  int npoints = -1, bool internal = false);
138 
139  // Copmutes the Cache data for VV10 dispersion
140  double compute_vv10_kernel(const std::map<std::string, SharedVector>& vals,
141  const std::vector<std::map<std::string, SharedVector>>& vv10_cache,
142  std::shared_ptr<BlockOPoints> block, int npoints = -1, bool do_grad = false);
143 
144  // => Input/Output <= //
145 
146  std::map<std::string, SharedVector>& values() { return values_; }
147  SharedVector value(const std::string& key) { return values_[key]; }
148  SharedVector vv_value(const std::string& key) { return vv_values_[key]; }
149 
150  std::vector<std::shared_ptr<Functional>>& x_functionals() { return x_functionals_; }
151  std::vector<std::shared_ptr<Functional>>& c_functionals() { return c_functionals_; }
152  std::shared_ptr<Functional> grac_x_functional() { return grac_x_functional_; }
153  std::shared_ptr<Functional> grac_c_functional() { return grac_c_functional_; }
154 
155  std::shared_ptr<Functional> x_functional(const std::string& name);
156  std::shared_ptr<Functional> c_functional(const std::string& name);
157  void add_x_functional(std::shared_ptr<Functional> fun);
158  void add_c_functional(std::shared_ptr<Functional> fun);
159  void set_grac_x_functional(std::shared_ptr<Functional> fun) {
160  needs_grac_ = true;
161  grac_x_functional_ = fun;
162  }
163  void set_grac_c_functional(std::shared_ptr<Functional> fun) {
164  needs_grac_ = true;
165  grac_c_functional_ = fun;
166  }
167 
168  // => Setters <= //
169 
170  void set_lock(bool locked) { locked_ = locked; }
171  void set_do_vv10(bool do_vv10) { needs_vv10_ = do_vv10; }
172  void set_name(const std::string& name) { name_ = name; }
173  void set_description(const std::string& description) { description_ = description; }
174  void set_citation(const std::string& citation) { citation_ = citation; }
175 
177  void set_deriv(int deriv) { deriv_ = deriv; }
178 
179  void set_x_omega(double omega);
180  void set_c_omega(double omega);
181  void set_x_alpha(double alpha);
182  void set_x_beta(double beta);
183  void set_c_alpha(double alpha);
184  void set_c_ss_alpha(double alpha);
185  void set_c_os_alpha(double alpha);
186  void set_vv10_b(double b);
187  void set_vv10_c(double c);
188  void set_grac_shift(double grac_shift);
189  void set_grac_alpha(double grac_alpha);
190  void set_grac_beta(double grac_beta);
191 
192  // => Accessors <= //
193 
194  std::string name() const { return name_; }
195  std::string description() const { return description_; }
196  std::string citation() const { return citation_; }
197 
198  int ansatz() const;
199  int max_points() const { return max_points_; }
200  int deriv() const { return deriv_; }
201 
202  double x_omega() const { return x_omega_; }
203  double c_omega() const { return c_omega_; }
204  double x_alpha() const { return x_alpha_; }
205  double x_beta() const { return x_beta_; }
206  double c_alpha() const { return c_alpha_; }
207  double c_ss_alpha() const { return c_ss_alpha_; }
208  double c_os_alpha() const { return c_os_alpha_; }
209  double vv10_b() const { return vv10_b_; }
210  double vv10_c() const { return vv10_c_; }
211  double grac_shift() const { return grac_shift_; }
212  double grac_alpha() const { return grac_alpha_; }
213  double grac_beta() const { return grac_beta_; }
214 
215  bool needs_xc() const { return ((c_functionals_.size() + x_functionals_.size()) > 0); }
216  bool needs_vv10() const { return needs_vv10_; };
217  bool needs_grac() const { return needs_grac_; };
218  bool PSI_API is_unpolarized() const;
219  bool PSI_API is_meta() const;
220  bool PSI_API is_gga() const;
221  bool is_x_lrc() const { return x_omega_ != 0.0; }
222  bool is_c_lrc() const { return c_omega_ != 0.0; }
223  bool is_x_hybrid() const { return x_alpha_ != 0.0; }
224  bool is_c_hybrid() const { return c_alpha_ != 0.0; }
225  bool is_c_scs_hybrid() const { return c_os_alpha_ != 0.0 || c_ss_alpha_ != 0.0; }
226  bool is_libxc_func() const { return libxc_xc_func_; }
227 
228  // => Utility <= //
229 
230  void print(std::string out_fname = "outfile", int print = 1) const;
231  void py_print() const { print("outfile", 1); }
232  void py_print_detail(int level) const { print("outfile", level); }
233 };
234 }
235 
236 #endif
bool needs_grac_
Definition: superfunctional.h:84
double grac_beta() const
Definition: superfunctional.h:213
void set_c_alpha(double alpha)
Definition: superfunctional.cc:337
std::map< std::string, SharedVector > & values()
Definition: superfunctional.h:146
std::vector< std::shared_ptr< Functional > > & x_functionals()
Definition: superfunctional.h:150
SharedVector vv_value(const std::string &key)
Definition: superfunctional.h:148
std::map< std::string, SharedVector > ac_values_
Definition: superfunctional.h:102
void allocate()
Definition: superfunctional.cc:442
double c_ss_alpha() const
Definition: superfunctional.h:207
std::shared_ptr< Functional > grac_x_functional()
Definition: superfunctional.h:152
double grac_shift() const
Definition: superfunctional.h:211
void set_c_ss_alpha(double alpha)
Definition: superfunctional.cc:368
void set_vv10_b(double b)
Definition: superfunctional.cc:341
double c_alpha() const
Definition: superfunctional.h:206
std::shared_ptr< Functional > grac_c_functional()
Definition: superfunctional.h:153
bool needs_vv10() const
Definition: superfunctional.h:216
void set_grac_c_functional(std::shared_ptr< Functional > fun)
Definition: superfunctional.h:163
double vv10_b_
Definition: superfunctional.h:93
double grac_alpha() const
Definition: superfunctional.h:212
std::map< std::string, SharedVector > values_
Definition: superfunctional.h:101
double x_omega_
Definition: superfunctional.h:74
double c_omega_
Definition: superfunctional.h:81
bool PSI_API is_meta() const
Definition: superfunctional.cc:408
int deriv_
Definition: superfunctional.h:100
std::string description() const
Definition: superfunctional.h:195
void set_deriv(int deriv)
Definition: superfunctional.h:177
std::vector< std::shared_ptr< Functional > > & c_functionals()
Definition: superfunctional.h:151
double vv10_c_
Definition: superfunctional.h:94
void set_max_points(int max_points)
Definition: superfunctional.h:176
bool is_c_hybrid() const
Definition: superfunctional.h:224
std::string name() const
Definition: superfunctional.h:194
double grac_shift_
Definition: superfunctional.h:87
void add_x_functional(std::shared_ptr< Functional > fun)
Definition: superfunctional.cc:376
double grac_alpha_
Definition: superfunctional.h:88
bool is_c_scs_hybrid() const
Definition: superfunctional.h:225
double x_alpha_
Definition: superfunctional.h:72
std::vector< std::shared_ptr< Functional > > c_functionals_
Definition: superfunctional.h:77
bool is_c_lrc() const
Definition: superfunctional.h:222
double x_alpha() const
Definition: superfunctional.h:204
void set_c_os_alpha(double alpha)
Definition: superfunctional.cc:372
void set_grac_beta(double grac_beta)
Definition: superfunctional.cc:356
void set_do_vv10(bool do_vv10)
Definition: superfunctional.h:171
SuperFunctional()
Definition: superfunctional.cc:47
void py_print() const
Definition: superfunctional.h:231
std::map< std::string, SharedVector > compute_vv10_cache(const std::map< std::string, SharedVector > &vals, std::shared_ptr< BlockOPoints > block, double rho_thresh, int npoints=-1, bool internal=false)
Definition: superfunctional.cc:696
std::shared_ptr< Functional > x_functional(const std::string &name)
Definition: superfunctional.cc:390
bool is_x_lrc() const
Definition: superfunctional.h:221
std::shared_ptr< Functional > c_functional(const std::string &name)
Definition: superfunctional.cc:384
void set_grac_x_functional(std::shared_ptr< Functional > fun)
Definition: superfunctional.h:159
void set_lock(bool locked)
Definition: superfunctional.h:170
std::shared_ptr< Functional > grac_c_functional_
Definition: superfunctional.h:86
double c_os_alpha_
Definition: superfunctional.h:80
std::shared_ptr< SuperFunctional > build_worker()
Definition: superfunctional.cc:106
void set_name(const std::string &name)
Definition: superfunctional.h:172
void test_functional(SharedVector rho_a, SharedVector rho_b, SharedVector gamma_aa, SharedVector gamma_ab, SharedVector gamma_bb, SharedVector tau_a, SharedVector tau_b)
Definition: superfunctional.cc:922
void set_x_omega(double omega)
Definition: superfunctional.cc:321
void set_c_omega(double omega)
Definition: superfunctional.cc:325
void set_vv10_c(double c)
Definition: superfunctional.cc:347
double c_ss_alpha_
Definition: superfunctional.h:79
bool needs_grac() const
Definition: superfunctional.h:217
std::string description_
Definition: superfunctional.h:66
double grac_beta_
Definition: superfunctional.h:89
int deriv() const
Definition: superfunctional.h:200
std::map< std::string, SharedVector > vv_values_
Definition: superfunctional.h:103
bool is_x_hybrid() const
Definition: superfunctional.h:223
int max_points() const
Definition: superfunctional.h:199
void common_init()
Definition: superfunctional.cc:49
bool needs_vv10_
Definition: superfunctional.h:92
bool needs_xc() const
Definition: superfunctional.h:215
void add_c_functional(std::shared_ptr< Functional > fun)
Definition: superfunctional.cc:380
bool locked_
Definition: superfunctional.h:68
void set_x_beta(double beta)
Definition: superfunctional.cc:333
std::string citation() const
Definition: superfunctional.h:196
double vv10_b() const
Definition: superfunctional.h:209
std::shared_ptr< Functional > grac_x_functional_
Definition: superfunctional.h:85
double x_beta_
Definition: superfunctional.h:73
std::string name_
Definition: superfunctional.h:65
void print(std::string out_fname="outfile", int print=1) const
Definition: superfunctional.cc:141
double x_omega() const
Definition: superfunctional.h:202
bool libxc_xc_func_
Definition: superfunctional.h:98
double compute_vv10_kernel(const std::map< std::string, SharedVector > &vals, const std::vector< std::map< std::string, SharedVector >> &vv10_cache, std::shared_ptr< BlockOPoints > block, int npoints=-1, bool do_grad=false)
Definition: superfunctional.cc:784
void set_description(const std::string &description)
Definition: superfunctional.h:173
#define PSI_API
Definition: pragma.h:155
void set_x_alpha(double alpha)
Definition: superfunctional.cc:329
double c_alpha_
Definition: superfunctional.h:78
void set_grac_alpha(double grac_alpha)
Definition: superfunctional.cc:352
void can_edit()
Definition: superfunctional.cc:316
Definition: superfunctional.h:62
void set_grac_shift(double grac_shift)
Definition: superfunctional.cc:360
void py_print_detail(int level) const
Definition: superfunctional.h:232
static std::shared_ptr< SuperFunctional > blank()
Definition: superfunctional.cc:77
bool PSI_API is_gga() const
Definition: superfunctional.cc:396
int ansatz() const
Definition: superfunctional.cc:935
double x_beta() const
Definition: superfunctional.h:205
std::vector< std::shared_ptr< Functional > > x_functionals_
Definition: superfunctional.h:71
double c_omega() const
Definition: superfunctional.h:203
double c_os_alpha() const
Definition: superfunctional.h:208
std::string citation_
Definition: superfunctional.h:67
static std::shared_ptr< SuperFunctional > XC_build(std::string name, bool unpolarized)
Definition: superfunctional.cc:78
int max_points_
Definition: superfunctional.h:99
void set_citation(const std::string &citation)
Definition: superfunctional.h:174
std::map< std::string, SharedVector > & compute_functional(const std::map< std::string, SharedVector > &vals, int npoints=-1)
Definition: superfunctional.cc:584
bool is_libxc_func() const
Definition: superfunctional.h:226
double vv10_c() const
Definition: superfunctional.h:210
std::shared_ptr< Vector > SharedVector
Definition: adc.h:51
virtual ~SuperFunctional()
Definition: superfunctional.cc:48
bool PSI_API is_unpolarized() const
Definition: superfunctional.cc:417
double vv10_beta_
Definition: superfunctional.h:95
SharedVector value(const std::string &key)
Definition: superfunctional.h:147