MADNESS 0.10.1
CalculationParameters.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 CalculationParameters
36/// \brief solution parameters for SCF calculations
37
38
39
40#ifndef MADNESS_CHEM_CALCULATIONPARAMETERS_H__INCLUDED
41#define MADNESS_CHEM_CALCULATIONPARAMETERS_H__INCLUDED
42
47
48
49namespace madness {
50
52 static constexpr char const* tag = "dft";
53
55
57 read_input_and_commandline_options(world, parser, "dft");
58 // NB: `--optimize` deliberately does NOT set anything here. It selects a
59 // workflow task (WorkflowBuilders::add_optimize_workflow_drivers); the
60 // `dft` group has no say in whether a geometry is optimized.
61 std::string inputfile=parser.value("input");
62 // std::string prefix=commandlineparser::remove_extension(commandlineparser::base_name(inputfile));
63 // if (prefix!="input") set_derived_value("prefix",prefix);
64 }
65
66 /// ctor reading out the input file
68 initialize<std::string>("prefix","mad","prefixes your output/restart/json/plot/etc files");
69 initialize<double>("charge",0.0,"total molecular charge");
70 initialize<std::string> ("xc","hf","XC input line");
71 initialize<std::string> ("hfexalg","multiworld_row","hf exchange algorithm; multiworld bounds memory, needs one subworld per rank",{"multiworld","multiworld_row","fetch_compute","smallmem","largemem"});
72 initialize<long> ("hfex_batch_granularity",1,"hfexalg=multiworld: orbital batches per rank; >1 balances better");
73 initialize<bool> ("hfex_cost_aware_assign",true,"hfexalg=multiworld: place tasks by measured cost, not by count");
74 initialize<int> ("hfex_local_accumulation",2,"hfexalg=multiworld: gather tile results 1=per subworld, 2=per node");
75 initialize<std::vector<std::string>>("memory",{"storefunction","nodereplicated","distributed"},"memory algorithm for storing functions (storing,cloud,target)");
76 initialize<double>("smear",0.0,"smearing parameter");
77 initialize<double>("econv",1.e-5,"energy convergence");
78 initialize<double>("dconv",1.e-4,"density convergence");
79 initialize<std::vector<std::string> >("convergence_criteria",{"bsh_residual","total_energy"},"possible values are: bsh_residual, total_energy, each_energy, density");
80 initialize<int> ("k",-1,"polynomial order");
81 initialize<double>("l",20,"user coordinates box size");
82 initialize<std::string>("deriv","abgv","derivative method",{"abgv","bspline","ble"});
83 initialize<std::string>("dft_deriv","abgv","derivative method for gga potentials",{"abgv","bspline","ble"});
84 initialize<double>("maxrotn",0.25,"step restriction used in autoshift algorithm");
85 initialize<int> ("nvalpha",0,"number of alpha virtuals to compute");
86 initialize<int> ("nvbeta",0,"number of beta virtuals to compute");
87 initialize<int> ("nopen",0,"number of unpaired electrons = nalpha-nbeta");
88 initialize<int> ("maxiter",25,"maximum number of iterations");
89 initialize<int> ("nio",1,"no. of io servers to use");
90 initialize<bool> ("spin_restricted",true,"true if spin restricted");
91 initialize<int> ("plotlo",0,"range of MOs to print (for both spins if polarized");
92 initialize<int> ("plothi",-1,"range of MOs to print (for both spins if polarized");
93 initialize<bool> ("plotdens",false,"If true print the density at convergence");
94 initialize<bool> ("plotcoul",false,"If true plot the total coulomb potential at convergence");
95 initialize<bool> ("plotcube",false,"If true also write Gaussian .cube files (for Avogadro/VMD) alongside .dx");
96 initialize<std::string> ("localize","new","localization method",{"pm","boys","new","canon"});
97 initialize<std::string> ("pointgroup","c1","use point (sub) group symmetry if not localized",{"c1","c2","ci","cs","c2v","c2h","d2","d2h"});
98 initialize<std::string>("restart","auto","where the initial orbitals come from: auto picks "
99 "between none/iterate/read_only by what is on disk",
100 {"auto","none","iterate","read_only","ao","nwchem"});
101 // Retired in favour of the `restart` modes above, but kept registered so a
102 // deck that still sets them gets a migration error instead of the single
103 // easily-missed warning that ignore_unknown_keys would produce. See the
104 // guard at the end of set_derived_values().
105 initialize<bool> ("restartao",false,"RETIRED -- use restart=ao");
106 initialize<bool> ("no_compute",false,"RETIRED -- use restart=read_only");
107 initialize<bool> ("save",true,"if true save orbitals to disk");
108 initialize<int> ("maxsub",10,"size of iterative subspace ... set to 0 or 1 to disable");
109 initialize<double> ("orbitalshift",0.0,"scf orbital shift: shift the occ orbitals to lower energies");
110 initialize<int> ("npt_plot",101,"no. of points to use in each dim for plots");
111// initialize<Tensor<double> > ("plot_cell",Tensor<double>(),"lo hi in each dimension for plotting (default is all space)");
112 initialize<std::vector<double> > ("plot_cell",std::vector<double>(),"lo hi in each dimension for plotting (default is all space)");
113 initialize<std::string> ("aobasis","6-31g","AO basis used for initial guess (6-31gss, 6-31g, 3-21g, sto-6g, sto-3g)");
114 initialize<bool> ("derivatives",false,"if true calculate nuclear derivatives");
115 initialize<bool> ("dipole",false,"if true calculate dipole moment");
116 initialize<bool> ("conv_only_dens",false,"if true remove bsh_residual from convergence criteria (deprecated)");
117 initialize<bool> ("psp_calc",false,"pseudopotential calculation for all atoms");
118 initialize<std::string> ("pcm_data","none","do a PCM (solvent) calculation");
119 initialize<std::string> ("ac_data","none","do a calculation with asymptotic correction (see ACParameters class in chem/AC.h for details)");
120 initialize<bool> ("pure_ae",true,"pure all electron calculation with no pseudo-atoms");
121 initialize<int> ("print_level",3,"0: no output; 1: final energy; 2: iterations; 3: timings; 10: debug");
122 initialize<std::string> ("molecular_structure","inputfile","where to read the molecule from: inputfile or name from the library");
123
124 // Next list inferred parameters
125 initialize<int> ("nalpha",-1,"number of alpha spin electrons");
126 initialize<int> ("nbeta",-1,"number of beta spin electrons");
127 initialize<int> ("nmo_alpha",-1,"number of alpha spin molecular orbitals");
128 initialize<int> ("nmo_beta",-1,"number of beta spin molecular orbitals");
129 initialize<double> ("lo",1.e-10,"smallest length scale we need to resolve");
130 initialize<std::vector<double> > ("protocol",{1.e-4,1.e-6},"calculation protocol");
131
132 // Retired geometry-optimization knobs. Geometry optimization is no longer
133 // something an SCF does to itself; it is a workflow task of its own
134 // (`madqc --optimize --wf=<scf|nemo>`, qcapp::OptimizeDriver) and every
135 // knob it has lives in the `optimization` group (ParameterManager.hpp).
136 //
137 // These stay registered, and error, rather than being deleted outright:
138 // ignore_unknown_keys is true by default, so a deleted key would let an
139 // old deck run as a plain single point after one warning nobody reads --
140 // silently returning an unoptimized geometry. See the guard at the end of
141 // set_derived_values().
142 initialize<bool> ("gopt",false,"RETIRED -- use `madqc --optimize`");
143 initialize<double> ("gtol",1.e-4,"RETIRED -- use optimization group `gtol`");
144 initialize<bool> ("gtest",false,"RETIRED -- never had an effect");
145 initialize<double> ("gval",1.e-5,"RETIRED -- use optimization group `value_precision`");
146 initialize<double> ("gprec",1.e-4,"RETIRED -- use optimization group `gradient_precision`");
147 initialize<int> ("gmaxiter",20,"RETIRED -- use optimization group `maxiter`");
148 initialize<bool> ("ginitial_hessian",false,"RETIRED -- use optimization group `initial_hessian`");
149 initialize<std::string> ("algopt","bfgs","RETIRED -- use optimization group `algopt`",{"bfgs","cg"});
150 initialize<int> ("nv_factor",1,"factor to multiply number of virtual orbitals with when automatically decreasing nvirt");
151 initialize<int> ("vnucextra",2,"load balance parameter for nuclear pot");
152 initialize<int> ("loadbalparts",2,"??");
153
154 //Keyword to use nwchem output for initial guess
155 initialize<std::string> ("nwfile","none","Base name of nwchem output files (.out and .movecs extensions) to read from");
156
157 }
158
159 std::string get_tag() const override {
160 return tag;
161 }
162
163 public:
165
166 std::string prefix() const {return get<std::string>("prefix");}
167
168 double econv() const {return get<double>("econv");}
169 double dconv() const {return get<double>("dconv");}
170
171 bool converge_density() const {
172 std::vector<std::string> criteria=get<std::vector<std::string> >("convergence_criteria");
173 return std::find(criteria.begin(),criteria.end(),"density")!=criteria.end();
174 }
176 std::vector<std::string> criteria=get<std::vector<std::string> >("convergence_criteria");
177 return std::find(criteria.begin(),criteria.end(),"bsh_residual")!=criteria.end();
178 }
180 std::vector<std::string> criteria=get<std::vector<std::string> >("convergence_criteria");
181 return std::find(criteria.begin(),criteria.end(),"total_energy")!=criteria.end();
182 }
183 bool converge_each_energy() const {
184 std::vector<std::string> criteria=get<std::vector<std::string> >("convergence_criteria");
185 return std::find(criteria.begin(),criteria.end(),"each_energy")!=criteria.end();
186 }
187
188 int nopen() const {return get<int>("nopen");}
189 int nalpha() const {return get<int>("nalpha");}
190 int nbeta() const {return get<int>("nbeta");}
191
192 int nvalpha() const {return get<int>("nvalpha");}
193 int nvbeta() const {return get<int>("nvbeta");}
194 int nv_factor() const {return get<int>("nv_factor");}
195
196 int nmo_alpha() const {return get<int>("nmo_alpha");}
197 int nmo_beta() const {return get<int>("nmo_beta");}
198
199 bool have_beta() const {return (nbeta()>0) and (not spin_restricted());}
200
201 bool spin_restricted() const {return get<bool>("spin_restricted");}
202
203 double lo() const {return get<double>("lo");}
204 double L() const {return get<double>("l");}
205 int k() const {return get<int>("k");}
206
207 std::string localize_method() const {return get<std::string>("localize");}
208 bool do_localize() const {return (localize_method()!="canon");}
209 bool localize_pm() const {return (localize_method()=="pm");}
210
211 std::string pointgroup() const {return get<std::string>("pointgroup");}
212 bool do_symmetry() const {return (pointgroup()!="c1");}
213 double charge() const {return get<double>("charge");}
214 int print_level() const {return get<int>("print_level");}
215
216 int maxiter() const {return get<int>("maxiter");}
217 double orbitalshift() const {return get<double>("orbitalshift");}
218
219 std::string deriv() const {return get<std::string>("deriv");}
220 std::string dft_deriv() const {return get<std::string>("dft_deriv");}
221 std::string pcm_data() const {return get<std::string>("pcm_data");}
222 std::string ac_data() const {return get<std::string>("ac_data");}
223 std::string xc() const {return get<std::string>("xc");}
224 std::string hfexalg() const {return get<std::string>("hfexalg");}
225 long hfex_batch_granularity() const {return get<long>("hfex_batch_granularity");}
226 bool hfex_cost_aware_assign() const {return get<bool>("hfex_cost_aware_assign");}
227 int hfex_local_accumulation() const {return get<int>("hfex_local_accumulation");}
228
229 std::vector<std::string> memory() const {return get<std::vector<std::string>>("memory");}
230
231 std::string aobasis() const {return get<std::string>("aobasis");}
232
233 std::vector<double> protocol() const {return get<std::vector<double> >("protocol");}
234 bool save() const {return get<bool>("save");}
235 /// the `restart` keyval as a string; parse with restart_mode_from_string()
236
237 /// Returns the spelling rather than the RestartMode enum because RestartPlan.h
238 /// includes this header, so the dependency cannot run the other way.
239 std::string restart() const {return get<std::string>("restart");}
240 bool restart_cphf() const {return get<bool>("restart_cphf");}
241
242 int maxsub() const {return get<int>("maxsub");}
243 double maxrotn() const {return get<double>("maxrotn");}
244
245 int vnucextra() const {return get<int>("vnucextra");}
246 int loadbalparts() const {return get<int>("loadbalparts");}
247
248
249 bool derivatives() const {return get<bool>("derivatives");}
250 bool dipole() const {return get<bool>("dipole");}
251
252 // NB: no gopt()/gtol()/gval()/gprec()/gmaxiter()/ginitial_hessian()/algopt()
253 // accessors. Those keyvals are retired; see the initialize() block above and
254 // the guard in set_derived_values(). The optimizer's knobs are in
255 // OptimizationParameters (chem/ParameterManager.hpp).
256
257 std::string nwfile() const {return get<std::string>("nwfile");}
258
260 std::vector<double> vcell=get<std::vector<double> >("plot_cell");
261 if (vcell.size()==0) return Tensor<double>();
262 Tensor<double> cell(3,2);
263 cell(0,0)=vcell[0];
264 cell(0,1)=vcell[1];
265 cell(1,0)=vcell[2];
266 cell(1,1)=vcell[3];
267 cell(2,0)=vcell[4];
268 cell(2,1)=vcell[5];
269 return cell;
270 }
271
272
274
275 for (size_t iatom = 0; iatom < molecule.natom(); iatom++) {
276 if (molecule.get_pseudo_atom(iatom)){
277 set_derived_value("pure_ae",false);
278 continue;
279 }
280 }
281 set_derived_value("aobasis",molecule.guess_file());;
282 const int n_core = molecule.n_core_orb_all();
283
284
285 std::vector<double> proto=get<std::vector<double> >("protocol");
286 // No ... The accuracy of computation is INDEPENDENT of the convergence requirement
287 // --- actually need more precision than convergence threshold in order to have
288 // variational principle working and for robust convergence
289 //proto.back()=get<double>("econv");
290 set_derived_value("protocol",proto);
291 // No ... the energy is variational! Don't need more accuracy in dconv --- in fact the opposite is true.
292 // set_derived_value("dconv",sqrt(get<double>("econv"))*0.1);
293
294 double z = molecule.total_nuclear_charge();
295 const double charge=get<double>("charge");
296 int nelec = int(z - charge - n_core*2);
297 if (fabs(nelec+charge+n_core*2-z) > 1e-6) {
298 error("non-integer number of electrons?", nelec+charge+n_core*2-z);
299 }
300
301 set_derived_value("nalpha",(nelec + nopen())/2);
302 set_derived_value("nbeta",(nelec - nopen())/2);
303
304 if (nalpha() < 0) error("negative number of alpha electrons?", nalpha());
305 if (nbeta() < 0) error("negative number of beta electrons?", nbeta());
306 if ((nalpha()+nbeta()) != nelec) error("nalpha+nbeta != nelec", nalpha()+nbeta());
307 if (nalpha() != nbeta()) set_derived_value("spin_restricted",false);
308
309 set_derived_value("nmo_alpha",nalpha() + nvalpha());
310 set_derived_value("nmo_beta",nbeta() + nvbeta());
311
312 // Unless overridden by the user use a cell big enough to
313 // have exp(-sqrt(2*I)*r) decay to 1e-6 with I=1ev=0.037Eh
314 // --> need 50 a.u. either side of the molecule
315 set_derived_value("l",molecule.bounding_cube() + 50.0);
316
317 //set_derived_value("lo",molecule.smallest_length_scale());
318
319 // set highest possible point group for symmetry
320 if (do_localize()) set_derived_value("pointgroup",std::string("c1"));
321 else set_derived_value("pointgroup",molecule.get_pointgroup());
322
323 // above two lines will not override user input, so check input is sane
324 if (do_localize() and do_symmetry()) {
325 error("\n\nsymmetry and localization cannot be used at the same time\n"
326 "switch from local to canonical orbitals (keyword canon)\n\n");
327 }
328
329 // Geometry optimization left the `dft` group entirely. `gopt` in particular
330 // must not be waved through: a deck that sets it expects an optimized
331 // geometry back, and silently returning a single point at the input
332 // geometry is a wrong answer, not a missing feature. They stay registered
333 // and erroring rather than being deleted, because ignore_unknown_keys is
334 // true by default and a deleted key would run the deck as a plain single
335 // point after one warning nobody reads.
336 for (const char* key : {"gopt","gtol","gtest","gval","gprec",
337 "gmaxiter","ginitial_hessian","algopt"}) {
338 if (is_user_defined(key))
339 error(("\n\n`" + std::string(key) + "` has been retired: geometry optimization is now a task of "
340 "its own.\nUse `madqc --optimize --wf=<scf|nemo>` and the `optimization` "
341 "parameter group\n(see `madqc --print_parameters=optimization`).\n\n").c_str());
342 }
343
344 // Retired keyvals. A clean break needs to be loud: ignore_unknown_keys is
345 // true by default, so deleting these outright would let an old deck run
346 // with different semantics after one warning nobody reads. They stay
347 // registered and erroring until the migration is old news.
348 if (is_user_defined("restartao"))
349 error("\n\n`restartao` has been retired: use `restart ao` instead\n\n");
350 if (is_user_defined("no_compute"))
351 error("\n\n`no_compute` has been retired: use `restart read_only` instead\n\n");
352
353 //NWChem only supports Boys localization (or canonical)
354 if (nwfile() != "none") {
355 set_derived_value("localize",std::string("boys"));
356 //Error if user requested something other than Boys
357 if(localize_method() != "boys" and localize_method() != "canon") error("NWchem initialization only supports Boys localization");
358 }
359 }
360};
361
362
363} // namespace madness
364
365#endif /* MADNESS_CHEM_CALCULATIONPARAMETERS_H__INCLUDED */
Definition molecule.h:129
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 is_user_defined(std::string key) const
Definition chem/QCCalculationParametersBase.h:315
void set_derived_value(const std::string &key, const T &value)
Definition chem/QCCalculationParametersBase.h:429
A tensor is a multidimensional array.
Definition tensor.h:318
A parallel world class.
Definition world.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void error(const char *msg)
Definition world.cc:147
Definition test_QCCalculationParametersBase.cc:72
Definition CalculationParameters.h:51
bool converge_each_energy() const
Definition CalculationParameters.h:183
std::vector< double > protocol() const
Definition CalculationParameters.h:233
double charge() const
Definition CalculationParameters.h:213
long hfex_batch_granularity() const
Definition CalculationParameters.h:225
CalculationParameters(const CalculationParameters &other)=default
void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition chem/QCCalculationParametersBase.h:332
bool converge_density() const
Definition CalculationParameters.h:171
int nv_factor() const
Definition CalculationParameters.h:194
bool do_symmetry() const
Definition CalculationParameters.h:212
bool localize_pm() const
Definition CalculationParameters.h:209
int hfex_local_accumulation() const
Definition CalculationParameters.h:227
void set_derived_values(const Molecule &molecule)
Definition CalculationParameters.h:273
std::string restart() const
the restart keyval as a string; parse with restart_mode_from_string()
Definition CalculationParameters.h:239
int k() const
Definition CalculationParameters.h:205
bool converge_bsh_residual() const
Definition CalculationParameters.h:175
std::vector< std::string > memory() const
Definition CalculationParameters.h:229
CalculationParameters()
ctor reading out the input file
Definition CalculationParameters.h:67
bool converge_total_energy() const
Definition CalculationParameters.h:179
Tensor< double > plot_cell() const
Definition CalculationParameters.h:259
std::string nwfile() const
Definition CalculationParameters.h:257
static constexpr char const * tag
Definition CalculationParameters.h:52
std::string prefix() const
Definition CalculationParameters.h:166
std::string ac_data() const
Definition CalculationParameters.h:222
int nmo_alpha() const
Definition CalculationParameters.h:196
int nopen() const
Definition CalculationParameters.h:188
bool dipole() const
Definition CalculationParameters.h:250
bool save() const
Definition CalculationParameters.h:234
double dconv() const
Definition CalculationParameters.h:169
double econv() const
Definition CalculationParameters.h:168
int nvalpha() const
Definition CalculationParameters.h:192
int vnucextra() const
Definition CalculationParameters.h:245
int print_level() const
Definition CalculationParameters.h:214
std::string deriv() const
Definition CalculationParameters.h:219
bool do_localize() const
Definition CalculationParameters.h:208
std::string hfexalg() const
Definition CalculationParameters.h:224
bool hfex_cost_aware_assign() const
Definition CalculationParameters.h:226
double L() const
Definition CalculationParameters.h:204
std::string localize_method() const
Definition CalculationParameters.h:207
int loadbalparts() const
Definition CalculationParameters.h:246
std::string aobasis() const
Definition CalculationParameters.h:231
int nalpha() const
Definition CalculationParameters.h:189
std::string dft_deriv() const
Definition CalculationParameters.h:220
int maxsub() const
Definition CalculationParameters.h:242
int nvbeta() const
Definition CalculationParameters.h:193
bool derivatives() const
Definition CalculationParameters.h:249
int nbeta() const
Definition CalculationParameters.h:190
int nmo_beta() const
Definition CalculationParameters.h:197
bool have_beta() const
Definition CalculationParameters.h:199
bool spin_restricted() const
Definition CalculationParameters.h:201
int maxiter() const
Definition CalculationParameters.h:216
double orbitalshift() const
Definition CalculationParameters.h:217
double lo() const
Definition CalculationParameters.h:203
std::string pcm_data() const
Definition CalculationParameters.h:221
bool restart_cphf() const
Definition CalculationParameters.h:240
std::string get_tag() const override
Definition CalculationParameters.h:159
std::string pointgroup() const
Definition CalculationParameters.h:211
double maxrotn() const
Definition CalculationParameters.h:243
std::string xc() const
Definition CalculationParameters.h:223
CalculationParameters(World &world, const commandlineparser &parser)
Definition CalculationParameters.h:56
very simple command line parser
Definition commandlineparser.h:28
std::string value(const std::string key) const
Definition commandlineparser.h:84
void e()
Definition test_sig.cc:75
static Molecule molecule
Definition testperiodicdft.cc:39