source: src/config.cpp@ b6d8a9

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 b6d8a9 was 36ec71, checked in by Frederik Heber <heber@…>, 16 years ago

Merge branch 'master' into ConcaveHull

Conflicts:

molecuilder/src/analyzer.cpp
molecuilder/src/bond.cpp
molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/datacreator.cpp
molecuilder/src/datacreator.hpp
molecuilder/src/defs.hpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/joiner.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp
molecuilder/src/parser.cpp
molecuilder/src/parser.hpp

merges:

compilation fixes:

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