source: src/config.cpp@ 14de469

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

-initial commit
-Minimum set of files needed from ESPACK SVN repository
-Switch to three tantamount package parts instead of all relating to pcp (as at some time Ralf's might find inclusion as well)

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