MADNESS 0.10.1
PNO.h
Go to the documentation of this file.
1/*
2 * PNO.h
3 *
4 * Created on: Oct 22, 2018
5 * Author: kottmanj
6 */
7
8#ifndef PAPER_CODE_PNO_H_
9#define PAPER_CODE_PNO_H_
10
11// convenience macro
12#define PAIRLOOP(it) for(ElectronPairIterator it=pit();it;++it)
13#define TIMER(timer) MyTimer timer=MyTimer(world).start();
14
17
18#include<madness/chem/CC2.h>
22
23namespace madness {
24// needed to plot cubefiles with madness
25extern std::vector<std::string> cubefile_header(std::string filename="input", const bool& no_orient=false);
26
27class PNO : public QCPropertyInterface {
28public:
29 typedef std::shared_ptr<operatorT> poperatorT;
30 PNO(World& world, const Nemo& nemo, const PNOParameters& parameters, const F12Parameters& paramf12)
31 : world(world),
32 param(parameters),
33 nemo(nemo),
34 J(world, &nemo),
35 K(ParametrizedExchange(world, nemo, parameters.exchange())),
36 T(world),
37 V(world, nemo.ncf),
38 F(world, &nemo),
39 Q( nemo.get_calc()->amo),
40 basis(world,nemo.get_calc()->molecule,8),
41 f12(world,nemo,basis,paramf12),
42 msg(world)
43 {
44 poisson = std::shared_ptr<real_convolution_3d>(CoulombOperatorPtr(
45 world, nemo.get_calc()->param.lo(),param.op_thresh()));
47 }
48
49 std::string name() const {return "PNO";};
50
51 static void help() {
52 print_header2("help page for PNO");
53 print("The PNO code computes MP2 energies using pair natural orbitals");
54 print("You can print all available calculation parameters by running\n");
55 print("pno --print_parameters\n");
56 print("You can perform a simple calculation by running\n");
57 print("pno --geometry=h2o.xyz\n");
58 print("provided you have an xyz file in your directory.");
59
60 }
61
62 static void print_parameters() {
64 print("default parameters for the pno program are\n");
65 param.print("pno", "end");
66
67 F12Parameters f12param(param);
68 print("\n\nadditional parameters for the correlation factor are\n");
69 f12param.print("f12", "end");
70
71 print("\n\nthe molecular geometry must be specified in a separate block:");
73 }
74
75 virtual bool selftest() {
76 return true;
77 };
78
79 /// Compute the projected MP2 energies: 2<ij|g|uij> - <ji|g|uij> for all pairs
80 /// gives back the PairEnergies structure with all singlet and triplet energies
82
83 /// solves whatever was specified in input
84 /// will call solve_mp2, solve_cispd etc
85 void solve()const{
86 std::vector<PNOPairs> dummy;
87 solve(dummy);
88 }
89 /// Solve for the PairType that is given
90 void solve(std::vector<PNOPairs>& all_pairs) const;
91
92 /// interfaces the BasisFunctions class
93 /// guesses a set of virtuals depending on the guesstype and what was specified in the parameters
95
96 /// convenience
98
99 /// only the f12 part of the excited state correction of CIS(D) (namely the terms s2b and s2c)
101 /// excited state correction of CIS(D) (namely the terms s2b and s2c)
102 /// f12 part is excluded (no need to recompute after every iteration)
104
105 /// ground state correction of CIS(D) (s4a, s4b, s4c)
106 /// f12 is excluded to avoid recomputation in iterations
108
109 /// The f12 part of the ground state correction of CIS(D) (s4a, s4b, s4c)
111
112 /// solve PNO-MP2 equations
113 void solve_mp2(std::vector<PNOPairs>& pairs)const{
114 if(pairs.empty()){
115 PNOPairs mp2(MP2_PAIRTYPE,f12.acmos.size());
116 solve_mp2(mp2);
117 pairs.push_back(mp2);
118 }else{
119 solve_mp2(pairs.front());
120 }
121 }
122 PNOPairs solve_mp2(PNOPairs& pairs) const;
123 /// solve the PNO-CIS(D) equations
124 std::vector<PNOPairs> solve_cispd(std::vector<PNOPairs>& pairs) const;
125
126 /// compute the average and the maximum rank of a set of PNOs
127 std::pair<size_t, size_t> get_average_rank(const std::valarray<vector_real_function_3d>& va) const;
128
129 /// change the state of insignificant pairs to frozen
130 /// This is based on:
131 /// 1. External Parameters (are some pairs demanded to be frozen)
132 /// 2. Energies (if the current energy is significantly below the MRA threshold there is no point in further optimizing)
133 /// 3. Spatial overlapp (if the norm of the product of the originating MOs is small: i.e. if ||(phi_i)*(phi_j)||_2 is small then pair_ij is insignificant)
135
136 /// Do MRA truncation on all pairs
137 /// pairs are extracted into one large vector and then compressed and truncated
138 /// this saves time since there are less fences
139 PNOPairs truncate_pairs(PNOPairs& pairs) const;
140
141 /// Truncate the ranks of pairs to the given maxrank
143
144 // small helper function to keep track of all keywords which mess with the guess
145 bool is_guess_from_scratch(const PairType& ct)const{
146 if(param.restart()==ALL_PAIRTYPE) return false;
147 else if(param.restart()==ct) return false;
148 else return true;
149 }
150
151 /// save PNOs on disc
152 void save_pnos(const PNOPairs& pairs) const;
153
154 /// load PNOs from disc
155 PNOPairs load_pnos(PNOPairs& pairs) const;
156
157 /// Initialize PNO pairs
158 /// If the guesstype is the default (UNKNOWN_GUESSTYPE) this will take the guess type from the parameters
159 PNOPairs initialize_pairs(PNOPairs& pairs, const GuessType& inpgt = UNKNOWN_GUESSTYPE) const;
160
161 /// compute all fluctuation potentials and store them in the pair structure
162 void update_fluctuation_potentials(PNOPairs& pairs) const;
163 /// Compute the MP2 fluctuation potential of a speficif pair
165 /// Compute the CIS(D) fluctuation potential of a specific pair
167 /// Iterate the pairs
168 /// The type of iteration depends on the parameters and the type of PNOPairs structure
169 /// This will call iterate_pairs_internal at some point
170 /// Depending on the parameters the pairs will be iterated adaptively or just once with one initial guess
171 PNOPairs iterate_pairs(PNOPairs& pairs) const;
172 /// Solve with adaptive solver descriped in the JPC paper
173 PNOPairs adaptive_solver(PNOPairs& pairs) const;
174 /// The actual function which interates the pairs
175 /// Guess functions have to be created before
176 PNOPairs iterate_pairs_internal(PNOPairs& pairs, const int maxiter, const double econv) const;
177
178 /// Grow the rank of pairs by creating guess functions and adding them
179 /// The type of guess is controlled by the parameters
180 PNOPairs grow_rank(PNOPairs& pairs, std::string exop) const;
181
182 /// convenience
184
185 /// solve the MP2 and CIS(D) amplitude equations
186 PairEnergies t_solve(PNOPairs& pairs, const Tensor<double>& F_occ,
187 const double R_convergence_threshold = 1e-6, const size_t max_niter = 100) const;
188
189 /// Compress the PNOs -> lose all PNOs which eigenvalue is below tpno
190 std::valarray<Tensor<double> > pno_compress(PNOPairs& pairs, const double tpno) const;
191
192 /// transform the pnos and all the intermediates/potentials and matrices stored in the PNOPair structure
193 PNOPairs transform_pairs(PNOPairs& pairs, const std::valarray<Tensor<double> >& U_ij) const;
194
195 /// Print information about the PNO rank of all pairs (i.e. the number of PNO functions)
196 void print_ranks(const PNOPairs& pairs)const;
197
198 /// Update all PNOs: i.e. compute Fock-residue potential (V+2J-K, K is reused if Kpno_ij intermeidate in pairs is initialized) and apply the Green's function
199 /// The fluctuation potentials have to be precomputed and stored in the pairs structure
200 bool update_pno(PNOPairs& pairs, const std::valarray<Tensor<double> >& rdm_evals_ij,const Tensor<double>& F_occ) const;
201
202 /// Convenience function to initialize all bsh operators
203 std::vector<poperatorT> make_bsh_operators(World& world, const tensorT& evals) const;
204
205 /// get the CIS potentials without Fock residue, i.e Q(2tJ - 2tK)|i> , with transformed K and J
207
208
209 /// the terms are expanded as follows:
210 /// Q (-J1 +K1) | i(1) > < a(2) | j(2) >
211 /// + Q | i(1) > < a(2) | -J(2) + K(2) | j(2) >
212 /// + i(1) * \int \dr2 1/|r12| a(2) j(2)
213 /// the first line is zero due to orthogonality of a and j, the second line is zero due to action of Q on i
214 template<typename projector>
216 const real_function_3d& moj,
217 const vector_real_function_3d& virtuals,
218 const projector& Qpr) const;
219
220 // not used by CIS(D) -> can still use K intermediates
221 vector_real_function_3d compute_Vreg_aj_i(const size_t& i, const size_t& j,
222 const vector_real_function_3d& virtuals,
223 const vector_real_function_3d& Kpno) const;
224
225 // used by CIS(D) (could also be used by MP2)
226 template<typename projector>
228 const real_function_3d& moj,
229 const vector_real_function_3d& virtuals, const projector& Qpr,
230 const vector_real_function_3d& Kpno =
232
233 // the Fock residue of the regularized potential for CIS(D) (vanishes for MP2)
234 // the minus sign is not included here
235 // this only evalues one part (has to be called twice: -compute_Vreg_aj_i_fock_residue(Vxi,moj) - compute_Vreg_aj_i_fock_residue(moi,Vxj)
236 // returns <a|Qf12|ket1ket2> = Q(<a|f12|ket2>*|ket1>
238 const real_function_3d& ket1, const real_function_3d& ket2,
239 const vector_real_function_3d& virtuals) const;
240 // returns <a|(OVxQ + QOVx)f|ij>_2 = OVx(<a|f12|j>*|i>) + Q(<a|OVxf12|j>*|i>), can apply Q global since QOVx=OVx
241 // use also <ta| = <a|OVx = (OVx^t|a>)^t
243 const real_function_3d& moi, const real_function_3d& moj,
244 const vector_real_function_3d& virtuals,
245 const vector_real_function_3d& Vx) const;
246
247
248
249 // compute Fluctuation Matrix without fluctuation potential (save memory in first iteration)
251
253
255
256
257 /// \param[in,out] A on input = real symmetric matrix, on output = diagonal
258 /// matrix of eigenvalues (from smallest to largest) \param[in,out] v on input
259 /// = basis in which input A is represented, on output = the eigenbasis of A
260 void canonicalize(PNOPairs& v) const;
261
262public:
264 PNOParameters param; ///< calculation parameters
272 std::shared_ptr<real_convolution_3d> poisson;
273 BasisFunctions basis; ///< class which holds all methods to read or create guess functions for PNO or CABS
275 /// convenience
276 size_t nocc()const{return nemo.get_calc()->amo.size();}
277 size_t nact()const{return nemo.get_calc()->amo.size()-param.freeze();}
278 ElectronPairIterator pit()const{ return f12.pit();} /// convenience
279 OrbitalIterator oit()const{return OrbitalIterator(nemo.get_calc()->amo.size(),param.freeze());}
281};
282
283
284
285} /* namespace madness */
286
287#endif /* PAPER_CODE_PNO_H_ */
Definition derivatives.cc:60
Definition PNOGuessFunctions.h:33
Definition SCFOperators.h:334
Definition PNOParameters.h:227
EnergyType energytype() const
Definition PNOParameters.h:256
Class that provides all necessary F12 Potentials and Integrals.
Definition PNOF12Potentials.h:18
ElectronPairIterator pit() const
Convenience: Get electron pair iterator.
Definition PNOF12Potentials.h:59
vector_real_function_3d acmos
Active Molecular Orbitals.
Definition PNOF12Potentials.h:35
F12Parameters param
parameters
Definition PNOF12Potentials.h:24
Computes matrix representation of the Fock operator.
Definition SCFOperators.h:805
Definition SCFOperators.h:188
static void print_parameters()
Definition molecule.cc:110
The Nemo class.
Definition nemo.h:326
std::shared_ptr< SCF > get_calc() const
Definition nemo.h:482
Definition SCFOperators.h:455
Definition PNOParameters.h:30
std::size_t freeze() const
Definition PNOParameters.h:158
PairType restart() const
Definition PNOParameters.h:195
bool f12() const
Definition PNOParameters.h:201
double op_thresh() const
Definition PNOParameters.h:194
Definition PNO.h:27
QProjector< double, 3 > Q
Definition PNO.h:271
bool update_pno(PNOPairs &pairs, const std::valarray< Tensor< double > > &rdm_evals_ij, const Tensor< double > &F_occ) const
Definition PNO.cpp:2156
std::vector< PNOPairs > solve_cispd(std::vector< PNOPairs > &pairs) const
solve the PNO-CIS(D) equations
Definition PNO.cpp:500
F12Potentials f12
Definition PNO.h:274
std::string name() const
Definition PNO.h:49
vector_real_function_3d compute_Vreg_aj_i(const size_t &i, const size_t &j, const vector_real_function_3d &virtuals, const vector_real_function_3d &Kpno) const
Definition PNO.cpp:2689
std::valarray< Tensor< double > > pno_compress(PNOPairs &pairs, const double tpno) const
Compress the PNOs -> lose all PNOs which eigenvalue is below tpno.
Definition PNO.cpp:1959
Tensor< double > compute_fluctuation_matrix(const ElectronPairIterator &it, const vector_real_function_3d &pnos, const vector_real_function_3d &Kpnos_in=vector_real_function_3d()) const
Definition PNO.cpp:2442
PNOPairs iterate_pairs(PNOPairs &pairs) const
Definition PNO.cpp:971
void canonicalize(PNOPairs &v) const
Definition PNO.cpp:2591
size_t nocc() const
convenience
Definition PNO.h:276
PNOParameters param
calculation parameters
Definition PNO.h:264
Kinetic< double, 3 > T
Definition PNO.h:268
PNOPairs initialize_pairs(PNOPairs &pairs, const GuessType &inpgt=UNKNOWN_GUESSTYPE) const
Definition PNO.cpp:741
vector_real_function_3d compute_Vreg_aj_i_commutator_response(const real_function_3d &moi, const real_function_3d &moj, const vector_real_function_3d &virtuals, const vector_real_function_3d &Vx) const
Definition PNO.cpp:2714
std::pair< size_t, size_t > get_average_rank(const std::valarray< vector_real_function_3d > &va) const
compute the average and the maximum rank of a set of PNOs
Definition PNO.cpp:636
PNOPairs compute_fluctuation_potential(const ElectronPairIterator &it, PNOPairs &pairs) const
Compute the MP2 fluctuation potential of a speficif pair.
Definition PNO.cpp:881
PNOPairs adaptive_solver(PNOPairs &pairs) const
Solve with adaptive solver descriped in the JPC paper.
Definition PNO.cpp:1000
virtual bool selftest()
Definition PNO.h:75
vector_real_function_3d guess_virtuals(const vector_real_function_3d &f=vector_real_function_3d(), const GuessType &inpgt=UNKNOWN_GUESSTYPE) const
Definition PNO.cpp:90
bool is_guess_from_scratch(const PairType &ct) const
Definition PNO.h:145
vector_real_function_3d compute_CIS_potentials(const vector_real_function_3d &xcis) const
get the CIS potentials without Fock residue, i.e Q(2tJ - 2tK)|i> , with transformed K and J
Definition PNO.cpp:2424
size_t nact() const
Definition PNO.h:277
PNOPairs transform_pairs(PNOPairs &pairs, const std::valarray< Tensor< double > > &U_ij) const
transform the pnos and all the intermediates/potentials and matrices stored in the PNOPair structure
Definition PNO.cpp:2047
Nemo nemo
Definition PNO.h:265
void check_orthonormality(const vector_real_function_3d &v) const
Definition PNO.cpp:2729
PairEnergies t_solve(PNOPairs &pairs, const Tensor< double > &F_occ, const double R_convergence_threshold=1e-6, const size_t max_niter=100) const
solve the MP2 and CIS(D) amplitude equations
Definition PNO.cpp:1747
PNOPairs load_pnos(PNOPairs &pairs) const
load PNOs from disc
Definition PNO.cpp:2617
PNO(World &world, const Nemo &nemo, const PNOParameters &parameters, const F12Parameters &paramf12)
Definition PNO.h:30
CCMessenger msg
Definition PNO.h:280
std::shared_ptr< operatorT> poperatorT
Definition PNO.h:29
ParametrizedExchange K
Definition PNO.h:267
PairEnergies compute_cispd_f12_correction_gs(const vector_real_function_3d &xcis, PairEnergies &energies) const
The f12 part of the ground state correction of CIS(D) (s4a, s4b, s4c)
Definition PNO.cpp:319
PairEnergies compute_projected_mp2_energies(PNOPairs &pairs) const
Definition PNO.cpp:12
PairEnergies compute_cispd_correction_gs(const vector_real_function_3d &xcis, const PNOPairs &pairs) const
Definition PNO.cpp:186
void save_pnos(const PNOPairs &pairs) const
save PNOs on disc
Definition PNO.cpp:2608
Nuclear< double, 3 > V
Definition PNO.h:269
OrbitalIterator oit() const
convenience
Definition PNO.h:279
PNOPairs truncate_pair_ranks(PNOPairs &pairs) const
Truncate the ranks of pairs to the given maxrank.
Definition PNO.cpp:722
void solve_mp2(std::vector< PNOPairs > &pairs) const
solve PNO-MP2 equations
Definition PNO.h:113
ElectronPairIterator pit() const
Definition PNO.h:278
PNOPairs orthonormalize_cholesky(PNOPairs &pairs) const
convenience
Definition PNO.cpp:1597
Tensor< double > compute_cispd_fluctuation_matrix(const ElectronPairIterator &it, PNOPairs &pairs) const
Definition PNO.cpp:2467
static void print_parameters()
Definition PNO.h:62
std::vector< poperatorT > make_bsh_operators(World &world, const tensorT &evals) const
Convenience function to initialize all bsh operators.
Definition PNO.cpp:2408
vector_real_function_3d compute_Vreg_aj_i_fock_residue(const real_function_3d &ket1, const real_function_3d &ket2, const vector_real_function_3d &virtuals) const
Definition PNO.cpp:2704
Fock< double, 3 > F
Definition PNO.h:270
void update_fluctuation_potentials(PNOPairs &pairs) const
compute all fluctuation potentials and store them in the pair structure
Definition PNO.cpp:2636
EnergyType energytype() const
convenience
Definition PNO.h:183
Coulomb< double, 3 > J
Definition PNO.h:266
BasisFunctions basis
class which holds all methods to read or create guess functions for PNO or CABS
Definition PNO.h:273
void solve() const
Definition PNO.h:85
PNOPairs iterate_pairs_internal(PNOPairs &pairs, const int maxiter, const double econv) const
Definition PNO.cpp:1113
PNOPairs grow_rank(PNOPairs &pairs, std::string exop) const
Definition PNO.cpp:1536
void print_ranks(const PNOPairs &pairs) const
Print information about the PNO rank of all pairs (i.e. the number of PNO functions)
Definition PNO.cpp:2134
PNOPairs compute_cispd_fluctuation_potential(const ElectronPairIterator &it, PNOPairs &pairs) const
Compute the CIS(D) fluctuation potential of a specific pair.
Definition PNO.cpp:909
World & world
Definition PNO.h:263
PairEnergies compute_cispd_f12_correction_es(const vector_real_function_3d &xcis, PairEnergies &energies) const
only the f12 part of the excited state correction of CIS(D) (namely the terms s2b and s2c)
Definition PNO.cpp:1654
vector_real_function_3d compute_V_aj_i(const real_function_3d &moi, const real_function_3d &moj, const vector_real_function_3d &virtuals, const projector &Qpr) const
Definition PNO.cpp:2659
static void help()
Definition PNO.h:51
PairEnergies compute_cispd_correction_es(const vector_real_function_3d &xcis, PNOPairs &pairs) const
Definition PNO.cpp:118
std::shared_ptr< real_convolution_3d > poisson
Definition PNO.h:272
PNOPairs freeze_insignificant_pairs(PNOPairs &pairs) const
Definition PNO.cpp:675
PNOPairs truncate_pairs(PNOPairs &pairs) const
Definition PNO.cpp:649
Definition PNOStructures.h:45
void print(const std::string header="", const std::string footer="") const
print all parameters
Definition QCCalculationParametersBase.cc:22
class implementing properties of QC models
Definition QCPropertyInterface.h:11
orthogonality projector
Definition projector.h:186
A tensor is a multidimension array.
Definition tensor.h:317
A parallel world class.
Definition world.h:132
const int maxiter
Definition gygi_soltion.cc:68
static const double v
Definition hatom_sf_dirac.cc:20
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static const char * filename
Definition legendre.cc:96
static SeparatedConvolution< double, 3 > * CoulombOperatorPtr(World &world, double lo, double eps, const BoundaryConditions< 3 > &bc=FunctionDefaults< 3 >::get_bc(), int k=FunctionDefaults< 3 >::get_k())
Factory function generating separated kernel for convolution with 1/r in 3D.
Definition operator.h:1762
void print_header2(const std::string &s)
medium section heading
Definition print.cc:54
EnergyType
Definition PNOParameters.h:21
@ HYLLERAAS_ENERGYTYPE
Definition PNOParameters.h:21
@ PROJECTED_ENERGYTYPE
Definition PNOParameters.h:21
std::vector< real_function_3d > vector_real_function_3d
Definition functypedefs.h:79
GuessType
Definition PNOParameters.h:25
@ UNKNOWN_GUESSTYPE
Definition PNOParameters.h:25
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:225
std::vector< std::string > cubefile_header(std::string filename="input", const bool &no_orient=false)
Definition molecule.cc:69
NDIM & f
Definition mra.h:2416
PairType
Definition PNOParameters.h:17
@ MP2_PAIRTYPE
Definition PNOParameters.h:17
@ ALL_PAIRTYPE
Definition PNOParameters.h:17
Definition CCStructures.h:77
Definition PNOStructures.h:174
iterates the third index for pair coupling
Definition PNOStructures.h:143
POD for PNO code.
Definition PNOStructures.h:245
POD structure for energies.
Definition PNOStructures.h:112
Definition dirac-hatom.cc:108
void e()
Definition test_sig.cc:75
static Molecule molecule
Definition testperiodicdft.cc:38