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