source: molecuilder/src/config.cpp@ f5306f

Last change on this file since f5306f was f5306f, checked in by Frederik Heber <heber@…>, 18 years ago

config::Load..() now get filename instead of pointer to file, bugfix for switch structure in command line parsin
g.

Load..() functions RetrieveConfigPath() - the path that is given for the config file on the command line - and p
ut it into config::configpath. This is necessary to allow later for a sensible storage path under fragmentation, as the old with defaultpath from the file was stupid, if the given path was wrong (whereas the config path always exists).
Switch structure in parsing the command line options needed to make better use of the already present flag in or
der to know when to just save and stop and when to continue to the interactive menu.

  • Property mode set to 100644
File size: 57.0 KB
Line 
1/** \file config.cpp
2 *
3 * Function implementations for the class config.
4 *
5 */
6
7#include "molecules.hpp"
8
9/************************************* Functions for class config ***************************/
10
11/** Constructor for config file class.
12 */
13config::config()
14{
15 mainname = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
16 defaultpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
17 pseudopotpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
18 configpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
19 strcpy(mainname,"pcp");
20 strcpy(defaultpath,"not specified");
21 strcpy(pseudopotpath,"not specified");
22
23 ProcPEGamma=8;
24 ProcPEPsi=1;
25 DoOutVis=0;
26 DoOutMes=1;
27 DoOutNICS=0;
28 DoOutOrbitals=0;
29 DoOutCurrent=0;
30 DoPerturbation=0;
31 DoFullCurrent=0;
32 CommonWannier=0;
33 SawtoothStart=0.01;
34 VectorPlane=0;
35 VectorCut=0;
36 UseAddGramSch=1;
37 Seed=1;
38
39 MaxOuterStep=0;
40 Deltat=0;
41 OutVisStep=10;
42 OutSrcStep=5;
43 TargetTemp=0.00095004455;
44 ScaleTempStep=25;
45 MaxPsiStep=0;
46 EpsWannier=1e-7;
47
48 MaxMinStep=100;
49 RelEpsTotalEnergy=1e-7;
50 RelEpsKineticEnergy=1e-5;
51 MaxMinStopStep=1;
52 MaxMinGapStopStep=0;
53 MaxInitMinStep=100;
54 InitRelEpsTotalEnergy=1e-5;
55 InitRelEpsKineticEnergy=1e-4;
56 InitMaxMinStopStep=1;
57 InitMaxMinGapStopStep=0;
58
59 //BoxLength[NDIM*NDIM];
60
61 ECut=128.;
62 MaxLevel=5;
63 RiemannTensor=0;
64 LevRFactor=0;
65 RiemannLevel=0;
66 Lev0Factor=2;
67 RTActualUse=0;
68 PsiType=0;
69 MaxPsiDouble=0;
70 PsiMaxNoUp=0;
71 PsiMaxNoDown=0;
72 AddPsis=0;
73
74 RCut=20.;
75 StructOpt=0;
76 IsAngstroem=1;
77 RelativeCoord=0;
78 MaxTypes=0;
79};
80
81
82/** Destructor for config file class.
83 */
84config::~config()
85{
86 Free((void **)&mainname, "config::~config: *mainname");
87 Free((void **)&defaultpath, "config::~config: *defaultpath");
88 Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
89 Free((void **)&configpath, "config::~config: *configpath");
90};
91
92/** Displays menu for editing each entry of the config file.
93 * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case
94 * for each entry of the config file structure.
95 */
96void config::Edit(molecule *mol)
97{
98 char choice;
99
100 do {
101 cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
102 cout << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl;
103 cout << Verbose(0) << " B - Default path (for runtime files)" << endl;
104 cout << Verbose(0) << " C - Path of pseudopotential files" << endl;
105 cout << Verbose(0) << " D - Number of coefficient sharing processes" << endl;
106 cout << Verbose(0) << " E - Number of wave function sharing processes" << endl;
107 cout << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl;
108 cout << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl;
109 cout << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl;
110 cout << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl;
111 cout << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl;
112 cout << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl;
113 cout << Verbose(0) << " L - 0: Wannier centres as calculated, 1: common centre for all, 2: unite centres according to spread, 3: cell centre, 4: shifted to nearest grid point" << endl;
114 cout << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl;
115 cout << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl;
116 cout << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl;
117 cout << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl;
118 cout << Verbose(0) << " Q - Initial integer value of random number generator" << endl;
119 cout << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl;
120 cout << Verbose(0) << " T - Output visual after ...th step" << endl;
121 cout << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl;
122 cout << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl;
123 cout << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl;
124 cout << Verbose(0) << " Z - Maximum number of minimization iterations" << endl;
125 cout << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl;
126 cout << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl;
127 cout << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl;
128 cout << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl;
129 cout << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl;
130 cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
131 cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
132 cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
133 cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
134 cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
135 cout << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl;
136 cout << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl;
137 cout << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl;
138 cout << Verbose(0) << " p - Number of Riemann levels" << endl;
139 cout << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl;
140 cout << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl;
141 cout << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl;
142 cout << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl;
143 cout << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl;
144 cout << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl;
145 cout << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl;
146 cout << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl;
147 cout << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl;
148 cout << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl;
149 cout << Verbose(0) << "=========================================================" << endl;
150 cout << Verbose(0) << "INPUT: ";
151 cin >> choice;
152
153 switch (choice) {
154 case 'A': // mainname
155 cout << Verbose(0) << "Old: " << config::mainname << "\t new: ";
156 cin >> config::mainname;
157 break;
158 case 'B': // defaultpath
159 cout << Verbose(0) << "Old: " << config::defaultpath << "\t new: ";
160 cin >> config::defaultpath;
161 break;
162 case 'C': // pseudopotpath
163 cout << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ";
164 cin >> config::pseudopotpath;
165 break;
166
167 case 'D': // ProcPEGamma
168 cout << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ";
169 cin >> config::ProcPEGamma;
170 break;
171 case 'E': // ProcPEPsi
172 cout << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ";
173 cin >> config::ProcPEPsi;
174 break;
175 case 'F': // DoOutVis
176 cout << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ";
177 cin >> config::DoOutVis;
178 break;
179 case 'G': // DoOutMes
180 cout << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ";
181 cin >> config::DoOutMes;
182 break;
183 case 'H': // DoOutOrbitals
184 cout << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ";
185 cin >> config::DoOutOrbitals;
186 break;
187 case 'I': // DoOutCurrent
188 cout << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ";
189 cin >> config::DoOutCurrent;
190 break;
191 case 'J': // DoFullCurrent
192 cout << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ";
193 cin >> config::DoFullCurrent;
194 break;
195 case 'K': // DoPerturbation
196 cout << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ";
197 cin >> config::DoPerturbation;
198 break;
199 case 'L': // CommonWannier
200 cout << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ";
201 cin >> config::CommonWannier;
202 break;
203 case 'M': // SawtoothStart
204 cout << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ";
205 cin >> config::SawtoothStart;
206 break;
207 case 'N': // VectorPlane
208 cout << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ";
209 cin >> config::VectorPlane;
210 break;
211 case 'O': // VectorCut
212 cout << Verbose(0) << "Old: " << config::VectorCut << "\t new: ";
213 cin >> config::VectorCut;
214 break;
215 case 'P': // UseAddGramSch
216 cout << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ";
217 cin >> config::UseAddGramSch;
218 break;
219 case 'Q': // Seed
220 cout << Verbose(0) << "Old: " << config::Seed << "\t new: ";
221 cin >> config::Seed;
222 break;
223
224 case 'R': // MaxOuterStep
225 cout << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ";
226 cin >> config::MaxOuterStep;
227 break;
228 case 'T': // OutVisStep
229 cout << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ";
230 cin >> config::OutVisStep;
231 break;
232 case 'U': // OutSrcStep
233 cout << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ";
234 cin >> config::OutSrcStep;
235 break;
236 case 'X': // MaxPsiStep
237 cout << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ";
238 cin >> config::MaxPsiStep;
239 break;
240 case 'Y': // EpsWannier
241 cout << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ";
242 cin >> config::EpsWannier;
243 break;
244
245 case 'Z': // MaxMinStep
246 cout << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ";
247 cin >> config::MaxMinStep;
248 break;
249 case 'a': // RelEpsTotalEnergy
250 cout << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ";
251 cin >> config::RelEpsTotalEnergy;
252 break;
253 case 'b': // RelEpsKineticEnergy
254 cout << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ";
255 cin >> config::RelEpsKineticEnergy;
256 break;
257 case 'c': // MaxMinStopStep
258 cout << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ";
259 cin >> config::MaxMinStopStep;
260 break;
261 case 'e': // MaxInitMinStep
262 cout << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ";
263 cin >> config::MaxInitMinStep;
264 break;
265 case 'f': // InitRelEpsTotalEnergy
266 cout << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ";
267 cin >> config::InitRelEpsTotalEnergy;
268 break;
269 case 'g': // InitRelEpsKineticEnergy
270 cout << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ";
271 cin >> config::InitRelEpsKineticEnergy;
272 break;
273 case 'h': // InitMaxMinStopStep
274 cout << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ";
275 cin >> config::InitMaxMinStopStep;
276 break;
277
278 case 'j': // BoxLength
279 cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
280 for (int i=0;i<6;i++) {
281 cout << Verbose(0) << "Cell size" << i << ": ";
282 cin >> mol->cell_size[i];
283 }
284 break;
285
286 case 'k': // ECut
287 cout << Verbose(0) << "Old: " << config::ECut << "\t new: ";
288 cin >> config::ECut;
289 break;
290 case 'l': // MaxLevel
291 cout << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ";
292 cin >> config::MaxLevel;
293 break;
294 case 'm': // RiemannTensor
295 cout << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ";
296 cin >> config::RiemannTensor;
297 break;
298 case 'n': // LevRFactor
299 cout << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ";
300 cin >> config::LevRFactor;
301 break;
302 case 'o': // RiemannLevel
303 cout << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ";
304 cin >> config::RiemannLevel;
305 break;
306 case 'p': // Lev0Factor
307 cout << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ";
308 cin >> config::Lev0Factor;
309 break;
310 case 'r': // RTActualUse
311 cout << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ";
312 cin >> config::RTActualUse;
313 break;
314 case 's': // PsiType
315 cout << Verbose(0) << "Old: " << config::PsiType << "\t new: ";
316 cin >> config::PsiType;
317 break;
318 case 't': // MaxPsiDouble
319 cout << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ";
320 cin >> config::MaxPsiDouble;
321 break;
322 case 'u': // PsiMaxNoUp
323 cout << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ";
324 cin >> config::PsiMaxNoUp;
325 break;
326 case 'v': // PsiMaxNoDown
327 cout << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ";
328 cin >> config::PsiMaxNoDown;
329 break;
330 case 'w': // AddPsis
331 cout << Verbose(0) << "Old: " << config::AddPsis << "\t new: ";
332 cin >> config::AddPsis;
333 break;
334
335 case 'x': // RCut
336 cout << Verbose(0) << "Old: " << config::RCut << "\t new: ";
337 cin >> config::RCut;
338 break;
339 case 'y': // StructOpt
340 cout << Verbose(0) << "Old: " << config::StructOpt << "\t new: ";
341 cin >> config::StructOpt;
342 break;
343 case 'z': // IsAngstroem
344 cout << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ";
345 cin >> config::IsAngstroem;
346 break;
347 case 'i': // RelativeCoord
348 cout << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ";
349 cin >> config::RelativeCoord;
350 break;
351 };
352 } while (choice != 'q');
353};
354
355/** Tests whether a given configuration file adhears to old or new syntax.
356 * \param *filename filename of config file to be tested
357 * \param *periode pointer to a periodentafel class with all elements
358 * \param *mol pointer to molecule containing all atoms of the molecule
359 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
360 */
361int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
362{
363 int test;
364 ifstream file(filename);
365
366 // search file for keyword: ProcPEGamma (new syntax)
367 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
368 file.close();
369 return 1;
370 }
371 // search file for keyword: ProcsGammaPsi (old syntax)
372 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
373 file.close();
374 return 0;
375 }
376 file.close();
377 return -1;
378}
379
380/** Returns private config::IsAngstroem.
381 * \return IsAngstroem
382 */
383bool config::GetIsAngstroem() const
384{
385 return (IsAngstroem == 1);
386};
387
388/** Returns private config::*defaultpath.
389 * \return *defaultpath
390 */
391char * config::GetDefaultPath() const
392{
393 return defaultpath;
394};
395
396
397/** Returns private config::*defaultpath.
398 * \return *defaultpath
399 */
400void config::SetDefaultPath(const char *path)
401{
402 strcpy(defaultpath, path);
403};
404
405/** Retrieves the path in the given config file name.
406 * \param *filename config file string
407 */
408void config::RetrieveConfigPath(char *filename)
409{
410 int last = -1;
411 for(int i=0;i<255;i++) {
412 if (filename[i] == '/')
413 last = i;
414 if (filename[i] == '\0')
415 break;
416 }
417 if (last == -1) { // no path in front, set to local directory.
418 strcpy(configpath, "./");
419 } else {
420 strncpy(configpath, filename, last+1);
421 if (last < 254)
422 configpath[last+1]='\0';
423 }
424 cout << "Found configpath: " << configpath << ", dir slash was found at " << last << "." << endl;
425};
426
427
428/** Initializes config file structure by loading elements from a give file.
429 * \param *file input file stream being the opened config file
430 * \param *periode pointer to a periodentafel class with all elements
431 * \param *mol pointer to molecule containing all atoms of the molecule
432 */
433void config::Load(char *filename, periodentafel *periode, molecule *mol)
434{
435 ifstream *file = new ifstream(filename);
436 if (file == NULL) {
437 cerr << "ERROR: config file " << filename << " missing!" << endl;
438 return;
439 }
440 RetrieveConfigPath(filename);
441 // ParseParameters
442
443 /* Oeffne Hauptparameterdatei */
444 int di;
445 double BoxLength[9];
446 string zeile;
447 string dummy;
448 element *elementhash[128];
449 char name[128];
450 char keyword[128];
451 int Z, No;
452 int verbose = 0;
453
454 /* Namen einlesen */
455
456 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
457 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
458 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
459 ParseForParameter(verbose,file,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
460 ParseForParameter(verbose,file,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
461
462 if (!ParseForParameter(verbose,file,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
463 config::Seed = 1;
464
465 if(!ParseForParameter(verbose,file,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
466 config::DoOutOrbitals = 0;
467 } else {
468 if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
469 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
470 }
471 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
472 if (config::DoOutVis < 0) config::DoOutVis = 0;
473 if (config::DoOutVis > 1) config::DoOutVis = 1;
474 if (!ParseForParameter(verbose,file,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
475 config::VectorPlane = -1;
476 if (!ParseForParameter(verbose,file,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
477 config::VectorCut = 0.;
478 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
479 if (config::DoOutMes < 0) config::DoOutMes = 0;
480 if (config::DoOutMes > 1) config::DoOutMes = 1;
481 if (!ParseForParameter(verbose,file,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
482 config::DoOutCurrent = 0;
483 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
484 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
485 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
486 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
487 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
488 if(!ParseForParameter(verbose,file,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
489 config::CommonWannier = 0;
490 } else {
491 if (config::CommonWannier < 0) config::CommonWannier = 0;
492 if (config::CommonWannier > 4) config::CommonWannier = 4;
493 }
494 if(!ParseForParameter(verbose,file,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
495 config::SawtoothStart = 0.01;
496 } else {
497 if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
498 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
499 }
500
501 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
502 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
503 ParseForParameter(verbose,file,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
504 ParseForParameter(verbose,file,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
505 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
506 //ParseForParameter(verbose,file,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
507 if (!ParseForParameter(verbose,file,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
508 config::EpsWannier = 1e-8;
509
510 // stop conditions
511 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
512 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
513 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
514
515 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
516 ParseForParameter(verbose,file,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
517 ParseForParameter(verbose,file,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
518 ParseForParameter(verbose,file,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
519 ParseForParameter(verbose,file,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
520 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
521 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
522 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
523
524 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
525 ParseForParameter(verbose,file,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
526 ParseForParameter(verbose,file,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
527 ParseForParameter(verbose,file,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
528 ParseForParameter(verbose,file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
529 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
530 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
531 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
532
533 // Unit cell and magnetic field
534 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
535 mol->cell_size[0] = BoxLength[0];
536 mol->cell_size[1] = BoxLength[3];
537 mol->cell_size[2] = BoxLength[4];
538 mol->cell_size[3] = BoxLength[6];
539 mol->cell_size[4] = BoxLength[7];
540 mol->cell_size[5] = BoxLength[8];
541 if (1) fprintf(stderr,"\n");
542
543 ParseForParameter(verbose,file,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
544 ParseForParameter(verbose,file,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
545 if (!ParseForParameter(verbose,file,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
546 config::DoFullCurrent = 0;
547 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
548 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
549 if (config::DoOutNICS < 0) config::DoOutNICS = 0;
550 if (config::DoOutNICS > 2) config::DoOutNICS = 2;
551 if (config::DoPerturbation == 0) {
552 config::DoFullCurrent = 0;
553 config::DoOutNICS = 0;
554 }
555
556 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
557 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
558 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
559 if (config::Lev0Factor < 2) {
560 config::Lev0Factor = 2;
561 }
562 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
563 if (di >= 0 && di < 2) {
564 config::RiemannTensor = di;
565 } else {
566 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
567 exit(1);
568 }
569 switch (config::RiemannTensor) {
570 case 0: //UseNoRT
571 if (config::MaxLevel < 2) {
572 config::MaxLevel = 2;
573 }
574 config::LevRFactor = 2;
575 config::RTActualUse = 0;
576 break;
577 case 1: // UseRT
578 if (config::MaxLevel < 3) {
579 config::MaxLevel = 3;
580 }
581 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
582 if (config::RiemannLevel < 2) {
583 config::RiemannLevel = 2;
584 }
585 if (config::RiemannLevel > config::MaxLevel-1) {
586 config::RiemannLevel = config::MaxLevel-1;
587 }
588 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
589 if (config::LevRFactor < 2) {
590 config::LevRFactor = 2;
591 }
592 config::Lev0Factor = 2;
593 config::RTActualUse = 2;
594 break;
595 }
596 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
597 if (di >= 0 && di < 2) {
598 config::PsiType = di;
599 } else {
600 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
601 exit(1);
602 }
603 switch (config::PsiType) {
604 case 0: // SpinDouble
605 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
606 ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
607 break;
608 case 1: // SpinUpDown
609 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
610 ParseForParameter(verbose,file,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
611 ParseForParameter(verbose,file,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
612 ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
613 break;
614 }
615
616 // IonsInitRead
617
618 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
619 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
620 ParseForParameter(verbose,file,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
621 if (!ParseForParameter(verbose,file,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
622 config::RelativeCoord = 0;
623 if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
624 config::StructOpt = 0;
625 for (int i=0; i < config::MaxTypes; i++) {
626 sprintf(name,"Ion_Type%i",i+1);
627 ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No, 1, critical);
628 ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
629 elementhash[i] = periode->FindElement(Z);
630 for(int j=0;j<No;j++) {
631 int repetition = 1; // which repeated keyword shall be read
632 sprintf(keyword,"%s_%i",name, j+1);
633 atom *neues = new atom();
634 // then parse for each atom the coordinates as often as present
635 while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) &&
636 ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) &&
637 ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional))
638 repetition++;
639 repetition--;
640 cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl;
641 ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
642 ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
643 ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
644 ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
645 if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
646 neues->v.x[0] = 0.;
647 if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
648 neues->v.x[1] = 0.;
649 if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
650 neues->v.x[2] = 0.;
651 neues->type = elementhash[i]; // find element type
652 mol->AddAtom(neues);
653 }
654 }
655 file->close();
656 delete(file);
657};
658
659/** Initializes config file structure by loading elements from a give file with old pcp syntax.
660 * \param *file input file stream being the opened config file with old pcp syntax
661 * \param *periode pointer to a periodentafel class with all elements
662 * \param *mol pointer to molecule containing all atoms of the molecule
663 */
664void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
665{
666 ifstream *file = new ifstream(filename);
667 if (file == NULL) {
668 cerr << "ERROR: config file " << filename << " missing!" << endl;
669 return;
670 }
671 RetrieveConfigPath(filename);
672 // ParseParameters
673
674 /* Oeffne Hauptparameterdatei */
675 int l, i, di;
676 double a,b;
677 double BoxLength[9];
678 string zeile;
679 string dummy;
680 element *elementhash[128];
681 int Z, No, AtomNo, found;
682 int verbose = 0;
683
684 /* Namen einlesen */
685
686 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
687 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
688 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
689 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
690 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
691 config::Seed = 1;
692 config::DoOutOrbitals = 0;
693 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
694 if (config::DoOutVis < 0) config::DoOutVis = 0;
695 if (config::DoOutVis > 1) config::DoOutVis = 1;
696 config::VectorPlane = -1;
697 config::VectorCut = 0.;
698 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
699 if (config::DoOutMes < 0) config::DoOutMes = 0;
700 if (config::DoOutMes > 1) config::DoOutMes = 1;
701 config::DoOutCurrent = 0;
702 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
703 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
704 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
705 config::CommonWannier = 0;
706 config::SawtoothStart = 0.01;
707
708 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
709 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
710 ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
711 ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
712 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
713 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
714 config::EpsWannier = 1e-8;
715
716 // stop conditions
717 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
718 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
719 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
720
721 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
722 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
723 ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
724 ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
725 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
726 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
727 config::MaxMinGapStopStep = 1;
728
729 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
730 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
731 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
732 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
733 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
734 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
735 config::InitMaxMinGapStopStep = 1;
736
737 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
738 mol->cell_size[0] = BoxLength[0];
739 mol->cell_size[1] = BoxLength[3];
740 mol->cell_size[2] = BoxLength[4];
741 mol->cell_size[3] = BoxLength[6];
742 mol->cell_size[4] = BoxLength[7];
743 mol->cell_size[5] = BoxLength[8];
744 if (1) fprintf(stderr,"\n");
745 config::DoPerturbation = 0;
746 config::DoFullCurrent = 0;
747
748 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
749 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
750 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
751 if (config::Lev0Factor < 2) {
752 config::Lev0Factor = 2;
753 }
754 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
755 if (di >= 0 && di < 2) {
756 config::RiemannTensor = di;
757 } else {
758 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
759 exit(1);
760 }
761 switch (config::RiemannTensor) {
762 case 0: //UseNoRT
763 if (config::MaxLevel < 2) {
764 config::MaxLevel = 2;
765 }
766 config::LevRFactor = 2;
767 config::RTActualUse = 0;
768 break;
769 case 1: // UseRT
770 if (config::MaxLevel < 3) {
771 config::MaxLevel = 3;
772 }
773 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
774 if (config::RiemannLevel < 2) {
775 config::RiemannLevel = 2;
776 }
777 if (config::RiemannLevel > config::MaxLevel-1) {
778 config::RiemannLevel = config::MaxLevel-1;
779 }
780 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
781 if (config::LevRFactor < 2) {
782 config::LevRFactor = 2;
783 }
784 config::Lev0Factor = 2;
785 config::RTActualUse = 2;
786 break;
787 }
788 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
789 if (di >= 0 && di < 2) {
790 config::PsiType = di;
791 } else {
792 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
793 exit(1);
794 }
795 switch (config::PsiType) {
796 case 0: // SpinDouble
797 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
798 config::AddPsis = 0;
799 break;
800 case 1: // SpinUpDown
801 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
802 ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
803 ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
804 config::AddPsis = 0;
805 break;
806 }
807
808 // IonsInitRead
809
810 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
811 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
812 config::RelativeCoord = 0;
813 config::StructOpt = 0;
814
815 // Routine from builder.cpp
816
817
818 for (i=0;i<128;i++) elementhash[i] = NULL;
819 cout << Verbose(0) << "Parsing Ions ..." << endl;
820 No=0;
821 found = 0;
822 while (getline(*file,zeile,'\n')) {
823 if (zeile.find("Ions_Data") == 0) {
824 cout << Verbose(1) << "found Ions_Data...begin parsing" << endl;
825 found ++;
826 }
827 if (found > 0) {
828 if (zeile.find("Ions_Data") == 0)
829 getline(*file,zeile,'\n'); // read next line and parse this one
830 istringstream input(zeile);
831 input >> AtomNo; // number of atoms
832 input >> Z; // atomic number
833 input >> a;
834 input >> l;
835 input >> l;
836 input >> b; // element mass
837 elementhash[No] = periode->FindElement(Z);
838 cout << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
839 for(i=0;i<AtomNo;i++) {
840 if (!getline(*file,zeile,'\n')) {// parse on and on
841 cout << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
842 // return 1;
843 } else {
844 //cout << Verbose(2) << "Reading line: " << zeile << endl;
845 }
846 istringstream input2(zeile);
847 atom *neues = new atom();
848 input2 >> neues->x.x[0]; // x
849 input2 >> neues->x.x[1]; // y
850 input2 >> neues->x.x[2]; // z
851 input2 >> l;
852 neues->type = elementhash[No]; // find element type
853 mol->AddAtom(neues);
854 }
855 No++;
856 }
857 }
858 file->close();
859 delete(file);
860};
861
862/** Stores all elements of config structure from which they can be re-read.
863 * \param output open output *file stream to write to
864 * \param *periode pointer to a periodentafel class with all elements
865 * \param *mol pointer to molecule containing all atoms of the molecule
866 */
867bool config::Save(ofstream *output, periodentafel *periode, molecule *mol) const
868{
869 bool result = true;
870 // bring MaxTypes up to date
871 mol->CountElements();
872 if (output != NULL) {
873 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
874 *output << endl;
875 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
876 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
877 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
878 *output << endl;
879 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
880 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
881 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
882 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
883 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
884 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
885 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
886 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
887 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
888 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
889 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
890 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
891 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
892 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
893 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
894 *output << endl;
895 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
896 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
897 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
898 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
899 *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
900 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
901 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
902 *output << endl;
903 *output << "# Values specifying when to stop" << endl;
904 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
905 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
906 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
907 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
908 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
909 *output << endl;
910 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
911 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
912 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
913 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
914 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
915 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
916 *output << endl;
917 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
918 *output << mol->cell_size[0] << "\t" << endl;
919 *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
920 *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
921 // FIXME
922 *output << endl;
923 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
924 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
925 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
926 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
927 switch (config::RiemannTensor) {
928 case 0: //UseNoRT
929 break;
930 case 1: // UseRT
931 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
932 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
933 break;
934 }
935 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
936 // write out both types for easier changing afterwards
937 // switch (PsiType) {
938 // case 0:
939 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
940 // break;
941 // case 1:
942 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
943 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
944 // break;
945 // }
946 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
947 *output << endl;
948 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
949 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
950 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
951 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
952 *output << "MaxTypes\t" << mol->ElementCount << "\t# maximum number of different ion types" << endl;
953 *output << endl;
954 result = result && mol->Checkout(output);
955 result = result && mol->Output(output);
956 return result;
957 } else
958 return false;
959};
960
961/** Reads parameter from a parsed file.
962 * The file is either parsed for a certain keyword or if null is given for
963 * the value in row yth and column xth. If the keyword was necessity#critical,
964 * then an error is thrown and the programme aborted.
965 * \warning value is modified (both in contents and position)!
966 * \param verbose 1 - print found value to stderr, 0 - don't
967 * \param file file to be parsed
968 * \param name Name of value in file (at least 3 chars!)
969 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
970 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
971 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
972 * counted from this unresetted position!)
973 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
974 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
975 * \param type Type of the Parameter to be read
976 * \param value address of the value to be read (must have been allocated)
977 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
978 * \param critical necessity of this keyword being specified (optional, critical)
979 * \return 1 - found, 0 - not found
980 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
981 */
982int config::ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
983 int i,j; // loop variables
984 int length = 0, maxlength = -1;
985 long file_position = file->tellg(); // mark current position
986 char *dummy1, *dummy, *free_dummy; // pointers in the line that is read in per step
987 dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
988
989 //fprintf(stderr,"Parsing for %s\n",name);
990 if (repetition == 0)
991 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
992 return 0;
993
994 int line = 0; // marks line where parameter was found
995 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
996 while((found != repetition)) {
997 dummy1 = dummy = free_dummy;
998 do {
999 file->getline(dummy1, 256); // Read the whole line
1000 if (file->eof()) {
1001 if ((critical) && (found == 0)) {
1002 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1003 //Error(InitReading, name);
1004 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1005 exit(255);
1006 } else {
1007 //if (!sequential)
1008 file->clear();
1009 file->seekg(file_position, ios::beg); // rewind to start position
1010 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1011 return 0;
1012 }
1013 }
1014 line++;
1015 } while (((dummy1[0] == '#') || (dummy1[0] == '\n')) && dummy != NULL); // skip commentary and empty lines
1016
1017 // C++ getline removes newline at end, thus re-add
1018 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1019 i = strlen(dummy1);
1020 dummy1[i] = '\n';
1021 dummy1[i+1] = '\0';
1022 }
1023 //fprintf(stderr,"line ends at %i, newline at %i\n", strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1024 if (dummy1 == NULL) {
1025 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1026 } else {
1027 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1028 }
1029 // Seek for possible end of keyword on line if given ...
1030 if (name != NULL) {
1031 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1032 if (dummy == NULL) {
1033 dummy = strchr(dummy1, ' '); // if not found seek for space
1034 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1035 dummy++;
1036 }
1037 if (dummy == NULL) {
1038 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1039 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1040 //Free((void **)&free_dummy);
1041 //Error(FileOpenParams, NULL);
1042 } else {
1043 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1044 }
1045 } else dummy = dummy1;
1046 // ... and check if it is the keyword!
1047 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1048 if ((name == NULL) || ((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name))) {
1049 found++; // found the parameter!
1050 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1051
1052 if (found == repetition) {
1053 for (i=0;i<xth;i++) { // i = rows
1054 if (type >= grid) {
1055 // grid structure means that grid starts on the next line, not right after keyword
1056 dummy1 = dummy = free_dummy;
1057 do {
1058 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1059 if (file->eof()) {
1060 if ((critical) && (found == 0)) {
1061 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1062 //Error(InitReading, name);
1063 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1064 exit(255);
1065 } else {
1066 //if (!sequential)
1067 file->clear();
1068 file->seekg(file_position, ios::beg); // rewind to start position
1069 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1070 return 0;
1071 }
1072 }
1073 line++;
1074 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1075 if (dummy1 == NULL){
1076 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1077 } else {
1078 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1079 }
1080 } else { // simple int, strings or doubles start in the same line
1081 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1082 dummy++;
1083 }
1084 // C++ getline removes newline at end, thus re-add
1085 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1086 j = strlen(dummy1);
1087 dummy1[j] = '\n';
1088 dummy1[j+1] = '\0';
1089 }
1090
1091 int start = (type >= grid) ? 0 : yth-1 ;
1092 for (j=start;j<yth;j++) { // j = columns
1093 // check for lower triangular area and upper triangular area
1094 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1095 *((double *)value) = 0.0;
1096 fprintf(stderr,"%f\t",*((double *)value));
1097 value = (void *)((long)value + sizeof(double));
1098 //value += sizeof(double);
1099 } else {
1100 // otherwise we must skip all interjacent tabs and spaces and find next value
1101 dummy1 = dummy;
1102 dummy = strchr(dummy1, '\t'); // seek for tab or space
1103 if (dummy == NULL) {
1104 dummy = strchr(dummy1, ' '); // if not found seek for space
1105 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1106 dummy++;
1107 }
1108/* while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1109 dummy++;*/
1110 if (dummy == NULL) { // if still zero returned ...
1111 dummy = strchr(dummy1, '\n'); // ... at line end then
1112 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1113 if (critical) {
1114 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1115 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1116 //return 0;
1117 exit(255);
1118 //Error(FileOpenParams, NULL);
1119 } else {
1120 //if (!sequential)
1121 file->clear();
1122 file->seekg(file_position, ios::beg); // rewind to start position
1123 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1124 return 0;
1125 }
1126 }
1127 } else {
1128 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1129 }
1130 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1131 switch(type) {
1132 case (row_int):
1133 *((int *)value) = atoi(dummy1);
1134 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1135 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1136 value = (void *)((long)value + sizeof(int));
1137 //value += sizeof(int);
1138 break;
1139 case(row_double):
1140 case(grid):
1141 case(lower_trigrid):
1142 case(upper_trigrid):
1143 *((double *)value) = atof(dummy1);
1144 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1145 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1146 value = (void *)((long)value + sizeof(double));
1147 //value += sizeof(double);
1148 break;
1149 case(double_type):
1150 *((double *)value) = atof(dummy1);
1151 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1152 //value += sizeof(double);
1153 break;
1154 case(int_type):
1155 *((int *)value) = atoi(dummy1);
1156 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1157 //value += sizeof(int);
1158 break;
1159 default:
1160 case(string_type):
1161 if (value != NULL) {
1162 if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1163 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1164 strncpy((char *)value, dummy1, length); // copy as much
1165 ((char *)value)[length] = '\0'; // and set end marker
1166 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1167 //value += sizeof(char);
1168 } else {
1169 }
1170 break;
1171 }
1172 }
1173 while (*dummy == '\t')
1174 dummy++;
1175 }
1176 }
1177 }
1178 }
1179 }
1180 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1181 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1182 if (!sequential) {
1183 file->clear();
1184 file->seekg(file_position, ios::beg); // rewind to start position
1185 }
1186 //fprintf(stderr, "End of Parsing\n\n");
1187
1188 return (found); // true if found, false if not
1189}
Note: See TracBrowser for help on using the repository browser.