MADNESS 0.10.1
PNOParameters.h
Go to the documentation of this file.
1/*
2 * PNOParameters.h
3 *
4 * Created on: Sep. 9, 2019
5 * Author: jsk
6 */
7
8#ifndef PNOPARAMETERS_H_
9#define PNOPARAMETERS_H_
10
11#include <vector>
12#include <map>
14
15namespace madness {
16
18inline std::string type(const PairType& n){ return "PairType";}
19std::ostream& operator << (std::ostream& os, const PairType& en);
20std::istream& operator >> (std::istream& os, PairType& en);
22inline std::string type(const EnergyType& n){ return "EnergyType";}
23std::ostream& operator << (std::ostream& os, const EnergyType& en);
24std::istream& operator >> (std::istream& os, EnergyType& en);
26inline std::string type(const GuessType& n){ return "GuessType";}
27std::ostream& operator << (std::ostream& os, const GuessType& en);
28std::istream& operator >> (std::istream& is, GuessType& en);
29
31public:
32
33
34 std::string get_tag() const override {
35 return std::string("pno");
36 }
37
38 template<typename T>
39 T assign_from_string(const std::string& string)const{
40 T result;
41 std::stringstream ss(string);
42 ss >> result;
43 return result;
44 }
45
49
53
58
64
66 initialize<int>("rank_increase", 15 , "maximum rank to increase in every macroiteration");
67 initialize<int>("chunk", 100 , "chunk of functions operated on in parallel when G or K is applied (prevent memory shortage)");
68 initialize<bool>("debug",false, "debug mode");
69 initialize<std::size_t>("freeze",0, "frozen core approximation");
70 initialize<int>("maxrank", 999, "maximal pno rank for all pairs");
71 initialize<std::string>("guesstype","exop", "the guesstype: exop (recommended, multiply polynomial excitation operators onto the occupied orbitals), empty (don't compute a guess), scf (use the ao basis from the SCF solver), partial_wave (create s,p,d ..., type functions and place on atoms), predefined (same as partial_wave but for predefined sets) ");
72 initialize<std::string>("exop", "multipole", "this string defines which excitation operators can be used, use 'dipole', 'dipole+', 'quadrupole', 'ocopole', or 'multipole', need to set guesstype to 'exop' which is the default ");
73 initialize<bool>("exop_trigo", true, "use trigonometric excitation operators ( x --> sin(x) ");
74 initialize<std::string>("partial_wave", "", "atom centered partial wave guess of format like 'h-2s1p-o-3s2p1d', need to set guesstype to 'partial_wave' and adaptive_solver to 'none' ");
75 initialize<std::string>("predefined", "", "predefined partial wave guesses of type pvxz with x=d,t,q,5,6, need to set guesstype to 'predefined' and adaptive_solver to 'none'");
76 initialize<int>("maxiter_t",100, "maximal number of iterations in the amplitude solver");
77 initialize<int>("maxiter_micro",10, "Maximum of iterations for every cycle in the adaptive solver");
78 initialize<int>("maxiter_macro",10, "Maximum of iterations of cycles in the adaptive solver");
79 initialize<double>("tpno", 1.e-8, "PNO cutoff threshold");
80 initialize<double>("tpno_tight",1.e-10, "PNO cutoff for the first iteration");
81 initialize<bool>("canonicalize_pno",true, "canonicalize the pnos before the amplitude solver");
82 initialize<double>("thresh", 1.e-3, "MRA threshold");
83 initialize<double>("econv_micro",1.e-3, "Energy convergence for microiterations (Greens function based optimization) in adaptive solver");
84 initialize<double>("econv_pairs",1.e-4, "ENergy convergence for individual pairs in adaptive solver. Converged pairs are frozen automatically");
85 initialize<double>("econv_macro",1.e-3, "Energy convergence for macroiterations in adaptive solver, no effect if adaptive_solver is deactivated");
86 initialize<double>("dconv",1.e-1, "convergence of every PNO in the Green's function solver");
87 initialize<double>("op_thresh",1.e-6, "MRA operator thresh");
88 initialize<std::string>("restart","none", "restart pairs of this type, use 'mp2', 'cispd', 'all' or 'none' ");
89 initialize<std::string>("no_compute","none", "do not compute the pairs of this type, use 'mp2', 'cispd', 'all' or 'none' ");
90 initialize<std::string>("no_opt","none", "do not optimize the pnos of this type, use 'mp2', 'cispd', 'all' or 'none' ");
91 initialize<std::string>("no_guess","none", "guess for this type will be empty, use 'mp2', 'cispd', 'all' or 'none' ");
92 initialize<std::string>("adaptive_solver","all", "Use adaptive solver for those pairs, use 'mp2', 'cispd', 'all' or 'none', works only in combination with guesstype 'exop' ");
93 initialize<bool>("kain", true, "use KAIN solver in amplitude solver");
94 initialize<std::size_t>("kain_subspace", 5 , "subspace size of the KAIN solver (amplitudes)");
95 initialize<bool>("f12",true, "use explicit correlation");
96 initialize<int> ("cispd_number", -1, "CIS(D) excitation numbers, to read in correct functions" );
97 initialize<double> ("cispd_energy", 0.0, "CIS energy" );
98 initialize<std::string> ("freeze_pairs", "none", "frozen pairs will not be optimized: Expected format 'a b c d' will freeze pairs ab and cd");
99 initialize<std::vector<int> >("freeze_pairs_of_orbital",std::vector<int>(), " All pairs which originate from this orbital will not be optimized");
100 initialize<std::vector<int> >("active_pairs_of_orbital",std::vector<int>(), " All pairs which originate from this orbital will not be frozen all other pairs will, if this vector is not empty");
101 initialize<bool>("no_opt_in_first_iteration", false, "Do not optimize in the first iteration (then the potentials do not have to be evaluated, use this for large guesses)");
102 initialize<std::string>("exchange", "full", "approximate exchange with 'neglect' or xc functional -> same syntax as moldft");
103 initialize<bool>("save_pnos",true, "Save the OBS-PNOs to a file, before and after orthonormalization.");
104 initialize<bool>("diagonal", false, "Compute only diagonal PNOs");
105 }
106
108
109 // auto determine freeze parameter for the first two shells
110 // deactivate by setting freeze 0 or any other value in the input file
111 size_t freeze = 0;
112 for(const Atom& atom: molecule.get_atoms()){
113 if (atom.atomic_number < 3){
114 // no frozen core for H and He
115 }else if(atom.atomic_number < 11){
116 freeze += 1;
117 }else if(atom.atomic_number < 19){
118 freeze += 5;
119 }
120 // beyond this point the parameter is better set manually
121 }
122 set_derived_value("freeze", freeze);
123
124 set_derived_value("no_guess", get<std::string >("no_compute"));
125 set_derived_value("restart", get<std::string>("no_compute"));
126 set_derived_value("tpno_tight", 0.01*tpno());
127
128 // set default values for adaptive solver
129 if(adaptive_solver()){
130 const std::string gt = "exop";
131 const std::string ex = "multipole";
132 set_derived_value("guesstype", gt);
133 set_derived_value("exop", ex);
134 set_derived_value("econv_macro", thresh());
135 set_derived_value("econv_micro", thresh());
136 set_derived_value("econv_pairs", 0.1*thresh());
137 }
138
139 }
140
141 std::vector<std::pair<int,int> > freeze_pairs()const{
142 const std::string str=get<std::string >("freeze_pairs");
143 std::vector<std::pair<int,int> > result;
144 if (str=="none"){
145 return result;
146 }
147 std::stringstream ss(str);
148 int i,j;
149 while(ss>>i){
150 ss>>j;
151 result.push_back(std::make_pair(i,j));
152 }
153 return result;
154 }
155 bool diagonal()const {return get<bool>("diagonal");}
156 bool save_pnos()const { return get<bool >("save_pnos");}
157 std::string exchange()const {return get<std::string>("exchange");}
158 bool exop_trigo()const { return get<bool >("exop_trigo");}
159 int rank_increase()const { return get<int >("rank_increase");}
160 int chunk()const { return get<int >("chunk");}
161 std::vector<std::vector<double> > protocol()const { return get<std::vector<std::vector<double> > >("protocol");}
162 bool debug()const { return get<bool >("debug");}
163 std::size_t freeze()const { return get<std::size_t >("freeze");}
164 int maxrank()const { return get<int >("maxrank");}
165 GuessType guesstype()const { return assign_from_string<GuessType>(get<std::string >("guesstype"));}
166 std::string exop()const { return get<std::string >("exop");}
167 std::map<std::string, std::vector<int> >partial_wave(const std::string& key = "partial_wave")const {
168 // return format atom-name, vector of numbers giving S, P, D, ... functions
169 std::string str=get<std::string >(key);
170 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
171 // madness parameter format does not allow blancs so we use '-' and transform them here
172 std::replace(str.begin(), str.end(), '-', ' ');
173 // expected input format: atom-name-3s2p1d atom-name-XsYpZd...
174 std::stringstream ss(str);
175 std::string symbol, pw_string;
176 std::map<std::string, std::vector<int> > result;
177 while(ss>>symbol){
178 ss>>pw_string;
179 std::vector<int> numbers(pw_string.size()/2);
180 std::vector<char> control = {'s', 'p', 'd', 'f', 'g', 'h', 'i', 'k'};
181 for (size_t i=0; i<pw_string.size()/2; ++i){
182 char l = pw_string[2*i+1];
183 char n = pw_string[2*i];
184 MADNESS_ASSERT(l==control[i]);
185 numbers[i]=(n-'0'); // need to convert ascii to int
186 }
187 result[symbol] = numbers;
188 }
189 return result;
190 }
191 std::string predefined_guess()const{ return get<std::string >("predefined");}
192 int maxiter()const { return maxiter_micro();}
193 int maxiter_t()const { return get<int >("maxiter_t");}
194 double tpno()const { return get<double >("tpno");}
195 double tpno_tight()const { return get<double >("tpno_tight");}
196 bool canonicalize_pno()const { return get<bool >("canonicalize_pno");}
197 double thresh()const { return get<double >("thresh");}
198 double dconv()const { return get<double >("dconv");}
199 double op_thresh()const { return get<double >("op_thresh");}
200 PairType restart()const {return assign_from_string<PairType>(get<std::string >("restart"));}
201 PairType no_compute()const { return assign_from_string<PairType>(get<std::string >("no_compute"));}
202 PairType no_opt()const { return assign_from_string<PairType>(get<std::string >("no_opt"));}
203 PairType no_guess()const { return assign_from_string<PairType>(get<std::string >("no_guess"));}
204 bool kain()const { return get<bool >("kain");}
205 std::size_t kain_subspace()const { return get<std::size_t >("kain_subspace");}
206 bool f12()const { return get<bool >("f12");}
207 std::vector<std::pair<int,double> > cispd()const {
208 // workaround new madness data format, can only do one excitation energy each run for now
209 const int number = get<int >("cispd_number");
210 const double energy = get<double >("cispd_energy");
211 if (number < 0){
212 return std::vector<std::pair<int,double> >();
213 }
214 else{
215 return std::vector<std::pair<int,double> >(1,std::make_pair(number, energy));
216 }
217 }
218 std::vector<int> freeze_pairs_of_orbital()const { return get<std::vector<int> >("freeze_pairs_of_orbital");}
219 std::vector<int> active_pairs_of_orbital()const { return get<std::vector<int> >("active_pairs_of_orbital");}
220 PairType adaptive_solver()const { return assign_from_string<PairType>(get<std::string >("adaptive_solver"));}
221 double econv()const { return econv_micro();}
222 double econv_pairs()const { return get<double >("econv_pairs");}
223 double econv_micro()const { return get<double >("econv_micro");}
224 double econv_macro()const { return get<double >("econv_macro");}
225 int maxiter_micro()const { return get<int >("maxiter_micro");}
226 int maxiter_macro()const { return get<int >("maxiter_macro");}
227 bool no_opt_in_first_iteration()const { return get<bool >("no_opt_in_first_iteration");}
228
229
230};
231
233public:
237
238 F12Parameters(World& world, const commandlineparser& parser, const PNOParameters& param, const std::string& TAG="pno") : PNOParameters(param){
241 }
242
243 std::string get_tag() const override {
244 return std::string("f12");
245 }
246
247
249 initialize<bool>("abs_c",true, " use auxilliary basis on f12Q[Kf12] part of energy (only if energytype is HYLLERAAS_ENERGYTYPE). If switched off the part neglected!");
250 initialize<bool>("abs_u",false, " use auxilliary basis on f12QUe part of energy (only if energytype is HYLLERAAS_ENERGYTYPE). If switched off the part is computed in full (recommended) ");
251 initialize<double>("cabs_thresh",1.e-4, " thresh for auxbasis part in f12 energy ");
252 initialize<std::string>("energytype", "projected", " the energytype is 'projected' or 'hylleraas' functional projected energies do not need auxilliary bases for the evaluation of the f12 energy. It's recommended to use projected_energies! For Hylleraas type you need to specify an auxbas from file OR internal");
253 initialize<double>("gamma",1.4, "The f12 length scale");
254 initialize<std::string>("auxbas", "none", "atom centered partial wave guess of format like 'h-2s1p-o-3s2p1d' ");
255 initialize<std::string>("auxbas_file", "none", " use external comp. aux. basis in addition to the pnos as auxbasis. Give the filename as parameter. Give the auxbas in turbomole format. Don't use contractions. If a file is specified the auxbas parameter has no effect");
256 }
257
258 bool f12()const { return get<bool >("f12");}
259 bool abs_c()const { return get<bool >("abs_c");}
260 bool abs_u()const { return get<bool >("abs_u");}
261 double cabs_thresh()const { return get<double >("cabs_thresh");}
262 std::string auxbas_file()const {
263 return get<std::string >("auxbas_file");
264 }
266 std::string key = get<std::string>("energytype");
267 std::transform(key.begin(), key.end(), key.begin(), ::tolower);
268 std::stringstream ss(key);
270 ss >> result;
272 return result;
273 }
274 double gamma()const { return get<double >("gamma");}
275 std::map<std::string,std::vector<int> > auxbas()const {
276 return partial_wave("auxbas");
277 }
278
280 if(energytype() == HYLLERAAS_ENERGYTYPE) set_derived_value("abs_c", true);
281 if(energytype() == HYLLERAAS_ENERGYTYPE) set_derived_value("abs_u", false);
282 set_derived_value("cabs_thresh", thresh());
283 }
284
285};
286
287} /* namespace madness */
288
289#endif /* PNOPARAMETERS_H_ */
Definition molecule.h:60
Definition PNOParameters.h:232
std::string get_tag() const override
Definition PNOParameters.h:243
void initialize_f12_parameters()
Definition PNOParameters.h:248
F12Parameters(World &world, const commandlineparser &parser, const PNOParameters &param, const std::string &TAG="pno")
Definition PNOParameters.h:238
bool abs_c() const
Definition PNOParameters.h:259
F12Parameters(const PNOParameters &param)
Definition PNOParameters.h:234
double cabs_thresh() const
Definition PNOParameters.h:261
void set_derived_values()
Definition PNOParameters.h:279
EnergyType energytype() const
Definition PNOParameters.h:265
double gamma() const
Definition PNOParameters.h:274
bool abs_u() const
Definition PNOParameters.h:260
std::map< std::string, std::vector< int > > auxbas() const
Definition PNOParameters.h:275
std::string auxbas_file() const
Definition PNOParameters.h:262
bool f12() const
Definition PNOParameters.h:258
Definition molecule.h:129
Definition PNOParameters.h:30
std::string exop() const
Definition PNOParameters.h:166
std::vector< std::vector< double > > protocol() const
Definition PNOParameters.h:161
bool save_pnos() const
Definition PNOParameters.h:156
std::size_t freeze() const
Definition PNOParameters.h:163
PairType no_compute() const
Definition PNOParameters.h:201
void set_derived_values(const Molecule &molecule)
Definition PNOParameters.h:107
double dconv() const
Definition PNOParameters.h:198
bool canonicalize_pno() const
Definition PNOParameters.h:196
GuessType guesstype() const
Definition PNOParameters.h:165
double tpno_tight() const
Definition PNOParameters.h:195
bool exop_trigo() const
Definition PNOParameters.h:158
int maxiter() const
Definition PNOParameters.h:192
PairType no_guess() const
Definition PNOParameters.h:203
void initialize_pno_parameters()
Definition PNOParameters.h:65
std::map< std::string, std::vector< int > > partial_wave(const std::string &key="partial_wave") const
Definition PNOParameters.h:167
double econv() const
Definition PNOParameters.h:221
PNOParameters(World &world, const commandlineparser &parser, const std::string &TAG="pno")
Definition PNOParameters.h:54
int maxiter_macro() const
Definition PNOParameters.h:226
PairType no_opt() const
Definition PNOParameters.h:202
T assign_from_string(const std::string &string) const
Definition PNOParameters.h:39
PNOParameters()
Definition PNOParameters.h:46
PNOParameters(World &world, const commandlineparser &parser, const Molecule &molecule, const std::string &TAG="pno")
Definition PNOParameters.h:59
std::vector< int > freeze_pairs_of_orbital() const
Definition PNOParameters.h:218
PNOParameters(const QCCalculationParametersBase &param)
Definition PNOParameters.h:50
std::string predefined_guess() const
Definition PNOParameters.h:191
std::vector< std::pair< int, double > > cispd() const
Definition PNOParameters.h:207
bool diagonal() const
Definition PNOParameters.h:155
std::vector< int > active_pairs_of_orbital() const
Definition PNOParameters.h:219
PairType restart() const
Definition PNOParameters.h:200
bool f12() const
Definition PNOParameters.h:206
double op_thresh() const
Definition PNOParameters.h:199
double tpno() const
Definition PNOParameters.h:194
int chunk() const
Definition PNOParameters.h:160
int maxiter_micro() const
Definition PNOParameters.h:225
bool kain() const
Definition PNOParameters.h:204
double econv_micro() const
Definition PNOParameters.h:223
int rank_increase() const
Definition PNOParameters.h:159
int maxrank() const
Definition PNOParameters.h:164
double thresh() const
Definition PNOParameters.h:197
std::vector< std::pair< int, int > > freeze_pairs() const
Definition PNOParameters.h:141
bool debug() const
Definition PNOParameters.h:162
PairType adaptive_solver() const
Definition PNOParameters.h:220
double econv_macro() const
Definition PNOParameters.h:224
bool no_opt_in_first_iteration() const
Definition PNOParameters.h:227
std::size_t kain_subspace() const
Definition PNOParameters.h:205
std::string exchange() const
Definition PNOParameters.h:157
double econv_pairs() const
Definition PNOParameters.h:222
int maxiter_t() const
Definition PNOParameters.h:193
std::string get_tag() const override
Definition PNOParameters.h:34
class for holding the parameters for calculation
Definition QCCalculationParametersBase.h:294
virtual void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition QCCalculationParametersBase.h:330
void set_derived_value(const std::string &key, const T &value)
Definition QCCalculationParametersBase.h:408
A parallel world class.
Definition world.h:132
double(* energy)()
Definition derivatives.cc:58
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
EnergyType
Definition PNOParameters.h:21
@ HYLLERAAS_ENERGYTYPE
Definition PNOParameters.h:21
@ UNKNOWN_ENERGYTYPE
Definition PNOParameters.h:21
@ PROJECTED_ENERGYTYPE
Definition PNOParameters.h:21
GuessType
Definition PNOParameters.h:25
@ PSI4_GUESSTYPE
Definition PNOParameters.h:25
@ EXOP_GUESSTYPE
Definition PNOParameters.h:25
@ SCF_GUESSTYPE
Definition PNOParameters.h:25
@ FROM_FILE_GUESSTYPE
Definition PNOParameters.h:25
@ PREDEFINED_GUESSTYPE
Definition PNOParameters.h:25
@ UNKNOWN_GUESSTYPE
Definition PNOParameters.h:25
@ EMPTY_GUESSTYPE
Definition PNOParameters.h:25
@ PARTIAL_WAVE_GUESSTYPE
Definition PNOParameters.h:25
std::istream & operator>>(std::istream &is, PairType &en)
Definition PNOParameters.cpp:24
std::string type(const PairType &n)
Definition PNOParameters.h:18
PairType
Definition PNOParameters.h:17
@ UNKNOWN_PAIRTYPE
Definition PNOParameters.h:17
@ CISPD_PAIRTYPE
Definition PNOParameters.h:17
@ MP2_PAIRTYPE
Definition PNOParameters.h:17
@ ALL_PAIRTYPE
Definition PNOParameters.h:17
@ NONE_PAIRTYPE
Definition PNOParameters.h:17
very simple command line parser
Definition commandlineparser.h:15
InputParameters param
Definition tdse.cc:203
double gt(const coord_t &r)
Definition testgconv.cc:142
static Molecule molecule
Definition testperiodicdft.cc:39