source: src/config.cpp@ ef9aae

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since ef9aae was 3a9fe9, checked in by Frederik Heber <heber@…>, 15 years ago

LoadMolecule externalized from Load()

  • Property mode set to 100644
File size: 90.7 KB
Line 
1/** \file config.cpp
2 *
3 * Function implementations for the class config.
4 *
5 */
6
7#include "atom.hpp"
8#include "config.hpp"
9#include "element.hpp"
10#include "helpers.hpp"
11#include "memoryallocator.hpp"
12#include "molecule.hpp"
13#include "periodentafel.hpp"
14
15/******************************** Functions for class ConfigFileBuffer **********************/
16
17/** Structure containing compare function for Ion_Type sorting.
18 */
19struct IonTypeCompare {
20 bool operator()(const char* s1, const char *s2) const {
21 char number1[8];
22 char number2[8];
23 char *dummy1, *dummy2;
24 //cout << s1 << " " << s2 << endl;
25 dummy1 = strchr(s1, '_')+sizeof(char)*5; // go just after "Ion_Type"
26 dummy2 = strchr(dummy1, '_');
27 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
28 number1[dummy2-dummy1]='\0';
29 dummy1 = strchr(s2, '_')+sizeof(char)*5; // go just after "Ion_Type"
30 dummy2 = strchr(dummy1, '_');
31 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
32 number2[dummy2-dummy1]='\0';
33 if (atoi(number1) != atoi(number2))
34 return (atoi(number1) < atoi(number2));
35 else {
36 dummy1 = strchr(s1, '_')+sizeof(char);
37 dummy1 = strchr(dummy1, '_')+sizeof(char);
38 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
39 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
40 number1[dummy2-dummy1]='\0';
41 dummy1 = strchr(s2, '_')+sizeof(char);
42 dummy1 = strchr(dummy1, '_')+sizeof(char);
43 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
44 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
45 number2[dummy2-dummy1]='\0';
46 return (atoi(number1) < atoi(number2));
47 }
48 }
49};
50
51/** Constructor for ConfigFileBuffer class.
52 */
53ConfigFileBuffer::ConfigFileBuffer()
54{
55 NoLines = 0;
56 CurrentLine = 0;
57 buffer = NULL;
58 LineMapping = NULL;
59}
60
61/** Constructor for ConfigFileBuffer class with filename to be parsed.
62 * \param *filename file name
63 */
64ConfigFileBuffer::ConfigFileBuffer(char *filename)
65{
66 NoLines = 0;
67 CurrentLine = 0;
68 buffer = NULL;
69 LineMapping = NULL;
70 ifstream *file = NULL;
71 char line[MAXSTRINGSIZE];
72
73 // prescan number of lines
74 file= new ifstream(filename);
75 if (file == NULL) {
76 cerr << "ERROR: config file " << filename << " missing!" << endl;
77 return;
78 }
79 NoLines = 0; // we're overcounting by one
80 long file_position = file->tellg(); // mark current position
81 do {
82 file->getline(line, 256);
83 NoLines++;
84 } while (!file->eof());
85 file->clear();
86 file->seekg(file_position, ios::beg);
87 cout << Verbose(1) << NoLines-1 << " lines were recognized." << endl;
88
89 // allocate buffer's 1st dimension
90 if (buffer != NULL) {
91 cerr << "ERROR: FileBuffer->buffer is not NULL!" << endl;
92 return;
93 } else
94 buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
95
96 // scan each line and put into buffer
97 int lines=0;
98 int i;
99 do {
100 buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
101 file->getline(buffer[lines], MAXSTRINGSIZE-1);
102 i = strlen(buffer[lines]);
103 buffer[lines][i] = '\n';
104 buffer[lines][i+1] = '\0';
105 lines++;
106 } while((!file->eof()) && (lines < NoLines));
107 cout << Verbose(1) << lines-1 << " lines were read into the buffer." << endl;
108
109 // close and exit
110 file->close();
111 file->clear();
112 delete(file);
113}
114
115/** Destructor for ConfigFileBuffer class.
116 */
117ConfigFileBuffer::~ConfigFileBuffer()
118{
119 for(int i=0;i<NoLines;++i)
120 Free(&buffer[i]);
121 Free(&buffer);
122 Free(&LineMapping);
123}
124
125
126/** Create trivial mapping.
127 */
128void ConfigFileBuffer::InitMapping()
129{
130 LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
131 for (int i=0;i<NoLines;i++)
132 LineMapping[i] = i;
133}
134
135/** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
136 * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
137 * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
138 * points to first Ion_Type entry.
139 * \param *FileBuffer pointer to buffer structure
140 * \param NoAtoms of subsequent lines to look at
141 */
142void ConfigFileBuffer::MapIonTypesInBuffer(int NoAtoms)
143{
144 map<const char *, int, IonTypeCompare> LineList;
145 if (LineMapping == NULL) {
146 cerr << "map pointer is NULL: " << LineMapping << endl;
147 return;
148 }
149
150 // put all into hashed map
151 for (int i=0; i<NoAtoms; ++i) {
152 LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
153 }
154
155 // fill map
156 int nr=0;
157 for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) {
158 if (CurrentLine+nr < NoLines)
159 LineMapping[CurrentLine+(nr++)] = runner->second;
160 else
161 cerr << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl;
162 }
163}
164
165/************************************* Functions for class config ***************************/
166
167/** Constructor for config file class.
168 */
169config::config()
170{
171 mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
172 defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
173 pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
174 databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
175 configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
176 configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
177 ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
178 ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
179 for (int j=0;j<MaxThermostats;j++)
180 ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
181 Thermostat = 4;
182 alpha = 0.;
183 ScaleTempStep = 25;
184 TempFrequency = 2.5;
185 strcpy(mainname,"pcp");
186 strcpy(defaultpath,"not specified");
187 strcpy(pseudopotpath,"not specified");
188 configpath[0]='\0';
189 configname[0]='\0';
190 basis = "3-21G";
191
192 strcpy(ThermostatNames[0],"None");
193 ThermostatImplemented[0] = 1;
194 strcpy(ThermostatNames[1],"Woodcock");
195 ThermostatImplemented[1] = 1;
196 strcpy(ThermostatNames[2],"Gaussian");
197 ThermostatImplemented[2] = 1;
198 strcpy(ThermostatNames[3],"Langevin");
199 ThermostatImplemented[3] = 1;
200 strcpy(ThermostatNames[4],"Berendsen");
201 ThermostatImplemented[4] = 1;
202 strcpy(ThermostatNames[5],"NoseHoover");
203 ThermostatImplemented[5] = 1;
204
205 FastParsing = false;
206 ProcPEGamma=8;
207 ProcPEPsi=1;
208 DoOutVis=0;
209 DoOutMes=1;
210 DoOutNICS=0;
211 DoOutOrbitals=0;
212 DoOutCurrent=0;
213 DoPerturbation=0;
214 DoFullCurrent=0;
215 DoWannier=0;
216 DoConstrainedMD=0;
217 CommonWannier=0;
218 SawtoothStart=0.01;
219 VectorPlane=0;
220 VectorCut=0;
221 UseAddGramSch=1;
222 Seed=1;
223
224 MaxOuterStep=0;
225 Deltat=0.01;
226 OutVisStep=10;
227 OutSrcStep=5;
228 TargetTemp=0.00095004455;
229 ScaleTempStep=25;
230 MaxPsiStep=0;
231 EpsWannier=1e-7;
232
233 MaxMinStep=100;
234 RelEpsTotalEnergy=1e-7;
235 RelEpsKineticEnergy=1e-5;
236 MaxMinStopStep=1;
237 MaxMinGapStopStep=0;
238 MaxInitMinStep=100;
239 InitRelEpsTotalEnergy=1e-5;
240 InitRelEpsKineticEnergy=1e-4;
241 InitMaxMinStopStep=1;
242 InitMaxMinGapStopStep=0;
243
244 //BoxLength[NDIM*NDIM];
245
246 ECut=128.;
247 MaxLevel=5;
248 RiemannTensor=0;
249 LevRFactor=0;
250 RiemannLevel=0;
251 Lev0Factor=2;
252 RTActualUse=0;
253 PsiType=0;
254 MaxPsiDouble=0;
255 PsiMaxNoUp=0;
256 PsiMaxNoDown=0;
257 AddPsis=0;
258
259 RCut=20.;
260 StructOpt=0;
261 IsAngstroem=1;
262 RelativeCoord=0;
263 MaxTypes=0;
264};
265
266
267/** Destructor for config file class.
268 */
269config::~config()
270{
271 Free(&mainname);
272 Free(&defaultpath);
273 Free(&pseudopotpath);
274 Free(&databasepath);
275 Free(&configpath);
276 Free(&configname);
277 Free(&ThermostatImplemented);
278 for (int j=0;j<MaxThermostats;j++)
279 Free(&ThermostatNames[j]);
280 Free(&ThermostatNames);
281};
282
283/** Readin of Thermostat related values from parameter file.
284 * \param *fb file buffer containing the config file
285 */
286void config::InitThermostats(class ConfigFileBuffer *fb)
287{
288 char *thermo = Malloc<char>(12, "IonsInitRead: thermo");
289 int verbose = 0;
290
291 // read desired Thermostat from file along with needed additional parameters
292 if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
293 if (strcmp(thermo, ThermostatNames[0]) == 0) { // None
294 if (ThermostatImplemented[0] == 1) {
295 Thermostat = None;
296 } else {
297 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
298 Thermostat = None;
299 }
300 } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock
301 if (ThermostatImplemented[1] == 1) {
302 Thermostat = Woodcock;
303 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
304 } else {
305 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
306 Thermostat = None;
307 }
308 } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian
309 if (ThermostatImplemented[2] == 1) {
310 Thermostat = Gaussian;
311 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
312 } else {
313 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
314 Thermostat = None;
315 }
316 } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin
317 if (ThermostatImplemented[3] == 1) {
318 Thermostat = Langevin;
319 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
320 if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
321 cout << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl;
322 } else {
323 alpha = 1.;
324 }
325 } else {
326 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
327 Thermostat = None;
328 }
329 } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen
330 if (ThermostatImplemented[4] == 1) {
331 Thermostat = Berendsen;
332 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
333 } else {
334 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
335 Thermostat = None;
336 }
337 } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover
338 if (ThermostatImplemented[5] == 1) {
339 Thermostat = NoseHoover;
340 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
341 alpha = 0.;
342 } else {
343 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
344 Thermostat = None;
345 }
346 } else {
347 cout << Verbose(1) << " Warning: thermostat name was not understood!" << endl;
348 Thermostat = None;
349 }
350 } else {
351 if ((MaxOuterStep > 0) && (TargetTemp != 0))
352 cout << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl;
353 Thermostat = None;
354 }
355 Free(&thermo);
356};
357
358
359/** Displays menu for editing each entry of the config file.
360 * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case
361 * for each entry of the config file structure.
362 */
363void config::Edit()
364{
365 char choice;
366
367 do {
368 cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
369 cout << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl;
370 cout << Verbose(0) << " B - Default path (for runtime files)" << endl;
371 cout << Verbose(0) << " C - Path of pseudopotential files" << endl;
372 cout << Verbose(0) << " D - Number of coefficient sharing processes" << endl;
373 cout << Verbose(0) << " E - Number of wave function sharing processes" << endl;
374 cout << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl;
375 cout << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl;
376 cout << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl;
377 cout << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl;
378 cout << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl;
379 cout << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl;
380 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;
381 cout << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl;
382 cout << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl;
383 cout << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl;
384 cout << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl;
385 cout << Verbose(0) << " Q - Initial integer value of random number generator" << endl;
386 cout << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl;
387 cout << Verbose(0) << " T - Output visual after ...th step" << endl;
388 cout << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl;
389 cout << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl;
390 cout << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl;
391 cout << Verbose(0) << " Z - Maximum number of minimization iterations" << endl;
392 cout << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl;
393 cout << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl;
394 cout << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl;
395 cout << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl;
396 cout << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl;
397 cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
398 cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
399// cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
400 cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
401 cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
402 cout << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl;
403 cout << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl;
404 cout << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl;
405 cout << Verbose(0) << " p - Number of Riemann levels" << endl;
406 cout << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl;
407 cout << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl;
408 cout << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl;
409 cout << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl;
410 cout << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl;
411 cout << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl;
412 cout << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl;
413 cout << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl;
414 cout << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl;
415 cout << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl;
416 cout << Verbose(0) << "=========================================================" << endl;
417 cout << Verbose(0) << "INPUT: ";
418 cin >> choice;
419
420 switch (choice) {
421 case 'A': // mainname
422 cout << Verbose(0) << "Old: " << config::mainname << "\t new: ";
423 cin >> config::mainname;
424 break;
425 case 'B': // defaultpath
426 cout << Verbose(0) << "Old: " << config::defaultpath << "\t new: ";
427 cin >> config::defaultpath;
428 break;
429 case 'C': // pseudopotpath
430 cout << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ";
431 cin >> config::pseudopotpath;
432 break;
433
434 case 'D': // ProcPEGamma
435 cout << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ";
436 cin >> config::ProcPEGamma;
437 break;
438 case 'E': // ProcPEPsi
439 cout << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ";
440 cin >> config::ProcPEPsi;
441 break;
442 case 'F': // DoOutVis
443 cout << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ";
444 cin >> config::DoOutVis;
445 break;
446 case 'G': // DoOutMes
447 cout << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ";
448 cin >> config::DoOutMes;
449 break;
450 case 'H': // DoOutOrbitals
451 cout << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ";
452 cin >> config::DoOutOrbitals;
453 break;
454 case 'I': // DoOutCurrent
455 cout << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ";
456 cin >> config::DoOutCurrent;
457 break;
458 case 'J': // DoFullCurrent
459 cout << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ";
460 cin >> config::DoFullCurrent;
461 break;
462 case 'K': // DoPerturbation
463 cout << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ";
464 cin >> config::DoPerturbation;
465 break;
466 case 'L': // CommonWannier
467 cout << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ";
468 cin >> config::CommonWannier;
469 break;
470 case 'M': // SawtoothStart
471 cout << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ";
472 cin >> config::SawtoothStart;
473 break;
474 case 'N': // VectorPlane
475 cout << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ";
476 cin >> config::VectorPlane;
477 break;
478 case 'O': // VectorCut
479 cout << Verbose(0) << "Old: " << config::VectorCut << "\t new: ";
480 cin >> config::VectorCut;
481 break;
482 case 'P': // UseAddGramSch
483 cout << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ";
484 cin >> config::UseAddGramSch;
485 break;
486 case 'Q': // Seed
487 cout << Verbose(0) << "Old: " << config::Seed << "\t new: ";
488 cin >> config::Seed;
489 break;
490
491 case 'R': // MaxOuterStep
492 cout << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ";
493 cin >> config::MaxOuterStep;
494 break;
495 case 'T': // OutVisStep
496 cout << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ";
497 cin >> config::OutVisStep;
498 break;
499 case 'U': // OutSrcStep
500 cout << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ";
501 cin >> config::OutSrcStep;
502 break;
503 case 'X': // MaxPsiStep
504 cout << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ";
505 cin >> config::MaxPsiStep;
506 break;
507 case 'Y': // EpsWannier
508 cout << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ";
509 cin >> config::EpsWannier;
510 break;
511
512 case 'Z': // MaxMinStep
513 cout << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ";
514 cin >> config::MaxMinStep;
515 break;
516 case 'a': // RelEpsTotalEnergy
517 cout << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ";
518 cin >> config::RelEpsTotalEnergy;
519 break;
520 case 'b': // RelEpsKineticEnergy
521 cout << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ";
522 cin >> config::RelEpsKineticEnergy;
523 break;
524 case 'c': // MaxMinStopStep
525 cout << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ";
526 cin >> config::MaxMinStopStep;
527 break;
528 case 'e': // MaxInitMinStep
529 cout << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ";
530 cin >> config::MaxInitMinStep;
531 break;
532 case 'f': // InitRelEpsTotalEnergy
533 cout << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ";
534 cin >> config::InitRelEpsTotalEnergy;
535 break;
536 case 'g': // InitRelEpsKineticEnergy
537 cout << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ";
538 cin >> config::InitRelEpsKineticEnergy;
539 break;
540 case 'h': // InitMaxMinStopStep
541 cout << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ";
542 cin >> config::InitMaxMinStopStep;
543 break;
544
545// case 'j': // BoxLength
546// cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
547// for (int i=0;i<6;i++) {
548// cout << Verbose(0) << "Cell size" << i << ": ";
549// cin >> mol->cell_size[i];
550// }
551// break;
552
553 case 'k': // ECut
554 cout << Verbose(0) << "Old: " << config::ECut << "\t new: ";
555 cin >> config::ECut;
556 break;
557 case 'l': // MaxLevel
558 cout << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ";
559 cin >> config::MaxLevel;
560 break;
561 case 'm': // RiemannTensor
562 cout << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ";
563 cin >> config::RiemannTensor;
564 break;
565 case 'n': // LevRFactor
566 cout << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ";
567 cin >> config::LevRFactor;
568 break;
569 case 'o': // RiemannLevel
570 cout << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ";
571 cin >> config::RiemannLevel;
572 break;
573 case 'p': // Lev0Factor
574 cout << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ";
575 cin >> config::Lev0Factor;
576 break;
577 case 'r': // RTActualUse
578 cout << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ";
579 cin >> config::RTActualUse;
580 break;
581 case 's': // PsiType
582 cout << Verbose(0) << "Old: " << config::PsiType << "\t new: ";
583 cin >> config::PsiType;
584 break;
585 case 't': // MaxPsiDouble
586 cout << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ";
587 cin >> config::MaxPsiDouble;
588 break;
589 case 'u': // PsiMaxNoUp
590 cout << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ";
591 cin >> config::PsiMaxNoUp;
592 break;
593 case 'v': // PsiMaxNoDown
594 cout << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ";
595 cin >> config::PsiMaxNoDown;
596 break;
597 case 'w': // AddPsis
598 cout << Verbose(0) << "Old: " << config::AddPsis << "\t new: ";
599 cin >> config::AddPsis;
600 break;
601
602 case 'x': // RCut
603 cout << Verbose(0) << "Old: " << config::RCut << "\t new: ";
604 cin >> config::RCut;
605 break;
606 case 'y': // StructOpt
607 cout << Verbose(0) << "Old: " << config::StructOpt << "\t new: ";
608 cin >> config::StructOpt;
609 break;
610 case 'z': // IsAngstroem
611 cout << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ";
612 cin >> config::IsAngstroem;
613 break;
614 case 'i': // RelativeCoord
615 cout << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ";
616 cin >> config::RelativeCoord;
617 break;
618 };
619 } while (choice != 'q');
620};
621
622/** Tests whether a given configuration file adhears to old or new syntax.
623 * \param *filename filename of config file to be tested
624 * \param *periode pointer to a periodentafel class with all elements
625 * \param *mol pointer to molecule containing all atoms of the molecule
626 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
627 */
628int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
629{
630 int test;
631 ifstream file(filename);
632
633 // search file for keyword: ProcPEGamma (new syntax)
634 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
635 file.close();
636 return 1;
637 }
638 // search file for keyword: ProcsGammaPsi (old syntax)
639 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
640 file.close();
641 return 0;
642 }
643 file.close();
644 return -1;
645}
646
647/** Returns private config::IsAngstroem.
648 * \return IsAngstroem
649 */
650bool config::GetIsAngstroem() const
651{
652 return (IsAngstroem == 1);
653};
654
655/** Returns private config::*defaultpath.
656 * \return *defaultpath
657 */
658char * config::GetDefaultPath() const
659{
660 return defaultpath;
661};
662
663
664/** Returns private config::*defaultpath.
665 * \return *defaultpath
666 */
667void config::SetDefaultPath(const char *path)
668{
669 strcpy(defaultpath, path);
670};
671
672/** Retrieves the path in the given config file name.
673 * \param filename config file string
674 */
675void config::RetrieveConfigPathAndName(string filename)
676{
677 char *ptr = NULL;
678 char *buffer = new char[MAXSTRINGSIZE];
679 strncpy(buffer, filename.c_str(), MAXSTRINGSIZE);
680 int last = -1;
681 for(last=MAXSTRINGSIZE;last--;) {
682 if (buffer[last] == '/')
683 break;
684 }
685 if (last == -1) { // no path in front, set to local directory.
686 strcpy(configpath, "./");
687 ptr = buffer;
688 } else {
689 strncpy(configpath, buffer, last+1);
690 ptr = &buffer[last+1];
691 if (last < 254)
692 configpath[last+1]='\0';
693 }
694 strcpy(configname, ptr);
695 cout << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl;
696 delete[](buffer);
697};
698
699/** Initializes ConfigFileBuffer from a file.
700 * \param *file input file stream being the opened config file
701 * \param *FileBuffer pointer to FileBuffer on return, should point to NULL
702 */
703void PrepareFileBuffer(char *filename, struct ConfigFileBuffer *&FileBuffer)
704{
705 if (FileBuffer != NULL) {
706 cerr << Verbose(1) << "WARNING: deleting present FileBuffer in PrepareFileBuffer()." << endl;
707 delete(FileBuffer);
708 }
709 FileBuffer = new ConfigFileBuffer(filename);
710
711 FileBuffer->InitMapping();
712};
713
714/** Loads a molecule from a ConfigFileBuffer.
715 * \param *mol molecule to load
716 * \param *FileBuffer ConfigFileBuffer to use
717 * \param *periode periodentafel for finding elements
718 * \param FastParsing whether to parse trajectories or not
719 */
720void LoadMolecule(molecule *&mol, struct ConfigFileBuffer *&FileBuffer, periodentafel *periode, bool FastParsing)
721{
722 int MaxTypes = 0;
723 element *elementhash[MAX_ELEMENTS];
724 char name[MAX_ELEMENTS];
725 char keyword[MAX_ELEMENTS];
726 int Z = -1;
727 int No[MAX_ELEMENTS];
728 int verbose = 0;
729 double value[3];
730
731 if (mol == NULL) {
732 cerr << "Molecule is not allocated in LoadMolecule(), exit.";
733 performCriticalExit();
734 }
735
736 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
737 if (MaxTypes == 0) {
738 cerr << "There are no atoms according to MaxTypes in this config file." << endl;
739 } else {
740 // prescan number of ions per type
741 cout << Verbose(0) << "Prescanning ions per type: " << endl;
742 int NoAtoms = 0;
743 for (int i=0; i < MaxTypes; i++) {
744 sprintf(name,"Ion_Type%i",i+1);
745 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
746 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
747 elementhash[i] = periode->FindElement(Z);
748 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
749 NoAtoms += No[i];
750 }
751 int repetition = 0; // which repeated keyword shall be read
752
753 // sort the lines via the LineMapping
754 sprintf(name,"Ion_Type%i",MaxTypes);
755 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
756 cerr << "There are no atoms in the config file!" << endl;
757 return;
758 }
759 FileBuffer->CurrentLine++;
760 //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
761 FileBuffer->MapIonTypesInBuffer(NoAtoms);
762 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
763 // cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
764 //}
765
766 map<int, atom *> AtomList[MaxTypes];
767 map<int, atom *> LinearList;
768 atom *neues = NULL;
769 if (!FastParsing) {
770 // parse in trajectories
771 bool status = true;
772 while (status) {
773 cout << "Currently parsing MD step " << repetition << "." << endl;
774 for (int i=0; i < MaxTypes; i++) {
775 sprintf(name,"Ion_Type%i",i+1);
776 for(int j=0;j<No[i];j++) {
777 sprintf(keyword,"%s_%i",name, j+1);
778 if (repetition == 0) {
779 neues = new atom();
780 AtomList[i][j] = neues;
781 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
782 neues->type = elementhash[i]; // find element type
783 } else
784 neues = AtomList[i][j];
785 status = (status &&
786 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
787 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
788 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
789 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
790 if (!status) break;
791
792 // check size of vectors
793 if (neues->Trajectory.R.size() <= (unsigned int)(repetition)) {
794 //cout << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
795 neues->Trajectory.R.resize(repetition+10);
796 neues->Trajectory.U.resize(repetition+10);
797 neues->Trajectory.F.resize(repetition+10);
798 }
799
800 // put into trajectories list
801 for (int d=0;d<NDIM;d++)
802 neues->Trajectory.R.at(repetition).x[d] = neues->x.x[d];
803
804 // parse velocities if present
805 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
806 neues->v.x[0] = 0.;
807 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
808 neues->v.x[1] = 0.;
809 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
810 neues->v.x[2] = 0.;
811 for (int d=0;d<NDIM;d++)
812 neues->Trajectory.U.at(repetition).x[d] = neues->v.x[d];
813
814 // parse forces if present
815 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
816 value[0] = 0.;
817 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
818 value[1] = 0.;
819 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
820 value[2] = 0.;
821 for (int d=0;d<NDIM;d++)
822 neues->Trajectory.F.at(repetition).x[d] = value[d];
823
824 // cout << "Parsed position of step " << (repetition) << ": (";
825 // for (int d=0;d<NDIM;d++)
826 // cout << neues->Trajectory.R.at(repetition).x[d] << " "; // next step
827 // cout << ")\t(";
828 // for (int d=0;d<NDIM;d++)
829 // cout << neues->Trajectory.U.at(repetition).x[d] << " "; // next step
830 // cout << ")\t(";
831 // for (int d=0;d<NDIM;d++)
832 // cout << neues->Trajectory.F.at(repetition).x[d] << " "; // next step
833 // cout << ")" << endl;
834 }
835 }
836 repetition++;
837 }
838 repetition--;
839 cout << "Found " << repetition << " trajectory steps." << endl;
840 if (repetition <= 1) // if onyl one step, desactivate use of trajectories
841 mol->MDSteps = 0;
842 else
843 mol->MDSteps = repetition;
844 } else {
845 // find the maximum number of MD steps so that we may parse last one (Ion_Type1_1 must always be present, because is the first atom)
846 repetition = 0;
847 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
848 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
849 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
850 repetition++;
851 cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
852 // parse in molecule coordinates
853 for (int i=0; i < MaxTypes; i++) {
854 sprintf(name,"Ion_Type%i",i+1);
855 for(int j=0;j<No[i];j++) {
856 sprintf(keyword,"%s_%i",name, j+1);
857 if (repetition == 0) {
858 neues = new atom();
859 AtomList[i][j] = neues;
860 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
861 neues->type = elementhash[i]; // find element type
862 } else
863 neues = AtomList[i][j];
864 // then parse for each atom the coordinates as often as present
865 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
866 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
867 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
868 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
869 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
870 neues->v.x[0] = 0.;
871 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
872 neues->v.x[1] = 0.;
873 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
874 neues->v.x[2] = 0.;
875 // here we don't care if forces are present (last in trajectories is always equal to current position)
876 neues->type = elementhash[i]; // find element type
877 mol->AddAtom(neues);
878 }
879 }
880 }
881 // put atoms into the molecule in their original order
882 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
883 mol->AddAtom(runner->second);
884 }
885 }
886};
887
888
889/** Initializes config file structure by loading elements from a give file.
890 * \param *file input file stream being the opened config file
891 * \param *periode pointer to a periodentafel class with all elements
892 * \param *mol pointer to molecule containing all atoms of the molecule
893 */
894void config::Load(char *filename, periodentafel *periode, molecule *mol)
895{
896 ifstream *file = new ifstream(filename);
897 if (file == NULL) {
898 cerr << "ERROR: config file " << filename << " missing!" << endl;
899 return;
900 }
901 file->close();
902 delete(file);
903 RetrieveConfigPathAndName(filename);
904
905 // ParseParameterFile
906 struct ConfigFileBuffer *FileBuffer = NULL;
907 PrepareFileBuffer(filename,FileBuffer);
908
909 /* Oeffne Hauptparameterdatei */
910 int di;
911 double BoxLength[9];
912 string zeile;
913 string dummy;
914 int verbose = 0;
915
916 InitThermostats(FileBuffer);
917
918 /* Namen einlesen */
919
920 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
921 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
922 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
923 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
924 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
925
926 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
927 config::Seed = 1;
928
929 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
930 config::DoOutOrbitals = 0;
931 } else {
932 if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
933 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
934 }
935 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
936 if (config::DoOutVis < 0) config::DoOutVis = 0;
937 if (config::DoOutVis > 1) config::DoOutVis = 1;
938 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
939 config::VectorPlane = -1;
940 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
941 config::VectorCut = 0.;
942 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
943 if (config::DoOutMes < 0) config::DoOutMes = 0;
944 if (config::DoOutMes > 1) config::DoOutMes = 1;
945 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
946 config::DoOutCurrent = 0;
947 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
948 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
949 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
950 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
951 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
952 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
953 config::DoWannier = 0;
954 } else {
955 if (config::DoWannier < 0) config::DoWannier = 0;
956 if (config::DoWannier > 1) config::DoWannier = 1;
957 }
958 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
959 config::CommonWannier = 0;
960 } else {
961 if (config::CommonWannier < 0) config::CommonWannier = 0;
962 if (config::CommonWannier > 4) config::CommonWannier = 4;
963 }
964 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
965 config::SawtoothStart = 0.01;
966 } else {
967 if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
968 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
969 }
970
971 if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
972 if (config::DoConstrainedMD < 0)
973 config::DoConstrainedMD = 0;
974 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
975 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
976 config::Deltat = 1;
977 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
978 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
979 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
980 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
981 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
982 config::EpsWannier = 1e-8;
983
984 // stop conditions
985 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
986 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
987 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
988
989 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
990 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
991 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
992 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
993 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
994 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
995 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
996 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
997
998 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
999 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
1000 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
1001 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
1002 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
1003 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
1004 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
1005 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
1006
1007 // Unit cell and magnetic field
1008 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
1009 mol->cell_size[0] = BoxLength[0];
1010 mol->cell_size[1] = BoxLength[3];
1011 mol->cell_size[2] = BoxLength[4];
1012 mol->cell_size[3] = BoxLength[6];
1013 mol->cell_size[4] = BoxLength[7];
1014 mol->cell_size[5] = BoxLength[8];
1015 //if (1) fprintf(stderr,"\n");
1016
1017 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
1018 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
1019 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
1020 config::DoFullCurrent = 0;
1021 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
1022 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
1023 if (config::DoOutNICS < 0) config::DoOutNICS = 0;
1024 if (config::DoOutNICS > 2) config::DoOutNICS = 2;
1025 if (config::DoPerturbation == 0) {
1026 config::DoFullCurrent = 0;
1027 config::DoOutNICS = 0;
1028 }
1029
1030 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
1031 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
1032 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
1033 if (config::Lev0Factor < 2) {
1034 config::Lev0Factor = 2;
1035 }
1036 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
1037 if (di >= 0 && di < 2) {
1038 config::RiemannTensor = di;
1039 } else {
1040 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
1041 exit(1);
1042 }
1043 switch (config::RiemannTensor) {
1044 case 0: //UseNoRT
1045 if (config::MaxLevel < 2) {
1046 config::MaxLevel = 2;
1047 }
1048 config::LevRFactor = 2;
1049 config::RTActualUse = 0;
1050 break;
1051 case 1: // UseRT
1052 if (config::MaxLevel < 3) {
1053 config::MaxLevel = 3;
1054 }
1055 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
1056 if (config::RiemannLevel < 2) {
1057 config::RiemannLevel = 2;
1058 }
1059 if (config::RiemannLevel > config::MaxLevel-1) {
1060 config::RiemannLevel = config::MaxLevel-1;
1061 }
1062 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
1063 if (config::LevRFactor < 2) {
1064 config::LevRFactor = 2;
1065 }
1066 config::Lev0Factor = 2;
1067 config::RTActualUse = 2;
1068 break;
1069 }
1070 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
1071 if (di >= 0 && di < 2) {
1072 config::PsiType = di;
1073 } else {
1074 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
1075 exit(1);
1076 }
1077 switch (config::PsiType) {
1078 case 0: // SpinDouble
1079 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
1080 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
1081 break;
1082 case 1: // SpinUpDown
1083 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
1084 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
1085 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
1086 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
1087 break;
1088 }
1089
1090 // IonsInitRead
1091
1092 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
1093 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
1094 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
1095 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
1096 config::RelativeCoord = 0;
1097 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
1098 config::StructOpt = 0;
1099
1100 LoadMolecule(mol, FileBuffer, periode, FastParsing);
1101
1102 delete(FileBuffer);
1103};
1104
1105/** Initializes config file structure by loading elements from a give file with old pcp syntax.
1106 * \param *file input file stream being the opened config file with old pcp syntax
1107 * \param *periode pointer to a periodentafel class with all elements
1108 * \param *mol pointer to molecule containing all atoms of the molecule
1109 */
1110void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
1111{
1112 ifstream *file = new ifstream(filename);
1113 if (file == NULL) {
1114 cerr << "ERROR: config file " << filename << " missing!" << endl;
1115 return;
1116 }
1117 RetrieveConfigPathAndName(filename);
1118 // ParseParameters
1119
1120 /* Oeffne Hauptparameterdatei */
1121 int l, i, di;
1122 double a,b;
1123 double BoxLength[9];
1124 string zeile;
1125 string dummy;
1126 element *elementhash[128];
1127 int Z, No, AtomNo, found;
1128 int verbose = 0;
1129
1130 /* Namen einlesen */
1131
1132 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
1133 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
1134 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
1135 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
1136 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
1137 config::Seed = 1;
1138 config::DoOutOrbitals = 0;
1139 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
1140 if (config::DoOutVis < 0) config::DoOutVis = 0;
1141 if (config::DoOutVis > 1) config::DoOutVis = 1;
1142 config::VectorPlane = -1;
1143 config::VectorCut = 0.;
1144 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
1145 if (config::DoOutMes < 0) config::DoOutMes = 0;
1146 if (config::DoOutMes > 1) config::DoOutMes = 1;
1147 config::DoOutCurrent = 0;
1148 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
1149 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
1150 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
1151 config::CommonWannier = 0;
1152 config::SawtoothStart = 0.01;
1153
1154 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
1155 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
1156 ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
1157 ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
1158 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
1159 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
1160 config::EpsWannier = 1e-8;
1161
1162 // stop conditions
1163 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
1164 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
1165 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
1166
1167 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
1168 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
1169 ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
1170 ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
1171 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
1172 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
1173 config::MaxMinGapStopStep = 1;
1174
1175 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
1176 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
1177 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
1178 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
1179 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
1180 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
1181 config::InitMaxMinGapStopStep = 1;
1182
1183 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
1184 mol->cell_size[0] = BoxLength[0];
1185 mol->cell_size[1] = BoxLength[3];
1186 mol->cell_size[2] = BoxLength[4];
1187 mol->cell_size[3] = BoxLength[6];
1188 mol->cell_size[4] = BoxLength[7];
1189 mol->cell_size[5] = BoxLength[8];
1190 if (1) fprintf(stderr,"\n");
1191 config::DoPerturbation = 0;
1192 config::DoFullCurrent = 0;
1193
1194 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
1195 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
1196 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
1197 if (config::Lev0Factor < 2) {
1198 config::Lev0Factor = 2;
1199 }
1200 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
1201 if (di >= 0 && di < 2) {
1202 config::RiemannTensor = di;
1203 } else {
1204 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
1205 exit(1);
1206 }
1207 switch (config::RiemannTensor) {
1208 case 0: //UseNoRT
1209 if (config::MaxLevel < 2) {
1210 config::MaxLevel = 2;
1211 }
1212 config::LevRFactor = 2;
1213 config::RTActualUse = 0;
1214 break;
1215 case 1: // UseRT
1216 if (config::MaxLevel < 3) {
1217 config::MaxLevel = 3;
1218 }
1219 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
1220 if (config::RiemannLevel < 2) {
1221 config::RiemannLevel = 2;
1222 }
1223 if (config::RiemannLevel > config::MaxLevel-1) {
1224 config::RiemannLevel = config::MaxLevel-1;
1225 }
1226 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
1227 if (config::LevRFactor < 2) {
1228 config::LevRFactor = 2;
1229 }
1230 config::Lev0Factor = 2;
1231 config::RTActualUse = 2;
1232 break;
1233 }
1234 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
1235 if (di >= 0 && di < 2) {
1236 config::PsiType = di;
1237 } else {
1238 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
1239 exit(1);
1240 }
1241 switch (config::PsiType) {
1242 case 0: // SpinDouble
1243 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
1244 config::AddPsis = 0;
1245 break;
1246 case 1: // SpinUpDown
1247 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
1248 ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
1249 ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
1250 config::AddPsis = 0;
1251 break;
1252 }
1253
1254 // IonsInitRead
1255
1256 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
1257 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
1258 config::RelativeCoord = 0;
1259 config::StructOpt = 0;
1260
1261 // Routine from builder.cpp
1262
1263
1264 for (i=MAX_ELEMENTS;i--;)
1265 elementhash[i] = NULL;
1266 cout << Verbose(0) << "Parsing Ions ..." << endl;
1267 No=0;
1268 found = 0;
1269 while (getline(*file,zeile,'\n')) {
1270 if (zeile.find("Ions_Data") == 0) {
1271 cout << Verbose(1) << "found Ions_Data...begin parsing" << endl;
1272 found ++;
1273 }
1274 if (found > 0) {
1275 if (zeile.find("Ions_Data") == 0)
1276 getline(*file,zeile,'\n'); // read next line and parse this one
1277 istringstream input(zeile);
1278 input >> AtomNo; // number of atoms
1279 input >> Z; // atomic number
1280 input >> a;
1281 input >> l;
1282 input >> l;
1283 input >> b; // element mass
1284 elementhash[No] = periode->FindElement(Z);
1285 cout << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
1286 for(i=0;i<AtomNo;i++) {
1287 if (!getline(*file,zeile,'\n')) {// parse on and on
1288 cout << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
1289 // return 1;
1290 } else {
1291 //cout << Verbose(2) << "Reading line: " << zeile << endl;
1292 }
1293 istringstream input2(zeile);
1294 atom *neues = new atom();
1295 input2 >> neues->x.x[0]; // x
1296 input2 >> neues->x.x[1]; // y
1297 input2 >> neues->x.x[2]; // z
1298 input2 >> l;
1299 neues->type = elementhash[No]; // find element type
1300 mol->AddAtom(neues);
1301 }
1302 No++;
1303 }
1304 }
1305 file->close();
1306 delete(file);
1307};
1308
1309/** Stores all elements of config structure from which they can be re-read.
1310 * \param *filename name of file
1311 * \param *periode pointer to a periodentafel class with all elements
1312 * \param *mol pointer to molecule containing all atoms of the molecule
1313 */
1314bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const
1315{
1316 bool result = true;
1317 // bring MaxTypes up to date
1318 mol->CountElements();
1319 ofstream *output = NULL;
1320 output = new ofstream(filename, ios::out);
1321 if (output != NULL) {
1322 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
1323 *output << endl;
1324 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
1325 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
1326 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
1327 *output << endl;
1328 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
1329 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
1330 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
1331 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
1332 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
1333 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
1334 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
1335 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
1336 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
1337 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
1338 *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
1339 switch(Thermostat) {
1340 default:
1341 case None:
1342 break;
1343 case Woodcock:
1344 *output << ScaleTempStep;
1345 break;
1346 case Gaussian:
1347 *output << ScaleTempStep;
1348 break;
1349 case Langevin:
1350 *output << TempFrequency << "\t" << alpha;
1351 break;
1352 case Berendsen:
1353 *output << TempFrequency;
1354 break;
1355 case NoseHoover:
1356 *output << HooverMass;
1357 break;
1358 };
1359 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
1360 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
1361 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
1362 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
1363 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
1364 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
1365 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
1366 *output << endl;
1367 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
1368 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
1369 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
1370 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
1371 *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
1372 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
1373 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
1374 *output << endl;
1375 *output << "# Values specifying when to stop" << endl;
1376 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
1377 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1378 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1379 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
1380 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
1381 *output << endl;
1382 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
1383 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
1384 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1385 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1386 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
1387 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
1388 *output << endl;
1389 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
1390 *output << mol->cell_size[0] << "\t" << endl;
1391 *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
1392 *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
1393 // FIXME
1394 *output << endl;
1395 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
1396 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
1397 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
1398 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
1399 switch (config::RiemannTensor) {
1400 case 0: //UseNoRT
1401 break;
1402 case 1: // UseRT
1403 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
1404 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
1405 break;
1406 }
1407 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
1408 // write out both types for easier changing afterwards
1409 // switch (PsiType) {
1410 // case 0:
1411 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
1412 // break;
1413 // case 1:
1414 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
1415 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
1416 // break;
1417 // }
1418 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
1419 *output << endl;
1420 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
1421 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
1422 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
1423 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
1424 *output << "MaxTypes\t" << mol->ElementCount << "\t# maximum number of different ion types" << endl;
1425 *output << endl;
1426 result = result && mol->Checkout(output);
1427 if (mol->MDSteps <=1 )
1428 result = result && mol->Output(output);
1429 else
1430 result = result && mol->OutputTrajectories(output);
1431 output->close();
1432 output->clear();
1433 delete(output);
1434 return result;
1435 } else
1436 return false;
1437};
1438
1439/** Stores all elements in a MPQC input file.
1440 * Note that this format cannot be parsed again.
1441 * \param *filename name of file (without ".in" suffix!)
1442 * \param *mol pointer to molecule containing all atoms of the molecule
1443 */
1444bool config::SaveMPQC(const char *filename, molecule *mol) const
1445{
1446 int ElementNo = 0;
1447 int AtomNo;
1448 atom *Walker = NULL;
1449 element *runner = NULL;
1450 Vector *center = NULL;
1451 ofstream *output = NULL;
1452 stringstream *fname = NULL;
1453
1454 // first without hessian
1455 fname = new stringstream;
1456 *fname << filename << ".in";
1457 output = new ofstream(fname->str().c_str(), ios::out);
1458 *output << "% Created by MoleCuilder" << endl;
1459 *output << "mpqc: (" << endl;
1460 *output << "\tsavestate = no" << endl;
1461 *output << "\tdo_gradient = yes" << endl;
1462 *output << "\tmole<MBPT2>: (" << endl;
1463 *output << "\t\tmaxiter = 200" << endl;
1464 *output << "\t\tbasis = $:basis" << endl;
1465 *output << "\t\tmolecule = $:molecule" << endl;
1466 *output << "\t\treference<CLHF>: (" << endl;
1467 *output << "\t\t\tbasis = $:basis" << endl;
1468 *output << "\t\t\tmolecule = $:molecule" << endl;
1469 *output << "\t\t)" << endl;
1470 *output << "\t)" << endl;
1471 *output << ")" << endl;
1472 *output << "molecule<Molecule>: (" << endl;
1473 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1474 *output << "\t{ atoms geometry } = {" << endl;
1475 center = mol->DetermineCenterOfAll(output);
1476 // output of atoms
1477 runner = mol->elemente->start;
1478 while (runner->next != mol->elemente->end) { // go through every element
1479 runner = runner->next;
1480 if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
1481 ElementNo++;
1482 AtomNo = 0;
1483 Walker = mol->start;
1484 while (Walker->next != mol->end) { // go through every atom of this element
1485 Walker = Walker->next;
1486 if (Walker->type == runner) { // if this atom fits to element
1487 AtomNo++;
1488 *output << "\t\t" << Walker->type->symbol << " [ " << Walker->x.x[0]-center->x[0] << "\t" << Walker->x.x[1]-center->x[1] << "\t" << Walker->x.x[2]-center->x[2] << " ]" << endl;
1489 }
1490 }
1491 }
1492 }
1493 delete(center);
1494 *output << "\t}" << endl;
1495 *output << ")" << endl;
1496 *output << "basis<GaussianBasisSet>: (" << endl;
1497 *output << "\tname = \"" << basis << "\"" << endl;
1498 *output << "\tmolecule = $:molecule" << endl;
1499 *output << ")" << endl;
1500 output->close();
1501 delete(output);
1502 delete(fname);
1503
1504 // second with hessian
1505 fname = new stringstream;
1506 *fname << filename << ".hess.in";
1507 output = new ofstream(fname->str().c_str(), ios::out);
1508 *output << "% Created by MoleCuilder" << endl;
1509 *output << "mpqc: (" << endl;
1510 *output << "\tsavestate = no" << endl;
1511 *output << "\tdo_gradient = yes" << endl;
1512 *output << "\tmole<CLHF>: (" << endl;
1513 *output << "\t\tmaxiter = 200" << endl;
1514 *output << "\t\tbasis = $:basis" << endl;
1515 *output << "\t\tmolecule = $:molecule" << endl;
1516 *output << "\t)" << endl;
1517 *output << "\tfreq<MolecularFrequencies>: (" << endl;
1518 *output << "\t\tmolecule=$:molecule" << endl;
1519 *output << "\t)" << endl;
1520 *output << ")" << endl;
1521 *output << "molecule<Molecule>: (" << endl;
1522 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1523 *output << "\t{ atoms geometry } = {" << endl;
1524 center = mol->DetermineCenterOfAll(output);
1525 // output of atoms
1526 runner = mol->elemente->start;
1527 while (runner->next != mol->elemente->end) { // go through every element
1528 runner = runner->next;
1529 if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
1530 ElementNo++;
1531 AtomNo = 0;
1532 Walker = mol->start;
1533 while (Walker->next != mol->end) { // go through every atom of this element
1534 Walker = Walker->next;
1535 if (Walker->type == runner) { // if this atom fits to element
1536 AtomNo++;
1537 *output << "\t\t" << Walker->type->symbol << " [ " << Walker->x.x[0]-center->x[0] << "\t" << Walker->x.x[1]-center->x[1] << "\t" << Walker->x.x[2]-center->x[2] << " ]" << endl;
1538 }
1539 }
1540 }
1541 }
1542 delete(center);
1543 *output << "\t}" << endl;
1544 *output << ")" << endl;
1545 *output << "basis<GaussianBasisSet>: (" << endl;
1546 *output << "\tname = \"3-21G\"" << endl;
1547 *output << "\tmolecule = $:molecule" << endl;
1548 *output << ")" << endl;
1549 output->close();
1550 delete(output);
1551 delete(fname);
1552
1553 return true;
1554};
1555
1556/** Reads parameter from a parsed file.
1557 * The file is either parsed for a certain keyword or if null is given for
1558 * the value in row yth and column xth. If the keyword was necessity#critical,
1559 * then an error is thrown and the programme aborted.
1560 * \warning value is modified (both in contents and position)!
1561 * \param verbose 1 - print found value to stderr, 0 - don't
1562 * \param *file file to be parsed
1563 * \param name Name of value in file (at least 3 chars!)
1564 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1565 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1566 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1567 * counted from this unresetted position!)
1568 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1569 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1570 * \param type Type of the Parameter to be read
1571 * \param value address of the value to be read (must have been allocated)
1572 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1573 * \param critical necessity of this keyword being specified (optional, critical)
1574 * \return 1 - found, 0 - not found
1575 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1576 */
1577int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
1578 int i,j; // loop variables
1579 int length = 0, maxlength = -1;
1580 long file_position = file->tellg(); // mark current position
1581 char *dummy1, *dummy, *free_dummy; // pointers in the line that is read in per step
1582 dummy1 = free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");
1583
1584 //fprintf(stderr,"Parsing for %s\n",name);
1585 if (repetition == 0)
1586 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1587 return 0;
1588
1589 int line = 0; // marks line where parameter was found
1590 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1591 while((found != repetition)) {
1592 dummy1 = dummy = free_dummy;
1593 do {
1594 file->getline(dummy1, 256); // Read the whole line
1595 if (file->eof()) {
1596 if ((critical) && (found == 0)) {
1597 Free(&free_dummy);
1598 //Error(InitReading, name);
1599 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1600 exit(255);
1601 } else {
1602 //if (!sequential)
1603 file->clear();
1604 file->seekg(file_position, ios::beg); // rewind to start position
1605 Free(&free_dummy);
1606 return 0;
1607 }
1608 }
1609 line++;
1610 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1611
1612 // C++ getline removes newline at end, thus re-add
1613 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1614 i = strlen(dummy1);
1615 dummy1[i] = '\n';
1616 dummy1[i+1] = '\0';
1617 }
1618 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1619
1620 if (dummy1 == NULL) {
1621 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1622 } else {
1623 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1624 }
1625 // Seek for possible end of keyword on line if given ...
1626 if (name != NULL) {
1627 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1628 if (dummy == NULL) {
1629 dummy = strchr(dummy1, ' '); // if not found seek for space
1630 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1631 dummy++;
1632 }
1633 if (dummy == NULL) {
1634 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1635 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1636 //Free((void **)&free_dummy);
1637 //Error(FileOpenParams, NULL);
1638 } else {
1639 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1640 }
1641 } else dummy = dummy1;
1642 // ... and check if it is the keyword!
1643 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1644 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1645 found++; // found the parameter!
1646 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1647
1648 if (found == repetition) {
1649 for (i=0;i<xth;i++) { // i = rows
1650 if (type >= grid) {
1651 // grid structure means that grid starts on the next line, not right after keyword
1652 dummy1 = dummy = free_dummy;
1653 do {
1654 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1655 if (file->eof()) {
1656 if ((critical) && (found == 0)) {
1657 Free(&free_dummy);
1658 //Error(InitReading, name);
1659 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1660 exit(255);
1661 } else {
1662 //if (!sequential)
1663 file->clear();
1664 file->seekg(file_position, ios::beg); // rewind to start position
1665 Free(&free_dummy);
1666 return 0;
1667 }
1668 }
1669 line++;
1670 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1671 if (dummy1 == NULL){
1672 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1673 } else {
1674 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1675 }
1676 } else { // simple int, strings or doubles start in the same line
1677 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1678 dummy++;
1679 }
1680 // C++ getline removes newline at end, thus re-add
1681 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1682 j = strlen(dummy1);
1683 dummy1[j] = '\n';
1684 dummy1[j+1] = '\0';
1685 }
1686
1687 int start = (type >= grid) ? 0 : yth-1 ;
1688 for (j=start;j<yth;j++) { // j = columns
1689 // check for lower triangular area and upper triangular area
1690 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1691 *((double *)value) = 0.0;
1692 fprintf(stderr,"%f\t",*((double *)value));
1693 value = (void *)((long)value + sizeof(double));
1694 //value += sizeof(double);
1695 } else {
1696 // otherwise we must skip all interjacent tabs and spaces and find next value
1697 dummy1 = dummy;
1698 dummy = strchr(dummy1, '\t'); // seek for tab or space
1699 if (dummy == NULL)
1700 dummy = strchr(dummy1, ' '); // if not found seek for space
1701 if (dummy == NULL) { // if still zero returned ...
1702 dummy = strchr(dummy1, '\n'); // ... at line end then
1703 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1704 if (critical) {
1705 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1706 Free(&free_dummy);
1707 //return 0;
1708 exit(255);
1709 //Error(FileOpenParams, NULL);
1710 } else {
1711 //if (!sequential)
1712 file->clear();
1713 file->seekg(file_position, ios::beg); // rewind to start position
1714 Free(&free_dummy);
1715 return 0;
1716 }
1717 }
1718 } else {
1719 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1720 }
1721 if (*dummy1 == '#') {
1722 // found comment, skipping rest of line
1723 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1724 if (!sequential) { // here we need it!
1725 file->seekg(file_position, ios::beg); // rewind to start position
1726 }
1727 Free(&free_dummy);
1728 return 0;
1729 }
1730 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1731 switch(type) {
1732 case (row_int):
1733 *((int *)value) = atoi(dummy1);
1734 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1735 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1736 value = (void *)((long)value + sizeof(int));
1737 //value += sizeof(int);
1738 break;
1739 case(row_double):
1740 case(grid):
1741 case(lower_trigrid):
1742 case(upper_trigrid):
1743 *((double *)value) = atof(dummy1);
1744 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1745 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1746 value = (void *)((long)value + sizeof(double));
1747 //value += sizeof(double);
1748 break;
1749 case(double_type):
1750 *((double *)value) = atof(dummy1);
1751 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1752 //value += sizeof(double);
1753 break;
1754 case(int_type):
1755 *((int *)value) = atoi(dummy1);
1756 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1757 //value += sizeof(int);
1758 break;
1759 default:
1760 case(string_type):
1761 if (value != NULL) {
1762 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1763 maxlength = MAXSTRINGSIZE;
1764 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1765 strncpy((char *)value, dummy1, length); // copy as much
1766 ((char *)value)[length] = '\0'; // and set end marker
1767 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1768 //value += sizeof(char);
1769 } else {
1770 }
1771 break;
1772 }
1773 }
1774 while (*dummy == '\t')
1775 dummy++;
1776 }
1777 }
1778 }
1779 }
1780 }
1781 if ((type >= row_int) && (verbose))
1782 fprintf(stderr,"\n");
1783 Free(&free_dummy);
1784 if (!sequential) {
1785 file->clear();
1786 file->seekg(file_position, ios::beg); // rewind to start position
1787 }
1788 //fprintf(stderr, "End of Parsing\n\n");
1789
1790 return (found); // true if found, false if not
1791}
1792
1793
1794/** Reads parameter from a parsed file.
1795 * The file is either parsed for a certain keyword or if null is given for
1796 * the value in row yth and column xth. If the keyword was necessity#critical,
1797 * then an error is thrown and the programme aborted.
1798 * \warning value is modified (both in contents and position)!
1799 * \param verbose 1 - print found value to stderr, 0 - don't
1800 * \param *FileBuffer pointer to buffer structure
1801 * \param name Name of value in file (at least 3 chars!)
1802 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1803 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1804 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1805 * counted from this unresetted position!)
1806 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1807 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1808 * \param type Type of the Parameter to be read
1809 * \param value address of the value to be read (must have been allocated)
1810 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1811 * \param critical necessity of this keyword being specified (optional, critical)
1812 * \return 1 - found, 0 - not found
1813 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1814 */
1815int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
1816 int i,j; // loop variables
1817 int length = 0, maxlength = -1;
1818 int OldCurrentLine = FileBuffer->CurrentLine;
1819 char *dummy1, *dummy; // pointers in the line that is read in per step
1820
1821 //fprintf(stderr,"Parsing for %s\n",name);
1822 if (repetition == 0)
1823 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1824 return 0;
1825
1826 int line = 0; // marks line where parameter was found
1827 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1828 while((found != repetition)) {
1829 dummy1 = dummy = NULL;
1830 do {
1831 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1832 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1833 if ((critical) && (found == 0)) {
1834 //Error(InitReading, name);
1835 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1836 exit(255);
1837 } else {
1838 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1839 return 0;
1840 }
1841 }
1842 if (dummy1 == NULL) {
1843 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1844 } else {
1845 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1846 }
1847 line++;
1848 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1849
1850 // Seek for possible end of keyword on line if given ...
1851 if (name != NULL) {
1852 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1853 if (dummy == NULL) {
1854 dummy = strchr(dummy1, ' '); // if not found seek for space
1855 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1856 dummy++;
1857 }
1858 if (dummy == NULL) {
1859 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1860 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1861 //Free(&free_dummy);
1862 //Error(FileOpenParams, NULL);
1863 } else {
1864 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1865 }
1866 } else dummy = dummy1;
1867 // ... and check if it is the keyword!
1868 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1869 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1870 found++; // found the parameter!
1871 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1872
1873 if (found == repetition) {
1874 for (i=0;i<xth;i++) { // i = rows
1875 if (type >= grid) {
1876 // grid structure means that grid starts on the next line, not right after keyword
1877 dummy1 = dummy = NULL;
1878 do {
1879 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1880 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1881 if ((critical) && (found == 0)) {
1882 //Error(InitReading, name);
1883 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1884 exit(255);
1885 } else {
1886 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1887 return 0;
1888 }
1889 }
1890 if (dummy1 == NULL) {
1891 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1892 } else {
1893 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1894 }
1895 line++;
1896 } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
1897 dummy = dummy1;
1898 } else { // simple int, strings or doubles start in the same line
1899 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1900 dummy++;
1901 }
1902
1903 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
1904 // check for lower triangular area and upper triangular area
1905 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1906 *((double *)value) = 0.0;
1907 fprintf(stderr,"%f\t",*((double *)value));
1908 value = (void *)((long)value + sizeof(double));
1909 //value += sizeof(double);
1910 } else {
1911 // otherwise we must skip all interjacent tabs and spaces and find next value
1912 dummy1 = dummy;
1913 dummy = strchr(dummy1, '\t'); // seek for tab or space
1914 if (dummy == NULL)
1915 dummy = strchr(dummy1, ' '); // if not found seek for space
1916 if (dummy == NULL) { // if still zero returned ...
1917 dummy = strchr(dummy1, '\n'); // ... at line end then
1918 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1919 if (critical) {
1920 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1921 //return 0;
1922 exit(255);
1923 //Error(FileOpenParams, NULL);
1924 } else {
1925 if (!sequential) { // here we need it!
1926 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1927 }
1928 return 0;
1929 }
1930 }
1931 } else {
1932 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1933 }
1934 if (*dummy1 == '#') {
1935 // found comment, skipping rest of line
1936 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1937 if (!sequential) { // here we need it!
1938 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1939 }
1940 return 0;
1941 }
1942 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1943 switch(type) {
1944 case (row_int):
1945 *((int *)value) = atoi(dummy1);
1946 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1947 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1948 value = (void *)((long)value + sizeof(int));
1949 //value += sizeof(int);
1950 break;
1951 case(row_double):
1952 case(grid):
1953 case(lower_trigrid):
1954 case(upper_trigrid):
1955 *((double *)value) = atof(dummy1);
1956 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1957 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1958 value = (void *)((long)value + sizeof(double));
1959 //value += sizeof(double);
1960 break;
1961 case(double_type):
1962 *((double *)value) = atof(dummy1);
1963 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1964 //value += sizeof(double);
1965 break;
1966 case(int_type):
1967 *((int *)value) = atoi(dummy1);
1968 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1969 //value += sizeof(int);
1970 break;
1971 default:
1972 case(string_type):
1973 if (value != NULL) {
1974 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1975 maxlength = MAXSTRINGSIZE;
1976 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1977 strncpy((char *)value, dummy1, length); // copy as much
1978 ((char *)value)[length] = '\0'; // and set end marker
1979 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1980 //value += sizeof(char);
1981 } else {
1982 }
1983 break;
1984 }
1985 }
1986 while (*dummy == '\t')
1987 dummy++;
1988 }
1989 }
1990 }
1991 }
1992 }
1993 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1994 if (!sequential) {
1995 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1996 }
1997 //fprintf(stderr, "End of Parsing\n\n");
1998
1999 return (found); // true if found, false if not
2000}
Note: See TracBrowser for help on using the repository browser.