Psi4
fisapt.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 FISAPT_H
30 #define FISAPT_H
31 
32 #include "psi4/libmints/typedefs.h"
33 #include "psi4/libmints/basisset.h"
36 
37 #include <map>
38 #include <tuple>
39 
40 namespace psi {
41 
42 class JK;
43 class BasisSet;
44 class DFHelper;
45 
46 namespace fisapt {
47 
48 class FISAPT {
49  protected:
50  // sSAPT0 exchange-scaling
51  double sSAPT0_scale_;
55  size_t doubles_;
57  std::shared_ptr<Wavefunction> reference_;
58 
60  std::shared_ptr<BasisSet> primary_;
61  std::shared_ptr<BasisSet> df_basis_scf_;
62 
64  std::shared_ptr<JK> jk_;
65 
67  std::map<std::string, double> scalars_;
69  std::map<std::string, std::shared_ptr<Vector> > vectors_;
71  std::map<std::string, std::shared_ptr<Matrix> > matrices_;
72 
73  // Build the ExchInd20 potential in the monomer A ov space
74  std::shared_ptr<Matrix> build_exch_ind_pot(std::map<std::string, std::shared_ptr<Matrix> >& vars);
75  // Build the Ind20 potential in the monomer A ov space
76  std::shared_ptr<Matrix> build_ind_pot(std::map<std::string, std::shared_ptr<Matrix> >& vars);
77 
78  // DFHelper object
79  std::shared_ptr<DFHelper> dfh_;
80 
83  // drop(<Matrix> or <Vector>, filepath) moved py-side
85  static std::shared_ptr<Matrix> extract_columns(const std::vector<int>& cols, std::shared_ptr<Matrix> A);
86 
87  public:
89  FISAPT(std::shared_ptr<Wavefunction> scf);
90  FISAPT(std::shared_ptr<Wavefunction> scf, Options& options);
91  virtual ~FISAPT();
92 
94  // void compute_energy(); moved py-side
95 
97  std::shared_ptr<Molecule> molecule() { return primary_->molecule(); }
98 
99  // => FISAPT 0th-Order Wavefunction <= //
100 
102  void common_init();
104  void print_header();
106  void localize();
108  void partition();
110  void overlap();
112  void kinetic();
114  void nuclear();
116  void coulomb();
118  void scf();
120  void freeze_core();
122  void unify();
124  void raw_plot(const std::string& filepath);
125 
126  // => F-SAPT0 <= //
127 
129  void flocalize();
131  void felst();
133  void fexch();
135  void find();
137  void fdisp();
139  // fdrop() moved py-side
140 
141  // => SAPT0 <= //
142 
144  void dHF();
146  void elst();
148  void exch();
150  void ind();
152  void print_trailer();
153 
155  void disp(std::map<std::string, SharedMatrix> matrix_cache, std::map<std::string, SharedVector> vector_cache,
156  bool do_print);
157  void sinf_disp(std::map<std::string, SharedMatrix> matrix_cache, std::map<std::string, SharedVector> vector_cache,
158  bool do_print);
159 
161  std::map<std::string, double>& scalars() { return scalars_; }
162  std::map<std::string, std::shared_ptr<Vector> >& vectors() { return vectors_; }
163  std::map<std::string, std::shared_ptr<Matrix> >& matrices() { return matrices_; }
164 };
165 
166 class FISAPTSCF {
167  protected:
170 
172  std::shared_ptr<JK> jk_;
173 
175  std::map<std::string, double> scalars_;
177  std::map<std::string, std::shared_ptr<Vector> > vectors_;
179  std::map<std::string, std::shared_ptr<Matrix> > matrices_;
180 
182  void print_orbitals(const std::string& header, int start, std::shared_ptr<Vector> eps);
183 
184  public:
185  FISAPTSCF(std::shared_ptr<JK> jk, // JK object
186  double enuc, // Nuclear repulsion energy
187  std::shared_ptr<Matrix> S, // Overlap integrals
188  std::shared_ptr<Matrix> X, // Restricted orthogonalization matrix [nbf x nmo]
189  std::shared_ptr<Matrix> T, // Kinetic integrals
190  std::shared_ptr<Matrix> V, // Potential integrals
191  std::shared_ptr<Matrix> W, // External embedding potential
192  std::shared_ptr<Matrix> C, // Guess for occupied orbitals [nbf x nocc]
193  Options& options);
194  virtual ~FISAPTSCF();
195 
196  void compute_energy();
197 
198  std::map<std::string, double>& scalars() { return scalars_; }
199  std::map<std::string, std::shared_ptr<Vector> >& vectors() { return vectors_; }
200  std::map<std::string, std::shared_ptr<Matrix> >& matrices() { return matrices_; }
201 };
202 
203 class CPHF_FISAPT {
204  friend class FISAPT;
205 
206  protected:
207  // => Global Data <= //
208 
209  // Convergence tolerance
210  double delta_;
211  // Maximum allowed iterations
212  int maxiter_;
213  // JK Object
214  std::shared_ptr<JK> jk_;
215 
216  // => Monomer A Problem <= //
217 
218  // Perturbation applied to A
219  std::shared_ptr<Matrix> w_A_;
220  // Response of A
221  std::shared_ptr<Matrix> x_A_;
222  // Active occ orbital coefficients of A
223  std::shared_ptr<Matrix> Cocc_A_;
224  // Active vir orbital coefficients of A
225  std::shared_ptr<Matrix> Cvir_A_;
226  // Active occ orbital eigenvalues of A
227  std::shared_ptr<Vector> eps_occ_A_;
228  // Active vir orbital eigenvalues of A
229  std::shared_ptr<Vector> eps_vir_A_;
230 
231  // => Monomer B Problem <= //
232 
233  // Perturbation applied to B
234  std::shared_ptr<Matrix> w_B_;
235  // Response of B
236  std::shared_ptr<Matrix> x_B_;
237  // Active occ orbital coefficients of B
238  std::shared_ptr<Matrix> Cocc_B_;
239  // Active vir orbital coefficients of B
240  std::shared_ptr<Matrix> Cvir_B_;
241  // Active occ orbital eigenvalues of B
242  std::shared_ptr<Vector> eps_occ_B_;
243  // Active vir orbital eigenvalues of B
244  std::shared_ptr<Vector> eps_vir_B_;
245 
246  // Form the s = Ab product for the provided vectors b (may or may not need more iterations)
247  std::map<std::string, std::shared_ptr<Matrix> > product(std::map<std::string, std::shared_ptr<Matrix> > b);
248  // Apply the denominator from r into z
249  void preconditioner(std::shared_ptr<Matrix> r, std::shared_ptr<Matrix> z, std::shared_ptr<Vector> o,
250  std::shared_ptr<Vector> v);
251 
252  public:
253  CPHF_FISAPT();
254  virtual ~CPHF_FISAPT();
255 
256  void compute_cphf();
257 };
258 
259 } // Namespace fisapt
260 
261 } // Namespace psi
262 
263 #endif
void print_header()
Print header, bases, sizes, etc.
Definition: fisapt.cc:89
void flocalize()
Localize.
Definition: fisapt.cc:2855
std::map< std::string, std::shared_ptr< Matrix > > & matrices()
Definition: fisapt.h:163
void partition()
Partition the nuclei and electrons.
Definition: fisapt.cc:121
void overlap()
Build the overlap integrals S.
Definition: fisapt.cc:485
std::shared_ptr< Matrix > x_A_
Definition: fisapt.h:221
std::map< std::string, double > scalars_
Map of scalars.
Definition: fisapt.h:175
void elst()
Electrostatics.
Definition: fisapt.cc:1175
std::shared_ptr< Vector > eps_occ_A_
Definition: fisapt.h:227
std::shared_ptr< Vector > eps_vir_B_
Definition: fisapt.h:244
virtual ~FISAPTSCF()
Definition: fisapt.cc:4526
static std::shared_ptr< Matrix > extract_columns(const std::vector< int > &cols, std::shared_ptr< Matrix > A)
Helper to extract columns from a matrix.
Definition: fisapt.cc:4496
std::shared_ptr< JK > jk_
Definition: fisapt.h:214
void print_orbitals(const std::string &header, int start, std::shared_ptr< Vector > eps)
Print orbitals.
Definition: fisapt.cc:4747
std::shared_ptr< Matrix > Cocc_A_
Definition: fisapt.h:223
void freeze_core()
Freeze the core orbitals.
Definition: fisapt.cc:697
Definition: fisapt.h:48
void nuclear()
Build the nuclear potentials V and interaction energies.
Definition: fisapt.cc:503
std::shared_ptr< BasisSet > primary_
Orbital Basis Set (full molecule)
Definition: fisapt.h:60
std::shared_ptr< Matrix > Cvir_A_
Definition: fisapt.h:225
double delta_
Definition: fisapt.h:210
void kinetic()
Build the kinetic integrals T.
Definition: fisapt.cc:494
void print_trailer()
Print SAPT results.
Definition: fisapt.cc:2669
CPHF_FISAPT()
Definition: fisapt.cc:4760
std::map< std::string, std::shared_ptr< Matrix > > matrices_
Map of matrices.
Definition: fisapt.h:179
void sinf_disp(std::map< std::string, SharedMatrix > matrix_cache, std::map< std::string, SharedVector > vector_cache, bool do_print)
Definition: fisapt.cc:2233
int * T
Definition: stringlist.cc:66
int maxiter_
Definition: fisapt.h:212
std::shared_ptr< DFHelper > dfh_
Definition: fisapt.h:79
std::map< std::string, double > & scalars()
Definition: fisapt.h:198
FISAPT(std::shared_ptr< Wavefunction > scf)
Initialize an FISAPT object with an SCF reference.
Definition: fisapt.cc:62
std::shared_ptr< Matrix > Cvir_B_
Definition: fisapt.h:240
std::shared_ptr< JK > jk_
Global JK object.
Definition: fisapt.h:64
double sSAPT0_scale_
Definition: fisapt.h:51
std::shared_ptr< Wavefunction > reference_
Reference wavefunction.
Definition: fisapt.h:57
void coulomb()
Build the J/K potentials for C, D, and E.
Definition: fisapt.cc:603
std::shared_ptr< Matrix > w_A_
Definition: fisapt.h:219
std::map< std::string, std::shared_ptr< Vector > > & vectors()
Definition: fisapt.h:199
void disp(std::map< std::string, SharedMatrix > matrix_cache, std::map< std::string, SharedVector > vector_cache, bool do_print)
Dispersion.
Definition: fisapt.cc:1807
FISAPTSCF(std::shared_ptr< JK > jk, double enuc, std::shared_ptr< Matrix > S, std::shared_ptr< Matrix > X, std::shared_ptr< Matrix > T, std::shared_ptr< Matrix > V, std::shared_ptr< Matrix > W, std::shared_ptr< Matrix > C, Options &options)
Definition: fisapt.cc:4514
void common_init()
Common initialization (bases, orbitals, eigenvalues, etc)
Definition: fisapt.cc:65
std::shared_ptr< Vector > eps_vir_A_
Definition: fisapt.h:229
size_t doubles_
Memory in doubles.
Definition: fisapt.h:55
std::shared_ptr< Matrix > x_B_
Definition: fisapt.h:236
std::shared_ptr< Matrix > w_B_
Definition: fisapt.h:234
std::shared_ptr< Vector > eps_occ_B_
Definition: fisapt.h:242
void ind()
Induction.
Definition: fisapt.cc:1406
void dHF()
Output.
Definition: fisapt.cc:851
std::shared_ptr< BasisSet > df_basis_scf_
Definition: fisapt.h:61
void find()
Induction.
Definition: fisapt.cc:3336
std::map< std::string, std::shared_ptr< Matrix > > matrices_
Map of matrices.
Definition: fisapt.h:71
void exch()
Exchange.
Definition: fisapt.cc:1207
void fexch()
Exchange.
Definition: fisapt.cc:3143
std::shared_ptr< JK > jk_
Global JK object.
Definition: fisapt.h:172
std::map< std::string, double > & scalars()
Return arrays.
Definition: fisapt.h:161
std::map< std::string, std::shared_ptr< Vector > > & vectors()
Definition: fisapt.h:162
std::shared_ptr< Matrix > build_ind_pot(std::map< std::string, std::shared_ptr< Matrix > > &vars)
Definition: fisapt.cc:1680
virtual ~CPHF_FISAPT()
Definition: fisapt.cc:4761
void compute_cphf()
Definition: fisapt.cc:4762
Definition: liboptions.h:352
void preconditioner(std::shared_ptr< Matrix > r, std::shared_ptr< Matrix > z, std::shared_ptr< Vector > o, std::shared_ptr< Vector > v)
Definition: fisapt.cc:4903
void unify()
Produce unified matrices for A&#39;, B&#39;, and C&#39;.
Definition: fisapt.cc:802
void raw_plot(const std::string &filepath)
Plot some analysis files.
Definition: fisapt.cc:2790
Options & options_
Global options object.
Definition: fisapt.h:53
void fdisp()
Dispersion.
Definition: fisapt.cc:3958
std::shared_ptr< Matrix > Cocc_B_
Definition: fisapt.h:238
std::shared_ptr< Matrix > build_exch_ind_pot(std::map< std::string, std::shared_ptr< Matrix > > &vars)
Definition: fisapt.cc:1693
std::shared_ptr< Molecule > molecule()
Gogo!
Definition: fisapt.h:97
std::map< std::string, std::shared_ptr< Matrix > > product(std::map< std::string, std::shared_ptr< Matrix > > b)
Definition: fisapt.cc:4920
std::map< std::string, std::shared_ptr< Vector > > vectors_
Map of vectors.
Definition: fisapt.h:177
void localize()
Localize the active occupied orbitals via IBO2.
Definition: fisapt.cc:101
virtual ~FISAPT()
Definition: fisapt.cc:64
Definition: fisapt.h:203
Definition: fisapt.h:166
void scf()
Solve the relaxed SCF equations for A0 and B0.
Definition: fisapt.cc:644
std::map< std::string, double > scalars_
Map of scalars.
Definition: fisapt.h:67
std::map< std::string, std::shared_ptr< Matrix > > & matrices()
Definition: fisapt.h:200
void compute_energy()
Definition: fisapt.cc:4527
Options & options_
Global options object.
Definition: fisapt.h:169
std::map< std::string, std::shared_ptr< Vector > > vectors_
Map of vectors.
Definition: fisapt.h:69
void felst()
Electrostatics.
Definition: fisapt.cc:2995