69 LBCost(
double leaf_value=1.0,
double parent_value=1.0)
70 : leaf_value(leaf_value)
71 , parent_value(parent_value)
88 mutable double coords_sum;
94 std::vector<real_function_3d> orbitals_;
98 std::vector<real_function_3d> R2orbitals_;
105 world(world), calc(calc1), coords_sum(-1.0), nemo_calc(world,calc1) {
114 double value(
const Tensor<double>& x) {
117 double xsq = x.sumsq();
174 orbitals_=
mul(world,nemo_calc.
R,nemo_calc.
get_calc()->amo);
176 R2orbitals_=
mul(world,R2,nemo_calc.
get_calc()->amo);
225 return R2orbitals_[i];
241 std::vector<real_function_3d>
nemos()
const {
249 return calc->
aeps[i];
258 return copy(coulomb);
292 if (
function.world().rank()==0) {
293 printf(
"final correlation energy %2d %2d %12.8f %12.8f\n",
324 template <
typename Archive>
void serialize (Archive& ar) {
325 bool fexist=
function.is_initialized();
327 ar & ij_gQf_ij & ji_gQf_ij & e_singlet & e_triplet & converged
328 & iteration & fexist & cexist;
329 if (fexist) ar &
function;
334 std::string name=
"pair_"+stringify(i)+stringify(j);
337 if (world.
rank()==0) printf(
"loading matrix elements %s",name.c_str());
340 if (world.
rank()==0) printf(
" %s\n",(converged)?
" converged":
" not converged");
342 if (world.
rank()==0)
print(
"could not find pair ",i,j,
" on disk");
348 std::string name=
"pair_"+stringify(i)+stringify(j);
349 if (world.
rank()==0) printf(
"storing matrix elements %s\n",name.c_str());
388 Parameters(
const std::string& input) : thresh_(-1.0), dconv_(-1.0),
389 i(-1), j(-1), freeze(0), restart(
false), maxsub(2),
maxiter(20) {
392 std::ifstream
f(input.c_str());
397 if (s ==
"end")
break;
398 else if (s ==
"econv")
f >> thresh_;
399 else if (s ==
"dconv")
f >> dconv_;
400 else if (s ==
"pair")
f >> i >> j;
401 else if (s ==
"maxsub")
f >> maxsub;
402 else if (s ==
"freeze")
f >> freeze;
403 else if (s ==
"restart") restart=
true;
407 if (dconv_<0.0) dconv_=
sqrt(thresh_)*0.1;
415 if (thresh_<0.0)
MADNESS_EXCEPTION(
"please provide the accuracy threshold for MP2",1);
423 CorrelationFactor corrfac;
427 double correlation_energy;
434 struct Intermediates {
442 Intermediates() : r12phi(), Kfphi0(), Uphi0(), KffKphi0() {};
444 Intermediates(
World& world,
const std::string& filename) :
function(), r12phi(),
445 Kfphi0(), Uphi0(), KffKphi0() {
446 std::ifstream
f(filename.c_str());
451 if (s ==
"end")
break;
452 else if (s ==
"function")
f >>
function;
453 else if (s ==
"r12phi")
f >> r12phi;
454 else if (s ==
"Kfphi0")
f >> Kfphi0;
455 else if (s ==
"Uphi0")
f >> Uphi0;
456 else if (s ==
"KffKphi0")
f >> KffKphi0;
459 if (world.
rank()==0)
print(
"found intermediate in control file: ",s);
463 template <
typename Archive>
void serialize (Archive& ar) {
464 ar &
function & r12phi & Kfphi0 & Uphi0 & KffKphi0;
470 Intermediates intermediates;
485 MADNESS_ASSERT(pairs.find(std::make_pair(i, j)) != pairs.end());
486 return pairs[std::make_pair(i, j)];
496 MADNESS_ASSERT(pairs.find(std::make_pair(i, j)) != pairs.end());
497 return pairs.find(std::make_pair(i, j))->second;
507 double value(
const Tensor<double>& x);
516 double thresh()
const {
return param.thresh_;}
557 template<
typename T,
size_t NDIM>
561 template<
typename T,
size_t NDIM>
626 const bool hc=
false)
const;
640 const bool hc=
false)
const;
656 const bool hc=
false)
const;
660 const bool hc=
false)
const;
674 const int i,
const int j)
const;
Nemo nemo_calc
Definition: mp2.h:102
double value()
return the molecular correlation energy energy (without the HF energy)
Definition: apps/chem/mp2.cc:151
double thresh() const
return the accuracy
Definition: mp2.h:516
real_function_6d constant_term
the first order contribution to the MP1 wave function
Definition: mp2.h:303
std::shared_ptr< PotentialManager > potentialmanager
Definition: chem/SCF.h:714
enhanced POD for the pair functions
Definition: mp2.h:275
Molecule molecule
Definition: chem/SCF.h:716
bool is_initialized() const
Returns true if the function is initialized.
Definition: mra.h:146
Definition: shared_ptr_bits.h:38
bool provides_gradient() const
Definition: mp2.h:108
The Nemo class.
Definition: nemo.h:138
double asymmetry(const real_function_6d &f, const std::string s) const
Definition: apps/chem/mp2.cc:425
real_function_3d R
the nuclear correlation factor
Definition: nemo.h:187
Main include file for MADNESS and defines Function interface.
std::vector< real_function_3d > orbitals() const
return full orbitals, multiplied with the nuclear correlation factor
Definition: mp2.h:205
real_function_3d R2orbital(const int i) const
return orbital i, multiplied with the square nuclear correlation factor
Definition: mp2.h:223
real_function_6d swap_particles(const real_function_6d &f) const
swap particles 1 and 2
Definition: apps/chem/mp2.cc:412
An archive for storing local or parallel data wrapping BinaryFstreamOutputArchive.
Definition: parar.h:241
double econv
Energy convergence.
Definition: chem/SCF.h:271
void print_energy() const
print the pair's energy
Definition: mp2.h:291
real_function_6d r12phi
orbital product multiplied with the correlation factor
Definition: mp2.h:302
SCF & get_calc()
Definition: mp2.h:190
void increment(ElectronPair &pair, real_convolution_6d &green)
compute increments: psi^1 = C + GV C + GVGV C + GVGVGV C + ..
Definition: apps/chem/mp2.cc:371
std::istream & position_stream(std::istream &f, const std::string &tag)
Definition: position_stream.cc:37
const ElectronPair & pair(const int i, const int j) const
return a reference to the electron pair for electrons i and j
Definition: mp2.h:494
double operator()(const Key< 6 > &key, const FunctionNode< double, 6 > &node) const
Definition: mp2.h:74
HartreeFock & get_hf()
return the underlying HF reference
Definition: mp2.h:513
coeffT & coeff()
Returns a non-const reference to the tensor containing the coeffs.
Definition: funcimpl.h:216
tensorT aeps
orbital energies for alpha and beta orbitals
Definition: chem/SCF.h:745
ElectronPair & pair(const int i, const int j)
return a reference to the electron pair for electrons i and j
Definition: mp2.h:483
void print_info(World &world) const
print the SCF parameters
Definition: apps/chem/mp2.cc:235
::std::string string
Definition: gtest-port.h:872
functionT make_coulomb_potential(const functionT &rho) const
make the Coulomb potential given the total density
Definition: chem/SCF.h:909
bool load_pair(World &world)
Definition: mp2.h:333
Convolutions in separated form (including Gaussian)
Definition: operator.h:117
real_function_6d Uphi0
the function U |phi^0> (U being Kutzelnigg's potential)
Definition: mp2.h:305
real_function_6d make_Rpsi(const ElectronPair &pair) const
Definition: apps/chem/mp2.cc:354
double coord_chksum() const
return a checksum for the geometry
Definition: mp2.h:501
void load_mos(World &world)
Definition: chem/SCF.cc:277
real_function_3d nemo(const int i) const
return nemo i, which is the regularized orbital
Definition: mp2.h:232
Definition: chem/SCF.h:712
Objects that implement their own parallel archive interface should derive from this.
Definition: parar.h:52
std::shared_ptr< SCF > get_calc() const
Definition: nemo.h:169
void test(const std::string filename)
Definition: apps/chem/mp2.cc:435
NDIM & f
Definition: mra.h:2179
void initial_guess(World &world)
Definition: chem/SCF.cc:788
std::shared_ptr< NuclearCorrelationFactor > nuclear_correlation
the nuclear correlation factor
Definition: nemo.h:184
MP2(World &world, const std::string &input)
ctor
Definition: apps/chem/mp2.cc:78
double e_singlet
the energy of the singlet pair ij
Definition: mp2.h:310
Function< T, NDIM > & scale(const Q q, bool fence=true)
Inplace, scale the function by a constant. No communication except for optional fence.
Definition: mra.h:896
void solve(World &world)
Definition: chem/SCF.cc:2072
void set_all_coords(const madness::Tensor< double > &newcoords)
Definition: chem/molecule.cc:199
vecfuncT amo
alpha and beta molecular orbitals
Definition: chem/SCF.h:729
a class for computing the first order wave function and MP2 pair energies
Definition: mp2.h:357
int natom() const
Definition: chem/molecule.h:148
double ij_gQf_ij
Definition: mp2.h:313
LBCost(double leaf_value=1.0, double parent_value=1.0)
Definition: mp2.h:69
double zeroth_order_energy(const int i, const int j) const
return the 0th order energy of pair ij (= sum of orbital energies)
Definition: mp2.h:519
madness::Tensor< double > get_all_coords() const
Definition: chem/molecule.cc:177
bool no_compute
If true use orbitals on disk, set value to computed.
Definition: chem/SCF.h:288
int i
Definition: mp2.h:300
CalculationParameters param
Definition: chem/SCF.h:717
The interface to be provided by functions to be optimized.
Definition: solvers.h:176
std::vector< real_function_3d > R2orbitals() const
return orbitals, multiplied with the square nuclear correlation factor
Definition: mp2.h:214
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
int j
orbitals i and j
Definition: mp2.h:300
static double uninitialized()
Definition: mp2.h:298
Example implementation of Krylov-subspace nonlinear equation solver.
void make_nuclear_potential(World &world)
Definition: chem/SCF.cc:448
real_function_3d orbital(const int i) const
return full orbital i, multiplied with the nuclear correlation factor
Definition: mp2.h:196
HartreeFock(World &world, std::shared_ptr< SCF > calc1)
Definition: mp2.h:104
tensorT aocc
occupation numbers for alpha and beta orbitals
Definition: chem/SCF.h:742
ElectronPair(const int i, const int j)
ctor; initialize energies with a large number
Definition: mp2.h:285
void save_mos(World &world)
Definition: chem/SCF.cc:260
double ji_gQf_ij
Definition: mp2.h:314
double parent_value
Definition: mp2.h:68
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
real_function_3d get_nuclear_potential() const
return the nuclear potential
Definition: mp2.h:262
std::vector< real_function_3d > nemos() const
return nemo, which are the regularized orbitals
Definition: mp2.h:241
enable_if_c< is_serializable< T >::value &&is_output_archive< Archive >::value >::type serialize(const Archive &ar, const T *t, unsigned int n)
Definition: archive.h:615
const int maxiter
Definition: gygi_soltion.cc:69
bool converged
is the pair function converged
Definition: mp2.h:317
double value(const Tensor< double > &x)
Definition: mp2.h:114
ElectronPair()
default ctor; initialize energies with a large number
Definition: mp2.h:279
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition: derivative.h:58
ProcessID rank() const
Returns the process rank in this world (same as MPI_Comm_rank()))
Definition: worldfwd.h:526
int nocc() const
return the number of occupied orbitals
Definition: mp2.h:267
std::vector< real_function_3d > phi_l_UK_phi0
< l(2) | U-K | phi^0(1,2)>
Definition: mp2.h:308
bool restart
If true restart from orbitals on disk.
Definition: chem/SCF.h:287
real_function_6d KffKphi0
the function [K,f12] |phi^0>
Definition: mp2.h:306
double orbital_energy(const int i) const
return orbital energy i
Definition: mp2.h:247
std::string aobasis
AO basis used for initial guess (6-31g or sto-3g)
Definition: chem/SCF.h:295
void store_pair(World &world)
Definition: mp2.h:347
Implements (2nd generation) static load/data balancing for functions.
void solve_residual_equations(ElectronPair &pair) const
solve the residual equation for electron pair (i,j)
Definition: apps/chem/mp2.cc:271
Tensor< double > gradient(const Tensor< double > &x)
Definition: mp2.h:181
double coord_chksum() const
Definition: mp2.h:187
void project(World &world)
Definition: chem/SCF.cc:427
double value()
Definition: nemo.h:161
functionT make_density(World &world, const tensorT &occ, const vecfuncT &v) const
Definition: chem/SCF.cc:999
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
const SCF & get_calc() const
Definition: mp2.h:189
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
tensorT derivatives(World &world)
Definition: chem/SCF.cc:1255
void serialize(Archive &ar)
serialize this ElectronPair
Definition: mp2.h:324
double value()
Definition: mp2.h:110
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
void project_ao_basis(World &world)
Definition: chem/SCF.cc:459
real_function_3d get_coulomb_potential() const
return the Coulomb potential
Definition: mp2.h:253
double leaf_value
Definition: mp2.h:67
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
std::vector< real_function_3d > phi_k_UK_phi0
< k(1) | U-K | phi^0(1,2)>
Definition: mp2.h:307
void set_protocol(World &world, double thresh)
Definition: chem/SCF.h:757
double e_triplet
the energy of the triplet pair ij
Definition: mp2.h:311
const double R2
Definition: vnucso.cc:89
int nalpha
Number of alpha spin electrons.
Definition: chem/SCF.h:301
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
static bool exists(World &world, const char *filename)
Returns true if the named, unopened archive exists on disk with read access ... collective.
Definition: parar.h:165
int iteration
current iteration for restart
Definition: mp2.h:316
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition: mra.h:1528
double compute_gQf(const int i, const int j, ElectronPair &pair) const
compute the matrix element
Definition: apps/chem/mp2.cc:476
long rank() const
Definition: gentensor.h:189
double current_energy
Definition: chem/SCF.h:749
bool spin_restricted
True if spin restricted.
Definition: chem/SCF.h:281