source: src/config.cpp@ d4d0dd

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 d4d0dd was 3c4f04, checked in by Frederik Heber <heber@…>, 16 years ago

BUGFIX: config::Load() added atoms in wrong order, hence resulting in wrong names.

  • config::Load() - int in LinearList should have been mapped not original one
  • Property mode set to 100755
File size: 90.6 KB
Line 
1/** \file config.cpp
2 *
3 * Function implementations for the class config.
4 *
5 */
6
7#include "molecules.hpp"
8
9/******************************** Functions for class 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 *source parameter file
279 */
280void config::InitThermostats(ifstream *source)
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,source,"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,source,"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,source,"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,source,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
314 if (ParseForParameter(verbose,source,"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,source,"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,source,"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 RetrieveConfigPathAndName(filename);
707
708 // ParseParameterFile
709 struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
710 FileBuffer->InitMapping();
711
712 /* Oeffne Hauptparameterdatei */
713 int di;
714 double BoxLength[9];
715 string zeile;
716 string dummy;
717 element *elementhash[MAX_ELEMENTS];
718 char name[MAX_ELEMENTS];
719 char keyword[MAX_ELEMENTS];
720 int Z, No[MAX_ELEMENTS];
721 int verbose = 0;
722 double value[3];
723
724 InitThermostats(file);
725
726 /* Namen einlesen */
727
728 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
729 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
730 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
731 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
732 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
733
734 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
735 config::Seed = 1;
736
737 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
738 config::DoOutOrbitals = 0;
739 } else {
740 if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
741 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
742 }
743 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
744 if (config::DoOutVis < 0) config::DoOutVis = 0;
745 if (config::DoOutVis > 1) config::DoOutVis = 1;
746 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
747 config::VectorPlane = -1;
748 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
749 config::VectorCut = 0.;
750 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
751 if (config::DoOutMes < 0) config::DoOutMes = 0;
752 if (config::DoOutMes > 1) config::DoOutMes = 1;
753 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
754 config::DoOutCurrent = 0;
755 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
756 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
757 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
758 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
759 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
760 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
761 config::DoWannier = 0;
762 } else {
763 if (config::DoWannier < 0) config::DoWannier = 0;
764 if (config::DoWannier > 1) config::DoWannier = 1;
765 }
766 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
767 config::CommonWannier = 0;
768 } else {
769 if (config::CommonWannier < 0) config::CommonWannier = 0;
770 if (config::CommonWannier > 4) config::CommonWannier = 4;
771 }
772 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
773 config::SawtoothStart = 0.01;
774 } else {
775 if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
776 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
777 }
778
779 if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
780 if (config::DoConstrainedMD < 0)
781 config::DoConstrainedMD = 0;
782 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
783 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
784 config::Deltat = 1;
785 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
786 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
787 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
788 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
789 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
790 config::EpsWannier = 1e-8;
791
792 // stop conditions
793 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
794 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
795 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
796
797 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
798 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
799 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
800 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
801 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
802 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
803 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
804 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
805
806 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
807 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
808 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
809 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
810 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
811 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
812 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
813 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
814
815 // Unit cell and magnetic field
816 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
817 mol->cell_size[0] = BoxLength[0];
818 mol->cell_size[1] = BoxLength[3];
819 mol->cell_size[2] = BoxLength[4];
820 mol->cell_size[3] = BoxLength[6];
821 mol->cell_size[4] = BoxLength[7];
822 mol->cell_size[5] = BoxLength[8];
823 //if (1) fprintf(stderr,"\n");
824
825 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
826 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
827 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
828 config::DoFullCurrent = 0;
829 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
830 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
831 if (config::DoOutNICS < 0) config::DoOutNICS = 0;
832 if (config::DoOutNICS > 2) config::DoOutNICS = 2;
833 if (config::DoPerturbation == 0) {
834 config::DoFullCurrent = 0;
835 config::DoOutNICS = 0;
836 }
837
838 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
839 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
840 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
841 if (config::Lev0Factor < 2) {
842 config::Lev0Factor = 2;
843 }
844 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
845 if (di >= 0 && di < 2) {
846 config::RiemannTensor = di;
847 } else {
848 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
849 exit(1);
850 }
851 switch (config::RiemannTensor) {
852 case 0: //UseNoRT
853 if (config::MaxLevel < 2) {
854 config::MaxLevel = 2;
855 }
856 config::LevRFactor = 2;
857 config::RTActualUse = 0;
858 break;
859 case 1: // UseRT
860 if (config::MaxLevel < 3) {
861 config::MaxLevel = 3;
862 }
863 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
864 if (config::RiemannLevel < 2) {
865 config::RiemannLevel = 2;
866 }
867 if (config::RiemannLevel > config::MaxLevel-1) {
868 config::RiemannLevel = config::MaxLevel-1;
869 }
870 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
871 if (config::LevRFactor < 2) {
872 config::LevRFactor = 2;
873 }
874 config::Lev0Factor = 2;
875 config::RTActualUse = 2;
876 break;
877 }
878 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
879 if (di >= 0 && di < 2) {
880 config::PsiType = di;
881 } else {
882 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
883 exit(1);
884 }
885 switch (config::PsiType) {
886 case 0: // SpinDouble
887 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
888 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
889 break;
890 case 1: // SpinUpDown
891 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
892 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
893 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
894 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
895 break;
896 }
897
898 // IonsInitRead
899
900 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
901 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
902 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
903 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
904 config::RelativeCoord = 0;
905 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
906 config::StructOpt = 0;
907 if (MaxTypes == 0) {
908 cerr << "There are no atoms according to MaxTypes in this config file." << endl;
909 } else {
910 // prescan number of ions per type
911 cout << Verbose(0) << "Prescanning ions per type: " << endl;
912 int NoAtoms = 0;
913 for (int i=0; i < config::MaxTypes; i++) {
914 sprintf(name,"Ion_Type%i",i+1);
915 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
916 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
917 elementhash[i] = periode->FindElement(Z);
918 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
919 NoAtoms += No[i];
920 }
921 int repetition = 0; // which repeated keyword shall be read
922
923 // sort the lines via the LineMapping
924 sprintf(name,"Ion_Type%i",config::MaxTypes);
925 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
926 cerr << "There are no atoms in the config file!" << endl;
927 return;
928 }
929 FileBuffer->CurrentLine++;
930 //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
931 FileBuffer->MapIonTypesInBuffer(NoAtoms);
932 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
933 // cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
934 //}
935
936 map<int, atom *> AtomList[config::MaxTypes];
937 map<int, atom *> LinearList;
938 atom *neues = NULL;
939 if (!FastParsing) {
940 // parse in trajectories
941 bool status = true;
942 while (status) {
943 cout << "Currently parsing MD step " << repetition << "." << endl;
944 for (int i=0; i < config::MaxTypes; i++) {
945 sprintf(name,"Ion_Type%i",i+1);
946 for(int j=0;j<No[i];j++) {
947 sprintf(keyword,"%s_%i",name, j+1);
948 if (repetition == 0) {
949 neues = new atom();
950 AtomList[i][j] = neues;
951 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
952 neues->type = elementhash[i]; // find element type
953 } else
954 neues = AtomList[i][j];
955 status = (status &&
956 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
957 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
958 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
959 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
960 if (!status) break;
961
962 // check size of vectors
963 if (mol->Trajectories[neues].R.size() <= (unsigned int)(repetition)) {
964 //cout << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
965 mol->Trajectories[neues].R.resize(repetition+10);
966 mol->Trajectories[neues].U.resize(repetition+10);
967 mol->Trajectories[neues].F.resize(repetition+10);
968 }
969
970 // put into trajectories list
971 for (int d=0;d<NDIM;d++)
972 mol->Trajectories[neues].R.at(repetition).x[d] = neues->x.x[d];
973
974 // parse velocities if present
975 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
976 neues->v.x[0] = 0.;
977 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
978 neues->v.x[1] = 0.;
979 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
980 neues->v.x[2] = 0.;
981 for (int d=0;d<NDIM;d++)
982 mol->Trajectories[neues].U.at(repetition).x[d] = neues->v.x[d];
983
984 // parse forces if present
985 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
986 value[0] = 0.;
987 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
988 value[1] = 0.;
989 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
990 value[2] = 0.;
991 for (int d=0;d<NDIM;d++)
992 mol->Trajectories[neues].F.at(repetition).x[d] = value[d];
993
994 // cout << "Parsed position of step " << (repetition) << ": (";
995 // for (int d=0;d<NDIM;d++)
996 // cout << mol->Trajectories[neues].R.at(repetition).x[d] << " "; // next step
997 // cout << ")\t(";
998 // for (int d=0;d<NDIM;d++)
999 // cout << mol->Trajectories[neues].U.at(repetition).x[d] << " "; // next step
1000 // cout << ")\t(";
1001 // for (int d=0;d<NDIM;d++)
1002 // cout << mol->Trajectories[neues].F.at(repetition).x[d] << " "; // next step
1003 // cout << ")" << endl;
1004 }
1005 }
1006 repetition++;
1007 }
1008 repetition--;
1009 cout << "Found " << repetition << " trajectory steps." << endl;
1010 mol->MDSteps = repetition;
1011 } else {
1012 // 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)
1013 repetition = 0;
1014 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
1015 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
1016 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
1017 repetition++;
1018 cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
1019 // parse in molecule coordinates
1020 for (int i=0; i < config::MaxTypes; i++) {
1021 sprintf(name,"Ion_Type%i",i+1);
1022 for(int j=0;j<No[i];j++) {
1023 sprintf(keyword,"%s_%i",name, j+1);
1024 if (repetition == 0) {
1025 neues = new atom();
1026 AtomList[i][j] = neues;
1027 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
1028 neues->type = elementhash[i]; // find element type
1029 } else
1030 neues = AtomList[i][j];
1031 // then parse for each atom the coordinates as often as present
1032 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
1033 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
1034 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
1035 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
1036 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
1037 neues->v.x[0] = 0.;
1038 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
1039 neues->v.x[1] = 0.;
1040 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
1041 neues->v.x[2] = 0.;
1042 // here we don't care if forces are present (last in trajectories is always equal to current position)
1043 neues->type = elementhash[i]; // find element type
1044 mol->AddAtom(neues);
1045 }
1046 }
1047 }
1048 // put atoms into the molecule in their original order
1049 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
1050 mol->AddAtom(runner->second);
1051 }
1052 }
1053 delete(FileBuffer);
1054};
1055
1056/** Initializes config file structure by loading elements from a give file with old pcp syntax.
1057 * \param *file input file stream being the opened config file with old pcp syntax
1058 * \param *periode pointer to a periodentafel class with all elements
1059 * \param *mol pointer to molecule containing all atoms of the molecule
1060 */
1061void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
1062{
1063 ifstream *file = new ifstream(filename);
1064 if (file == NULL) {
1065 cerr << "ERROR: config file " << filename << " missing!" << endl;
1066 return;
1067 }
1068 RetrieveConfigPathAndName(filename);
1069 // ParseParameters
1070
1071 /* Oeffne Hauptparameterdatei */
1072 int l, i, di;
1073 double a,b;
1074 double BoxLength[9];
1075 string zeile;
1076 string dummy;
1077 element *elementhash[128];
1078 int Z, No, AtomNo, found;
1079 int verbose = 0;
1080
1081 /* Namen einlesen */
1082
1083 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
1084 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
1085 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
1086 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
1087 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
1088 config::Seed = 1;
1089 config::DoOutOrbitals = 0;
1090 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
1091 if (config::DoOutVis < 0) config::DoOutVis = 0;
1092 if (config::DoOutVis > 1) config::DoOutVis = 1;
1093 config::VectorPlane = -1;
1094 config::VectorCut = 0.;
1095 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
1096 if (config::DoOutMes < 0) config::DoOutMes = 0;
1097 if (config::DoOutMes > 1) config::DoOutMes = 1;
1098 config::DoOutCurrent = 0;
1099 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
1100 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
1101 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
1102 config::CommonWannier = 0;
1103 config::SawtoothStart = 0.01;
1104
1105 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
1106 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
1107 ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
1108 ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
1109 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
1110 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
1111 config::EpsWannier = 1e-8;
1112
1113 // stop conditions
1114 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
1115 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
1116 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
1117
1118 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
1119 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
1120 ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
1121 ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
1122 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
1123 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
1124 config::MaxMinGapStopStep = 1;
1125
1126 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
1127 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
1128 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
1129 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
1130 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
1131 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
1132 config::InitMaxMinGapStopStep = 1;
1133
1134 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
1135 mol->cell_size[0] = BoxLength[0];
1136 mol->cell_size[1] = BoxLength[3];
1137 mol->cell_size[2] = BoxLength[4];
1138 mol->cell_size[3] = BoxLength[6];
1139 mol->cell_size[4] = BoxLength[7];
1140 mol->cell_size[5] = BoxLength[8];
1141 if (1) fprintf(stderr,"\n");
1142 config::DoPerturbation = 0;
1143 config::DoFullCurrent = 0;
1144
1145 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
1146 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
1147 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
1148 if (config::Lev0Factor < 2) {
1149 config::Lev0Factor = 2;
1150 }
1151 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
1152 if (di >= 0 && di < 2) {
1153 config::RiemannTensor = di;
1154 } else {
1155 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
1156 exit(1);
1157 }
1158 switch (config::RiemannTensor) {
1159 case 0: //UseNoRT
1160 if (config::MaxLevel < 2) {
1161 config::MaxLevel = 2;
1162 }
1163 config::LevRFactor = 2;
1164 config::RTActualUse = 0;
1165 break;
1166 case 1: // UseRT
1167 if (config::MaxLevel < 3) {
1168 config::MaxLevel = 3;
1169 }
1170 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
1171 if (config::RiemannLevel < 2) {
1172 config::RiemannLevel = 2;
1173 }
1174 if (config::RiemannLevel > config::MaxLevel-1) {
1175 config::RiemannLevel = config::MaxLevel-1;
1176 }
1177 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
1178 if (config::LevRFactor < 2) {
1179 config::LevRFactor = 2;
1180 }
1181 config::Lev0Factor = 2;
1182 config::RTActualUse = 2;
1183 break;
1184 }
1185 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
1186 if (di >= 0 && di < 2) {
1187 config::PsiType = di;
1188 } else {
1189 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
1190 exit(1);
1191 }
1192 switch (config::PsiType) {
1193 case 0: // SpinDouble
1194 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
1195 config::AddPsis = 0;
1196 break;
1197 case 1: // SpinUpDown
1198 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
1199 ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
1200 ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
1201 config::AddPsis = 0;
1202 break;
1203 }
1204
1205 // IonsInitRead
1206
1207 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
1208 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
1209 config::RelativeCoord = 0;
1210 config::StructOpt = 0;
1211
1212 // Routine from builder.cpp
1213
1214
1215 for (i=MAX_ELEMENTS;i--;)
1216 elementhash[i] = NULL;
1217 cout << Verbose(0) << "Parsing Ions ..." << endl;
1218 No=0;
1219 found = 0;
1220 while (getline(*file,zeile,'\n')) {
1221 if (zeile.find("Ions_Data") == 0) {
1222 cout << Verbose(1) << "found Ions_Data...begin parsing" << endl;
1223 found ++;
1224 }
1225 if (found > 0) {
1226 if (zeile.find("Ions_Data") == 0)
1227 getline(*file,zeile,'\n'); // read next line and parse this one
1228 istringstream input(zeile);
1229 input >> AtomNo; // number of atoms
1230 input >> Z; // atomic number
1231 input >> a;
1232 input >> l;
1233 input >> l;
1234 input >> b; // element mass
1235 elementhash[No] = periode->FindElement(Z);
1236 cout << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
1237 for(i=0;i<AtomNo;i++) {
1238 if (!getline(*file,zeile,'\n')) {// parse on and on
1239 cout << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
1240 // return 1;
1241 } else {
1242 //cout << Verbose(2) << "Reading line: " << zeile << endl;
1243 }
1244 istringstream input2(zeile);
1245 atom *neues = new atom();
1246 input2 >> neues->x.x[0]; // x
1247 input2 >> neues->x.x[1]; // y
1248 input2 >> neues->x.x[2]; // z
1249 input2 >> l;
1250 neues->type = elementhash[No]; // find element type
1251 mol->AddAtom(neues);
1252 }
1253 No++;
1254 }
1255 }
1256 file->close();
1257 delete(file);
1258};
1259
1260/** Stores all elements of config structure from which they can be re-read.
1261 * \param *filename name of file
1262 * \param *periode pointer to a periodentafel class with all elements
1263 * \param *mol pointer to molecule containing all atoms of the molecule
1264 */
1265bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const
1266{
1267 bool result = true;
1268 // bring MaxTypes up to date
1269 mol->CountElements();
1270 ofstream *output = NULL;
1271 output = new ofstream(filename, ios::out);
1272 if (output != NULL) {
1273 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
1274 *output << endl;
1275 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
1276 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
1277 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
1278 *output << endl;
1279 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
1280 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
1281 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
1282 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
1283 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
1284 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
1285 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
1286 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
1287 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
1288 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
1289 *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
1290 switch(Thermostat) {
1291 default:
1292 case None:
1293 break;
1294 case Woodcock:
1295 *output << ScaleTempStep;
1296 break;
1297 case Gaussian:
1298 *output << ScaleTempStep;
1299 break;
1300 case Langevin:
1301 *output << TempFrequency << "\t" << alpha;
1302 break;
1303 case Berendsen:
1304 *output << TempFrequency;
1305 break;
1306 case NoseHoover:
1307 *output << HooverMass;
1308 break;
1309 };
1310 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
1311 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
1312 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
1313 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
1314 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
1315 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
1316 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
1317 *output << endl;
1318 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
1319 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
1320 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
1321 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
1322 *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
1323 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
1324 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
1325 *output << endl;
1326 *output << "# Values specifying when to stop" << endl;
1327 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
1328 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1329 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1330 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
1331 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
1332 *output << endl;
1333 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
1334 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
1335 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1336 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1337 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
1338 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
1339 *output << endl;
1340 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
1341 *output << mol->cell_size[0] << "\t" << endl;
1342 *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
1343 *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
1344 // FIXME
1345 *output << endl;
1346 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
1347 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
1348 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
1349 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
1350 switch (config::RiemannTensor) {
1351 case 0: //UseNoRT
1352 break;
1353 case 1: // UseRT
1354 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
1355 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
1356 break;
1357 }
1358 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
1359 // write out both types for easier changing afterwards
1360 // switch (PsiType) {
1361 // case 0:
1362 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
1363 // break;
1364 // case 1:
1365 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
1366 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
1367 // break;
1368 // }
1369 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
1370 *output << endl;
1371 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
1372 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
1373 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
1374 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
1375 *output << "MaxTypes\t" << mol->ElementCount << "\t# maximum number of different ion types" << endl;
1376 *output << endl;
1377 result = result && mol->Checkout(output);
1378 if (mol->MDSteps <=1 )
1379 result = result && mol->Output(output);
1380 else
1381 result = result && mol->OutputTrajectories(output);
1382 output->close();
1383 output->clear();
1384 delete(output);
1385 return result;
1386 } else
1387 return false;
1388};
1389
1390/** Stores all elements in a MPQC input file.
1391 * Note that this format cannot be parsed again.
1392 * \param *filename name of file (without ".in" suffix!)
1393 * \param *mol pointer to molecule containing all atoms of the molecule
1394 */
1395bool config::SaveMPQC(const char *filename, molecule *mol) const
1396{
1397 int ElementNo = 0;
1398 int AtomNo;
1399 atom *Walker = NULL;
1400 element *runner = NULL;
1401 Vector *center = NULL;
1402 ofstream *output = NULL;
1403 stringstream *fname = NULL;
1404
1405 // first without hessian
1406 fname = new stringstream;
1407 *fname << filename << ".in";
1408 output = new ofstream(fname->str().c_str(), ios::out);
1409 *output << "% Created by MoleCuilder" << endl;
1410 *output << "mpqc: (" << endl;
1411 *output << "\tsavestate = no" << endl;
1412 *output << "\tdo_gradient = yes" << endl;
1413 *output << "\tmole<MBPT2>: (" << endl;
1414 *output << "\t\tmaxiter = 200" << endl;
1415 *output << "\t\tbasis = $:basis" << endl;
1416 *output << "\t\tmolecule = $:molecule" << endl;
1417 *output << "\t\treference<CLHF>: (" << endl;
1418 *output << "\t\t\tbasis = $:basis" << endl;
1419 *output << "\t\t\tmolecule = $:molecule" << endl;
1420 *output << "\t\t)" << endl;
1421 *output << "\t)" << endl;
1422 *output << ")" << endl;
1423 *output << "molecule<Molecule>: (" << endl;
1424 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1425 *output << "\t{ atoms geometry } = {" << endl;
1426 center = mol->DetermineCenterOfAll(output);
1427 // output of atoms
1428 runner = mol->elemente->start;
1429 while (runner->next != mol->elemente->end) { // go through every element
1430 runner = runner->next;
1431 if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
1432 ElementNo++;
1433 AtomNo = 0;
1434 Walker = mol->start;
1435 while (Walker->next != mol->end) { // go through every atom of this element
1436 Walker = Walker->next;
1437 if (Walker->type == runner) { // if this atom fits to element
1438 AtomNo++;
1439 *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;
1440 }
1441 }
1442 }
1443 }
1444 delete(center);
1445 *output << "\t}" << endl;
1446 *output << ")" << endl;
1447 *output << "basis<GaussianBasisSet>: (" << endl;
1448 *output << "\tname = \"" << basis << "\"" << endl;
1449 *output << "\tmolecule = $:molecule" << endl;
1450 *output << ")" << endl;
1451 output->close();
1452 delete(output);
1453 delete(fname);
1454
1455 // second with hessian
1456 fname = new stringstream;
1457 *fname << filename << ".hess.in";
1458 output = new ofstream(fname->str().c_str(), ios::out);
1459 *output << "% Created by MoleCuilder" << endl;
1460 *output << "mpqc: (" << endl;
1461 *output << "\tsavestate = no" << endl;
1462 *output << "\tdo_gradient = yes" << endl;
1463 *output << "\tmole<CLHF>: (" << endl;
1464 *output << "\t\tmaxiter = 200" << endl;
1465 *output << "\t\tbasis = $:basis" << endl;
1466 *output << "\t\tmolecule = $:molecule" << endl;
1467 *output << "\t)" << endl;
1468 *output << "\tfreq<MolecularFrequencies>: (" << endl;
1469 *output << "\t\tmolecule=$:molecule" << 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 = \"3-21G\"" << endl;
1498 *output << "\tmolecule = $:molecule" << endl;
1499 *output << ")" << endl;
1500 output->close();
1501 delete(output);
1502 delete(fname);
1503
1504 return true;
1505};
1506
1507/** Reads parameter from a parsed file.
1508 * The file is either parsed for a certain keyword or if null is given for
1509 * the value in row yth and column xth. If the keyword was necessity#critical,
1510 * then an error is thrown and the programme aborted.
1511 * \warning value is modified (both in contents and position)!
1512 * \param verbose 1 - print found value to stderr, 0 - don't
1513 * \param *file file to be parsed
1514 * \param name Name of value in file (at least 3 chars!)
1515 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1516 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1517 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1518 * counted from this unresetted position!)
1519 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1520 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1521 * \param type Type of the Parameter to be read
1522 * \param value address of the value to be read (must have been allocated)
1523 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1524 * \param critical necessity of this keyword being specified (optional, critical)
1525 * \return 1 - found, 0 - not found
1526 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1527 */
1528int 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) {
1529 int i,j; // loop variables
1530 int length = 0, maxlength = -1;
1531 long file_position = file->tellg(); // mark current position
1532 char *dummy1, *dummy, *free_dummy; // pointers in the line that is read in per step
1533 dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
1534
1535 //fprintf(stderr,"Parsing for %s\n",name);
1536 if (repetition == 0)
1537 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1538 return 0;
1539
1540 int line = 0; // marks line where parameter was found
1541 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1542 while((found != repetition)) {
1543 dummy1 = dummy = free_dummy;
1544 do {
1545 file->getline(dummy1, 256); // Read the whole line
1546 if (file->eof()) {
1547 if ((critical) && (found == 0)) {
1548 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1549 //Error(InitReading, name);
1550 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1551 exit(255);
1552 } else {
1553 //if (!sequential)
1554 file->clear();
1555 file->seekg(file_position, ios::beg); // rewind to start position
1556 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1557 return 0;
1558 }
1559 }
1560 line++;
1561 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1562
1563 // C++ getline removes newline at end, thus re-add
1564 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1565 i = strlen(dummy1);
1566 dummy1[i] = '\n';
1567 dummy1[i+1] = '\0';
1568 }
1569 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1570
1571 if (dummy1 == NULL) {
1572 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1573 } else {
1574 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1575 }
1576 // Seek for possible end of keyword on line if given ...
1577 if (name != NULL) {
1578 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1579 if (dummy == NULL) {
1580 dummy = strchr(dummy1, ' '); // if not found seek for space
1581 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1582 dummy++;
1583 }
1584 if (dummy == NULL) {
1585 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1586 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1587 //Free((void **)&free_dummy);
1588 //Error(FileOpenParams, NULL);
1589 } else {
1590 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1591 }
1592 } else dummy = dummy1;
1593 // ... and check if it is the keyword!
1594 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1595 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1596 found++; // found the parameter!
1597 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1598
1599 if (found == repetition) {
1600 for (i=0;i<xth;i++) { // i = rows
1601 if (type >= grid) {
1602 // grid structure means that grid starts on the next line, not right after keyword
1603 dummy1 = dummy = free_dummy;
1604 do {
1605 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1606 if (file->eof()) {
1607 if ((critical) && (found == 0)) {
1608 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1609 //Error(InitReading, name);
1610 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1611 exit(255);
1612 } else {
1613 //if (!sequential)
1614 file->clear();
1615 file->seekg(file_position, ios::beg); // rewind to start position
1616 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1617 return 0;
1618 }
1619 }
1620 line++;
1621 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1622 if (dummy1 == NULL){
1623 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1624 } else {
1625 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1626 }
1627 } else { // simple int, strings or doubles start in the same line
1628 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1629 dummy++;
1630 }
1631 // C++ getline removes newline at end, thus re-add
1632 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1633 j = strlen(dummy1);
1634 dummy1[j] = '\n';
1635 dummy1[j+1] = '\0';
1636 }
1637
1638 int start = (type >= grid) ? 0 : yth-1 ;
1639 for (j=start;j<yth;j++) { // j = columns
1640 // check for lower triangular area and upper triangular area
1641 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1642 *((double *)value) = 0.0;
1643 fprintf(stderr,"%f\t",*((double *)value));
1644 value = (void *)((long)value + sizeof(double));
1645 //value += sizeof(double);
1646 } else {
1647 // otherwise we must skip all interjacent tabs and spaces and find next value
1648 dummy1 = dummy;
1649 dummy = strchr(dummy1, '\t'); // seek for tab or space
1650 if (dummy == NULL)
1651 dummy = strchr(dummy1, ' '); // if not found seek for space
1652 if (dummy == NULL) { // if still zero returned ...
1653 dummy = strchr(dummy1, '\n'); // ... at line end then
1654 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1655 if (critical) {
1656 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1657 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1658 //return 0;
1659 exit(255);
1660 //Error(FileOpenParams, NULL);
1661 } else {
1662 //if (!sequential)
1663 file->clear();
1664 file->seekg(file_position, ios::beg); // rewind to start position
1665 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1666 return 0;
1667 }
1668 }
1669 } else {
1670 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1671 }
1672 if (*dummy1 == '#') {
1673 // found comment, skipping rest of line
1674 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1675 if (!sequential) { // here we need it!
1676 file->seekg(file_position, ios::beg); // rewind to start position
1677 }
1678 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1679 return 0;
1680 }
1681 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1682 switch(type) {
1683 case (row_int):
1684 *((int *)value) = atoi(dummy1);
1685 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1686 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1687 value = (void *)((long)value + sizeof(int));
1688 //value += sizeof(int);
1689 break;
1690 case(row_double):
1691 case(grid):
1692 case(lower_trigrid):
1693 case(upper_trigrid):
1694 *((double *)value) = atof(dummy1);
1695 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1696 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1697 value = (void *)((long)value + sizeof(double));
1698 //value += sizeof(double);
1699 break;
1700 case(double_type):
1701 *((double *)value) = atof(dummy1);
1702 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1703 //value += sizeof(double);
1704 break;
1705 case(int_type):
1706 *((int *)value) = atoi(dummy1);
1707 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1708 //value += sizeof(int);
1709 break;
1710 default:
1711 case(string_type):
1712 if (value != NULL) {
1713 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1714 maxlength = MAXSTRINGSIZE;
1715 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1716 strncpy((char *)value, dummy1, length); // copy as much
1717 ((char *)value)[length] = '\0'; // and set end marker
1718 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1719 //value += sizeof(char);
1720 } else {
1721 }
1722 break;
1723 }
1724 }
1725 while (*dummy == '\t')
1726 dummy++;
1727 }
1728 }
1729 }
1730 }
1731 }
1732 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1733 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
1734 if (!sequential) {
1735 file->clear();
1736 file->seekg(file_position, ios::beg); // rewind to start position
1737 }
1738 //fprintf(stderr, "End of Parsing\n\n");
1739
1740 return (found); // true if found, false if not
1741}
1742
1743
1744/** Reads parameter from a parsed file.
1745 * The file is either parsed for a certain keyword or if null is given for
1746 * the value in row yth and column xth. If the keyword was necessity#critical,
1747 * then an error is thrown and the programme aborted.
1748 * \warning value is modified (both in contents and position)!
1749 * \param verbose 1 - print found value to stderr, 0 - don't
1750 * \param *FileBuffer pointer to buffer structure
1751 * \param name Name of value in file (at least 3 chars!)
1752 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1753 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1754 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1755 * counted from this unresetted position!)
1756 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1757 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1758 * \param type Type of the Parameter to be read
1759 * \param value address of the value to be read (must have been allocated)
1760 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1761 * \param critical necessity of this keyword being specified (optional, critical)
1762 * \return 1 - found, 0 - not found
1763 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1764 */
1765int 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) {
1766 int i,j; // loop variables
1767 int length = 0, maxlength = -1;
1768 int OldCurrentLine = FileBuffer->CurrentLine;
1769 char *dummy1, *dummy; // pointers in the line that is read in per step
1770
1771 //fprintf(stderr,"Parsing for %s\n",name);
1772 if (repetition == 0)
1773 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1774 return 0;
1775
1776 int line = 0; // marks line where parameter was found
1777 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1778 while((found != repetition)) {
1779 dummy1 = dummy = NULL;
1780 do {
1781 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1782 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1783 if ((critical) && (found == 0)) {
1784 //Error(InitReading, name);
1785 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1786 exit(255);
1787 } else {
1788 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1789 return 0;
1790 }
1791 }
1792 if (dummy1 == NULL) {
1793 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1794 } else {
1795 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1796 }
1797 line++;
1798 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1799
1800 // Seek for possible end of keyword on line if given ...
1801 if (name != NULL) {
1802 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1803 if (dummy == NULL) {
1804 dummy = strchr(dummy1, ' '); // if not found seek for space
1805 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1806 dummy++;
1807 }
1808 if (dummy == NULL) {
1809 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1810 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1811 //Free((void **)&free_dummy);
1812 //Error(FileOpenParams, NULL);
1813 } else {
1814 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1815 }
1816 } else dummy = dummy1;
1817 // ... and check if it is the keyword!
1818 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1819 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1820 found++; // found the parameter!
1821 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1822
1823 if (found == repetition) {
1824 for (i=0;i<xth;i++) { // i = rows
1825 if (type >= grid) {
1826 // grid structure means that grid starts on the next line, not right after keyword
1827 dummy1 = dummy = NULL;
1828 do {
1829 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1830 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1831 if ((critical) && (found == 0)) {
1832 //Error(InitReading, name);
1833 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1834 exit(255);
1835 } else {
1836 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1837 return 0;
1838 }
1839 }
1840 if (dummy1 == NULL) {
1841 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1842 } else {
1843 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1844 }
1845 line++;
1846 } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
1847 dummy = dummy1;
1848 } else { // simple int, strings or doubles start in the same line
1849 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1850 dummy++;
1851 }
1852
1853 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
1854 // check for lower triangular area and upper triangular area
1855 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1856 *((double *)value) = 0.0;
1857 fprintf(stderr,"%f\t",*((double *)value));
1858 value = (void *)((long)value + sizeof(double));
1859 //value += sizeof(double);
1860 } else {
1861 // otherwise we must skip all interjacent tabs and spaces and find next value
1862 dummy1 = dummy;
1863 dummy = strchr(dummy1, '\t'); // seek for tab or space
1864 if (dummy == NULL)
1865 dummy = strchr(dummy1, ' '); // if not found seek for space
1866 if (dummy == NULL) { // if still zero returned ...
1867 dummy = strchr(dummy1, '\n'); // ... at line end then
1868 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1869 if (critical) {
1870 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1871 //return 0;
1872 exit(255);
1873 //Error(FileOpenParams, NULL);
1874 } else {
1875 if (!sequential) { // here we need it!
1876 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1877 }
1878 return 0;
1879 }
1880 }
1881 } else {
1882 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1883 }
1884 if (*dummy1 == '#') {
1885 // found comment, skipping rest of line
1886 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1887 if (!sequential) { // here we need it!
1888 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1889 }
1890 return 0;
1891 }
1892 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1893 switch(type) {
1894 case (row_int):
1895 *((int *)value) = atoi(dummy1);
1896 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1897 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1898 value = (void *)((long)value + sizeof(int));
1899 //value += sizeof(int);
1900 break;
1901 case(row_double):
1902 case(grid):
1903 case(lower_trigrid):
1904 case(upper_trigrid):
1905 *((double *)value) = atof(dummy1);
1906 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1907 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1908 value = (void *)((long)value + sizeof(double));
1909 //value += sizeof(double);
1910 break;
1911 case(double_type):
1912 *((double *)value) = atof(dummy1);
1913 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1914 //value += sizeof(double);
1915 break;
1916 case(int_type):
1917 *((int *)value) = atoi(dummy1);
1918 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1919 //value += sizeof(int);
1920 break;
1921 default:
1922 case(string_type):
1923 if (value != NULL) {
1924 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1925 maxlength = MAXSTRINGSIZE;
1926 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1927 strncpy((char *)value, dummy1, length); // copy as much
1928 ((char *)value)[length] = '\0'; // and set end marker
1929 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1930 //value += sizeof(char);
1931 } else {
1932 }
1933 break;
1934 }
1935 }
1936 while (*dummy == '\t')
1937 dummy++;
1938 }
1939 }
1940 }
1941 }
1942 }
1943 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1944 if (!sequential) {
1945 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1946 }
1947 //fprintf(stderr, "End of Parsing\n\n");
1948
1949 return (found); // true if found, false if not
1950}
Note: See TracBrowser for help on using the repository browser.