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