source: src/config.cpp@ d2a294

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 d2a294 was c750cc, checked in by Frederik Heber <heber@…>, 17 years ago

char lengths of 255 and MAXDUMMYSTRING replaced with define MAXSTRINGSIZE in molecuilder and pcp

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