MADNESS  version 0.9
potentialmanager.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  $Id$
32 */
33 #ifndef MADNESS_CHEM_POTENTIALMANAGER_H__INCLUDED
34 #define MADNESS_CHEM_POTENTIALMANAGER_H__INCLUDED
35 
38 
39 #include <chem/corepotential.h>
40 #include <chem/atomutil.h>
41 #include <madness/world/array.h>
42 #include <vector>
43 #include <string>
44 #include <iostream>
45 #include <fstream>
46 #include <sstream>
47 #include <algorithm>
48 #include <ctype.h>
49 #include <cmath>
50 #include <madness/tensor/tensor.h>
51 #include <madness/misc/misc.h>
52 
53 namespace madness {
55 private:
56  const Molecule& molecule;
57 public:
59  : molecule(molecule) {}
60 
61  double operator()(const coord_3d& x) const {
62  return molecule.nuclear_attraction_potential(x[0], x[1], x[2]);
63  }
64 
65  std::vector<coord_3d> special_points() const {return molecule.get_all_coords_vec();}
66 };
67 
69 private:
70  const Molecule& molecule;
71 public:
73  : molecule(molecule) {}
74 
75  double operator()(const coord_3d& x) const {
76  return molecule.molecular_core_potential(x[0], x[1], x[2]);
77  }
78 
79  std::vector<coord_3d> special_points() const {return molecule.get_all_coords_vec();}
80 };
81 
82 class CoreOrbitalFunctor : public FunctionFunctorInterface<double,3> {
83  const Molecule molecule;
84  const int atom;
85  const unsigned int core;
86  const int m;
87 public:
88  CoreOrbitalFunctor(Molecule& molecule, int atom, unsigned int core, int m)
89  : molecule(molecule), atom(atom), core(core), m(m) {};
90  double operator()(const coord_3d& r) const {
91  return molecule.core_eval(atom, core, m, r[0], r[1], r[2]);
92  };
93 };
94 
96  const Molecule molecule;
97  const int atom, axis;
98  const unsigned int core;
99  const int m;
100 public:
101  CoreOrbitalDerivativeFunctor(Molecule& molecule, int atom, int axis, unsigned int core, int m)
102  : molecule(molecule), atom(atom), axis(axis), core(core), m(m) {};
103  double operator()(const coord_3d& r) const {
104  return molecule.core_derivative(atom, axis, core, m, r[0], r[1], r[2]);
105  };
106 };
107 
108 
110 private:
111 Molecule molecule;
112 real_function_3d vnuc;
113 std::string core_type;
114 
115 public:
116  PotentialManager(const Molecule& molecule, const std::string& core_type)
117  : molecule(molecule), core_type(core_type) {}
118 
120  return vnuc;
121  }
122 
123  vector_real_function_3d core_projection(World & world, const vector_real_function_3d& psi, const bool include_Bc = true)
124  {
125  int npsi = psi.size();
126  if (npsi == 0) return psi;
127  int natom = molecule.natom();
128  vector_real_function_3d proj = zero_functions<double,3>(world, npsi);
129  real_tensor overlap_sum(static_cast<long>(npsi));
130 
131  for (int i=0; i<natom; ++i) {
132  Atom at = molecule.get_atom(i);
133  unsigned int atn = at.atomic_number;
134  unsigned int nshell = molecule.n_core_orb(atn);
135  if (nshell == 0) continue;
136  for (unsigned int c=0; c<nshell; ++c) {
137  unsigned int l = molecule.get_core_l(atn, c);
138  int max_m = (l+1)*(l+2)/2;
139  nshell -= max_m - 1;
140  for (int m=0; m<max_m; ++m) {
141  real_function_3d core = real_factory_3d(world).functor(real_functor_3d(new CoreOrbitalFunctor(molecule, i, c, m)));
142  real_tensor overlap = inner(world, core, psi);
143  overlap_sum += overlap;
144  for (int j=0; j<npsi; ++j) {
145  if (include_Bc) overlap[j] *= molecule.get_core_bc(atn, c);
146  proj[j] += core.scale(overlap[j]);
147  }
148  }
149  }
150  world.gop.fence();
151  }
152  if (world.rank() == 0) print("sum_k <core_k|psi_i>:", overlap_sum);
153  return proj;
154  }
155 
156  double core_projector_derivative(World & world, const vector_real_function_3d& mo, const real_tensor& occ, int atom, int axis)
157  {
158  vector_real_function_3d cores, dcores;
159  std::vector<double> bc;
160  unsigned int atn = molecule.get_atom(atom).atomic_number;
161  unsigned int ncore = molecule.n_core_orb(atn);
162 
163  // projecting core & d/dx core
164  for (unsigned int c=0; c<ncore; ++c) {
165  unsigned int l = molecule.get_core_l(atn, c);
166  int max_m = (l+1)*(l+2)/2;
167  for (int m=0; m<max_m; ++m) {
168  real_functor_3d func = real_functor_3d(new CoreOrbitalFunctor(molecule, atom, c, m));
169  cores.push_back(real_function_3d(real_factory_3d(world).functor(func).truncate_on_project()));
170  func = real_functor_3d(new CoreOrbitalDerivativeFunctor(molecule, atom, axis, c, m));
171  dcores.push_back(real_function_3d(real_factory_3d(world).functor(func).truncate_on_project()));
172  bc.push_back(molecule.get_core_bc(atn, c));
173  }
174  }
175 
176  // calc \sum_i occ_i <psi_i|(\sum_c Bc d/dx |core><core|)|psi_i>
177  double r = 0.0;
178  for (unsigned int c=0; c<cores.size(); ++c) {
179  double rcore= 0.0;
180  real_tensor rcores = inner(world, cores[c], mo);
181  real_tensor rdcores = inner(world, dcores[c], mo);
182  for (unsigned int i=0; i<mo.size(); ++i) {
183  rcore += rdcores[i] * rcores[i] * occ[i];
184  }
185  r += 2.0 * bc[c] * rcore;
186  }
187 
188  return r;
189  }
190 
192  if (core_type.substr(0,3) == "mcp") {
193  //START_TIMER(world);
194  gaxpy(world, 1.0, Vpsi, 1.0, core_projection(world, amo));
195  //END_TIMER(world, "MCP Core Projector");
196  }
197  }
198 
200  double safety = 0.1;
201  double vtol = FunctionDefaults<3>::get_thresh() * safety;
202  vnuc = real_factory_3d(world).functor(real_functor_3d(new MolecularPotentialFunctor(molecule))).thresh(vtol).truncate_on_project();
204  vnuc.reconstruct();
205  if (core_type != "") {
206  real_function_3d c_pot = real_factory_3d(world).functor(real_functor_3d(new MolecularCorePotentialFunctor(molecule))).thresh(vtol).initial_level(4);
208  c_pot.reconstruct();
209  vnuc += c_pot;
210  vnuc.truncate();
211  }
212  }
213 };
214 }
215 
216 #endif
double core_eval(int atom, unsigned int core, int m, double x, double y, double z) const
Definition: chem/molecule.cc:648
unsigned int n_core_orb(unsigned int atn) const
Definition: chem/molecule.h:123
Definition: shared_ptr_bits.h:38
Definition: potentialmanager.h:68
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
MolecularPotentialFunctor(const Molecule &molecule)
Definition: potentialmanager.h:58
Function< T, NDIM > & truncate(double tol=0.0, bool fence=true)
Truncate the function with optional fence. Compresses with fence if not compressed.
Definition: mra.h:577
Header to declare stuff which has not yet found a home.
FunctionDefaults holds default paramaters as static class members.
Definition: funcdefaults.h:175
void gaxpy(World &world, Q alpha, std::vector< Function< T, NDIM > > &a, Q beta, const std::vector< Function< R, NDIM > > &b, bool fence=true)
Generalized A*X+Y for vectors of functions -— a[i] = alpha*a[i] + beta*b[i].
Definition: vmra.h:680
MolecularCorePotentialFunctor(const Molecule &molecule)
Definition: potentialmanager.h:72
CoreOrbitalDerivativeFunctor(Molecule &molecule, int atom, int axis, unsigned int core, int m)
Definition: potentialmanager.h:101
std::vector< madness::Vector< double, 3 > > get_all_coords_vec() const
Definition: chem/molecule.cc:188
double operator()(const coord_3d &x) const
Definition: potentialmanager.h:75
void make_nuclear_potential(World &world)
Definition: potentialmanager.h:199
::std::string string
Definition: gtest-port.h:872
std::vector< coord_3d > special_points() const
Override this to return list of special points to be refined more deeply.
Definition: potentialmanager.h:79
double nuclear_attraction_potential(double x, double y, double z) const
Definition: chem/molecule.cc:579
double get_core_bc(unsigned int atn, unsigned int c) const
Definition: chem/molecule.h:134
std::vector< coord_3d > special_points() const
Override this to return list of special points to be refined more deeply.
Definition: potentialmanager.h:65
double core_derivative(int atom, int axis, unsigned int core, int m, double x, double y, double z) const
Definition: chem/molecule.cc:657
static const double & get_thresh()
Returns the default threshold.
Definition: funcdefaults.h:225
void set_thresh(double value, bool fence=true)
Sets the vaule of the truncation threshold. Optional global fence.
Definition: mra.h:552
std::vector< real_function_3d > vector_real_function_3d
Definition: functypedefs.h:79
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
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product
Definition: nemo.h:112
Definition: potentialmanager.h:54
Function< double, 3 > real_function_3d
Definition: functypedefs.h:65
Defines and implements most of Tensor.
Definition: potentialmanager.h:95
int natom() const
Definition: chem/molecule.h:148
void reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm...
Definition: mra.h:737
CoreOrbitalFunctor(Molecule &molecule, int atom, unsigned int core, int m)
Definition: potentialmanager.h:88
vector_real_function_3d core_projection(World &world, const vector_real_function_3d &psi, const bool include_Bc=true)
Definition: potentialmanager.h:123
double psi(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:42
unsigned int atomic_number
Atomic number.
Definition: chem/molecule.h:58
unsigned int get_core_l(unsigned int atn, unsigned int c) const
Definition: chem/molecule.h:130
void apply_nonlocal_potential(World &world, const vector_real_function_3d &amo, vector_real_function_3d Vpsi)
Definition: potentialmanager.h:191
double operator()(const coord_3d &r) const
Definition: potentialmanager.h:90
Tensor< double > real_tensor
Definition: functypedefs.h:40
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
std::shared_ptr< FunctionFunctorInterface< double, 3 > > real_functor_3d
Definition: functypedefs.h:107
double operator()(const coord_3d &x) const
Definition: potentialmanager.h:61
Definition: chem/molecule.h:55
Abstract base class interface required for functors used as input to Functions.
Definition: function_interface.h:58
PotentialManager(const Molecule &molecule, const std::string &core_type)
Definition: potentialmanager.h:116
const double m
Definition: gfit.cc:199
impl world gop fence()
Definition: potentialmanager.h:82
Definition: chem/molecule.h:83
real_function_3d vnuclear()
Definition: potentialmanager.h:119
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
FunctionFactory< double, 3 > real_factory_3d
Definition: functypedefs.h:93
Definition: potentialmanager.h:109
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
double core_projector_derivative(World &world, const vector_real_function_3d &mo, const real_tensor &occ, int atom, int axis)
Definition: potentialmanager.h:156
const Atom & get_atom(unsigned int i) const
Definition: chem/molecule.cc:223
double molecular_core_potential(double x, double y, double z) const
Definition: chem/molecule.cc:670
double operator()(const coord_3d &r) const
Definition: potentialmanager.h:103