MADNESS 0.10.1
SCF.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 $Id$
33 */
34
35/// \file moldft.cc
36/// \brief Molecular HF and DFT code
37/// \defgroup moldft The molecular density functional and Hartree-Fock code
38
39
40#ifndef MADNESS_CHEM_SCF_H__INCLUDED
41#define MADNESS_CHEM_SCF_H__INCLUDED
42
43#include <memory>
44
46#include <madness/mra/mra.h>
47
59#include<madness/chem/pcm.h>
61
62#include <madness/tensor/tensor_json.hpp>
63#include <memory>
64
65namespace madness {
66
67typedef std::shared_ptr<WorldDCPmapInterface<Key<3> > > pmapT;
69typedef std::shared_ptr<FunctionFunctorInterface<double, 3> > functorT;
71typedef std::vector<functionT> vecfuncT;
72typedef std::pair<vecfuncT, vecfuncT> pairvecfuncT;
73typedef std::vector<pairvecfuncT> subspaceT;
78typedef std::shared_ptr<operatorT> poperatorT;
80typedef std::vector<complex_functionT> cvecfuncT;
82
83
84template<typename T, int NDIM>
85struct lbcost {
86 double leaf_value;
88
90
91 double operator()(const Key<NDIM>& key, const FunctionNode<T, NDIM>& node) const {
92 if (key.level() < 1) {
93 return 100.0 * (leaf_value + parent_value);
94 } else if (node.is_leaf()) {
95 return leaf_value;
96 } else {
97 return parent_value;
98 }
99 }
100};
101
102
103inline double mask1(double x) {
104 /* Iterated first beta function to switch smoothly
105 from 0->1 in [0,1]. n iterations produce 2*n-1
106 zero derivatives at the end points. Order of polyn
107 is 3^n.
108
109 Currently use one iteration so that first deriv.
110 is zero at interior boundary and is exactly representable
111 by low order multiwavelet without refinement */
112
113 x = (x * x * (3. - 2. * x));
114 return x;
115}
116
117static double mask3(const coordT& ruser) {
118 coordT rsim;
119 user_to_sim(ruser, rsim);
120 double x = rsim[0], y = rsim[1], z = rsim[2];
121 double lo = 0.0625, hi = 1.0 - lo, result = 1.0;
122 double rlo = 1.0 / lo;
123
124 if (x < lo)
125 result *= mask1(x * rlo);
126 else if (x > hi)
127 result *= mask1((1.0 - x) * rlo);
128 if (y < lo)
129 result *= mask1(y * rlo);
130 else if (y > hi)
131 result *= mask1((1.0 - y) * rlo);
132 if (z < lo)
133 result *= mask1(z * rlo);
134 else if (z > hi)
135 result *= mask1((1.0 - z) * rlo);
136
137 return result;
138}
139
140/// A MADNESS functor to compute either x, y, or z
141class DipoleFunctor : public FunctionFunctorInterface<double, 3> {
142private:
143 const int axis;
144public:
146
147 double operator()(const coordT& x) const {
148 return x[axis];
149 }
150};
151
152
153/// A MADNESS functor to compute the cartesian moment x^i * y^j * z^k (i, j, k integer and >= 0)
154class MomentFunctor : public FunctionFunctorInterface<double, 3> {
155private:
156 const int i, j, k;
157public:
158 MomentFunctor(int i, int j, int k) : i(i), j(j), k(k) {}
159
160 MomentFunctor(const std::vector<int>& x) : i(x[0]), j(x[1]), k(x[2]) {}
161
162 double operator()(const coordT& r) const {
163 double xi = 1.0, yj = 1.0, zk = 1.0;
164 for (int p = 0; p < i; ++p) xi *= r[0];
165 for (int p = 0; p < j; ++p) yj *= r[1];
166 for (int p = 0; p < k; ++p) zk *= r[2];
167 return xi * yj * zk;
168 }
169};
170
171 class scf_data {
172
173 std::map<std::string, std::vector<double>> e_data;
176 int iter;
177 public:
178
179 scf_data();
180
181 void to_json(json &j) const;
182
183 void print_data();
184
185 void add_data(std::map<std::string, double> values);
186
187 void add_gradient(const Tensor<double> &grad);
188 };
189
190
191class SCF {
192public:
193 std::shared_ptr<PotentialManager> potentialmanager;
194 std::shared_ptr<GTHPseudopotential<double> > gthpseudopotential;
201
203
204 /// alpha and beta molecular orbitals
206
207 /// sets of orbitals grouped by their orbital energies (for localization?)
208 /// only orbitals within the same set will be mixed to localize
209 std::vector<int> aset, bset;
210
211 /// MRA projection of the minimal basis set
213
214 std::vector<int> at_to_bf, at_nbf;
215
216 /// occupation numbers for alpha and beta orbitals
218
219 /// orbital energies for alpha and beta orbitals
222 std::vector<std::shared_ptr<real_derivative_3d> > gradop;
223 double vtol;
225 double converged_for_thresh=1.e10; ///< mos are converged for this threshold
226 double converged_for_dconv=1.e10; ///< mos are converged for this density
227 double converged_for_tconv=1.e10; ///< derivatives of mos are converged for this threshold
228
229 /// forwarding constructor
230 SCF(World& world, const commandlineparser& parser)
231 : SCF(world, CalculationParameters(world, parser), Molecule(world, parser)) {}
232
233 /// collective constructor for SCF uses contents of file \c filename and broadcasts to all nodes
234 SCF(World& world, const CalculationParameters& param, const Molecule& molecule);
235
236 void copy_data(World& world, const SCF& other);
237
238 static void help() {
239 print_header2("help page for MOLDFT ");
240 print("The moldft code computes Hartree-Fock and DFT energies and gradients, It is the fastest code in MADNESS");
241 print("and considered the reference implementation. No nuclear correlation factor can be used");
242 print("SCF orbitals are the basis for post-SCF calculations like");
243 print("excitation energies (cis), correlation energies (cc2), local potentials (oep), etc\n\n");
244 print("You can print all available calculation parameters by running\n");
245 print("moldft --print_parameters\n");
246 print("You can perform a simple calculation by running\n");
247 print("moldft --geometry=h2o.xyz\n");
248 print("provided you have an xyz file in your directory.");
249
250 }
251
252 static void print_parameters() {
254 print("default parameters for the moldft program are");
255 param.print("dft", "end");
256 print("\n\nthe molecular geometry must be specified in a separate block:");
258 }
259
260 void set_print_timings(const bool value);
261
262 template<std::size_t NDIM>
263 void set_protocol(World& world, double thresh) {
264 int k;
265 // Allow for imprecise conversion of threshold
266 if (thresh >= 0.9e-2)
267 k = 4;
268 else if (thresh >= 0.9e-4)
269 k = 6;
270 else if (thresh >= 0.9e-6)
271 k = 8;
272 else if (thresh >= 0.9e-8)
273 k = 10;
274 else
275 k = 12;
276
277 // k defaults to make sense with thresh, override by providing k in input file
278 if (param.k() == -1) {
280 // param.k=k;
281 } else {
283 }
284 // don't forget to adapt the molecular smoothing parameter!! NO ... it is independent
285 // molecule.set_eprec(std::min(thresh,molecule.get_eprec()));
289 // FunctionDefaults<NDIM>::set_truncate_mode(1);
295 double safety = 0.1;
298 gradop = gradient_operator<double, 3>(world);
299
300 // Update coefficients if using a different derivative
301 if (param.deriv() == "bspline") {
302 for (int i = 0; i < 3; ++i) (*gradop[i]).set_bspline1();
303 } else if (param.deriv() == "ble") {
304 for (int i = 0; i < 3; ++i) (*gradop[i]).set_ble1();
305 }
306
307 mask = functionT(factoryT(world).f(mask3).initial_level(4).norefine());
308 if (world.rank() == 0 and param.print_level() > 1) {
309 print("\nSolving NDIM=", NDIM, " with thresh", thresh, " k",
310 FunctionDefaults<NDIM>::get_k(), " conv", std::max(thresh, param.dconv()), "\n");
311 }
312 }
313
314 /// getter for the molecular orbitals, alpha spin
315 const vecfuncT& get_amo() const { return amo; }
316
317 /// getter for the molecular orbitals, beta spin
318 const vecfuncT& get_bmo() const { return bmo; }
319
320 /// getter for the occupation numbers, alpha spin
321 const tensorT& get_aocc() const { return aocc; }
322
323 /// getter for the occupation numbers, alpha spin
324 const tensorT& get_bocc() const { return bocc; }
325
326 bool is_spin_restricted() const { return param.get<bool>("spin_restricted"); }
327
328 void save_mos(World& world);
329
330 void load_mos(World& world);
331
332 bool restart_aos(World& world);
333
334 void do_plots(World& world);
335
336 void project(World& world);
337
338 void make_nuclear_potential(World& world);
339
341
343 const Molecule& molecule);
344
345 void reset_aobasis(const std::string& aobasisname) {
346 aobasis = AtomicBasisSet(); // reset
347 aobasis.read_file(aobasisname);
348 }
349
350 /// group orbitals into sets of similar orbital energies for localization
351
352 /// @param[in] eps orbital energies
353 /// @param[in] occ occupation numbers
354 /// @param[in] nmo number of MOs for the given spin
355 /// @return vector of length nmo with the set index for each MO
356 std::vector<int> group_orbital_sets(World& world, const tensorT& eps,
357 const tensorT& occ, const int nmo) const;
358
359 static void analyze_vectors(World& world, const vecfuncT& mo,
360 const vecfuncT& ao, double vtol,
361 const Molecule& molecule, const int print_level,
362 const AtomicBasisSet& aobasis, const tensorT& occ = tensorT(),
363 const tensorT& energy = tensorT(), const std::vector<int>& set = std::vector<int>());
364
365 distmatT kinetic_energy_matrix(World& world, const vecfuncT& v) const;
366
367 void get_initial_orbitals(World& world);
368
369 void initial_guess(World& world);
370
371 void initial_guess_from_nwchem(World& world);
372
373 void initial_load_bal(World& world);
374
375 functionT make_density(World& world, const tensorT& occ, const vecfuncT& v) const;
376
377 functionT make_density(World& world, const tensorT& occ, const cvecfuncT& v);
378
379 static std::vector<poperatorT> make_bsh_operators(World& world, const tensorT& evals,
381
382 // Used only for initial guess that is always spin-restricted LDA
383 static functionT make_lda_potential(World& world, const functionT& arho);
384
385
386 // functionT make_dft_potential(World & world, const vecfuncT& vf, int ispin, int what)
387 // {
388 // return multiop_values<double, xc_potential, 3>(xc_potential(xc, ispin, what), vf);
389 // }
390
391 double make_dft_energy(World& world, const vecfuncT& vf, int ispin) {
392 functionT vlda = multiop_values<double, xc_functional, 3>(xc_functional(xc), vf);
393 return vlda.trace();
394 }
395
396 vecfuncT apply_potential(World& world, const tensorT& occ,
397 const vecfuncT& amo,
398 const functionT& vlocal, double& exc, double& enl, int ispin);
399
400 tensorT derivatives(World& world, const functionT& rho) const;
401
402 /// compute the total dipole moment of the molecule
403
404 /// @param[in] rho the total (alpha + beta) density
405 /// @return the x,y,z components of the el. + nucl. dipole moment
406 tensorT dipole(World& world, const functionT& rho) const;
407
408 void vector_stats(const std::vector<double>& v, double& rms,
409 double& maxabsval) const;
410
411 vecfuncT compute_residual(World& world, tensorT& occ, tensorT& fock,
412 const vecfuncT& psi, vecfuncT& Vpsi, double& err);
413
415 const vecfuncT& Vpsi, const tensorT& occ,
416 double& ekinetic) const;
417
418 /// make the Coulomb potential given the total density
420 return apply(*coulop, rho);
421 }
422
423 /// Compute the two-electron integrals over the provided set of orbitals
424
425 /// Returned is a *replicated* tensor of \f$(ij|kl)\f$ with \f$i>=j\f$
426 /// and \f$k>=l\f$. The symmetry \f$(ij|kl)=(kl|ij)\f$ is enforced.
427 Tensor<double> twoint(World& world, const vecfuncT& psi) const;
428
429 /// compute the unitary transformation that diagonalizes the fock matrix
430
431 /// @param[in] world the world
432 /// @param[in] overlap the overlap matrix of the orbitals
433 /// @param[in,out] fock the fock matrix; diagonal upon exit
434 /// @param[out] evals the orbital energies
435 /// @param[in] occ the occupation numbers
436 /// @param[in] thresh_degenerate threshold for orbitals being degenerate
437 /// @return the unitary matrix U: U^T F U = evals
438 tensorT get_fock_transformation(World& world, const tensorT& overlap,
439 tensorT& fock, tensorT& evals, const tensorT& occ,
440 const double thresh_degenerate) const;
441
442
443 /// diagonalize the fock matrix, taking care of degenerate states
444
445 /// Vpsi is passed in to make sure orbitals and Vpsi are in phase
446 /// @param[in] world the world
447 /// @param[in,out] fock the fock matrix (diagonal upon exit)
448 /// @param[in,out] psi the orbitals
449 /// @param[in,out] Vpsi the orbital times the potential
450 /// @param[out] evals the orbital energies
451 /// @param[in] occ occupation numbers
452 /// @param[in] thresh threshold for rotation and truncation
453 /// @return the unitary matrix U: U^T F U = evals
455 vecfuncT& psi, vecfuncT& Vpsi, tensorT& evals,
456 const tensorT& occ, const double thresh) const;
457
458
459 void loadbal(World& world, functionT& arho, functionT& brho, functionT& arho_old,
460 functionT& brho_old, subspaceT& subspace);
461
462
463 void rotate_subspace(World& world, const tensorT& U, subspaceT& subspace,
464 int lo, int nfunc, double trantol) const;
465
466 void rotate_subspace(World& world, const distmatT& U, subspaceT& subspace,
467 int lo, int nfunc, double trantol) const;
468
469 void update_subspace(World& world,
470 vecfuncT& Vpsia, vecfuncT& Vpsib,
471 tensorT& focka, tensorT& fockb,
473 double& bsh_residual, double& update_residual);
474
475 /// perform step restriction following the KAIN solver
476
477 /// undo the rotation from the KAIN solver if the rotation exceeds the
478 /// maxrotn parameter
479 /// @param[in] world the world
480 /// @param[in] mo vector of orbitals from previous iteration
481 /// @param[in,out] mo_new vector of orbitals from the KAIN solver
482 /// @param[in] spin "alpha" or "beta" for user information
483 /// @return max residual
484 double do_step_restriction(World& world, const vecfuncT& mo,
485 vecfuncT& mo_new, std::string spin) const;
486
487 /// orthonormalize the vectors
488
489 /// @param[in] world the world
490 /// @param[in,out] amo_new the vectors to be orthonormalized
491 void orthonormalize(World& world, vecfuncT& amo_new) const;
492
493 void orthonormalize(World& world, vecfuncT& amo_new, int nocc) const;
494
496 complex_functionT r = psi; // Shallow copy violates constness !!!!!!!!!!!!!!!!!
497 coordT lo, hi;
498 lo[2] = -10;
499 hi[2] = +10;
500
501 r.reconstruct();
502 r.broaden();
503 r.broaden();
504 r.broaden();
505 r.broaden();
506 r = apply_1d_realspace_push(*q1d, r, 2);
507 r.sum_down();
508 r = apply_1d_realspace_push(*q1d, r, 1);
509 r.sum_down();
510 r = apply_1d_realspace_push(*q1d, r, 0);
511 r.sum_down();
512
513 return r;
514 }
515
516 // For given protocol, solve the DFT/HF/response equations
517 void solve(World& world);
518
519 void output_calc_info_schema() const;
520
521 void output_scf_info_schema(const std::map<std::string, double> &vals,
522 const tensorT &dipole_T) const;
523
524};
525
526// Computes molecular energy as a function of the geometry
527// This is cludgy ... need better factorization of functionality
528// between calculation, main program and this ... or just merge it all.
532 mutable double coords_sum; // sum of square of coords at last solved geometry
533
534public:
537
538 std::string name() const { return "Molecularenerg"; }
539
540 bool selftest() { return true; }
541
542 bool provides_gradient() const { return true; }
543
544 double value(const Tensor<double>& x) {
545 double xsq = x.sumsq();
546 if (xsq == coords_sum) {
547 return calc.current_energy;
548 }
550 coords_sum = xsq;
551
552 // read converged wave function from disk if there is one
553 if (calc.param.no_compute()) {
557 return calc.current_energy;
558 }
559
560 // initialize the PCM solver for this geometry
561 if (calc.param.pcm_data() != "none") {
563 }
564
566
567 // AOs are needed for final analysis, and for localization
568 calc.reset_aobasis("sto-3g");
569 calc.ao.clear(); world.gop.fence();
571
572 // The below is missing convergence test logic, etc.
573
574 // Make the nuclear potential, initial orbitals, etc.
575 for (unsigned int proto = 0; proto < calc.param.protocol().size(); proto++) {
576
577 int nvalpha = calc.param.nmo_alpha() - calc.param.nalpha();
578 int nvbeta = calc.param.nmo_beta() - calc.param.nbeta();
579 int nvalpha_start, nv_old;
580
581 //repeat with gradually decreasing nvirt, only for first protocol
582 if (proto == 0 && nvalpha > 0) {
583 nvalpha_start = nvalpha * calc.param.nv_factor();
584 } else {
585 nvalpha_start = nvalpha;
586 }
587
588 nv_old = nvalpha_start;
589
590 for (int nv = nvalpha_start; nv >= nvalpha; nv -= nvalpha) {
591
592 if (nv > 0 && world.rank() == 0) std::cout << "Running with " << nv << " virtual states" << std::endl;
593
594 calc.param.set_user_defined_value("nmo_alpha", calc.param.nalpha() + nv);
595 // check whether this is sensible for spin restricted case
597 if (nvbeta == nvalpha) {
598 calc.param.set_user_defined_value("nmo_beta", calc.param.nbeta() + nv);
599 } else {
600 calc.param.set_user_defined_value("nmo_beta", calc.param.nbeta() + nv + nvbeta - nvalpha);
601 }
602 }
603
606
607 if (nv != nv_old) {
608 calc.amo.resize(calc.param.nmo_alpha());
609 calc.bmo.resize(calc.param.nmo_beta());
610
612 for (int i = 0; i < calc.param.nalpha(); ++i)
613 calc.aocc[i] = 1.0;
614
616 for (int i = 0; i < calc.param.nbeta(); ++i)
617 calc.bocc[i] = 1.0;
618
619 // might need to resize aset, bset, but for the moment this doesn't seem to be necessary
620
621 }
622
623 // project orbitals into higher k
624 if (proto > 0) calc.project(world);
625
626 // If the basis for the inital guess was not sto-3g
627 // switch to sto-3g since this is needed for analysis
628 // of the MOs and orbital localization
629 // Only do this if not starting from NWChem.
630 // analysis will be done on NWChem orbitals.
631
632 if (calc.param.aobasis() != "sto-3g") { // was also && calc.param.nwfile() == "none"
633 calc.reset_aobasis("sto-3g");
634 }
635 calc.ao.clear(); world.gop.fence();
638
639 if (calc.param.save())
641
642 nv_old = nv;
643 // exit loop over decreasing nvirt if nvirt=0
644 if (nv == 0) break;
645
646 }
647
648 }
649 return calc.current_energy;
650 }
651
653 value(x); // Ensures DFT equations are solved at this geometry
654
656 functionT brho = rho;
659 rho.gaxpy(1.0, brho, 1.0);
660
661 return calc.derivatives(world, rho);
662 }
663
664
666 value(molecule.get_all_coords().flat()); // Ensures DFT equations are solved at this geometry
667
669 functionT brho = rho;
672 rho.gaxpy(1.0, brho, 1.0);
673
676 }
677
679 nlohmann::json j = {};
680 vec_pair_ints int_vals;
681 vec_pair_T<double> double_vals;
682 vec_pair_tensor_T<double> double_tensor_vals;
683
685
686 nlohmann::json calc_precision={ };
687 calc_precision["eprec"]=calc.molecule.parameters.eprec();
688 calc_precision["dconv"]=calc.param.dconv();
689 calc_precision["econv"]=calc.param.econv();
690 calc_precision["thresh"]=FunctionDefaults<3>::get_thresh();
691 calc_precision["k"]=FunctionDefaults<3>::get_k();
692
693 auto mol_json=this->calc.molecule.to_json();
694
695 int_vals.push_back({"calcinfo_nmo", param.nmo_alpha() + param.nmo_beta()});
696 int_vals.push_back({"calcinfo_nalpha", param.nalpha()});
697 int_vals.push_back({"calcinfo_nbeta", param.nbeta()});
698 int_vals.push_back({"calcinfo_natom", calc.molecule.natom()});
699
700
701 to_json(j, int_vals);
702 double_vals.push_back({"return_energy", value(calc.molecule.get_all_coords().flat())});
703 to_json(j, double_vals);
704 double_tensor_vals.push_back({"scf_eigenvalues_a", calc.aeps});
705 if (param.nbeta() != 0 && !param.spin_restricted()) {
706 double_tensor_vals.push_back({"scf_eigenvalues_b", calc.beps});
707 }
708
709 to_json(j, double_tensor_vals);
710 param.to_json(j);
712
713 j["precision"]=calc_precision;
714 j["molecule"]=mol_json;
715
716 output_schema(param.prefix()+".calc_info", j);
717 }
718
719
720};
721}
722
723#endif /* SCF_H_ */
724
Operators for the molecular HF and DFT code.
A MADNESS functor to compute either x, y, or z.
Definition preal.cc:115
Contracted Gaussian basis.
Definition madness/chem/molecularbasis.h:469
void read_file(std::string filename)
read the atomic basis set from file
Definition molecularbasis.cc:119
Provides the common functionality/interface of all 1D convolutions.
Definition convolution1d.h:258
DipoleFunctor(int axis)
Definition SCF.h:145
double operator()(const coordT &x) const
Definition SCF.h:147
const int axis
Definition solver.h:167
Manages data associated with a row/column/block distributed array.
Definition distributed_matrix.h:388
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static int get_k()
Returns the default wavelet order.
Definition funcdefaults.h:163
static void set_apply_randomize(bool value)
Sets the random load balancing for integral operators flag.
Definition funcdefaults.h:294
static void set_thresh(double value)
Sets the default threshold.
Definition funcdefaults.h:183
static void set_k(int value)
Sets the default wavelet order.
Definition funcdefaults.h:170
static const double & get_thresh()
Returns the default threshold.
Definition funcdefaults.h:176
static void set_autorefine(bool value)
Sets the default adaptive autorefinement flag.
Definition funcdefaults.h:260
static void set_project_randomize(bool value)
Sets the random load balancing for projection flag.
Definition funcdefaults.h:305
static void set_initial_level(int value)
Sets the default initial projection level.
Definition funcdefaults.h:200
static void set_cubic_cell(double lo, double hi)
Sets the user cell to be cubic with each dimension having range [lo,hi].
Definition funcdefaults.h:362
static void set_refine(bool value)
Sets the default adaptive refinement flag.
Definition funcdefaults.h:248
FunctionFactory implements the named-parameter idiom for Function.
Definition function_factory.h:86
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:127
bool is_leaf() const
Returns true if this does not have children.
Definition funcimpl.h:213
A multiresolution adaptive numerical function.
Definition mra.h:139
void broaden(const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), bool fence=true) const
Inplace broadens support in scaling function basis.
Definition mra.h:878
void sum_down(bool fence=true) const
Sums scaling coeffs down tree restoring state with coeffs only at leaves. Optional fence....
Definition mra.h:840
T trace() const
Returns global value of int(f(x),x) ... global comm required.
Definition mra.h:1154
const Function< T, NDIM > & reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm.
Definition mra.h:817
Function< T, NDIM > & gaxpy(const T &alpha, const Function< Q, NDIM > &other, const R &beta, bool fence=true)
Inplace, general bi-linear operation in wavelet basis. No communication except for optional fence.
Definition mra.h:1025
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:69
Level level() const
Definition key.h:168
Definition SCF.h:529
bool selftest()
Definition SCF.h:540
bool provides_gradient() const
Override this to return true if the derivative is implemented.
Definition SCF.h:542
double value(const Tensor< double > &x)
Should return the value of the objective function.
Definition SCF.h:544
World & world
Definition SCF.h:530
SCF & calc
Definition SCF.h:531
double coords_sum
Definition SCF.h:532
void output_calc_info_schema()
Definition SCF.h:678
madness::Tensor< double > gradient(const Tensor< double > &x)
Should return the derivative of the function.
Definition SCF.h:652
void energy_and_gradient(const Molecule &molecule, double &energy, Tensor< double > &gradient)
Definition SCF.h:665
std::string name() const
Definition SCF.h:538
MolecularEnergy(World &world, SCF &calc)
Definition SCF.h:535
Definition molecule.h:129
void set_all_coords(const madness::Tensor< double > &newcoords)
Definition molecule.cc:424
madness::Tensor< double > get_all_coords() const
Definition molecule.cc:402
size_t natom() const
Definition molecule.h:415
static void print_parameters()
Definition molecule.cc:115
json to_json() const
Definition molecule.cc:462
GeometryParameters parameters
Definition molecule.h:286
A MADNESS functor to compute the cartesian moment x^i * y^j * z^k (i, j, k integer and >= 0)
Definition SCF.h:154
const int j
Definition SCF.h:156
double operator()(const coordT &r) const
Definition SCF.h:162
MomentFunctor(int i, int j, int k)
Definition SCF.h:158
const int i
Definition SCF.h:156
MomentFunctor(const std::vector< int > &x)
Definition SCF.h:160
const int k
Definition SCF.h:156
interface class to the PCMSolver library
Definition pcm.h:52
void set_user_defined_value(const std::string &key, const T &value)
Definition QCCalculationParametersBase.h:521
T get(const std::string key) const
Definition QCCalculationParametersBase.h:304
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
Definition SCF.h:191
void copy_data(World &world, const SCF &other)
Definition SCF.cc:268
void do_plots(World &world)
Definition SCF.cc:504
tensorT derivatives(World &world, const functionT &rho) const
Definition SCF.cc:1447
void save_mos(World &world)
Definition SCF.cc:282
void output_scf_info_schema(const std::map< std::string, double > &vals, const tensorT &dipole_T) const
Definition SCF.cc:143
static vecfuncT project_ao_basis_only(World &world, const AtomicBasisSet &aobasis, const Molecule &molecule)
Definition SCF.cc:598
const tensorT & get_aocc() const
getter for the occupation numbers, alpha spin
Definition SCF.h:321
std::shared_ptr< GTHPseudopotential< double > > gthpseudopotential
Definition SCF.h:194
void make_nuclear_potential(World &world)
Definition SCF.cc:573
void get_initial_orbitals(World &world)
get the initial orbitals for a calculation
Definition SCF.cc:454
std::vector< int > aset
Definition SCF.h:209
static void print_parameters()
Definition SCF.h:252
AtomicBasisSet aobasis
Definition SCF.h:199
SCF(World &world, const commandlineparser &parser)
forwarding constructor
Definition SCF.h:230
vecfuncT ao
MRA projection of the minimal basis set.
Definition SCF.h:212
scf_data e_data
Definition SCF.h:202
void initial_guess(World &world)
Definition SCF.cc:986
vecfuncT apply_potential(World &world, const tensorT &occ, const vecfuncT &amo, const functionT &vlocal, double &exc, double &enl, int ispin)
Definition SCF.cc:1343
vecfuncT amo
alpha and beta molecular orbitals
Definition SCF.h:205
vecfuncT compute_residual(World &world, tensorT &occ, tensorT &fock, const vecfuncT &psi, vecfuncT &Vpsi, double &err)
Definition SCF.cc:1558
const tensorT & get_bocc() const
getter for the occupation numbers, alpha spin
Definition SCF.h:324
std::vector< int > at_to_bf
Definition SCF.h:214
std::vector< int > bset
Definition SCF.h:209
distmatT kinetic_energy_matrix(World &world, const vecfuncT &v) const
Definition SCF.cc:670
tensorT bocc
Definition SCF.h:217
double vtol
Definition SCF.h:223
tensorT dipole(World &world, const functionT &rho) const
compute the total dipole moment of the molecule
Definition SCF.cc:1520
PCM pcm
Definition SCF.h:198
bool is_spin_restricted() const
Definition SCF.h:326
poperatorT coulop
Definition SCF.h:221
double make_dft_energy(World &world, const vecfuncT &vf, int ispin)
Definition SCF.h:391
void output_calc_info_schema() const
Definition SCF.cc:159
static void help()
Definition SCF.h:238
void update_subspace(World &world, vecfuncT &Vpsia, vecfuncT &Vpsib, tensorT &focka, tensorT &fockb, subspaceT &subspace, tensorT &Q, double &bsh_residual, double &update_residual)
Definition SCF.cc:1913
Molecule molecule
Definition SCF.h:195
void load_mos(World &world)
Definition SCF.cc:322
tensorT beps
Definition SCF.h:220
tensorT diag_fock_matrix(World &world, tensorT &fock, vecfuncT &psi, vecfuncT &Vpsi, tensorT &evals, const tensorT &occ, const double thresh) const
diagonalize the fock matrix, taking care of degenerate states
Definition SCF.cc:1811
const vecfuncT & get_amo() const
getter for the molecular orbitals, alpha spin
Definition SCF.h:315
static void analyze_vectors(World &world, const vecfuncT &mo, const vecfuncT &ao, double vtol, const Molecule &molecule, const int print_level, const AtomicBasisSet &aobasis, const tensorT &occ=tensorT(), const tensorT &energy=tensorT(), const std::vector< int > &set=std::vector< int >())
Definition SCF.cc:612
XCfunctional xc
Definition SCF.h:197
void initial_load_bal(World &world)
Definition SCF.cc:1253
std::vector< int > at_nbf
Definition SCF.h:214
double do_step_restriction(World &world, const vecfuncT &mo, vecfuncT &mo_new, std::string spin) const
perform step restriction following the KAIN solver
Definition SCF.cc:2055
std::vector< std::shared_ptr< real_derivative_3d > > gradop
Definition SCF.h:222
void set_print_timings(const bool value)
Definition SCF.cc:264
double converged_for_dconv
mos are converged for this density
Definition SCF.h:226
tensorT get_fock_transformation(World &world, const tensorT &overlap, tensorT &fock, tensorT &evals, const tensorT &occ, const double thresh_degenerate) const
compute the unitary transformation that diagonalizes the fock matrix
Definition SCF.cc:1780
bool restart_aos(World &world)
Definition SCF.cc:700
tensorT aeps
orbital energies for alpha and beta orbitals
Definition SCF.h:220
functionT make_coulomb_potential(const functionT &rho) const
make the Coulomb potential given the total density
Definition SCF.h:419
tensorT make_fock_matrix(World &world, const vecfuncT &psi, const vecfuncT &Vpsi, const tensorT &occ, double &ekinetic) const
Definition SCF.cc:1692
double converged_for_tconv
derivatives of mos are converged for this threshold
Definition SCF.h:227
Tensor< double > twoint(World &world, const vecfuncT &psi) const
Compute the two-electron integrals over the provided set of orbitals.
Definition SCF.cc:1750
tensorT aocc
occupation numbers for alpha and beta orbitals
Definition SCF.h:217
void set_protocol(World &world, double thresh)
Definition SCF.h:263
static functionT make_lda_potential(World &world, const functionT &arho)
Definition SCF.cc:1335
functionT make_density(World &world, const tensorT &occ, const vecfuncT &v) const
Definition SCF.cc:1270
void rotate_subspace(World &world, const tensorT &U, subspaceT &subspace, int lo, int nfunc, double trantol) const
Definition SCF.cc:1879
void reset_aobasis(const std::string &aobasisname)
Definition SCF.h:345
void project(World &world)
Definition SCF.cc:551
double converged_for_thresh
mos are converged for this threshold
Definition SCF.h:225
CalculationParameters param
Definition SCF.h:196
double current_energy
Definition SCF.h:224
void loadbal(World &world, functionT &arho, functionT &brho, functionT &arho_old, functionT &brho_old, subspaceT &subspace)
Definition SCF.cc:1844
void vector_stats(const std::vector< double > &v, double &rms, double &maxabsval) const
Definition SCF.cc:1546
vecfuncT project_ao_basis(World &world, const AtomicBasisSet &aobasis)
Definition SCF.cc:590
std::vector< int > group_orbital_sets(World &world, const tensorT &eps, const tensorT &occ, const int nmo) const
group orbitals into sets of similar orbital energies for localization
Definition SCF.cc:1228
complex_functionT APPLY(const complex_operatorT *q1d, const complex_functionT &psi)
Definition SCF.h:495
void initial_guess_from_nwchem(World &world)
Definition SCF.cc:753
functionT mask
Definition SCF.h:200
std::shared_ptr< PotentialManager > potentialmanager
Definition SCF.h:193
static std::vector< poperatorT > make_bsh_operators(World &world, const tensorT &evals, const CalculationParameters &param)
Definition SCF.cc:1311
const vecfuncT & get_bmo() const
getter for the molecular orbitals, beta spin
Definition SCF.h:318
vecfuncT bmo
Definition SCF.h:205
void solve(World &world)
Definition SCF.cc:2177
void orthonormalize(World &world, vecfuncT &amo_new) const
orthonormalize the vectors
Definition SCF.cc:2127
Convolutions in separated form (including Gaussian)
Definition operator.h:139
A tensor is a multidimensional array.
Definition tensor.h:317
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1384
T sumsq() const
Returns the sum of the squares of the elements.
Definition tensor.h:1669
Tensor< T > flat()
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition tensor.h:1555
A simple, fixed dimension vector.
Definition vector.h:64
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
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
Simplified interface to XC functionals.
Definition xcfunctional.h:43
Definition SCF.h:171
std::map< std::string, std::vector< double > > e_data
Definition SCF.h:173
void add_gradient(const Tensor< double > &grad)
Definition SCF.cc:230
int iter
Definition SCF.h:176
void to_json(json &j) const
Definition SCF.cc:213
void add_data(std::map< std::string, double > values)
Definition SCF.cc:190
json hessian
Definition SCF.h:175
json gradient
Definition SCF.h:174
scf_data()
Definition SCF.cc:200
void print_data()
Definition SCF.cc:226
Declaration of core potential related class.
double(* energy)()
Definition derivatives.cc:58
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
double psi(const Vector< double, 3 > &r)
Definition hatom_energy.cc:78
static const double v
Definition hatom_sf_dirac.cc:20
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void print_header2(const std::string &s)
medium section heading
Definition print.cc:54
Function< TENSOR_RESULT_TYPE(typename opT::opT, R), NDIM > apply_1d_realspace_push(const opT &op, const Function< R, NDIM > &f, int axis, bool fence=true)
Definition mra.h:2296
Vector< double, 3 > coordT
Definition corepotential.cc:54
static SeparatedConvolution< double, 3 > * CoulombOperatorPtr(World &world, double lo, double eps, const array_of_bools< 3 > &lattice_sum=FunctionDefaults< 3 >::get_bc().is_periodic(), int k=FunctionDefaults< 3 >::get_k())
Factory function generating separated kernel for convolution with 1/r in 3D.
Definition operator.h:1818
nlohmann::json json
Definition QCCalculationParametersBase.h:28
static void user_to_sim(const Vector< double, NDIM > &xuser, Vector< double, NDIM > &xsim)
Convert user coords (cell[][]) to simulation coords ([0,1]^ndim)
Definition funcdefaults.h:425
Tensor< double > tensorT
Definition distpm.cc:21
Function< std::complex< double >, 3 > complex_functionT
Definition SCF.h:79
std::vector< pairvecfuncT > subspaceT
Definition SCF.h:73
double mask1(double x)
Definition SCF.h:103
DistributedMatrix< double > distmatT
Definition SCF.h:75
std::pair< vecfuncT, vecfuncT > pairvecfuncT
Definition SCF.h:72
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
FunctionFactory< double, 3 > factoryT
Definition corepotential.cc:57
response_space apply(World &world, std::vector< std::vector< std::shared_ptr< real_convolution_3d > > > &op, response_space &f)
Definition basic_operators.cc:43
std::shared_ptr< operatorT> poperatorT
Definition SCF.h:78
Function< double, 3 > functionT
Definition corepotential.cc:56
NDIM & f
Definition mra.h:2481
void to_json(nlohmann::json &j)
std::shared_ptr< FunctionFunctorInterface< double, 3 > > functorT
Definition corepotential.cc:55
std::vector< complex_functionT > cvecfuncT
Definition SCF.h:80
vector< functionT > vecfuncT
Definition corepotential.cc:58
static double mask3(const coordT &ruser)
Definition SCF.h:117
std::shared_ptr< WorldDCPmapInterface< Key< 3 > > > pmapT
Definition SCF.h:67
std::vector< Function< T, NDIM > > grad(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
shorthand gradient operator
Definition vmra.h:2033
Convolution1D< double_complex > complex_operatorT
Definition SCF.h:81
SeparatedConvolution< double, 3 > operatorT
Definition SCF.h:77
static const size_t nfunc
Definition pcr.cc:63
Declaration of molecule-related classes and functions.
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
Defines interfaces for optimization and non-linear equation solvers.
std::string prefix
Definition tdse.cc:71
Definition CalculationParameters.h:51
std::vector< double > protocol() const
Definition CalculationParameters.h:210
int nv_factor() const
Definition CalculationParameters.h:175
int k() const
Definition CalculationParameters.h:187
int nmo_alpha() const
Definition CalculationParameters.h:177
bool save() const
Definition CalculationParameters.h:211
double dconv() const
Definition CalculationParameters.h:150
double econv() const
Definition CalculationParameters.h:149
int print_level() const
Definition CalculationParameters.h:196
std::string deriv() const
Definition CalculationParameters.h:201
double L() const
Definition CalculationParameters.h:186
std::string aobasis() const
Definition CalculationParameters.h:208
int nalpha() const
Definition CalculationParameters.h:170
int nbeta() const
Definition CalculationParameters.h:171
int nmo_beta() const
Definition CalculationParameters.h:178
bool no_compute() const
Definition CalculationParameters.h:183
bool spin_restricted() const
Definition CalculationParameters.h:182
double lo() const
Definition CalculationParameters.h:185
std::string pcm_data() const
Definition CalculationParameters.h:203
Definition convolution1d.h:991
double eprec() const
Definition molecule.h:258
The interface to be provided by functions to be optimized.
Definition solvers.h:176
very simple command line parser
Definition commandlineparser.h:15
Definition SCF.h:85
double parent_value
Definition SCF.h:87
lbcost(double leaf_value=1.0, double parent_value=0.0)
Definition SCF.h:89
double leaf_value
Definition SCF.h:86
double operator()(const Key< NDIM > &key, const FunctionNode< T, NDIM > &node) const
Definition SCF.h:91
Class to compute the energy functional.
Definition xcfunctional.h:360
InputParameters param
Definition tdse.cc:203
constexpr std::size_t NDIM
Definition testgconv.cc:54
static Molecule molecule
Definition testperiodicdft.cc:39
static Subspace * subspace
Definition testperiodicdft.cc:41