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