MADNESS  version 0.9
scfparam.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 
38 
39 
40 #ifndef MADNESS_SCFPARAM_H
41 #define MADNESS_SCFPARAM_H
42 
43 #include <madness/tensor/tensor.h>
44 #include <moldft/molecule.h>
45 #include <moldft/molecularbasis.h>
46 
47 typedef Tensor<double> tensorT;
48 
49 struct SCFParameters {
50  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
51  // !!! !!!
52  // !!! If you add more data don't forget to add them to serialize method !!!
53  // !!! !!!
54  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
55 
56  // First list input parameters
57  double charge;
58  double smear;
59  double econv;
60  double dconv;
61  double L;
62  double maxrotn;
63  int nvalpha;
64  int nvbeta;
65  int nopen;
66  int maxiter;
67  int nio;
69  int plotlo,plothi;
70  bool plotdens;
71  bool plotcoul;
72  bool localize;
73  bool localize_pm;
74  bool restart;
75  unsigned int maxsub;
76  int npt_plot;
80  bool derivatives;
81  bool dipole;
83  // Next list inferred parameters
84  int nalpha;
85  int nbeta;
86  int nmo_alpha;
87  int nmo_beta;
88  double lo;
90  std::vector<double> protocol_data;
91  bool gopt;
92  double gtol;
93  bool gtest;
94  double gval;
95  double gprec;
96  int gmaxiter;
98 
99  template <typename Archive>
100  void serialize(Archive& ar) {
101  ar & charge & smear & econv & dconv & L & maxrotn & nvalpha & nvbeta & nopen & maxiter & nio & spin_restricted;
102  ar & plotlo & plothi & plotdens & plotcoul & localize & localize_pm & restart & maxsub & npt_plot & plot_cell & aobasis;
103  ar & nalpha & nbeta & nmo_alpha & nmo_beta & lo;
104  ar & core_type & derivatives & conv_only_dens & dipole;
105  ar & xc_data & protocol_data;
106  ar & gopt & gtol & gtest & gval & gprec & gmaxiter & algopt;
107  }
108 
110  : charge(0.0)
111  , smear(0.0)
112  , econv(1e-5)
113  , dconv(1e-4)
114  , L(0.0)
115  , maxrotn(0.25)
116  , nvalpha(0)
117  , nvbeta(0)
118  , nopen(0)
119  , maxiter(20)
120  , nio(1)
121  , spin_restricted(true)
122  , plotlo(0)
123  , plothi(-1)
124  , plotdens(false)
125  , plotcoul(false)
126  , localize(true)
127  , localize_pm(false)
128  , restart(false)
129  , maxsub(8)
130  , npt_plot(101)
131  , aobasis("6-31g")
132  , core_type("")
133  , derivatives(false)
134  , dipole(false)
135  , conv_only_dens(false)
136  , nalpha(0)
137  , nbeta(0)
138  , nmo_alpha(0)
139  , nmo_beta(0)
140  , lo(1e-10)
141  , xc_data("lda")
142  , protocol_data(madness::vector_factory(1e-4, 1e-6))
143  , gopt(false)
144  , gtol(1e-3)
145  , gtest(false)
146  , gval(1e-5)
147  , gprec(1e-4)
148  , gmaxiter(20)
149  , algopt("BFGS")
150  {}
151 
152 
153  void read_file(const std::string& filename) {
154  std::ifstream f(filename.c_str());
155  position_stream(f, "dft");
156  std::string s;
157  xc_data = "lda";
158  protocol_data = madness::vector_factory(1e-4, 1e-6);
159 
160  while (f >> s) {
161  if (s == "end") {
162  break;
163  }
164  else if (s == "charge") {
165  f >> charge;
166  }
167  else if (s == "smear") {
168  f >> smear;
169  }
170  else if (s == "econv") {
171  f >> econv;
172  }
173  else if (s == "dconv") {
174  f >> dconv;
175  }
176  else if (s == "L") {
177  f >> L;
178  }
179  else if (s == "maxrotn") {
180  f >> maxrotn;
181  }
182  else if (s == "nvalpha") {
183  f >> nvalpha;
184  }
185  else if (s == "nvbeta") {
186  f >> nvbeta;
187  }
188  else if (s == "nopen") {
189  f >> nopen;
190  }
191  else if (s == "unrestricted") {
192  spin_restricted = false;
193  }
194  else if (s == "restricted") {
195  spin_restricted = true;
196  }
197  else if (s == "maxiter") {
198  f >> maxiter;
199  }
200  else if (s == "nio") {
201  f >> nio;
202  }
203  else if (s == "xc") {
204  char buf[1024];
205  f.getline(buf,sizeof(buf));
206  xc_data = buf;
207  }
208  else if (s == "protocol") {
209  std::string buf;
210  std::getline(f,buf);
211  protocol_data = std::vector<double>();
212  double d;
213  std::stringstream s(buf);
214  while (s >> d) protocol_data.push_back(d);
215  }
216  else if (s == "plotmos") {
217  f >> plotlo >> plothi;
218  }
219  else if (s == "plotdens") {
220  plotdens = true;
221  }
222  else if (s == "plotcoul") {
223  plotcoul = true;
224  }
225  else if (s == "plotnpt") {
226  f >> npt_plot;
227  }
228  else if (s == "plotcell") {
229  plot_cell = tensorT(3L,2L);
230  f >> plot_cell(0,0) >> plot_cell(0,1) >> plot_cell(1,0) >> plot_cell(1,1) >> plot_cell(2,0) >> plot_cell(2,1);
231  }
232  else if (s == "aobasis") {
233  f >> aobasis;
234  if (aobasis!="sto-3g" && aobasis!="6-31g") {
235  std::cout << "moldft: unrecognized aobasis (sto-3g or 6-31g only): " << aobasis << std::endl;
236  MADNESS_EXCEPTION("input_error", 0);
237  }
238  }
239  else if (s == "canon") {
240  localize = false;
241  }
242  else if (s == "local") {
243  localize = true;
244  }
245  else if (s == "pm") {
246  localize_pm = true;
247  }
248  else if (s == "boys") {
249  localize_pm = false;
250  }
251  else if (s == "restart") {
252  restart = true;
253  }
254  else if (s == "maxsub") {
255  f >> maxsub;
256  if (maxsub <= 0) maxsub = 1;
257  if (maxsub > 20) maxsub = 20;
258  }
259  else if (s == "core_type") {
260  f >> core_type;
261  }
262  else if (s == "derivatives") {
263  derivatives = true;
264  }
265  else if (s == "dipole") {
266  dipole = true;
267  }
268  else if (s == "convonlydens") {
269  conv_only_dens = true;
270  }
271  else if (s == "gopt") {
272  gopt = true;
273  }
274  else if (s == "gtol") {
275  f >> gtol;
276  }
277  else if (s == "gtest") {
278  gtest = true;
279  }
280  else if (s == "gval") {
281  f >> gval;
282  }
283  else if (s == "gprec") {
284  f >> gprec;
285  }
286  else if (s == "gmaxiter") {
287  f >> gmaxiter;
288  }
289  else if (s == "algopt") {
290  char buf[1024];
291  f.getline(buf,sizeof(buf));
292  algopt = buf;
293  }
294  else {
295  std::cout << "moldft: unrecognized input keyword " << s << std::endl;
296  MADNESS_EXCEPTION("input error",0);
297  }
298  if (nopen != 0) spin_restricted = false;
299  }
300  }
301 
302  void set_molecular_info(const Molecule& molecule, const AtomicBasisSet& aobasis, unsigned int n_core) {
303  double z = molecule.total_nuclear_charge();
304  int nelec = int(z - charge - n_core*2);
305  if (fabs(nelec+charge+n_core*2-z) > 1e-6) {
306  error("non-integer number of electrons?", nelec+charge+n_core*2-z);
307  }
308  nalpha = (nelec + nopen)/2;
309  nbeta = (nelec - nopen)/2;
310  if (nalpha < 0) error("negative number of alpha electrons?", nalpha);
311  if (nbeta < 0) error("negative number of beta electrons?", nbeta);
312  if ((nalpha+nbeta) != nelec) error("nalpha+nbeta != nelec", nalpha+nbeta);
313  nmo_alpha = nalpha + nvalpha;
314  nmo_beta = nbeta + nvbeta;
315  if (nalpha != nbeta) spin_restricted = false;
316 
317  // Ensure we have enough basis functions to guess the requested
318  // number of states ... a minimal basis for a closed-shell atom
319  // might not have any functions for virtuals.
320  int nbf = aobasis.nbf(molecule);
321  nmo_alpha = std::min(nbf,nmo_alpha);
322  nmo_beta = std::min(nbf,nmo_beta);
323  if (nalpha>nbf || nbeta>nbf) error("too few basis functions?", nbf);
324  nvalpha = nmo_alpha - nalpha;
325  nvbeta = nmo_beta - nbeta;
326 
327  // Unless overridden by the user use a cell big enough to
328  // have exp(-sqrt(2*I)*r) decay to 1e-6 with I=1ev=0.037Eh
329  // --> need 50 a.u. either side of the molecule
330 
331  if (L == 0.0) {
332  L = molecule.bounding_cube() + 50.0;
333  }
334 
335  lo = molecule.smallest_length_scale();
336  }
337 
338  void print(World& world) const {
339  //time_t t = time((time_t *) 0);
340  //char *tmp = ctime(&t);
341  //tmp[strlen(tmp)-1] = 0; // lose the trailing newline
342 
343  //madness::print(" date of calculation ", tmp);
344  madness::print(" restart ", restart);
345  madness::print(" number of processes ", world.size());
346  madness::print(" no. of io servers ", nio);
347  madness::print(" simulation cube ", -L, L);
348  madness::print(" total charge ", charge);
349  madness::print(" smearing ", smear);
350  madness::print(" number of electrons ", nalpha, nbeta);
351  madness::print(" number of orbitals ", nmo_alpha, nmo_beta);
352  madness::print(" spin restricted ", spin_restricted);
353  madness::print(" xc functional ", xc_data);
354 #ifdef MADNESS_HAS_LIBXC
355  madness::print(" xc libraray ", "libxc");
356 #else
357  madness::print(" xc libraray ", "default (lda only)");
358 #endif
359  if (core_type != "")
360  madness::print(" core type ", core_type);
361  madness::print(" initial guess basis ", aobasis);
362  madness::print(" max krylov subspace ", maxsub);
363  madness::print(" compute protocol ", protocol_data);
364  madness::print(" energy convergence ", econv);
365  madness::print(" density convergence ", dconv);
366  madness::print(" maximum rotation ", maxrotn);
367  if (conv_only_dens)
368  madness::print(" Convergence criterion is only density delta.");
369  else
370  madness::print(" Convergence criteria are density delta & BSH residual.");
371  madness::print(" plot density ", plotdens);
372  madness::print(" plot coulomb ", plotcoul);
373  madness::print(" plot orbital ", plotlo, plothi);
374  madness::print(" plot npoints ", npt_plot);
375  if (plot_cell.size() > 0)
376  madness::print(" plot volume ", plot_cell(0,0), plot_cell(0,1),
377  plot_cell(1,0), plot_cell(1,1), plot_cell(2,0), plot_cell(2,1));
378  else
379  madness::print(" plot volume ", "default");
380 
381  std::string loctype = "boys";
382  if (localize_pm) loctype = "pm";
383  if (localize)
384  madness::print(" localized orbitals ", loctype);
385  else
386  madness::print(" canonical orbitals ");
387  if (derivatives)
388  madness::print(" calc derivatives ");
389  if (dipole)
390  madness::print(" calc dipole ");
391  }
392 //};
393  void gprint(World& world) const {
394  madness::print(" Optimizer parameters: ");
395  madness::print(" Maximum iterations (gmaxiter) ", gmaxiter);
396  madness::print(" Tolerance (gtol) ", gtol);
397  madness::print(" Gradient value (gval) ", gval);
398  madness::print(" Gradient precision (gprec) ", gprec);
399  madness::print(" Optimization algorithm (algopt) ", algopt);
400  madness::print(" Gradient numerical test (gtest) ", gtest);
401  }
402 };
403 
404 
405 #endif
406 
bool localize_pm
If true use PM for localization.
Definition: scfparam.h:73
Tensor< double > tensorT
Definition: DFcode/distpm.cc:13
bool derivatives
If true calculate derivatives.
Definition: scfparam.h:80
std::string aobasis
AO basis used for initial guess (6-31g or sto-3g)
Definition: scfparam.h:78
bool gopt
geometry optimizer
Definition: scfparam.h:91
tensorT plot_cell
lo hi in each dimension for plotting (default is all space)
Definition: scfparam.h:77
std::vector< double > protocol_data
Calculation protocol.
Definition: scfparam.h:90
int nalpha
Number of alpha spin electrons.
Definition: scfparam.h:84
double L
User coordinates box size.
Definition: scfparam.h:61
int nopen
Number of unpaired electrons = napha-nbeta.
Definition: scfparam.h:65
std::istream & position_stream(std::istream &f, const std::string &tag)
Definition: position_stream.cc:37
bool plotcoul
If true plot the total coulomb potential at convergence.
Definition: scfparam.h:71
double dconv
Density convergence.
Definition: scfparam.h:60
bool restart
If true restart from orbitals on disk.
Definition: scfparam.h:74
int plotlo
Definition: scfparam.h:69
::std::string string
Definition: gtest-port.h:872
void read_file(const std::string &filename)
Definition: scfparam.h:153
int nbf(const Molecule &molecule) const
Given a molecule count the number of basis functions.
Definition: DFcode/molecularbasis.h:555
double gtol
geometry tolerance
Definition: scfparam.h:92
double total_nuclear_charge() const
Definition: DFcode/molecule.cc:542
NDIM & f
Definition: mra.h:2179
double smallest_length_scale() const
Definition: DFcode/molecule.cc:300
Definition: DFcode/molecule.h:82
bool conv_only_dens
If true remove bsh_residual from convergence criteria how ugly name is...
Definition: scfparam.h:82
void gprint(World &world) const
Definition: scfparam.h:393
int maxiter
Maximum number of iterations.
Definition: scfparam.h:66
double maxrotn
Step restriction used in autoshift algorithm.
Definition: scfparam.h:62
int gmaxiter
optimization maxiter
Definition: scfparam.h:96
int nio
No. of io servers to use.
Definition: scfparam.h:67
unsigned int maxsub
Size of iterative subspace ... set to 0 or 1 to disable.
Definition: scfparam.h:75
Defines and implements most of Tensor.
double econv
Energy convergence.
Definition: scfparam.h:59
double charge
Total molecular charge.
Definition: scfparam.h:57
Tensor< double > tensorT
Definition: scfparam.h:47
double gval
value precision
Definition: scfparam.h:94
SCFParameters()
Definition: scfparam.h:109
void serialize(Archive &ar)
Definition: scfparam.h:100
bool gtest
geometry tolerance
Definition: scfparam.h:93
int nvbeta
Number of beta virtuals to compute.
Definition: scfparam.h:64
const mpreal min(const mpreal &x, const mpreal &y)
Definition: mpreal.h:2675
int nmo_beta
Number of beta spin molecular orbitals.
Definition: scfparam.h:87
int nvalpha
Number of alpha virtuals to compute.
Definition: scfparam.h:63
double smear
Smearing parameter.
Definition: scfparam.h:58
std::string core_type
core potential type ("" or "mcp")
Definition: scfparam.h:79
int nmo_alpha
Number of alpha spin molecular orbitals.
Definition: scfparam.h:86
void error(const char *msg, int code)
Definition: oldtest.cc:57
Definition: scfparam.h:49
void set_molecular_info(const Molecule &molecule, const AtomicBasisSet &aobasis, unsigned int n_core)
Definition: scfparam.h:302
bool dipole
If true calculatio dipole moment.
Definition: scfparam.h:81
double bounding_cube() const
Returns the half width of the bounding cube.
Definition: DFcode/molecule.cc:532
std::string xc_data
XC input line.
Definition: scfparam.h:89
int plothi
Range of MOs to print (for both spins if polarized)
Definition: scfparam.h:69
std::string algopt
algorithm used for optimization
Definition: scfparam.h:97
void print(World &world) const
Definition: scfparam.h:338
int npt_plot
No. of points to use in each dim for plots.
Definition: scfparam.h:76
bool plotdens
If true print the density at convergence.
Definition: scfparam.h:70
double lo
Smallest length scale we need to resolve.
Definition: scfparam.h:88
std::vector< T > vector_factory(const T &v0)
Returns a std::vector initialized from the arguments.
Definition: vector_factory.h:50
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
int nbeta
Number of beta spin electrons.
Definition: scfparam.h:85
bool spin_restricted
True if spin restricted.
Definition: scfparam.h:68
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Contracted Gaussian basis.
Definition: DFcode/molecularbasis.h:390
double gprec
gradient precision
Definition: scfparam.h:95
bool localize
If true solve for localized orbitals.
Definition: scfparam.h:72