source: src/config.cpp@ aa5702

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

corrected molecule::VerletForceIntegration() and analyzer creates data and plot file for shielding values

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