MADNESS 0.10.1
DFParameters.h
Go to the documentation of this file.
1
2/// \file DFParameters
3/// \brief Input parameters for a Dirac Fock calculation.
4
5#ifndef MADNESS_APPS_DFPARAMS_H_INCLUDED
6#define MADNESS_APPS_DFPARAMS_H_INCLUDED
7
8#include "DFConvergence.h"
10#include <filesystem>
11#include <cctype>
12#include <string>
13
14namespace madness {
15
16 /// Clean archive name by stripping 5-digit rank suffix (.00000) if present,
17 /// and appending .restartdata if only the base prefix was specified.
18 inline std::string clean_archive_filename(std::string name) {
19 if (name.empty()) return name;
20 // Trim whitespace
21 const auto first = name.find_first_not_of(" \t\n\r");
22 if (first == std::string::npos) return "";
23 const auto last = name.find_last_not_of(" \t\n\r");
24 name = name.substr(first, (last - first + 1));
25
26 // Strip 5-digit chunk suffix (.00000, etc.) if provided
27 if (name.size() > 6 && name[name.size() - 6] == '.') {
28 bool all_digits = true;
29 for (size_t i = name.size() - 5; i < name.size(); ++i) {
30 if (!std::isdigit(static_cast<unsigned char>(name[i]))) {
31 all_digits = false;
32 break;
33 }
34 }
35 if (all_digits) {
36 name.erase(name.size() - 6);
37 }
38 }
39 // If name.00000 doesn't exist, but name.restartdata.00000 exists, append .restartdata
40 if (!std::filesystem::exists(name + ".00000") && std::filesystem::exists(name + ".restartdata.00000")) {
41 name += ".restartdata";
42 }
43 return name;
44 }
45
47 // List of input parameters
48 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
49 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50 // If you add something here, don't forget to add it to serializable!
51 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
52 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 std::string archive; ///< Name of input archive to read in ground state
54 int job; ///< Indicates the type of job to do
55 ///< Values | Job
56 ///< --------------------------------------------------------------
57 ///< 0 | Dirac Fock on occupied orbitals only (Default)
58 ///< --------------------------------------------------------------
59 ///< Add more values here
60 ///<
61 int max_iter; ///< Maximum number of iterations
62 double small; ///< Minimum length scale to be resolved
63 double thresh; ///< Accuracy criterion when truncating
64 double dconv; ///< Accuracy criterion for charge density. Defaults to thresh.
65 double thresh_mul; ///< Accuracy criterion for sparse multiplication. Defaults to thresh.
66 int k; ///< Number of legendre polynomials in scaling basis
67 bool kain; ///< Turns on KAIN nonlinear solver
68 int maxsub; ///< Sets maximum subspace size for KAIN
69 double maxrotn; ///< maximum step allowed by kain
70 bool restart; ///< Indicates this is a restarted DF job
71 int nucleus; ///< Indicates which nucleus model to use (1 for fermi, anything else for Gaussian)
72 bool do_save; ///< Whether or not to save after each iteration. Defaults to true. Turn off with 'no_save'
73 std::string savefile; ///< Gives the file to save the archive each iteration Default: DFrestartdata (in working directory)
74 int lb_iter; ///< How many iterations to load balance (after the initial load balancing)
75 bool nwchem; ///< Indicates archive given is actually an nwchem file for starting the job
76 bool lineplot; ///< Whether or not to make lineplots at the end of the job
77 bool no_compute; ///< If true, will skip all computation
78 double bohr_rad; ///< bohr radius in fm (default: 52917.7210544 CODATA2022)
79 double speed_of_light; ///< speed_of_light in au (default: 137.03599917697017 CODATA2022)
80 int min_iter; ///< minimum number of iterations (default: 2)
81 bool Krestricted; ///< Calculation should be performed in Kramers-restricted manner (default: false)
82 DFConvergenceCriterion convergence_criteria; ///< Which quantities must converge before the loop stops
83 ///< Value | Criterion
84 ///< --------------------------------------------------------------
85 ///< bsh_residual | max BSH residual <= thresh (Default)
86 ///< --------------------------------------------------------------
87 ///< energy_density_residual | relative total energy change <= thresh,
88 ///< | density change <= dconv * nelec, and
89 ///< | max BSH residual <= 100 * thresh
90 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
91 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
92 // If you add something here, don't forget to add it to serializable!
93 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
95
96 template<typename Archive>
97 void serialize(Archive& ar){
98 int convergence_criteria_value = static_cast<int>(convergence_criteria);
100 if constexpr (Archive::is_input_archive) {
101 convergence_criteria = static_cast<DFConvergenceCriterion>(convergence_criteria_value);
102 }
103 }
104
105 // Default constructor
107 : job(0)
108 , max_iter(20)
109 , small(1e-5)
110 , thresh(1e-6)
111 , dconv(1e-6)
112 , thresh_mul(1e-6)
113 , k(8)
114 , kain(false)
115 , maxsub(10)
116 , maxrotn(0.25)
117 , restart(false)
118 , nucleus(0)
119 , do_save(true)
120 , savefile("DFrestartdata")
121 , lb_iter(20)
122 , nwchem(false)
123 , lineplot(false)
124 , no_compute(false)
125 , bohr_rad(52917.7210544) // bohr radius in fm from CODATA 2022
126 , speed_of_light(137.03599917697017) // speed of light in atomic units from CODATA 2022
127 , min_iter(2)
128 , Krestricted(false)
130 {}
131
132 // Initializes DFParameters using the contents of file \c filename
133 void read_file(const std::string& filename){
134 std::ifstream f(filename.c_str());
135 read(f);
136 }
137
138 // Initializes DFParameters using the contents of stream \c f
139 void read(std::istream& f){
140 position_stream(f, "DiracFock");
141 std::string s;
142
143 // dconv and thresh_mul default to the final value of thresh. An
144 // explicit value must survive in any keyword order.
145 bool dconv_was_set = false;
146 bool thresh_mul_was_set = false;
147
148 while(f >> s){
149 if(s == "end"){
150 break;
151 }
152 else if (s[0] == '#'){
153 std::string dummy;
154 std::getline(f, dummy);
155 continue;
156 }
157 else if (s == "archive"){
158 f >> archive;
160 }
161 else if (s == "job"){
162 f >> job;
163 }
164 else if (s == "max_iter"){
165 f >> max_iter;
166 }
167 else if (s == "small"){
168 f >> small;
169 }
170 else if (s == "thresh"){
171 f >> thresh;
172 }
173 else if (s == "dconv"){
174 f >> dconv;
175 dconv_was_set = true;
176 }
177 else if (s == "thresh_mul"){
178 f >> thresh_mul;
179 thresh_mul_was_set = true;
180 }
181 else if (s == "k"){
182 f >> k;
183 }
184 else if (s == "kain"){
185 kain = true;
186 }
187 else if (s == "maxsub"){
188 f >> maxsub;
189 }
190 else if (s == "maxrotn"){
191 f >> maxrotn;
192 }
193 else if (s == "restart"){
194 restart = true;
195 }
196 else if (s == "nucleus"){
197 f >> nucleus;
198 }
199 else if (s == "no_save"){
200 do_save = false;
201 }
202 else if (s == "savefile"){
203 f >> savefile;
205 }
206 else if (s == "lb_iter"){
207 f >> lb_iter;
208 }
209 else if (s == "nwchem"){
210 nwchem = true;
211 }
212 else if (s == "lineplot"){
213 lineplot = true;
214 }
215 else if (s == "no_compute"){
216 no_compute = true;
217 }
218 else if (s == "bohr_rad"){
219 f >> bohr_rad;
220 }
221 else if (s == "speed_of_light"){
222 f >> speed_of_light;
223 }
224 else if (s == "min_iter"){
225 f >> min_iter;
226 }
227 else if (s == "Krestricted"){
228 Krestricted = true;
229 }
230 else if (s == "convergence_criteria"){
231 std::string keyword;
232 f >> keyword;
234 std::cout << "Dirac Fock: unrecognized convergence_criteria " << keyword
235 << " (allowed: bsh_residual, energy_density_residual)" << std::endl;
236 MADNESS_EXCEPTION("input error", 0);
237 }
238 }
239 else{
240 std::cout << "Dirac Fock: unrecognized input keyword " << s << std::endl;
241 MADNESS_EXCEPTION("input error", 0);
242 }
243 }
244
245 if (not dconv_was_set) dconv = thresh;
246 if (not thresh_mul_was_set) thresh_mul = thresh;
247 } // end read()
248
249 // Prints all information
250 void print_params() const{
251 madness::print("\n Input Dirac Fock Parameters");
252 madness::print(" -------------------------");
253 madness::print(" Initial Guess File:", archive);
254 madness::print(" Job:", job);
255 madness::print(" Refinement Threshold:", thresh);
256 madness::print(" Multiplication Threshold:", thresh_mul);
257 madness::print(" k:", k);
258 madness::print("Smallest Resolved Length Scale:", small);
259 madness::print(" Bohr radius in fm:", bohr_rad);
260 madness::print(" Speed of light in au:", speed_of_light);
261 madness::print(" Max Iterations:", max_iter);
262 madness::print(" Use KAIN Solver:", kain);
263 if(kain) madness::print(" KAIN Solver Subspace Size:", maxsub);
264 madness::print(" Save:", do_save);
265 madness::print(" save file:", savefile);
266 if(nucleus == 1){
267 madness::print(" Nucleus: fermi");
268 }
269 else if (nucleus == 2) {
270 madness::print(" Nucleus: point");
271 }
272 else{
273 madness::print(" Nucleus: gaussian");
274 }
275 madness::print(" Kramers restriction:", Krestricted);
277 madness::print(" Do Lineplots:", lineplot);
278 }
279 };
280
281}
282#endif
283
284//kthxbye
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
static const char * filename
Definition legendre.cc:96
std::istream & position_stream(std::istream &f, const std::string &tag, bool rewind=true)
Definition position_stream.cc:48
const char * df_convergence_criterion_name(const DFConvergenceCriterion criterion)
Definition DFConvergence.h:30
std::string clean_archive_filename(std::string name)
Definition DFParameters.h:18
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:227
NDIM & f
Definition mra.h:2668
DFConvergenceCriterion
Definition DFConvergence.h:11
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
bool df_convergence_criterion_from_string(const std::string &keyword, DFConvergenceCriterion &criterion)
Definition DFConvergence.h:17
Definition DFParameters.h:46
double thresh_mul
Accuracy criterion for sparse multiplication. Defaults to thresh.
Definition DFParameters.h:65
bool no_compute
If true, will skip all computation.
Definition DFParameters.h:77
int k
Number of legendre polynomials in scaling basis.
Definition DFParameters.h:66
void read(std::istream &f)
Definition DFParameters.h:139
double maxrotn
maximum step allowed by kain
Definition DFParameters.h:69
double small
Minimum length scale to be resolved.
Definition DFParameters.h:62
bool kain
Turns on KAIN nonlinear solver.
Definition DFParameters.h:67
bool restart
Indicates this is a restarted DF job.
Definition DFParameters.h:70
int lb_iter
How many iterations to load balance (after the initial load balancing)
Definition DFParameters.h:74
int min_iter
minimum number of iterations (default: 2)
Definition DFParameters.h:80
double dconv
Accuracy criterion for charge density. Defaults to thresh.
Definition DFParameters.h:64
std::string archive
Name of input archive to read in ground state.
Definition DFParameters.h:53
int max_iter
Maximum number of iterations.
Definition DFParameters.h:61
double speed_of_light
speed_of_light in au (default: 137.03599917697017 CODATA2022)
Definition DFParameters.h:79
bool lineplot
Whether or not to make lineplots at the end of the job.
Definition DFParameters.h:76
bool Krestricted
Calculation should be performed in Kramers-restricted manner (default: false)
Definition DFParameters.h:81
void serialize(Archive &ar)
Definition DFParameters.h:97
double thresh
Accuracy criterion when truncating.
Definition DFParameters.h:63
DFConvergenceCriterion convergence_criteria
Definition DFParameters.h:82
void print_params() const
Definition DFParameters.h:250
std::string savefile
Gives the file to save the archive each iteration Default: DFrestartdata (in working directory)
Definition DFParameters.h:73
double bohr_rad
bohr radius in fm (default: 52917.7210544 CODATA2022)
Definition DFParameters.h:78
int job
Definition DFParameters.h:54
void read_file(const std::string &filename)
Definition DFParameters.h:133
bool nwchem
Indicates archive given is actually an nwchem file for starting the job.
Definition DFParameters.h:75
int nucleus
Indicates which nucleus model to use (1 for fermi, anything else for Gaussian)
Definition DFParameters.h:71
DFParameters()
Definition DFParameters.h:106
bool do_save
Whether or not to save after each iteration. Defaults to true. Turn off with 'no_save'.
Definition DFParameters.h:72
int maxsub
Sets maximum subspace size for KAIN.
Definition DFParameters.h:68
void e()
Definition test_sig.cc:75