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