/
fisapt.h
273 lines (228 loc) · 8.49 KB
/
fisapt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* @BEGIN LICENSE
*
* Psi4: an open-source quantum chemistry software package
*
* Copyright (c) 2007-2024 The Psi4 Developers.
*
* The copyrights for code used from other parties are included in
* the corresponding files.
*
* This file is part of Psi4.
*
* Psi4 is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* Psi4 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with Psi4; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @END LICENSE
*/
#ifndef FISAPT_H
#define FISAPT_H
#include "psi4/libmints/typedefs.h"
#include "psi4/libmints/basisset.h"
#include "psi4/libmints/wavefunction.h"
#include "psi4/libpsi4util/PsiOutStream.h"
#include <map>
#include <tuple>
namespace psi {
class JK;
class BasisSet;
class DFHelper;
namespace fisapt {
class FISAPT {
protected:
// sSAPT0 exchange-scaling
double sSAPT0_scale_;
/// Global options object
Options& options_;
/// Memory in doubles
size_t doubles_;
/// Reference wavefunction
std::shared_ptr<Wavefunction> reference_;
/// Orbital Basis Set (full molecule)
std::shared_ptr<BasisSet> primary_;
std::shared_ptr<BasisSet> df_basis_scf_;
/// Global JK object
std::shared_ptr<JK> jk_;
/// Map of scalars
std::map<std::string, double> scalars_;
/// Map of vectors
std::map<std::string, std::shared_ptr<Vector> > vectors_;
/// Map of matrices
std::map<std::string, std::shared_ptr<Matrix> > matrices_;
// Build the ExchInd20 potential in the monomer A ov space
std::shared_ptr<Matrix> build_exch_ind_pot(std::map<std::string, std::shared_ptr<Matrix> >& vars);
std::shared_ptr<Matrix> build_exch_ind_pot_par(std::map<std::string, std::shared_ptr<Matrix> >& vars);
std::shared_ptr<Matrix> build_exch_ind_pot_perp(std::map<std::string, std::shared_ptr<Matrix> >& vars);
std::shared_ptr<Matrix> build_exch_ind_pot_avg(std::map<std::string, std::shared_ptr<Matrix> >& vars);
// Build the Ind20 potential in the monomer A ov space
std::shared_ptr<Matrix> build_ind_pot(std::map<std::string, std::shared_ptr<Matrix> >& vars);
// DFHelper object
std::shared_ptr<DFHelper> dfh_;
/// Helper to drop a matrix to filepath/A->name().dat
/// Helper to drop a vector to filepath/A->name().dat
// drop(<Matrix> or <Vector>, filepath) moved py-side
/// Helper to extract columns from a matrix
static std::shared_ptr<Matrix> extract_columns(const std::vector<int>& cols, std::shared_ptr<Matrix> A);
/// Link types as strings, now reused throghout
std::vector<std::string> typesL;
public:
/// Initialize an FISAPT object with an SCF reference
FISAPT(std::shared_ptr<Wavefunction> scf);
FISAPT(std::shared_ptr<Wavefunction> scf, Options& options);
virtual ~FISAPT();
/// Gogo!
// void compute_energy(); moved py-side
/// Get Molecule associated with FISAPT
std::shared_ptr<Molecule> molecule() { return primary_->molecule(); }
// => FISAPT 0th-Order Wavefunction <= //
/// Common initialization (bases, orbitals, eigenvalues, etc)
void common_init();
/// Print header, bases, sizes, etc
void print_header();
/// Localize the active occupied orbitals via IBO2
void localize();
/// Partition the nuclei and electrons
void partition();
/// Build the overlap integrals S
void overlap();
/// Build the kinetic integrals T
void kinetic();
/// Build the nuclear potentials V and interaction energies
void nuclear();
/// Build the J/K potentials for C, D, and E
void coulomb();
/// Solve the relaxed SCF equations for A0 and B0
void scf();
/// Freeze the core orbitals
void freeze_core();
/// Produce unified matrices for A', B', and C'
void unify();
/// Produce unified matrices for A', B', and C' part2
void unify_part2();
/// Create requested cube files
void do_cubes();
/// Plot some analysis files
void raw_plot(const std::string& filepath);
// => F-SAPT0 <= //
/// Localize
void flocalize();
/// Electrostatics
void felst();
/// Exchange
void fexch();
/// Induction
void find();
/// Dispersion
void fdisp();
/// Output
// fdrop() moved py-side
// => SAPT0 <= //
/// Delta HF
void dHF();
/// Electrostatics
void elst();
/// Exchange
void exch();
/// Induction
void ind();
/// Print SAPT results
void print_trailer();
/// Dispersion
void disp(std::map<std::string, SharedMatrix> matrix_cache, std::map<std::string, SharedVector> vector_cache,
bool do_print);
void sinf_disp(std::map<std::string, SharedMatrix> matrix_cache, std::map<std::string, SharedVector> vector_cache,
bool do_print);
/// Return arrays
std::map<std::string, double>& scalars() { return scalars_; }
std::map<std::string, std::shared_ptr<Vector> >& vectors() { return vectors_; }
std::map<std::string, std::shared_ptr<Matrix> >& matrices() { return matrices_; }
};
class FISAPTSCF {
protected:
/// Global options object
Options& options_;
/// Global JK object
std::shared_ptr<JK> jk_;
/// Map of scalars
std::map<std::string, double> scalars_;
/// Map of vectors
std::map<std::string, std::shared_ptr<Vector> > vectors_;
/// Map of matrices
std::map<std::string, std::shared_ptr<Matrix> > matrices_;
/// Print orbitals
void print_orbitals(const std::string& header, int start, std::shared_ptr<Vector> eps);
public:
FISAPTSCF(std::shared_ptr<JK> jk, // JK object
double enuc, // Nuclear repulsion energy
std::shared_ptr<Matrix> S, // Overlap integrals
std::shared_ptr<Matrix> X, // Restricted orthogonalization matrix [nbf x nmo]
std::shared_ptr<Matrix> T, // Kinetic integrals
std::shared_ptr<Matrix> V, // Potential integrals
std::shared_ptr<Matrix> W, // External embedding potential
std::shared_ptr<Matrix> C, // Guess for occupied orbitals [nbf x nocc]
Options& options);
virtual ~FISAPTSCF();
void compute_energy();
std::map<std::string, double>& scalars() { return scalars_; }
std::map<std::string, std::shared_ptr<Vector> >& vectors() { return vectors_; }
std::map<std::string, std::shared_ptr<Matrix> >& matrices() { return matrices_; }
};
class CPHF_FISAPT {
friend class FISAPT;
protected:
// => Global Data <= //
// Convergence tolerance
double delta_;
// Maximum allowed iterations
int maxiter_;
// JK Object
std::shared_ptr<JK> jk_;
// => Monomer A Problem <= //
// Perturbation applied to A
std::shared_ptr<Matrix> w_A_;
// Response of A
std::shared_ptr<Matrix> x_A_;
// Active occ orbital coefficients of A
std::shared_ptr<Matrix> Cocc_A_;
// Active vir orbital coefficients of A
std::shared_ptr<Matrix> Cvir_A_;
// Active occ orbital eigenvalues of A
std::shared_ptr<Vector> eps_occ_A_;
// Active vir orbital eigenvalues of A
std::shared_ptr<Vector> eps_vir_A_;
// => Monomer B Problem <= //
// Perturbation applied to B
std::shared_ptr<Matrix> w_B_;
// Response of B
std::shared_ptr<Matrix> x_B_;
// Active occ orbital coefficients of B
std::shared_ptr<Matrix> Cocc_B_;
// Active vir orbital coefficients of B
std::shared_ptr<Matrix> Cvir_B_;
// Active occ orbital eigenvalues of B
std::shared_ptr<Vector> eps_occ_B_;
// Active vir orbital eigenvalues of B
std::shared_ptr<Vector> eps_vir_B_;
// Form the s = Ab product for the provided vectors b (may or may not need more iterations)
std::map<std::string, std::shared_ptr<Matrix> > product(std::map<std::string, std::shared_ptr<Matrix> > b);
// Apply the denominator from r into z
void preconditioner(std::shared_ptr<Matrix> r, std::shared_ptr<Matrix> z, std::shared_ptr<Vector> o,
std::shared_ptr<Vector> v);
public:
CPHF_FISAPT();
virtual ~CPHF_FISAPT();
void compute_cphf();
};
} // Namespace fisapt
} // Namespace psi
#endif