source: src/config.cpp@ 57066a

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 57066a was d52e70c, checked in by Frederik Heber <heber@…>, 16 years ago

Small fixes.

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