MADNESS 0.10.1
nemo.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30 */
31
32/*!
33 \file examples/nemo.h
34 \brief solve the HF equations using numerical exponential MOs
35
36 The source is
37 <a href=http://code.google.com/p/m-a-d-n-e-s-s/source/browse/local
38 /trunk/src/apps/examples/nemo.h>here</a>.
39
40 */
41
42#ifndef NEMO_H_
43#define NEMO_H_
44
45#include <madness/mra/mra.h>
48#include <madness/mra/lbdeux.h>
49#include<madness/chem/SCF.h>
55#include <madness/mra/vmra.h>
56#include<madness/chem/pcm.h>
57#include<madness/chem/AC.h>
59#include "Results.h"
63
64namespace madness {
65
66class PNO;
67class OEP;
68
69
71
72public:
73
74 explicit NemoBase(World& w) : world(w) {}
75
76 virtual ~NemoBase() {}
77
78 virtual std::shared_ptr<Fock<double,3>> make_fock_operator() const {
79 MADNESS_EXCEPTION("implement make_fock operator for your derived NemoBase class",1);
80 return std::shared_ptr<Fock<double,3>>();
81 }
82
83 /// create an instance of the derived object based on the input parameters
84 std::shared_ptr<NuclearCorrelationFactor> get_ncf_ptr() const {
85 return ncf;
86 }
87
88 /// normalize the nemos
89 template<typename T, std::size_t NDIM>
90 void static normalize(std::vector<Function<T,NDIM> >& nemo,
92
93 if (nemo.size()==0) return;
94 World& world=nemo[0].world();
95 // compute the norm of the reconstructed orbitals, includes the factor
96 std::vector<Function<T,NDIM> > mos = (metric.is_initialized()) ? metric*nemo : nemo;
97 std::vector<double> norms = norm2s(world, mos);
98
99 // scale the nemos, excludes the nuclear correlation factor
100 std::vector<double> invnorm(norms.size());
101 for (std::size_t i = 0; i < norms.size(); ++i)
102 invnorm[i] = 1.0 / norms[i];
103 scale(world, nemo, invnorm);
104 }
105
106 template<typename T>
107 static Tensor<T> Q2(const Tensor<T>& s) {
108 Tensor<T> Q = -0.5*s;
109 for (int i=0; i<s.dim(0); ++i) Q(i,i) += 1.5;
110 return Q;
111 }
112
113 /// orthonormalize the vectors
114 template<typename T, std::size_t NDIM>
115 void orthonormalize(std::vector<Function<T,NDIM> >& nemo,
117 const double trantol=FunctionDefaults<NDIM>::get_thresh()*0.01) const {
118
119 if (nemo.size()==0) return;
120 normalize(nemo,metric);
121 double maxq;
122 do {
123 std::vector<Function<T,NDIM> > Rnemo = (metric.is_initialized()) ? metric*nemo : nemo;
124 Tensor<T> Q = Q2(matrix_inner(world, Rnemo, Rnemo));
125 maxq=0.0;
126 for (int i=0; i<Q.dim(0); ++i)
127 for (int j=0; j<i; ++j)
128 maxq = std::max(maxq,std::abs(Q(i,j)));
129
130 Q.screen(trantol); // ???? Is this really needed?
131 nemo = transform(world, nemo, Q, trantol, true);
132 truncate(world, nemo);
133// if (world.rank() == 0) print("ORTHOG2: maxq trantol", maxq, trantol);
134
135 } while (maxq>0.01);
136 normalize(nemo,metric);
137 }
138
139 template<typename T, std::size_t NDIM>
141 return sum(world,abssq(world,nemo)).truncate();
142 }
143
144 virtual bool need_recompute_factors_and_potentials(const double thresh) const {
145 bool need=false;
146 if ((not R.is_initialized()) or (R.thresh()>thresh)) need=true;
147 if (not ncf) need=true;
148 if ((not R_square.is_initialized()) or (R_square.thresh()>thresh)) need=true;
149 return need;
150 };
151
153 R.clear();
154 R_square.clear();
155 ncf.reset();
156 };
157
159 const std::shared_ptr<PotentialManager>& pm,
160 const std::pair<std::string,double>& ncf_parameter) {
161
162 // construct the nuclear correlation factor:
163 if (not ncf) {
165 }
166
167 // re-project the ncf
169 R = ncf->function();
171 R_square = ncf->square();
173 }
174
175 /// compute the nuclear gradients
177 const Molecule& molecule) const;
178
179 /// compute kinetic energy as square of the "analytical" expectation value
180
181 /// @param[in] the nemo orbitals F
182 /// @return T = 1/2 \sum_i \int R^2 U1.U1 F^2 + 2 R^2 U1.grad(F) + R^2 grad(F)^2
183 template<typename T, std::size_t NDIM>
184 double compute_kinetic_energy(const std::vector<Function<T,NDIM> >& nemo) const {
185
186 // T = 0.5\sum_i \int R^2 U1.U1 F^2 - 2 R^2 U1.grad(F) F + R^2 grad(F)^2
187 // = 0.5 (<U1.U1 | rho > + <R^2|grad(F)^2> - 2<R^2 | U1.grad(F) >)
188 // note: U1=-grad(R)/R
189 //auto id=nemo.front().world().id();
190 //auto id1=R_square.world().id();
191 //auto worldid=world.id();
192 world.gop.fence();
193 real_function_3d dens=dot(world,nemo,nemo)*R_square;
196 double ke1=inner(dens,U1dotU1);
197
198 double ke2=0.0;
199 double ke3=0.0;
200 //double ke3_real=0.0;
201 //double ke3_imag=0.0;
202
203 for (size_t axis = 0; axis < NDIM; axis++) {
204 real_derivative_3d D = free_space_derivative<double, NDIM>(world, axis);
205 const std::vector<Function<T,NDIM> > dnemo = apply(world, D, nemo);
206
207 real_function_3d term2=dot(world,dnemo,nemo)*ncf->U1(axis);
208 double tmp=-2.0*inner(R_square,term2);
209// ke3_real -=2.0*std::real(tmp);
210// ke3_imag -=2.0*std::imag(tmp);
211 ke3 +=tmp;
212
213 const real_function_3d term1=dot(world,dnemo,dnemo);
214 world.gop.fence();
215 ke2 += inner(term1,R_square);
216
217 }
218// if (ke3_imag>1.e-8) {
219// print("kinetic energy, imaginary part: ",ke3_imag);
220// MADNESS_EXCEPTION("imaginary kinetic energy",1);
221// }
222// double ke=2.0*(ke1+ke2+ke3_real); // closed shell
223 double ke=2.0*(ke1+ke2+ke3); // closed shell
224 return 0.5*ke;
225 }
226
227 /// compute kinetic energy as square of the "analytical" derivative of the orbitals
228
229 /// @param[in] the nemo orbitals F
230 /// @return T = 1/2 \sum_i || grad(R)*F_i + R*grad(F_i)||^2
231 template<typename T, std::size_t NDIM>
232 double compute_kinetic_energy1(const std::vector<Function<T,NDIM> >& nemo) const {
233 timer timer1(world);
234 double ke=0.0;
235 for (int i=0; i<nemo.size(); ++i) {
236 double fnorm2=norm2(world,-1.0*R*ncf->U1vec()*nemo[i] + R*grad(nemo[i]));
237 ke+=2.0*fnorm2*fnorm2;
238 }
239 timer1.end("compute_kinetic_energy1");
240 return 0.5*ke;
241 }
242
243
244 /// compute kinetic energy as square of the "analytical" derivative of the orbitals
245
246 /// @param[in] the nemo orbitals F
247 /// @return T = 1/2 \sum_i || grad(R)*F_i + R*grad(F_i)||^2
248 template<typename T, std::size_t NDIM>
249 double compute_kinetic_energy1a(const std::vector<Function<T,NDIM> >& nemo) const {
250 timer timer1(world);
251 double ke=0.0;
252 for (int i=0; i<NDIM; ++i) {
253 std::vector< std::shared_ptr< Derivative<T,NDIM> > > grad=
254 gradient_operator<T,NDIM>(world);
255 double fnorm2=norm2(world,R*(-1.0*ncf->U1(i)*nemo + apply(world,*(grad[i]),nemo)));
256 ke+=2.0*fnorm2*fnorm2;
257 }
258 timer1.end("compute_kinetic_energy1a");
259 return 0.5*ke;
260 }
261
262 /// compute kinetic energy as direct derivative of the orbitals (probably imprecise)
263
264 /// @param[in] the nemo orbitals F
265 /// @return T = 1/2 \sum_i || grad(R*F_i)||^2
266 template<typename T, std::size_t NDIM>
267 double compute_kinetic_energy2(const std::vector<Function<T,NDIM> >& nemo) const {
268
269 // it's ok to use phi here, no regularization necessary for this eigenvalue
270 double E_kin = 0.0;
271 for (int axis = 0; axis < 3; axis++) {
272 real_derivative_3d D = free_space_derivative<double, 3>(world, axis);
273 const vecfuncT dphi = apply(world, D,R*nemo);
274 E_kin += 0.5 * (inner(world, dphi, dphi)).sum();
275 // -1/2 sum <Psi|Nabla^2|Psi> = 1/2 sum <NablaPsi|NablaPsi> (integration by parts)
276 }
277 E_kin *= 2.0; // 2 because closed shell
278 return E_kin;
279 }
280
281
282 bool check_convergence(const std::vector<double> energies,
283 const std::vector<double> oldenergies, const double bsh_norm,
284 const double delta_density, const CalculationParameters& param,
285 const double econv, const double dconv) const {
286
287 double maxenergychange=fabs(energies.size()-oldenergies.size()); // >0 if oldenergyvec not initialized
288 for (auto iter1=energies.begin(), iter2=oldenergies.begin();
289 (iter1!=energies.end() and iter2!=oldenergies.end()); iter1++, iter2++) {
290 maxenergychange=std::max(maxenergychange,fabs(*iter1 - *iter2));
291 }
292 double delta_energy=fabs(energies[0]-oldenergies[0]);
293
294 bool bsh_conv=param.converge_bsh_residual() ? bsh_norm<dconv : true;
295 bool total_energy_conv=param.converge_total_energy() ? delta_energy<econv : true;
296 bool each_energy_conv=param.converge_each_energy() ? maxenergychange<econv*3.0 : true;
297 bool density_conv=param.converge_density() ? delta_density<dconv : true;
298
299 if (world.rank()==0 and param.print_level()>2) {
300 std::stringstream line;
301 line << "convergence: bshresidual, energy change, max energy change, density change "
302 << std::scientific << std::setprecision(1)
303 << bsh_norm << " " << delta_energy << " "
304 << maxenergychange << " " << delta_density;
305 print(line.str());
306 }
307
308 return (bsh_conv and density_conv and each_energy_conv and total_energy_conv);
309 }
310
312
313 /// the nuclear correlation factor
314 std::shared_ptr<NuclearCorrelationFactor> ncf;
315
316 /// the nuclear correlation factor
318
319 /// the square of the nuclear correlation factor
321
322
323};
324
325
326/// The Nemo class
327class Nemo: public NemoBase, public QCPropertyInterface {
328 typedef std::shared_ptr<real_convolution_3d> poperatorT;
329 friend class PNO;
330 friend class TDHF;
331
332public:
333 /// class holding parameters for a nemo calculation beyond the standard dft parameters from moldft
335 static constexpr char const* tag = "nemo";
336
341
345
346 std::string get_tag() const override {
347 return std::string("dft");
348 }
349
351 // check if parameters are initialized for a nemo calculation already
352 if (parameter_exists("ncf")) return;
353 initialize<std::pair<std::string,double> > ("ncf",{"slater",2.0},"nuclear correlation factor");
354 initialize<bool> ("hessian",false,"compute the hessian matrix");
355 initialize<bool> ("read_cphf",false,"read the converged orbital response for nuclear displacements from file");
356 initialize<bool> ("restart_cphf",false,"read the guess orbital response for nuclear displacements from file");
357 initialize<bool> ("purify_hessian",false,"symmetrize the hessian matrix based on atomic charges");
358 }
359
360 std::pair<std::string,double> ncf() const {return get<std::pair<std::string,double> >("ncf");}
361 bool hessian() const {return get<bool>("hessian");}
362
363 };
364
365
366public:
367 std::filesystem::path work_dir;
368
369 /// ctor
370
371 /// @param[in] world1 the world
372 /// @param[in] calc the SCF
373// Nemo(World& world1, std::shared_ptr<SCF> calc, const std::string inputfile);
374
375 Nemo(World& world, const commandlineparser& parser);
376
378 const Molecule& molecule);
379
380 std::string name() const {return "nemo";}
381 bool selftest() {return false;}
382
383 static void help() {
384 print_header2("help page for NEMO");
385 print("The nemo code computes Hartree-Fock and DFT energies, gradients and hessians using a nuclear correlation factor");
386 print("that regularizes the singular nuclear potential. SCF orbitals for the basis for post-SCF calculations like");
387 print("excitation energies (cis), correlation energies (cc2), local potentials (oep), etc\n");
388 print("A nemo calculation input is mostly identical to a moldft calculation input, but it uses the additional input");
389 print("parameter ncf (nuclear correlation factor)\n");
390 print("You can print all available calculation parameters by running\n");
391 print("nemo --print_parameters\n");
392 print("You can perform a simple calculation by running\n");
393 print("nemo --geometry=h2o.xyz\n");
394 print("provided you have an xyz file in your directory.");
395
396 }
397
398 static void print_parameters() {
400 print("default parameters for the nemo program are");
401 param.print("nemo","end");
402 print("\n\nthe molecular geometry must be specified in a separate block:");
404 }
405
406
407 bool check_converged(const Tensor<double>& x) const {
408 double xsq = x.sumsq();
409 return (xsq == coords_sum);
410 }
411
412 virtual double value() {return value(calc->molecule.get_all_coords());}
413
414 virtual double value(const Tensor<double>& x);
415
416 void load_mos(World& w) {
417 calc->load_mos(w);
418 }
419
420 /// compute dipole moment and gradient at the current geometry
421 virtual nlohmann::json analyze() const;
422
423 /// compute the nuclear gradients
425
426 bool provides_gradient() const {return true;}
427
428 /// returns the molecular hessian matrix at structure x
430
431 /// construct the fock operator based on the calculation parameters (K or XC?)
432 virtual std::shared_ptr<Fock<double,3>> make_fock_operator() const;
433
434 /// purify and symmetrize the hessian
435
436 /// The hessian should be symmetric, but it is not, because
437 /// \f[
438 /// \langle i^{Y_B}|H^{X_A}|i\rangle \neq \langle i|H^{X_A}|i^{Y_B}\rangle
439 /// \f]
440 /// does holds analytically, but not numerically. If the two numbers
441 /// differ, pick the more trustworthy, which is the one with a heavy
442 /// atom causing the perturbed density and the light atom being the
443 /// nuclear singularity.
444 /// @param[in] hessian the raw hessian
445 /// @return a symmetrized hessian
447
448
449 /// solve the CPHF equations for the nuclear displacements
450
451 /// this function computes that part of the orbital response that is
452 /// orthogonal to the occupied space. If no NCF's are used this
453 /// corresponds to the normal response. If NCF's are used the part
454 /// parallel to the occupied space must be added!
455 /// \f[
456 /// F^X = F^\perp + F^\parallel
457 /// \f]
458 /// cf parallel_CPHF()
459 /// @param[in] iatom the atom A to be moved
460 /// @param[in] iaxis the coordinate X of iatom to be moved
461 /// @return \ket{i^X} or \ket{F^\perp}
462 vecfuncT solve_cphf(const size_t iatom, const int iaxis, const Tensor<double>& fock,
463 const vecfuncT& guess, const vecfuncT& rhsconst,
464 const Tensor<double>& incomplete_hessian, const vecfuncT& parallel,
465 const SCFProtocol& p, const std::string& xc_data) const;
466
467 /// solve the CPHF equation for all displacements
468
469 /// this function computes the nemo response F^X
470 /// \f[
471 /// F^X = F^\perp + F^\parallel
472 /// \f]
473 /// To reconstruct the unregularized orbital response (not recommended):
474 /// \f[
475 /// i^X = R^X F + R F^X
476 /// \f]
477 /// The orbital response i^X constructed in this way is automatically
478 /// orthogonal to the occupied space because of the parallel term F^\parallel
479 /// @return a vector of the nemo response F^X for all displacements
480 std::vector<vecfuncT> compute_all_cphf();
481
482 /// this function computes that part of the orbital response that is
483 /// parallel to the occupied space.
484 /// \f[
485 /// F^X = F^\perp + F^\parallel
486 /// \f]
487 /// If no NCF's are used F^\parallel vanishes.
488 /// If NCF's are used this term does not vanish because the derivatives of
489 /// the NCF does not vanish, and it is given by
490 /// \f[
491 /// F_i^\parallel = -\frac{1}{2}\sum_k|F_k ><F_k | (R^2)^X | F_i>
492 /// \f]
493 vecfuncT compute_cphf_parallel_term(const size_t iatom, const int iaxis) const;
494
495 /// compute the IR intensities in the double harmonic approximation
496
497 /// use the projected normal modes; units are km/mol
498 /// @param[in] normalmodes the normal modes
499 /// @param[in] dens_pt the perturbed densities for each nuclear displacement
501 const vecfuncT& dens_pt) const;
502
503 std::shared_ptr<SCF> get_calc() const {return calc;}
504
506 const CalculationParameters& get_calc_param() const {return calc->param;}
507
508 PCM get_pcm()const{return pcm;}
509
510 /// compute the Fock matrix from scratch
511 tensorT compute_fock_matrix(const vecfuncT& nemo, const tensorT& occ) const;
512
513 /// return a reference to the molecule
514 Molecule& molecule() {return calc->molecule;}
515
516 /// return a reference to the molecule
518 return calc->molecule;
519 }
520
521 /// make the density (alpha or beta)
523 const vecfuncT& nemo) const;
524
525 /// make the density using different bra and ket vectors
526
527 /// e.g. for computing the perturbed density \sum_i \phi_i \phi_i^X
528 /// or when using nemos: \sum_i R2nemo_i nemo_i
530 const vecfuncT& bra, const vecfuncT& ket, const bool refine=false) const;
531
532 /// make the derivative of the density
533
534 /// \f$ \nabla\rho = 2R^X R \rho_R + R^2\nabla \rho_R \f$
535 /// @param[in] rhonemo the regularized density
536 /// @param[in] axis the component of the nabla operator
537 /// @return the gradient of the *reconstructed* density
539 const int axis) const;
540
541 /// compute the reduced densities sigma (gamma) for GGA functionals
543 const real_function_3d& rho2) const;
544
545
546 /// the Laplacian of the density
547
548 /// The Laplacian should currently only be used for subsequent convolution
549 /// with a Green's function (which is reasonably stable), but not on its own!
550 ///
551 /// The Laplacian of the cuspy density is numerically fairly unstable:
552 /// - a singular term may be rewritten using the nuclear potential (see below)
553 /// - the Laplacian of the regularized density is still very noisy
554 ///
555 /// It may be computed as
556 /// \f[
557 /// \Delta \rho = \Delta (R^2 \rho_R)
558 /// = \Delta (R^2) \rho_R + 2\nabla R \nabla \rho_R + R^2 \Delta \rho_R
559 /// = 2 R^2 U1^2 \rho_R -4 R^2 ( U-V ) \rho_R + R^2 \Delta\rho_R
560 /// \f]
561 /// where we can use the identity
562 /// \f[
563 /// U=V + R^{-1}[T,R]
564 /// -2 R (U-V) = \Delta R + 2\nabla R\dot \nabla
565 /// \f]
566 /// first term comes from the definition of the U potential as the commutator
567 /// over the kinetic energy (aka the Laplacian)
568 /// @param[in] rhonemo the regularized density \rho_R
569 /// @return the laplacian of the reconstructed density \Delta (R^2\rho_R)
571
572 /// compute the kinetic energy potential using Eq. (16) of
573 /// R. A. King and N. C. Handy, “Kinetic energy functionals from the Kohn–Sham potential,”
574 /// Phys. Chem. Chem. Phys., vol. 2, no. 22, pp. 5049–5056, 2000.
576
577
578 /// smooth a function by projecting it onto k-1 and then average with k
579
580 /// kept it here for further testing
582 int k=f.get_impl()->get_k();
583 real_function_3d fproj=project(f,k-1);
584 real_function_3d freproj=project(fproj,k);
585 f=0.5*(f+freproj);
586 }
587
588protected:
589
590 std::shared_ptr<SCF> calc;
591
592public:
594
595protected:
597
598public:
599
600 /// return the symmetry_projector
604
605private:
606
607 /// sum of square of coords at last solved geometry
608 mutable double coords_sum;
609
610protected:
611 /// a poisson solver
612 std::shared_ptr<real_convolution_3d> poisson;
613
614 /// asymptotic correction for DFT
616
617// /// apply the AC scheme of Tozer/Handy with the multipole approximation
618// Function<double,3> apply_ac(const Function<double,3>& vxc)const{
619// return ac.apply(vxc);
620// }
621//
622// /// apply the AC scheme of Tozer/Handy using the hartree potential
623// Function<double,3> apply_ac(const Function<double,3>& vxc, const Function<double,3>& vhartree)const{
624// return ac.apply(vxc,vhartree);
625// }
626//
627// /// apply the AC scheme of Tozer/Handy
628// Function<double,3> apply_ac_excited(Function<double,3>& vxc, const Function<double,3>& vhartree)const{
629// return ac.apply_potential(vxc,vhartree);
630// }
631
632private:
633 /// polarizable continuum model
635// AC<3> ac;
636
637protected:
638 /// adapt the thresholds consistently to a common value
639 void set_protocol(const double thresh) {
640
641 calc->set_protocol<3>(world,thresh);
642
644 timer timer1(world,get_calc_param().print_level()>2);
645 get_calc()->make_nuclear_potential(world);
646 construct_nuclear_correlation_factor(calc->molecule, calc->potentialmanager, get_nemo_param().ncf());
647 timer1.end("reproject ncf");
648 }
649
650 // (re) construct the Poisson solver
651 poisson = std::shared_ptr<real_convolution_3d>(
653
654 // set thresholds for the MOs
657
658 }
659
660 /// solve the HF equations
661 double solve(const SCFProtocol& proto);
662
663 /// given nemos, compute the HF energy using the regularized expressions for T and V
664 std::vector<double> compute_energy_regularized(const vecfuncT& nemo, const vecfuncT& Jnemo,
665 const vecfuncT& Knemo, const vecfuncT& Unemo) const;
666
667 /// compute the reconstructed orbitals, and all potentials applied on nemo
668
669 /// to use these potentials in the fock matrix computation they must
670 /// be multiplied by the nuclear correlation factor
671 /// @param[in] nemo the nemo orbitals
672 /// @param[out] Jnemo Coulomb operator applied on the nemos
673 /// @param[out] Knemo exchange operator applied on the nemos
674 /// @param[out] pcmnemo PCM (solvent) potential applied on the nemos
675 /// @param[out] Unemo regularized nuclear potential applied on the nemos
676 void compute_nemo_potentials(const vecfuncT& nemo,
677 vecfuncT& Jnemo, vecfuncT& Knemo, vecfuncT& xcnemo, vecfuncT& pcmnemo,
678 vecfuncT& Unemo) const;
679
680 /// return the Coulomb potential
682
683 /// compute the incomplete hessian
684
685 /// incomplete hessian is the nuclear-nuclear contribution, and the
686 /// contribution from the second derivative of the nuclear potential,
687 /// and also the derivative of the nuclear correlation factor.
688 /// i.e. all contributions that *do not* contain the regularized perturbed
689 /// density, but it will contain parts of the perturbed density
691
692 /// compute the complementary incomplete hessian
693
694 /// @param[in] xi the response functions including the parallel part
696 const std::vector<vecfuncT>& xi) const;
697
698 /// compute the constant term for the CPHF equations
699
700 /// mainly all terms with the nuclear correlation factor's derivatives
701 vecfuncT make_cphf_constant_term(const size_t iatom, const int iaxis,
702 const vecfuncT& R2nemo, const real_function_3d& rhonemo) const;
703
704public:
705
706 bool is_dft() const {return calc->xc.is_dft();}
707
708 bool do_pcm() const {return get_calc_param().pcm_data() != "none";}
709
710 bool do_ac() const {return get_calc_param().ac_data() != "none";}
711
712 AC<3> get_ac() const {return ac;}
713
714 bool do_symmetry() const {return (symmetry_projector.get_pointgroup()!="C1");}
715
716protected:
717
718 /// localize the nemo orbitals
719 vecfuncT localize(const vecfuncT& nemo, const double dconv, const bool randomize) const;
720protected:
721 /// return the threshold for vanishing elements in orbital rotations
722 double trantol() const {
723 return calc->vtol / std::min(30.0, double(get_calc()->amo.size()));
724 }
725
726 void make_plots(const real_function_3d &f,const std::string &name="function")const{
727 double width = FunctionDefaults<3>::get_cell_min_width()/2.0 - 1.e-3;
729 coord_3d start(0.0); start[0]=-width;
730 coord_3d end(0.0); end[0]=width;
731 plot_line(("line_"+name).c_str(),1000,start,end,f);
732 }
733
734 /// save a function
735 template<typename T, size_t NDIM>
736 void save_function(const std::vector<Function<T,NDIM> >& f, const std::string name) const;
737
738 /// load a function
739 template<typename T, size_t NDIM>
740 void load_function(std::vector<Function<T,NDIM> >& f, const std::string name) const;
741
742};
743
744/// save a function
745template<typename T, size_t NDIM>
746void Nemo::save_function(const std::vector<Function<T,NDIM> >& f, const std::string name) const {
747 if (world.rank()==0) print("saving vector of functions",name);
749 ar & f.size();
750 for (const Function<T,NDIM>& ff:f) ar & ff;
751}
752
753/// load a function
754template<typename T, size_t NDIM>
755void Nemo::load_function(std::vector<Function<T,NDIM> >& f, const std::string name) const {
756 if (world.rank()==0) print("loading vector of functions",name);
758 std::size_t fsize=0;
759 ar & fsize;
760 f.resize(fsize);
761 for (std::size_t i=0; i<fsize; ++i) ar & f[i];
762}
763
764}
765
766#endif /* NEMO_H_ */
767
double w(double t, double eps)
Definition DKops.h:22
solution protocol for SCF calculations
Definition AC.h:427
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static double get_cell_min_width()
Returns the minimum width of any user cell dimension.
Definition funcdefaults.h:391
A multiresolution adaptive numerical function.
Definition mra.h:139
double thresh() const
Returns value of truncation threshold. No communication.
Definition mra.h:672
void set_thresh(double value, bool fence=true)
Sets the value of the truncation threshold. Optional global fence.
Definition mra.h:682
void clear(bool fence=true)
Clears the function as if constructed uninitialized. Optional fence.
Definition mra.h:979
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:167
Definition molecule.h:129
static void print_parameters()
Definition molecule.cc:120
Definition nemo.h:70
std::shared_ptr< NuclearCorrelationFactor > ncf
the nuclear correlation factor
Definition nemo.h:314
double compute_kinetic_energy1a(const std::vector< Function< T, NDIM > > &nemo) const
compute kinetic energy as square of the "analytical" derivative of the orbitals
Definition nemo.h:249
double compute_kinetic_energy1(const std::vector< Function< T, NDIM > > &nemo) const
compute kinetic energy as square of the "analytical" derivative of the orbitals
Definition nemo.h:232
std::shared_ptr< NuclearCorrelationFactor > get_ncf_ptr() const
create an instance of the derived object based on the input parameters
Definition nemo.h:84
virtual void invalidate_factors_and_potentials()
Definition nemo.h:152
static void normalize(std::vector< Function< T, NDIM > > &nemo, const Function< double, NDIM > metric=Function< double, NDIM >())
normalize the nemos
Definition nemo.h:90
NemoBase(World &w)
Definition nemo.h:74
real_function_3d R
the nuclear correlation factor
Definition nemo.h:317
Function< typename Tensor< T >::scalar_type, NDIM > compute_density(const std::vector< Function< T, NDIM > > nemo) const
Definition nemo.h:140
virtual std::shared_ptr< Fock< double, 3 > > make_fock_operator() const
Definition nemo.h:78
virtual bool need_recompute_factors_and_potentials(const double thresh) const
Definition nemo.h:144
real_function_3d R_square
the square of the nuclear correlation factor
Definition nemo.h:320
Tensor< double > compute_gradient(const real_function_3d &rhonemo, const Molecule &molecule) const
compute the nuclear gradients
Definition madness/chem/nemo.cc:104
double compute_kinetic_energy(const std::vector< Function< T, NDIM > > &nemo) const
compute kinetic energy as square of the "analytical" expectation value
Definition nemo.h:184
static Tensor< T > Q2(const Tensor< T > &s)
Definition nemo.h:107
void construct_nuclear_correlation_factor(const Molecule &molecule, const std::shared_ptr< PotentialManager > &pm, const std::pair< std::string, double > &ncf_parameter)
Definition nemo.h:158
double compute_kinetic_energy2(const std::vector< Function< T, NDIM > > &nemo) const
compute kinetic energy as direct derivative of the orbitals (probably imprecise)
Definition nemo.h:267
World & world
Definition nemo.h:311
void orthonormalize(std::vector< Function< T, NDIM > > &nemo, const Function< double, NDIM > metric=Function< double, NDIM >(), const double trantol=FunctionDefaults< NDIM >::get_thresh() *0.01) const
orthonormalize the vectors
Definition nemo.h:115
virtual ~NemoBase()
Definition nemo.h:76
bool check_convergence(const std::vector< double > energies, const std::vector< double > oldenergies, const double bsh_norm, const double delta_density, const CalculationParameters &param, const double econv, const double dconv) const
Definition nemo.h:282
The Nemo class.
Definition nemo.h:327
void set_protocol(const double thresh)
adapt the thresholds consistently to a common value
Definition nemo.h:639
bool do_symmetry() const
Definition nemo.h:714
virtual double value()
Definition nemo.h:412
projector_irrep get_symmetry_projector() const
return the symmetry_projector
Definition nemo.h:601
tensorT compute_fock_matrix(const vecfuncT &nemo, const tensorT &occ) const
compute the Fock matrix from scratch
Definition madness/chem/nemo.cc:360
double trantol() const
return the threshold for vanishing elements in orbital rotations
Definition nemo.h:722
const NemoCalculationParameters & get_nemo_param() const
Definition nemo.h:505
std::filesystem::path work_dir
Definition nemo.h:367
Molecule & molecule() const
return a reference to the molecule
Definition nemo.h:517
vecfuncT compute_cphf_parallel_term(const size_t iatom, const int iaxis) const
Definition madness/chem/nemo.cc:1625
void load_function(std::vector< Function< T, NDIM > > &f, const std::string name) const
load a function
Definition nemo.h:755
std::shared_ptr< SCF > get_calc() const
Definition nemo.h:503
Tensor< double > purify_hessian(const Tensor< double > &hessian) const
purify and symmetrize the hessian
Definition madness/chem/nemo.cc:1093
std::shared_ptr< real_convolution_3d > poperatorT
Definition nemo.h:328
real_function_3d get_coulomb_potential(const vecfuncT &psi) const
return the Coulomb potential
Definition madness/chem/nemo.cc:695
std::vector< double > compute_energy_regularized(const vecfuncT &nemo, const vecfuncT &Jnemo, const vecfuncT &Knemo, const vecfuncT &Unemo) const
given nemos, compute the HF energy using the regularized expressions for T and V
Definition madness/chem/nemo.cc:534
Tensor< double > gradient(const Tensor< double > &x)
compute the nuclear gradients
Definition madness/chem/nemo.cc:887
virtual nlohmann::json analyze() const
compute dipole moment and gradient at the current geometry
Definition madness/chem/nemo.cc:269
const CalculationParameters & get_calc_param() const
Definition nemo.h:506
double solve(const SCFProtocol &proto)
solve the HF equations
Definition madness/chem/nemo.cc:387
vecfuncT solve_cphf(const size_t iatom, const int iaxis, const Tensor< double > &fock, const vecfuncT &guess, const vecfuncT &rhsconst, const Tensor< double > &incomplete_hessian, const vecfuncT &parallel, const SCFProtocol &p, const std::string &xc_data) const
solve the CPHF equations for the nuclear displacements
Definition madness/chem/nemo.cc:1277
Tensor< double > make_incomplete_hessian() const
compute the incomplete hessian
Definition madness/chem/nemo.cc:1138
std::vector< vecfuncT > compute_all_cphf()
solve the CPHF equation for all displacements
Definition madness/chem/nemo.cc:1445
Tensor< double > make_incomplete_hessian_response_part(const std::vector< vecfuncT > &xi) const
compute the complementary incomplete hessian
Definition madness/chem/nemo.cc:1196
real_function_3d make_density(const Tensor< double > &occ, const vecfuncT &nemo) const
make the density (alpha or beta)
Definition madness/chem/nemo.cc:701
const NemoCalculationParameters nemo_param
Definition nemo.h:593
real_function_3d make_laplacian_density(const real_function_3d &rhonemo) const
the Laplacian of the density
Definition madness/chem/nemo.cc:745
static void smoothen(real_function_3d &f)
smooth a function by projecting it onto k-1 and then average with k
Definition nemo.h:581
PCM get_pcm() const
Definition nemo.h:508
Tensor< double > compute_IR_intensities(const Tensor< double > &normalmodes, const vecfuncT &dens_pt) const
compute the IR intensities in the double harmonic approximation
Definition madness/chem/nemo.cc:1644
virtual std::shared_ptr< Fock< double, 3 > > make_fock_operator() const
construct the fock operator based on the calculation parameters (K or XC?)
Definition madness/chem/nemo.cc:311
std::shared_ptr< SCF > calc
Definition nemo.h:590
void load_mos(World &w)
Definition nemo.h:416
static void print_parameters()
Definition nemo.h:398
bool check_converged(const Tensor< double > &x) const
Definition nemo.h:407
bool provides_gradient() const
Override this to return true if the derivative is implemented.
Definition nemo.h:426
real_function_3d kinetic_energy_potential(const vecfuncT &nemo) const
Definition madness/chem/nemo.cc:787
void compute_nemo_potentials(const vecfuncT &nemo, vecfuncT &Jnemo, vecfuncT &Knemo, vecfuncT &xcnemo, vecfuncT &pcmnemo, vecfuncT &Unemo) const
compute the reconstructed orbitals, and all potentials applied on nemo
Definition madness/chem/nemo.cc:612
PCM pcm
polarizable continuum model
Definition nemo.h:634
VibrationalResults hessian(const Tensor< double > &x)
returns the molecular hessian matrix at structure x
Definition madness/chem/nemo.cc:916
void save_function(const std::vector< Function< T, NDIM > > &f, const std::string name) const
save a function
Definition nemo.h:746
void make_plots(const real_function_3d &f, const std::string &name="function") const
Definition nemo.h:726
bool do_ac() const
Definition nemo.h:710
projector_irrep symmetry_projector
Definition nemo.h:596
double coords_sum
sum of square of coords at last solved geometry
Definition nemo.h:608
std::shared_ptr< real_convolution_3d > poisson
a poisson solver
Definition nemo.h:612
real_function_3d make_sigma(const real_function_3d &rho1, const real_function_3d &rho2) const
compute the reduced densities sigma (gamma) for GGA functionals
Definition madness/chem/nemo.cc:860
real_function_3d make_ddensity(const real_function_3d &rhonemo, const int axis) const
make the derivative of the density
Definition madness/chem/nemo.cc:728
AC< 3 > ac
asymptotic correction for DFT
Definition nemo.h:615
vecfuncT localize(const vecfuncT &nemo, const double dconv, const bool randomize) const
localize the nemo orbitals
Definition madness/chem/nemo.cc:294
bool do_pcm() const
Definition nemo.h:708
bool selftest()
Definition nemo.h:381
AC< 3 > get_ac() const
Definition nemo.h:712
vecfuncT make_cphf_constant_term(const size_t iatom, const int iaxis, const vecfuncT &R2nemo, const real_function_3d &rhonemo) const
compute the constant term for the CPHF equations
Definition madness/chem/nemo.cc:1225
Molecule & molecule()
return a reference to the molecule
Definition nemo.h:514
std::string name() const
Definition nemo.h:380
static void help()
Definition nemo.h:383
bool is_dft() const
Definition nemo.h:706
functor for a local U1 dot U1 potential
Definition correlationfactor.h:532
interface class to the PCMSolver library
Definition pcm.h:52
Definition PNO.h:27
class for holding the parameters for calculation
Definition chem/QCCalculationParametersBase.h:296
void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition chem/QCCalculationParametersBase.h:332
bool parameter_exists(const std::string &key) const
Definition chem/QCCalculationParametersBase.h:582
class implementing properties of QC models
Definition QCPropertyInterface.h:11
struct for running a protocol of subsequently tightening precision
Definition SCFProtocol.h:47
Definition TDHF.h:214
A tensor is a multidimensional array.
Definition tensor.h:318
T sumsq() const
Returns the sum of the squares of the elements.
Definition tensor.h:1670
Definition Results.h:196
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:176
A parallel world class.
Definition world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:320
WorldGopInterface & gop
Global operations.
Definition world.h:207
An archive for storing local or parallel data, wrapping a BinaryFstreamInputArchive.
Definition parallel_archive.h:366
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition parallel_archive.h:321
Definition pointgroupsymmetry.h:98
std::string get_pointgroup() const
get the point group name
Definition pointgroupsymmetry.h:170
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
static double lo
Definition dirac-hatom.cc:23
Defines/implements plotting interface for functions.
double psi(const Vector< double, 3 > &r)
Definition hatom_energy.cc:78
Implements (2nd generation) static load/data balancing for functions.
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
optimize the geometrical structure of a molecule
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::shared_ptr< NuclearCorrelationFactor > create_nuclear_correlation_factor(World &world, const Molecule &molecule, const std::shared_ptr< PotentialManager > potentialmanager, const std::string inputline)
create and return a new nuclear correlation factor
Definition correlationfactor.cc:45
void print_header2(const std::string &s)
medium section heading
Definition print.cc:54
Function< double, NDIM > abssq(const Function< double_complex, NDIM > &z, bool fence=true)
Returns a new function that is the square of the absolute value of the input.
Definition mra.h:2901
std::vector< double > norm2s(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition vmra.h:869
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:731
void truncate(World &world, std::vector< Function< T, NDIM > > &v, double tol=0.0, bool fence=true)
Truncates a vector of functions.
Definition vmra.h:335
void set_thresh(World &world, std::vector< Function< T, NDIM > > &v, double thresh, bool fence=true)
Sets the threshold in a vector of functions.
Definition vmra.h:1310
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition vmra.h:895
void plot_plane(World &world, const Function< double, NDIM > &function, const std::string name)
Definition funcplot.h:625
FunctionFactory< double, 3 > real_factory_3d
Definition functypedefs.h:108
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:226
void refine(World &world, const std::vector< Function< T, NDIM > > &vf, bool fence=true)
refine the functions according to the autorefine criteria
Definition vmra.h:196
NDIM & f
Definition mra.h:2604
Function< TENSOR_RESULT_TYPE(T, R), NDIM > dot(World &world, const std::vector< Function< T, NDIM > > &a, const std::vector< Function< R, NDIM > > &b, bool fence=true)
Multiplies and sums two vectors of functions r = \sum_i a[i] * b[i].
Definition vmra.h:1590
static SeparatedConvolution< double, 3 > * CoulombOperatorPtr(World &world, double lo, double eps, const std::array< LatticeRange, 3 > &lattice_ranges=FunctionDefaults< 3 >::get_bc().lattice_range(), int k=FunctionDefaults< 3 >::get_k())
Factory function generating separated kernel for convolution with 1/r in 3D.
Definition operator.h:1776
vector< functionT > vecfuncT
Definition corepotential.cc:58
CCPairFunction< T, NDIM > apply(const SeparatedConvolution< T, NDIM/2 > &op, const CCPairFunction< T, NDIM > &arg)
apply the operator to the argument
Definition ccpairfunction.h:896
std::vector< Function< T, NDIM > > grad(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
shorthand gradient operator
Definition vmra.h:2059
Function< T, CCPairFunction< T, NDIM >::LDIM > inner(const CCPairFunction< T, NDIM > &c, const Function< T, CCPairFunction< T, NDIM >::LDIM > &f, const std::tuple< int, int, int > v1, const std::tuple< int, int, int > v2)
Definition ccpairfunction.h:993
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition vmra.h:847
void plot_line(World &world, const char *filename, int npt, const Vector< double, NDIM > &lo, const Vector< double, NDIM > &hi, const opT &op)
Generates ASCII file tabulating f(r) at npoints along line r=lo,...,hi.
Definition funcplot.h:442
Function< T, NDIM > project(const Function< T, NDIM > &other, int k=FunctionDefaults< NDIM >::get_k(), double thresh=FunctionDefaults< NDIM >::get_thresh(), bool fence=true)
Definition mra.h:2587
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
Derivative< double, 3 > real_derivative_3d
Definition functypedefs.h:185
void matrix_inner(DistributedMatrix< T > &A, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< T, NDIM > > &g, bool sym=false)
Definition distpm.cc:46
static long abs(long a)
Definition tensor.h:219
Implementation of Krylov-subspace nonlinear equation solver.
Implements most functionality of separated operators.
double Q(double a)
Definition relops.cc:20
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
const double xi
Exponent for delta function approx.
Definition siam_example.cc:60
Definition test_ar.cc:204
Definition CalculationParameters.h:51
std::string ac_data() const
Definition CalculationParameters.h:205
std::string pcm_data() const
Definition CalculationParameters.h:204
Definition molecular_optimizer.h:46
virtual Molecule & molecule()
return the molecule of the target
Definition molecular_optimizer.h:49
class holding parameters for a nemo calculation beyond the standard dft parameters from moldft
Definition nemo.h:334
void initialize_nemo_parameters()
Definition nemo.h:350
std::pair< std::string, double > ncf() const
Definition nemo.h:360
bool hessian() const
Definition nemo.h:361
static constexpr char const * tag
Definition nemo.h:335
NemoCalculationParameters(World &world, const commandlineparser &parser)
Definition nemo.h:337
std::string get_tag() const override
Definition nemo.h:346
NemoCalculationParameters()
Definition nemo.h:342
very simple command line parser
Definition commandlineparser.h:28
Definition timing_utilities.h:9
double end(const std::string msg)
Definition timing_utilities.h:56
Definition dirac-hatom.cc:112
InputParameters param
Definition tdse.cc:203
static double guess(const coordT &r)
Definition tdse.confused.cc:345
AtomicInt sum
Definition test_atomicint.cc:46
constexpr std::size_t NDIM
Definition testgconv.cc:54
std::size_t axis
Definition testpdiff.cc:59
Defines operations on vectors of Functions.