source: src/config.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 99.6 KB
Line 
1/** \file config.cpp
2 *
3 * Function implementations for the class config.
4 *
5 */
6
7// include config.h
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include "Helpers/MemDebug.hpp"
13
14#include <stdio.h>
15#include <cstring>
16
17#include "atom.hpp"
18#include "bond.hpp"
19#include "bondgraph.hpp"
20#include "config.hpp"
21#include "ConfigFileBuffer.hpp"
22#include "element.hpp"
23#include "Helpers/helpers.hpp"
24#include "Helpers/Info.hpp"
25#include "lists.hpp"
26#include "Helpers/Verbose.hpp"
27#include "Helpers/Log.hpp"
28#include "molecule.hpp"
29#include "molecule.hpp"
30#include "periodentafel.hpp"
31#include "ThermoStatContainer.hpp"
32#include "World.hpp"
33#include "LinearAlgebra/Matrix.hpp"
34#include "Box.hpp"
35
36/************************************* Functions for class config ***************************/
37
38/** Constructor for config file class.
39 */
40config::config() :
41 BG(NULL),
42 Thermostats(0),
43 PsiType(0),
44 MaxPsiDouble(0),
45 PsiMaxNoUp(0),
46 PsiMaxNoDown(0),
47 MaxMinStopStep(1),
48 InitMaxMinStopStep(1),
49 ProcPEGamma(8),
50 ProcPEPsi(1),
51 configname(NULL),
52 FastParsing(false),
53 Deltat(0.01),
54 basis(""),
55 databasepath(NULL),
56 DoConstrainedMD(0),
57 MaxOuterStep(0),
58 mainname(NULL),
59 defaultpath(NULL),
60 pseudopotpath(NULL),
61 DoOutVis(0),
62 DoOutMes(1),
63 DoOutNICS(0),
64 DoOutOrbitals(0),
65 DoOutCurrent(0),
66 DoFullCurrent(0),
67 DoPerturbation(0),
68 DoWannier(0),
69 CommonWannier(0),
70 SawtoothStart(0.01),
71 VectorPlane(0),
72 VectorCut(0.),
73 UseAddGramSch(1),
74 Seed(1),
75 OutVisStep(10),
76 OutSrcStep(5),
77 MaxPsiStep(0),
78 EpsWannier(1e-7),
79 MaxMinStep(100),
80 RelEpsTotalEnergy(1e-7),
81 RelEpsKineticEnergy(1e-5),
82 MaxMinGapStopStep(0),
83 MaxInitMinStep(100),
84 InitRelEpsTotalEnergy(1e-5),
85 InitRelEpsKineticEnergy(1e-4),
86 InitMaxMinGapStopStep(0),
87 ECut(128.),
88 MaxLevel(5),
89 RiemannTensor(0),
90 LevRFactor(0),
91 RiemannLevel(0),
92 Lev0Factor(2),
93 RTActualUse(0),
94 AddPsis(0),
95 RCut(20.),
96 StructOpt(0),
97 IsAngstroem(1),
98 RelativeCoord(0),
99 MaxTypes(0)
100{
101 mainname = new char[MAXSTRINGSIZE];
102 defaultpath = new char[MAXSTRINGSIZE];
103 pseudopotpath = new char[MAXSTRINGSIZE];
104 databasepath = new char[MAXSTRINGSIZE];
105 configname = new char[MAXSTRINGSIZE];
106 Thermostats = new ThermoStatContainer();
107 strcpy(mainname,"pcp");
108 strcpy(defaultpath,"not specified");
109 strcpy(pseudopotpath,"not specified");
110 configname[0]='\0';
111 basis = "3-21G";
112};
113
114/** Destructor for config file class.
115 */
116config::~config()
117{
118 delete[](mainname);
119 delete[](defaultpath);
120 delete[](pseudopotpath);
121 delete[](databasepath);
122 delete[](configname);
123 if (Thermostats != NULL)
124 delete(Thermostats);
125
126 if (BG != NULL)
127 delete(BG);
128};
129
130/** Displays menu for editing each entry of the config file.
131 * Nothing fancy here, just lots of Log() << Verbose(0)s for the menu and a switch/case
132 * for each entry of the config file structure.
133 */
134void config::Edit()
135{
136 char choice;
137
138 do {
139 DoLog(0) && (Log() << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl);
140 DoLog(0) && (Log() << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl);
141 DoLog(0) && (Log() << Verbose(0) << " B - Default path (for runtime files)" << endl);
142 DoLog(0) && (Log() << Verbose(0) << " C - Path of pseudopotential files" << endl);
143 DoLog(0) && (Log() << Verbose(0) << " D - Number of coefficient sharing processes" << endl);
144 DoLog(0) && (Log() << Verbose(0) << " E - Number of wave function sharing processes" << endl);
145 DoLog(0) && (Log() << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl);
146 DoLog(0) && (Log() << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl);
147 DoLog(0) && (Log() << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl);
148 DoLog(0) && (Log() << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl);
149 DoLog(0) && (Log() << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl);
150 DoLog(0) && (Log() << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl);
151 DoLog(0) && (Log() << 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);
152 DoLog(0) && (Log() << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl);
153 DoLog(0) && (Log() << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl);
154 DoLog(0) && (Log() << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl);
155 DoLog(0) && (Log() << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl);
156 DoLog(0) && (Log() << Verbose(0) << " Q - Initial integer value of random number generator" << endl);
157 DoLog(0) && (Log() << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl);
158 DoLog(0) && (Log() << Verbose(0) << " T - Output visual after ...th step" << endl);
159 DoLog(0) && (Log() << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl);
160 DoLog(0) && (Log() << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl);
161 DoLog(0) && (Log() << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl);
162 DoLog(0) && (Log() << Verbose(0) << " Z - Maximum number of minimization iterations" << endl);
163 DoLog(0) && (Log() << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl);
164 DoLog(0) && (Log() << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl);
165 DoLog(0) && (Log() << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl);
166 DoLog(0) && (Log() << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl);
167 DoLog(0) && (Log() << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl);
168 DoLog(0) && (Log() << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl);
169 DoLog(0) && (Log() << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl);
170// Log() << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
171 DoLog(0) && (Log() << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl);
172 DoLog(0) && (Log() << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl);
173 DoLog(0) && (Log() << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl);
174 DoLog(0) && (Log() << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl);
175 DoLog(0) && (Log() << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl);
176 DoLog(0) && (Log() << Verbose(0) << " p - Number of Riemann levels" << endl);
177 DoLog(0) && (Log() << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl);
178 DoLog(0) && (Log() << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl);
179 DoLog(0) && (Log() << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl);
180 DoLog(0) && (Log() << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl);
181 DoLog(0) && (Log() << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl);
182 DoLog(0) && (Log() << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl);
183 DoLog(0) && (Log() << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl);
184 DoLog(0) && (Log() << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl);
185 DoLog(0) && (Log() << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl);
186 DoLog(0) && (Log() << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl);
187 DoLog(0) && (Log() << Verbose(0) << "=========================================================" << endl);
188 DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
189 cin >> choice;
190
191 switch (choice) {
192 case 'A': // mainname
193 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::mainname << "\t new: ");
194 cin >> config::mainname;
195 break;
196 case 'B': // defaultpath
197 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::defaultpath << "\t new: ");
198 cin >> config::defaultpath;
199 break;
200 case 'C': // pseudopotpath
201 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ");
202 cin >> config::pseudopotpath;
203 break;
204
205 case 'D': // ProcPEGamma
206 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ");
207 cin >> config::ProcPEGamma;
208 break;
209 case 'E': // ProcPEPsi
210 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ");
211 cin >> config::ProcPEPsi;
212 break;
213 case 'F': // DoOutVis
214 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ");
215 cin >> config::DoOutVis;
216 break;
217 case 'G': // DoOutMes
218 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ");
219 cin >> config::DoOutMes;
220 break;
221 case 'H': // DoOutOrbitals
222 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ");
223 cin >> config::DoOutOrbitals;
224 break;
225 case 'I': // DoOutCurrent
226 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ");
227 cin >> config::DoOutCurrent;
228 break;
229 case 'J': // DoFullCurrent
230 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ");
231 cin >> config::DoFullCurrent;
232 break;
233 case 'K': // DoPerturbation
234 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ");
235 cin >> config::DoPerturbation;
236 break;
237 case 'L': // CommonWannier
238 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ");
239 cin >> config::CommonWannier;
240 break;
241 case 'M': // SawtoothStart
242 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ");
243 cin >> config::SawtoothStart;
244 break;
245 case 'N': // VectorPlane
246 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ");
247 cin >> config::VectorPlane;
248 break;
249 case 'O': // VectorCut
250 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorCut << "\t new: ");
251 cin >> config::VectorCut;
252 break;
253 case 'P': // UseAddGramSch
254 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ");
255 cin >> config::UseAddGramSch;
256 break;
257 case 'Q': // Seed
258 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Seed << "\t new: ");
259 cin >> config::Seed;
260 break;
261
262 case 'R': // MaxOuterStep
263 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ");
264 cin >> config::MaxOuterStep;
265 break;
266 case 'T': // OutVisStep
267 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ");
268 cin >> config::OutVisStep;
269 break;
270 case 'U': // OutSrcStep
271 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ");
272 cin >> config::OutSrcStep;
273 break;
274 case 'X': // MaxPsiStep
275 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ");
276 cin >> config::MaxPsiStep;
277 break;
278 case 'Y': // EpsWannier
279 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ");
280 cin >> config::EpsWannier;
281 break;
282
283 case 'Z': // MaxMinStep
284 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ");
285 cin >> config::MaxMinStep;
286 break;
287 case 'a': // RelEpsTotalEnergy
288 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ");
289 cin >> config::RelEpsTotalEnergy;
290 break;
291 case 'b': // RelEpsKineticEnergy
292 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ");
293 cin >> config::RelEpsKineticEnergy;
294 break;
295 case 'c': // MaxMinStopStep
296 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ");
297 cin >> config::MaxMinStopStep;
298 break;
299 case 'e': // MaxInitMinStep
300 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ");
301 cin >> config::MaxInitMinStep;
302 break;
303 case 'f': // InitRelEpsTotalEnergy
304 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ");
305 cin >> config::InitRelEpsTotalEnergy;
306 break;
307 case 'g': // InitRelEpsKineticEnergy
308 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ");
309 cin >> config::InitRelEpsKineticEnergy;
310 break;
311 case 'h': // InitMaxMinStopStep
312 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ");
313 cin >> config::InitMaxMinStopStep;
314 break;
315
316// case 'j': // BoxLength
317// Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
318// double * const cell_size = World::getInstance().getDomain();
319// for (int i=0;i<6;i++) {
320// Log() << Verbose(0) << "Cell size" << i << ": ";
321// cin >> cell_size[i];
322// }
323// break;
324
325 case 'k': // ECut
326 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ECut << "\t new: ");
327 cin >> config::ECut;
328 break;
329 case 'l': // MaxLevel
330 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ");
331 cin >> config::MaxLevel;
332 break;
333 case 'm': // RiemannTensor
334 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ");
335 cin >> config::RiemannTensor;
336 break;
337 case 'n': // LevRFactor
338 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ");
339 cin >> config::LevRFactor;
340 break;
341 case 'o': // RiemannLevel
342 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ");
343 cin >> config::RiemannLevel;
344 break;
345 case 'p': // Lev0Factor
346 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ");
347 cin >> config::Lev0Factor;
348 break;
349 case 'r': // RTActualUse
350 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ");
351 cin >> config::RTActualUse;
352 break;
353 case 's': // PsiType
354 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiType << "\t new: ");
355 cin >> config::PsiType;
356 break;
357 case 't': // MaxPsiDouble
358 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ");
359 cin >> config::MaxPsiDouble;
360 break;
361 case 'u': // PsiMaxNoUp
362 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ");
363 cin >> config::PsiMaxNoUp;
364 break;
365 case 'v': // PsiMaxNoDown
366 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ");
367 cin >> config::PsiMaxNoDown;
368 break;
369 case 'w': // AddPsis
370 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::AddPsis << "\t new: ");
371 cin >> config::AddPsis;
372 break;
373
374 case 'x': // RCut
375 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RCut << "\t new: ");
376 cin >> config::RCut;
377 break;
378 case 'y': // StructOpt
379 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::StructOpt << "\t new: ");
380 cin >> config::StructOpt;
381 break;
382 case 'z': // IsAngstroem
383 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ");
384 cin >> config::IsAngstroem;
385 break;
386 case 'i': // RelativeCoord
387 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ");
388 cin >> config::RelativeCoord;
389 break;
390 };
391 } while (choice != 'q');
392};
393
394/** Tests whether a given configuration file adhears to old or new syntax.
395 * \param *filename filename of config file to be tested
396 * \param *periode pointer to a periodentafel class with all elements
397 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
398 */
399int config::TestSyntax(const char * const filename, const periodentafel * const periode) const
400{
401 int test;
402 ifstream file(filename);
403
404 // search file for keyword: ProcPEGamma (new syntax)
405 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
406 file.close();
407 return 1;
408 }
409 // search file for keyword: ProcsGammaPsi (old syntax)
410 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
411 file.close();
412 return 0;
413 }
414 file.close();
415 return -1;
416}
417
418/** Returns private config::IsAngstroem.
419 * \return IsAngstroem
420 */
421bool config::GetIsAngstroem() const
422{
423 return (IsAngstroem == 1);
424};
425
426/** Returns private config::*defaultpath.
427 * \return *defaultpath
428 */
429char * config::GetDefaultPath() const
430{
431 return defaultpath;
432};
433
434
435/** Returns private config::*defaultpath.
436 * \return *defaultpath
437 */
438void config::SetDefaultPath(const char * const path)
439{
440 strcpy(defaultpath, path);
441};
442
443/** Loads a molecule from a ConfigFileBuffer.
444 * \param *mol molecule to load
445 * \param *FileBuffer ConfigFileBuffer to use
446 * \param *periode periodentafel for finding elements
447 * \param FastParsing whether to parse trajectories or not
448 */
449void LoadMolecule(molecule * const &mol, struct ConfigFileBuffer * const &FileBuffer, const periodentafel * const periode, const bool FastParsing)
450{
451 int MaxTypes = 0;
452 const element *elementhash[MAX_ELEMENTS];
453 char name[MAX_ELEMENTS];
454 char keyword[MAX_ELEMENTS];
455 int Z = -1;
456 int No[MAX_ELEMENTS];
457 int verbose = 0;
458 double value[3];
459
460 if (mol == NULL) {
461 DoeLog(0) && (eLog()<< Verbose(0) << "Molecule is not allocated in LoadMolecule(), exit.");
462 performCriticalExit();
463 }
464
465 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
466 if (MaxTypes == 0) {
467 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms according to MaxTypes in this config file." << endl);
468 //performCriticalExit();
469 } else {
470 // prescan number of ions per type
471 DoLog(0) && (Log() << Verbose(0) << "Prescanning ions per type: " << endl);
472 int NoAtoms = 0;
473 for (int i=0; i < MaxTypes; i++) {
474 sprintf(name,"Ion_Type%i",i+1);
475 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
476 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
477 elementhash[i] = periode->FindElement(Z);
478 DoLog(1) && (Log() << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl);
479 NoAtoms += No[i];
480 }
481 int repetition = 0; // which repeated keyword shall be read
482
483 // sort the lines via the LineMapping
484 sprintf(name,"Ion_Type%i",MaxTypes);
485 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
486 DoeLog(0) && (eLog()<< Verbose(0) << "There are no atoms in the config file!" << endl);
487 performCriticalExit();
488 return;
489 }
490 FileBuffer->CurrentLine++;
491 //Log() << Verbose(0) << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
492 FileBuffer->MapIonTypesInBuffer(NoAtoms);
493 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
494 // Log() << Verbose(0) << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
495 //}
496
497 map<int, atom *> AtomList[MaxTypes];
498 map<int, atom *> LinearList;
499 atom *neues = NULL;
500 Vector position;
501 if (!FastParsing) {
502 // parse in trajectories
503 bool status = true;
504 while (status) {
505 DoLog(0) && (Log() << Verbose(0) << "Currently parsing MD step " << repetition << "." << endl);
506 for (int i=0; i < MaxTypes; i++) {
507 sprintf(name,"Ion_Type%i",i+1);
508 for(int j=0;j<No[i];j++) {
509 sprintf(keyword,"%s_%i",name, j+1);
510 if (repetition == 0) {
511 neues = World::getInstance().createAtom();
512 AtomList[i][j] = neues;
513 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
514 neues->setType(elementhash[i]); // find element type
515 } else
516 neues = AtomList[i][j];
517 status = (status &&
518 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &position[0], 1, (repetition == 0) ? critical : optional) &&
519 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &position[1], 1, (repetition == 0) ? critical : optional) &&
520 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &position[2], 1, (repetition == 0) ? critical : optional) &&
521 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
522 if (!status)
523 break;
524 neues ->setPosition(position);
525
526 // check size of vectors
527 if (neues->Trajectory.R.size() <= (unsigned int)(repetition)) {
528 //Log() << Verbose(0) << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
529 neues->Trajectory.R.resize(repetition+10);
530 neues->Trajectory.U.resize(repetition+10);
531 neues->Trajectory.F.resize(repetition+10);
532 }
533
534 // put into trajectories list
535 for (int d=0;d<NDIM;d++)
536 neues->Trajectory.R.at(repetition)[d] = neues->at(d);
537
538 // parse velocities if present
539 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->AtomicVelocity[0], 1,optional))
540 neues->AtomicVelocity[0] = 0.;
541 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->AtomicVelocity[1], 1,optional))
542 neues->AtomicVelocity[1] = 0.;
543 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->AtomicVelocity[2], 1,optional))
544 neues->AtomicVelocity[2] = 0.;
545 for (int d=0;d<NDIM;d++)
546 neues->Trajectory.U.at(repetition)[d] = neues->AtomicVelocity[d];
547
548 // parse forces if present
549 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
550 value[0] = 0.;
551 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
552 value[1] = 0.;
553 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
554 value[2] = 0.;
555 for (int d=0;d<NDIM;d++)
556 neues->Trajectory.F.at(repetition)[d] = value[d];
557
558 // Log() << Verbose(0) << "Parsed position of step " << (repetition) << ": (";
559 // for (int d=0;d<NDIM;d++)
560 // Log() << Verbose(0) << neues->Trajectory.R.at(repetition).x[d] << " "; // next step
561 // Log() << Verbose(0) << ")\t(";
562 // for (int d=0;d<NDIM;d++)
563 // Log() << Verbose(0) << neues->Trajectory.U.at(repetition).x[d] << " "; // next step
564 // Log() << Verbose(0) << ")\t(";
565 // for (int d=0;d<NDIM;d++)
566 // Log() << Verbose(0) << neues->Trajectory.F.at(repetition).x[d] << " "; // next step
567 // Log() << Verbose(0) << ")" << endl;
568 }
569 }
570 repetition++;
571 }
572 repetition--;
573 DoLog(0) && (Log() << Verbose(0) << "Found " << repetition << " trajectory steps." << endl);
574 if (repetition <= 1) // if onyl one step, desactivate use of trajectories
575 mol->MDSteps = 0;
576 else
577 mol->MDSteps = repetition;
578 } else {
579 // 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)
580 repetition = 0;
581 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
582 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
583 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
584 repetition++;
585 DoLog(0) && (Log() << Verbose(0) << "I found " << repetition << " times the keyword Ion_Type1_1." << endl);
586 // parse in molecule coordinates
587 for (int i=0; i < MaxTypes; i++) {
588 sprintf(name,"Ion_Type%i",i+1);
589 for(int j=0;j<No[i];j++) {
590 sprintf(keyword,"%s_%i",name, j+1);
591 if (repetition == 0) {
592 neues = World::getInstance().createAtom();
593 AtomList[i][j] = neues;
594 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
595 neues->setType(elementhash[i]); // find element type
596 } else
597 neues = AtomList[i][j];
598 // then parse for each atom the coordinates as often as present
599 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &position[0], repetition,critical);
600 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &position[1], repetition,critical);
601 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &position[2], repetition,critical);
602 neues->setPosition(position);
603 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
604 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->AtomicVelocity[0], repetition,optional))
605 neues->AtomicVelocity[0] = 0.;
606 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->AtomicVelocity[1], repetition,optional))
607 neues->AtomicVelocity[1] = 0.;
608 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->AtomicVelocity[2], repetition,optional))
609 neues->AtomicVelocity[2] = 0.;
610 // here we don't care if forces are present (last in trajectories is always equal to current position)
611 neues->setType(elementhash[i]); // find element type
612 mol->AddAtom(neues);
613 }
614 }
615 }
616 // put atoms into the molecule in their original order
617 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
618 mol->AddAtom(runner->second);
619 }
620 }
621};
622
623
624/** Initializes config file structure by loading elements from a give file.
625 * \param *file input file stream being the opened config file
626 * \param BondGraphFileName file name of the bond length table file, if string is left blank, no table is parsed.
627 * \param *periode pointer to a periodentafel class with all elements
628 * \param *&MolList pointer to MoleculeListClass, on return containing all parsed molecules in system
629 */
630void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
631{
632 molecule *mol = World::getInstance().createMolecule();
633 ifstream *file = new ifstream(filename);
634 if (file == NULL) {
635 DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
636 return;
637 }
638 file->close();
639 delete(file);
640
641 // ParseParameterFile
642 class ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
643
644 /* Oeffne Hauptparameterdatei */
645 int di = 0;
646 double BoxLength[9];
647 string zeile;
648 string dummy;
649 int verbose = 0;
650
651 //TODO: This is actually sensible?: if (MaxOuterStep > 0)
652 ParseThermostats(FileBuffer);
653
654 /* Namen einlesen */
655
656 // 1. parse in options
657 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
658 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
659 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
660 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
661 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
662
663 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
664 config::Seed = 1;
665
666 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
667 config::DoOutOrbitals = 0;
668 } else {
669 if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
670 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
671 }
672 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
673 if (config::DoOutVis < 0) config::DoOutVis = 0;
674 if (config::DoOutVis > 1) config::DoOutVis = 1;
675 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
676 config::VectorPlane = -1;
677 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
678 config::VectorCut = 0.;
679 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
680 if (config::DoOutMes < 0) config::DoOutMes = 0;
681 if (config::DoOutMes > 1) config::DoOutMes = 1;
682 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
683 config::DoOutCurrent = 0;
684 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
685 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
686 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
687 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
688 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
689 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
690 config::DoWannier = 0;
691 } else {
692 if (config::DoWannier < 0) config::DoWannier = 0;
693 if (config::DoWannier > 1) config::DoWannier = 1;
694 }
695 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
696 config::CommonWannier = 0;
697 } else {
698 if (config::CommonWannier < 0) config::CommonWannier = 0;
699 if (config::CommonWannier > 4) config::CommonWannier = 4;
700 }
701 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
702 config::SawtoothStart = 0.01;
703 } else {
704 if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
705 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
706 }
707
708 if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
709 if (config::DoConstrainedMD < 0)
710 config::DoConstrainedMD = 0;
711 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
712 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
713 config::Deltat = 1;
714 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
715 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
716 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
717 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
718 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
719 config::EpsWannier = 1e-8;
720
721 // stop conditions
722 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
723 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
724 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
725
726 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
727 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
728 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
729 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
730 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
731 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
732 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
733 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
734
735 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
736 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
737 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
738 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
739 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
740 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
741 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
742 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
743
744 // Unit cell and magnetic field
745 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
746 double * cell_size = new double[6];
747 cell_size[0] = BoxLength[0];
748 cell_size[1] = BoxLength[3];
749 cell_size[2] = BoxLength[4];
750 cell_size[3] = BoxLength[6];
751 cell_size[4] = BoxLength[7];
752 cell_size[5] = BoxLength[8];
753 World::getInstance().setDomain(cell_size);
754 delete cell_size;
755 //if (1) fprintf(stderr,"\n");
756
757 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
758 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
759 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
760 config::DoFullCurrent = 0;
761 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
762 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
763 if (config::DoOutNICS < 0) config::DoOutNICS = 0;
764 if (config::DoOutNICS > 2) config::DoOutNICS = 2;
765 if (config::DoPerturbation == 0) {
766 config::DoFullCurrent = 0;
767 config::DoOutNICS = 0;
768 }
769
770 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
771 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
772 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
773 if (config::Lev0Factor < 2) {
774 config::Lev0Factor = 2;
775 }
776 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
777 if (di >= 0 && di < 2) {
778 config::RiemannTensor = di;
779 } else {
780 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
781 exit(1);
782 }
783 switch (config::RiemannTensor) {
784 case 0: //UseNoRT
785 if (config::MaxLevel < 2) {
786 config::MaxLevel = 2;
787 }
788 config::LevRFactor = 2;
789 config::RTActualUse = 0;
790 break;
791 case 1: // UseRT
792 if (config::MaxLevel < 3) {
793 config::MaxLevel = 3;
794 }
795 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
796 if (config::RiemannLevel < 2) {
797 config::RiemannLevel = 2;
798 }
799 if (config::RiemannLevel > config::MaxLevel-1) {
800 config::RiemannLevel = config::MaxLevel-1;
801 }
802 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
803 if (config::LevRFactor < 2) {
804 config::LevRFactor = 2;
805 }
806 config::Lev0Factor = 2;
807 config::RTActualUse = 2;
808 break;
809 }
810 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
811 if (di >= 0 && di < 2) {
812 config::PsiType = di;
813 } else {
814 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
815 exit(1);
816 }
817 switch (config::PsiType) {
818 case 0: // SpinDouble
819 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
820 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
821 break;
822 case 1: // SpinUpDown
823 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
824 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
825 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
826 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
827 break;
828 }
829
830 // IonsInitRead
831
832 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
833 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
834 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
835 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
836 config::RelativeCoord = 0;
837 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
838 config::StructOpt = 0;
839
840 // 2. parse the bond graph file if given
841 if (BG == NULL) {
842 BG = new BondGraph(IsAngstroem);
843 if (BG->LoadBondLengthTable(BondGraphFileName)) {
844 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
845 } else {
846 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
847 }
848 }
849
850 // 3. parse the molecule in
851 LoadMolecule(mol, FileBuffer, periode, FastParsing);
852 mol->SetNameFromFilename(filename);
853 mol->ActiveFlag = true;
854 MolList->insert(mol);
855
856 // 4. dissect the molecule into connected subgraphs
857 // don't do this here ...
858 //MolList->DissectMoleculeIntoConnectedSubgraphs(mol,this);
859 //delete(mol);
860
861 delete(FileBuffer);
862};
863
864/** Initializes config file structure by loading elements from a give file with old pcp syntax.
865 * \param *file input file stream being the opened config file with old pcp syntax
866 * \param BondGraphFileName file name of the bond length table file, if string is left blank, no table is parsed.
867 * \param *periode pointer to a periodentafel class with all elements
868 * \param *&MolList pointer to MoleculeListClass, on return containing all parsed molecules in system
869 */
870void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
871{
872 molecule *mol = World::getInstance().createMolecule();
873 ifstream *file = new ifstream(filename);
874 if (file == NULL) {
875 DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
876 return;
877 }
878 // ParseParameters
879
880 /* Oeffne Hauptparameterdatei */
881 int l = 0;
882 int i = 0;
883 int di = 0;
884 double a = 0.;
885 double b = 0.;
886 double BoxLength[9];
887 string zeile;
888 string dummy;
889 const element *elementhash[128];
890 int Z = -1;
891 int No = -1;
892 int AtomNo = -1;
893 int found = 0;
894 int verbose = 0;
895
896 mol->ActiveFlag = true;
897 MolList->insert(mol);
898 /* Namen einlesen */
899
900 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
901 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
902 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
903 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
904 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
905 config::Seed = 1;
906 config::DoOutOrbitals = 0;
907 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
908 if (config::DoOutVis < 0) config::DoOutVis = 0;
909 if (config::DoOutVis > 1) config::DoOutVis = 1;
910 config::VectorPlane = -1;
911 config::VectorCut = 0.;
912 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
913 if (config::DoOutMes < 0) config::DoOutMes = 0;
914 if (config::DoOutMes > 1) config::DoOutMes = 1;
915 config::DoOutCurrent = 0;
916 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
917 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
918 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
919 config::CommonWannier = 0;
920 config::SawtoothStart = 0.01;
921
922 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
923 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
924 ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
925 ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
926 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
927 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(Thermostats->ScaleTempStep), 1, optional);
928 config::EpsWannier = 1e-8;
929
930 // stop conditions
931 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
932 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
933 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
934
935 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
936 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
937 ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
938 ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
939 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
940 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
941 config::MaxMinGapStopStep = 1;
942
943 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
944 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
945 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
946 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
947 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
948 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
949 config::InitMaxMinGapStopStep = 1;
950
951 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
952 double * cell_size = new double[6];
953 cell_size[0] = BoxLength[0];
954 cell_size[1] = BoxLength[3];
955 cell_size[2] = BoxLength[4];
956 cell_size[3] = BoxLength[6];
957 cell_size[4] = BoxLength[7];
958 cell_size[5] = BoxLength[8];
959 World::getInstance().setDomain(cell_size);
960 delete[] cell_size;
961 if (1) fprintf(stderr,"\n");
962 config::DoPerturbation = 0;
963 config::DoFullCurrent = 0;
964
965 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
966 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
967 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
968 if (config::Lev0Factor < 2) {
969 config::Lev0Factor = 2;
970 }
971 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
972 if (di >= 0 && di < 2) {
973 config::RiemannTensor = di;
974 } else {
975 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
976 exit(1);
977 }
978 switch (config::RiemannTensor) {
979 case 0: //UseNoRT
980 if (config::MaxLevel < 2) {
981 config::MaxLevel = 2;
982 }
983 config::LevRFactor = 2;
984 config::RTActualUse = 0;
985 break;
986 case 1: // UseRT
987 if (config::MaxLevel < 3) {
988 config::MaxLevel = 3;
989 }
990 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
991 if (config::RiemannLevel < 2) {
992 config::RiemannLevel = 2;
993 }
994 if (config::RiemannLevel > config::MaxLevel-1) {
995 config::RiemannLevel = config::MaxLevel-1;
996 }
997 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
998 if (config::LevRFactor < 2) {
999 config::LevRFactor = 2;
1000 }
1001 config::Lev0Factor = 2;
1002 config::RTActualUse = 2;
1003 break;
1004 }
1005 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
1006 if (di >= 0 && di < 2) {
1007 config::PsiType = di;
1008 } else {
1009 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
1010 exit(1);
1011 }
1012 switch (config::PsiType) {
1013 case 0: // SpinDouble
1014 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
1015 config::AddPsis = 0;
1016 break;
1017 case 1: // SpinUpDown
1018 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
1019 ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
1020 ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
1021 config::AddPsis = 0;
1022 break;
1023 }
1024
1025 // IonsInitRead
1026
1027 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
1028 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
1029 config::RelativeCoord = 0;
1030 config::StructOpt = 0;
1031
1032
1033 // 2. parse the bond graph file if given
1034 BG = new BondGraph(IsAngstroem);
1035 if (BG->LoadBondLengthTable(BondGraphFileName)) {
1036 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
1037 } else {
1038 DoLog(0) && (Log() << Verbose(0) << "Bond length table loading failed." << endl);
1039 }
1040
1041 // Routine from builder.cpp
1042
1043 for (i=MAX_ELEMENTS;i--;)
1044 elementhash[i] = NULL;
1045 DoLog(0) && (Log() << Verbose(0) << "Parsing Ions ..." << endl);
1046 No=0;
1047 found = 0;
1048 while (getline(*file,zeile,'\n')) {
1049 if (zeile.find("Ions_Data") == 0) {
1050 DoLog(1) && (Log() << Verbose(1) << "found Ions_Data...begin parsing" << endl);
1051 found ++;
1052 }
1053 if (found > 0) {
1054 if (zeile.find("Ions_Data") == 0)
1055 getline(*file,zeile,'\n'); // read next line and parse this one
1056 istringstream input(zeile);
1057 input >> AtomNo; // number of atoms
1058 input >> Z; // atomic number
1059 input >> a;
1060 input >> l;
1061 input >> l;
1062 input >> b; // element mass
1063 elementhash[No] = periode->FindElement(Z);
1064 DoLog(1) && (Log() << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl);
1065 for(i=0;i<AtomNo;i++) {
1066 if (!getline(*file,zeile,'\n')) {// parse on and on
1067 DoLog(2) && (Log() << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl);
1068 // return 1;
1069 } else {
1070 //Log() << Verbose(2) << "Reading line: " << zeile << endl;
1071 }
1072 istringstream input2(zeile);
1073 atom *neues = World::getInstance().createAtom();
1074 double tmp;
1075 for (int j=0;j<NDIM;j++) {
1076 input2 >> tmp;
1077 neues->set(j,tmp);
1078 }
1079 input2 >> l;
1080 neues->setType(elementhash[No]); // find element type
1081 mol->AddAtom(neues);
1082 }
1083 No++;
1084 }
1085 }
1086 file->close();
1087 delete(file);
1088};
1089
1090/** Stores all elements of config structure from which they can be re-read.
1091 * \param *filename name of file
1092 * \param *periode pointer to a periodentafel class with all elements
1093 * \param *mol pointer to molecule containing all atoms of the molecule
1094 */
1095bool config::Save(const char * const filename, const periodentafel * const periode, molecule * const mol) const
1096{
1097 bool result = true;
1098 const Matrix &domain = World::getInstance().getDomain().getM();
1099 ofstream * const output = new ofstream(filename, ios::out);
1100 if (output != NULL) {
1101 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
1102 *output << endl;
1103 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
1104 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
1105 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
1106 *output << endl;
1107 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
1108 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
1109 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
1110 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
1111 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
1112 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
1113 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
1114 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
1115 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
1116 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
1117 *output << "Thermostat\t" << Thermostats->ThermostatNames[Thermostats->Thermostat] << "\t";
1118 switch(Thermostats->Thermostat) {
1119 default:
1120 case None:
1121 break;
1122 case Woodcock:
1123 *output << Thermostats->ScaleTempStep;
1124 break;
1125 case Gaussian:
1126 *output << Thermostats->ScaleTempStep;
1127 break;
1128 case Langevin:
1129 *output << Thermostats->TempFrequency << "\t" << Thermostats->alpha;
1130 break;
1131 case Berendsen:
1132 *output << Thermostats->TempFrequency;
1133 break;
1134 case NoseHoover:
1135 *output << Thermostats->HooverMass;
1136 break;
1137 };
1138 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
1139 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
1140 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
1141 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
1142 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
1143 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
1144 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
1145 *output << endl;
1146 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
1147 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
1148 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
1149 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
1150 *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
1151 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
1152 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
1153 *output << endl;
1154 *output << "# Values specifying when to stop" << endl;
1155 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
1156 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1157 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1158 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
1159 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
1160 *output << endl;
1161 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
1162 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
1163 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1164 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1165 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
1166 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
1167 *output << endl;
1168 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
1169 *output << domain.at(0,0) << "\t" << endl;
1170 *output << domain.at(1,0) << "\t" << domain.at(1,1) << "\t" << endl;
1171 *output << domain.at(2,0) << "\t" << domain.at(2,1) << "\t" << domain.at(2,2) << "\t" << endl;
1172 // FIXME
1173 *output << endl;
1174 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
1175 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
1176 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
1177 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
1178 switch (config::RiemannTensor) {
1179 case 0: //UseNoRT
1180 break;
1181 case 1: // UseRT
1182 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
1183 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
1184 break;
1185 }
1186 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
1187 // write out both types for easier changing afterwards
1188 // switch (PsiType) {
1189 // case 0:
1190 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
1191 // break;
1192 // case 1:
1193 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
1194 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
1195 // break;
1196 // }
1197 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
1198 *output << endl;
1199 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
1200 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
1201 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
1202 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
1203 *output << "MaxTypes\t" << mol->getElementCount() << "\t# maximum number of different ion types" << endl;
1204 *output << endl;
1205 result = result && mol->Checkout(output);
1206 if (mol->MDSteps <=1 )
1207 result = result && mol->Output(output);
1208 else
1209 result = result && mol->OutputTrajectories(output);
1210 output->close();
1211 output->clear();
1212 delete(output);
1213 return result;
1214 } else {
1215 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file:" << filename << endl);
1216 return false;
1217 }
1218};
1219
1220/** Stores all elements in a MPQC input file.
1221 * Note that this format cannot be parsed again.
1222 * \param *filename name of file (without ".in" suffix!)
1223 * \param *mol pointer to molecule containing all atoms of the molecule
1224 */
1225bool config::SaveMPQC(const char * const filename, const molecule * const mol) const
1226{
1227 int AtomNo = -1;
1228 Vector *center = NULL;
1229 ofstream *output = NULL;
1230
1231 // first without hessian
1232 {
1233 stringstream * const fname = new stringstream;;
1234 *fname << filename << ".in";
1235 output = new ofstream(fname->str().c_str(), ios::out);
1236 if (output == NULL) {
1237 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file:" << fname << endl);
1238 delete(fname);
1239 return false;
1240 }
1241 *output << "% Created by MoleCuilder" << endl;
1242 *output << "mpqc: (" << endl;
1243 *output << "\tsavestate = no" << endl;
1244 *output << "\tdo_gradient = yes" << endl;
1245 *output << "\tmole<MBPT2>: (" << endl;
1246 *output << "\t\tmaxiter = 200" << endl;
1247 *output << "\t\tbasis = $:basis" << endl;
1248 *output << "\t\tmolecule = $:molecule" << endl;
1249 *output << "\t\treference<CLHF>: (" << endl;
1250 *output << "\t\t\tbasis = $:basis" << endl;
1251 *output << "\t\t\tmolecule = $:molecule" << endl;
1252 *output << "\t\t)" << endl;
1253 *output << "\t)" << endl;
1254 *output << ")" << endl;
1255 *output << "molecule<Molecule>: (" << endl;
1256 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1257 *output << "\t{ atoms geometry } = {" << endl;
1258 center = mol->DetermineCenterOfAll();
1259 // output of atoms
1260 AtomNo = 0;
1261 mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
1262 delete(center);
1263 *output << "\t}" << endl;
1264 *output << ")" << endl;
1265 *output << "basis<GaussianBasisSet>: (" << endl;
1266 *output << "\tname = \"" << basis << "\"" << endl;
1267 *output << "\tmolecule = $:molecule" << endl;
1268 *output << ")" << endl;
1269 output->close();
1270 delete(output);
1271 delete(fname);
1272 }
1273
1274 // second with hessian
1275 {
1276 stringstream * const fname = new stringstream;
1277 *fname << filename << ".hess.in";
1278 output = new ofstream(fname->str().c_str(), ios::out);
1279 if (output == NULL) {
1280 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc hessian output file:" << fname << endl);
1281 delete(fname);
1282 return false;
1283 }
1284 *output << "% Created by MoleCuilder" << endl;
1285 *output << "mpqc: (" << endl;
1286 *output << "\tsavestate = no" << endl;
1287 *output << "\tdo_gradient = yes" << endl;
1288 *output << "\tmole<CLHF>: (" << endl;
1289 *output << "\t\tmaxiter = 200" << endl;
1290 *output << "\t\tbasis = $:basis" << endl;
1291 *output << "\t\tmolecule = $:molecule" << endl;
1292 *output << "\t)" << endl;
1293 *output << "\tfreq<MolecularFrequencies>: (" << endl;
1294 *output << "\t\tmolecule=$:molecule" << endl;
1295 *output << "\t)" << endl;
1296 *output << ")" << endl;
1297 *output << "molecule<Molecule>: (" << endl;
1298 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1299 *output << "\t{ atoms geometry } = {" << endl;
1300 center = mol->DetermineCenterOfAll();
1301 // output of atoms
1302 AtomNo = 0;
1303 mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
1304 delete(center);
1305 *output << "\t}" << endl;
1306 *output << ")" << endl;
1307 *output << "basis<GaussianBasisSet>: (" << endl;
1308 *output << "\tname = \"3-21G\"" << endl;
1309 *output << "\tmolecule = $:molecule" << endl;
1310 *output << ")" << endl;
1311 output->close();
1312 delete(output);
1313 delete(fname);
1314 }
1315
1316 return true;
1317};
1318
1319/** Stores all atoms from all molecules in a PDB input file.
1320 * Note that this format cannot be parsed again.
1321 * \param *filename name of file (without ".in" suffix!)
1322 * \param *MolList pointer to MoleculeListClass containing all atoms
1323 */
1324bool config::SavePDB(const char * const filename, const MoleculeListClass * const MolList) const
1325{
1326 int AtomNo = -1;
1327 int MolNo = 0;
1328 FILE *f = NULL;
1329
1330 char name[MAXSTRINGSIZE];
1331 strncpy(name, filename, MAXSTRINGSIZE-1);
1332 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
1333 f = fopen(name, "w" );
1334 if (f == NULL) {
1335 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
1336 return false;
1337 }
1338 fprintf(f, "# Created by MoleCuilder\n");
1339
1340 for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
1341 int *elementNo = new int[MAX_ELEMENTS];
1342 for (int i=0;i<MAX_ELEMENTS;i++)
1343 elementNo[i] = 0;
1344 AtomNo = 0;
1345 for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
1346 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->Z]);
1347 elementNo[(*iter)->getType()->Z] = (elementNo[(*iter)->getType()->Z]+1) % 100; // confine to two digits
1348 fprintf(f,
1349 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
1350 (*iter)->nr, /* atom serial number */
1351 name, /* atom name */
1352 (*MolRunner)->name, /* residue name */
1353 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
1354 MolNo, /* residue sequence number */
1355 (*iter)->at(0), /* position X in Angstroem */
1356 (*iter)->at(1), /* position Y in Angstroem */
1357 (*iter)->at(2), /* position Z in Angstroem */
1358 (double)(*iter)->getType()->Valence, /* occupancy */
1359 (double)(*iter)->getType()->NoValenceOrbitals, /* temperature factor */
1360 "0", /* segment identifier */
1361 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
1362 "0"); /* charge */
1363 AtomNo++;
1364 }
1365 delete[](elementNo);
1366 MolNo++;
1367 }
1368 fclose(f);
1369
1370 return true;
1371};
1372
1373/** Stores all atoms in a PDB input file.
1374 * Note that this format cannot be parsed again.
1375 * \param *filename name of file (without ".in" suffix!)
1376 * \param *mol pointer to molecule
1377 */
1378bool config::SavePDB(const char * const filename, const molecule * const mol) const
1379{
1380 int AtomNo = -1;
1381 FILE *f = NULL;
1382
1383 int *elementNo = new int[MAX_ELEMENTS];
1384 for (int i=0;i<MAX_ELEMENTS;i++)
1385 elementNo[i] = 0;
1386 char name[MAXSTRINGSIZE];
1387 strncpy(name, filename, MAXSTRINGSIZE-1);
1388 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
1389 f = fopen(name, "w" );
1390 if (f == NULL) {
1391 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
1392 delete[](elementNo);
1393 return false;
1394 }
1395 fprintf(f, "# Created by MoleCuilder\n");
1396
1397 AtomNo = 0;
1398 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
1399 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->Z]);
1400 elementNo[(*iter)->getType()->Z] = (elementNo[(*iter)->getType()->Z]+1) % 100; // confine to two digits
1401 fprintf(f,
1402 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
1403 (*iter)->nr, /* atom serial number */
1404 name, /* atom name */
1405 mol->name, /* residue name */
1406 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
1407 0, /* residue sequence number */
1408 (*iter)->at(0), /* position X in Angstroem */
1409 (*iter)->at(1), /* position Y in Angstroem */
1410 (*iter)->at(2), /* position Z in Angstroem */
1411 (double)(*iter)->getType()->Valence, /* occupancy */
1412 (double)(*iter)->getType()->NoValenceOrbitals, /* temperature factor */
1413 "0", /* segment identifier */
1414 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
1415 "0"); /* charge */
1416 AtomNo++;
1417 }
1418 fclose(f);
1419 delete[](elementNo);
1420
1421 return true;
1422};
1423
1424/** Stores all atoms in a TREMOLO data input file.
1425 * Note that this format cannot be parsed again.
1426 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
1427 * \param *filename name of file (without ".in" suffix!)
1428 * \param *mol pointer to molecule
1429 */
1430bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
1431{
1432 ofstream *output = NULL;
1433 stringstream * const fname = new stringstream;
1434
1435 *fname << filename << ".data";
1436 output = new ofstream(fname->str().c_str(), ios::out);
1437 if (output == NULL) {
1438 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
1439 delete(fname);
1440 return false;
1441 }
1442
1443 // scan maximum number of neighbours
1444 int MaxNeighbours = 0;
1445 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
1446 const int count = (*iter)->ListOfBonds.size();
1447 if (MaxNeighbours < count)
1448 MaxNeighbours = count;
1449 }
1450 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
1451
1452 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
1453 *output << (*iter)->nr << "\t";
1454 *output << (*iter)->getName() << "\t";
1455 *output << mol->name << "\t";
1456 *output << 0 << "\t";
1457 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
1458 *output << static_cast<double>((*iter)->getType()->Valence) << "\t";
1459 *output << (*iter)->getType()->getSymbol() << "\t";
1460 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
1461 *output << (*runner)->GetOtherAtom(*iter)->nr << "\t";
1462 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
1463 *output << "-\t";
1464 *output << endl;
1465 }
1466 output->flush();
1467 output->close();
1468 delete(output);
1469 delete(fname);
1470
1471 return true;
1472};
1473
1474/** Stores all atoms from all molecules in a TREMOLO data input file.
1475 * Note that this format cannot be parsed again.
1476 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
1477 * \param *filename name of file (without ".in" suffix!)
1478 * \param *MolList pointer to MoleculeListClass containing all atoms
1479 */
1480bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
1481{
1482 Info FunctionInfo(__func__);
1483 ofstream *output = NULL;
1484 stringstream * const fname = new stringstream;
1485
1486 *fname << filename << ".data";
1487 output = new ofstream(fname->str().c_str(), ios::out);
1488 if (output == NULL) {
1489 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
1490 delete(fname);
1491 return false;
1492 }
1493
1494 // scan maximum number of neighbours
1495 int MaxNeighbours = 0;
1496 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1497 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1498 const int count = (*iter)->ListOfBonds.size();
1499 if (MaxNeighbours < count)
1500 MaxNeighbours = count;
1501 }
1502 }
1503 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
1504
1505 // create global to local id map
1506 map<int, int> LocalNotoGlobalNoMap;
1507 {
1508 unsigned int MolCounter = 0;
1509 int AtomNo = 1;
1510 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1511 for(molecule::iterator AtomRunner = (*MolWalker)->begin(); AtomRunner != (*MolWalker)->end(); ++AtomRunner) {
1512 LocalNotoGlobalNoMap.insert( pair<int,int>((*AtomRunner)->getId(), AtomNo++) );
1513 }
1514 MolCounter++;
1515 }
1516 ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
1517 }
1518
1519 // write the file
1520 {
1521 int MolCounter = 0;
1522 int AtomNo = 0;
1523 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1524 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1525 *output << LocalNotoGlobalNoMap[ (*iter)->getId() ] << "\t";
1526 *output << (*iter)->getName() << "\t";
1527 *output << (*MolWalker)->name << "\t";
1528 *output << MolCounter+1 << "\t";
1529 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
1530 *output << (double)(*iter)->getType()->Valence << "\t";
1531 *output << (*iter)->getType()->getSymbol() << "\t";
1532 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
1533 *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom((*iter))->getId() ] << "\t";
1534 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
1535 *output << "-\t";
1536 *output << endl;
1537 AtomNo++;
1538 }
1539 MolCounter++;
1540 }
1541 }
1542
1543 // store & free
1544 output->flush();
1545 output->close();
1546 delete(output);
1547 delete(fname);
1548
1549 return true;
1550};
1551
1552
1553/** Tries given filename or standard on saving the config file.
1554 * \param *ConfigFileName name of file
1555 * \param *periode pointer to periodentafel structure with all the elements
1556 * \param *molecules list of molecules structure with all the atoms and coordinates
1557 */
1558void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
1559{
1560 char filename[MAXSTRINGSIZE];
1561 ofstream output;
1562 molecule *mol = NULL;
1563
1564 // first save as PDB data
1565 if (ConfigFileName != NULL)
1566 strcpy(filename, ConfigFileName);
1567 if (output == NULL)
1568 strcpy(filename,"main_pcp_linux");
1569 Log() << Verbose(0) << "Saving as pdb input ... " << endl;
1570 if (SavePDB(filename, molecules))
1571 Log() << Verbose(0) << "\t... done." << endl;
1572 else
1573 Log() << Verbose(0) << "\t... failed." << endl;
1574
1575 // then save as tremolo data file
1576 if (ConfigFileName != NULL)
1577 strcpy(filename, ConfigFileName);
1578 if (output == NULL)
1579 strcpy(filename,"main_pcp_linux");
1580 Log() << Verbose(0) << "Saving as tremolo data input ... " << endl;
1581 if (SaveTREMOLO(filename, molecules))
1582 Log() << Verbose(0) << "\t... done." << endl;
1583 else
1584 Log() << Verbose(0) << "\t... failed." << endl;
1585
1586 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1587 int N = molecules->ListOfMolecules.size();
1588 if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
1589 int *src = new int[N];
1590 N=0;
1591 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1592 src[N++] = (*ListRunner)->IndexNr;
1593 }
1594 mol = World::getInstance().createMolecule();
1595 mol->SetNameFromFilename(ConfigFileName);
1596 //mol->CalculateOrbitals(*this);
1597 delete[](src);
1598 } else {
1599 if (!molecules->ListOfMolecules.empty()) {
1600 mol = *(molecules->ListOfMolecules.begin());
1601 mol->doCountAtoms();
1602 //mol->CalculateOrbitals(*this);
1603 } else {
1604 DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
1605 }
1606 }
1607
1608 Log() << Verbose(0) << "Storing configuration ... " << endl;
1609 // get correct valence orbitals
1610 if (ConfigFileName != NULL) { // test the file name
1611 strcpy(filename, ConfigFileName);
1612 output.open(filename, ios::trunc);
1613 } else if (strlen(configname) != 0) {
1614 strcpy(filename, configname);
1615 output.open(configname, ios::trunc);
1616 } else {
1617 strcpy(filename, DEFAULTCONFIG);
1618 output.open(DEFAULTCONFIG, ios::trunc);
1619 }
1620 output.close();
1621 output.clear();
1622 Log() << Verbose(0) << "Saving of config file ... " << endl;
1623 if (Save(filename, periode, mol))
1624 Log() << Verbose(0) << "\t... successful." << endl;
1625 else
1626 Log() << Verbose(0) << "\t... failed." << endl;
1627
1628 // and save to xyz file
1629 if (ConfigFileName != NULL) {
1630 strcpy(filename, ConfigFileName);
1631 strcat(filename, ".xyz");
1632 output.open(filename, ios::trunc);
1633 }
1634 if (output == NULL) {
1635 strcpy(filename,"main_pcp_linux");
1636 strcat(filename, ".xyz");
1637 output.open(filename, ios::trunc);
1638 }
1639 Log() << Verbose(0) << "Saving of XYZ file ... " << endl;
1640 if (mol->MDSteps <= 1) {
1641 if (mol->OutputXYZ(&output))
1642 Log() << Verbose(0) << "\t... successful." << endl;
1643 else
1644 Log() << Verbose(0) << "\t... failed." << endl;
1645 } else {
1646 if (mol->OutputTrajectoriesXYZ(&output))
1647 Log() << Verbose(0) << "\t... successful." << endl;
1648 else
1649 Log() << Verbose(0) << "\t... failed." << endl;
1650 }
1651 output.close();
1652 output.clear();
1653
1654 // and save as MPQC configuration
1655 if (ConfigFileName != NULL)
1656 strcpy(filename, ConfigFileName);
1657 if (output == NULL)
1658 strcpy(filename,"main_pcp_linux");
1659 Log() << Verbose(0) << "Saving as mpqc input .. " << endl;
1660 if (SaveMPQC(filename, mol))
1661 Log() << Verbose(0) << "\t... done." << endl;
1662 else
1663 Log() << Verbose(0) << "\t... failed." << endl;
1664
1665 // don't destroy molecule as it contains all our atoms
1666 //World::getInstance().destroyMolecule(mol);
1667};
1668
1669/** Reads parameter from a parsed file.
1670 * The file is either parsed for a certain keyword or if null is given for
1671 * the value in row yth and column xth. If the keyword was necessity#critical,
1672 * then an error is thrown and the programme aborted.
1673 * \warning value is modified (both in contents and position)!
1674 * \param verbose 1 - print found value to stderr, 0 - don't
1675 * \param *file file to be parsed
1676 * \param name Name of value in file (at least 3 chars!)
1677 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1678 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1679 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1680 * counted from this unresetted position!)
1681 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1682 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1683 * \param type Type of the Parameter to be read
1684 * \param value address of the value to be read (must have been allocated)
1685 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1686 * \param critical necessity of this keyword being specified (optional, critical)
1687 * \return 1 - found, 0 - not found
1688 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1689 */
1690int ParseForParameter(const int verbose, ifstream * const file, const char * const name, const int sequential, const int xth, const int yth, const int type, void * value, const int repetition, const int critical) {
1691 int i = 0;
1692 int j = 0; // loop variables
1693 int length = 0;
1694 int maxlength = -1;
1695 long file_position = file->tellg(); // mark current position
1696 char *dummy1 = NULL;
1697 char *dummy = NULL;
1698 char free_dummy[MAXSTRINGSIZE]; // pointers in the line that is read in per step
1699 dummy1 = free_dummy;
1700
1701 //fprintf(stderr,"Parsing for %s\n",name);
1702 if (repetition == 0)
1703 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1704 return 0;
1705
1706 int line = 0; // marks line where parameter was found
1707 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1708 while((found != repetition)) {
1709 dummy1 = dummy = free_dummy;
1710 do {
1711 file->getline(dummy1, 256); // Read the whole line
1712 if (file->eof()) {
1713 if ((critical) && (found == 0)) {
1714 //Error(InitReading, name);
1715 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1716 exit(255);
1717 } else {
1718 //if (!sequential)
1719 file->clear();
1720 file->seekg(file_position, ios::beg); // rewind to start position
1721 return 0;
1722 }
1723 }
1724 line++;
1725 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1726
1727 // C++ getline removes newline at end, thus re-add
1728 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1729 i = strlen(dummy1);
1730 dummy1[i] = '\n';
1731 dummy1[i+1] = '\0';
1732 }
1733 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1734
1735 if (dummy1 == NULL) {
1736 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1737 } else {
1738 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1739 }
1740 // Seek for possible end of keyword on line if given ...
1741 if (name != NULL) {
1742 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1743 if (dummy == NULL) {
1744 dummy = strchr(dummy1, ' '); // if not found seek for space
1745 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1746 dummy++;
1747 }
1748 if (dummy == NULL) {
1749 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1750 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1751 //Error(FileOpenParams, NULL);
1752 } else {
1753 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1754 }
1755 } else dummy = dummy1;
1756 // ... and check if it is the keyword!
1757 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1758 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1759 found++; // found the parameter!
1760 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1761
1762 if (found == repetition) {
1763 for (i=0;i<xth;i++) { // i = rows
1764 if (type >= grid) {
1765 // grid structure means that grid starts on the next line, not right after keyword
1766 dummy1 = dummy = free_dummy;
1767 do {
1768 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1769 if (file->eof()) {
1770 if ((critical) && (found == 0)) {
1771 //Error(InitReading, name);
1772 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1773 exit(255);
1774 } else {
1775 //if (!sequential)
1776 file->clear();
1777 file->seekg(file_position, ios::beg); // rewind to start position
1778 return 0;
1779 }
1780 }
1781 line++;
1782 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1783 if (dummy1 == NULL){
1784 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1785 } else {
1786 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1787 }
1788 } else { // simple int, strings or doubles start in the same line
1789 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1790 dummy++;
1791 }
1792 // C++ getline removes newline at end, thus re-add
1793 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1794 j = strlen(dummy1);
1795 dummy1[j] = '\n';
1796 dummy1[j+1] = '\0';
1797 }
1798
1799 int start = (type >= grid) ? 0 : yth-1 ;
1800 for (j=start;j<yth;j++) { // j = columns
1801 // check for lower triangular area and upper triangular area
1802 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1803 *((double *)value) = 0.0;
1804 fprintf(stderr,"%f\t",*((double *)value));
1805 value = (void *)((long)value + sizeof(double));
1806 //value += sizeof(double);
1807 } else {
1808 // otherwise we must skip all interjacent tabs and spaces and find next value
1809 dummy1 = dummy;
1810 dummy = strchr(dummy1, '\t'); // seek for tab or space
1811 if (dummy == NULL)
1812 dummy = strchr(dummy1, ' '); // if not found seek for space
1813 if (dummy == NULL) { // if still zero returned ...
1814 dummy = strchr(dummy1, '\n'); // ... at line end then
1815 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1816 if (critical) {
1817 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1818 //return 0;
1819 exit(255);
1820 //Error(FileOpenParams, NULL);
1821 } else {
1822 //if (!sequential)
1823 file->clear();
1824 file->seekg(file_position, ios::beg); // rewind to start position
1825 return 0;
1826 }
1827 }
1828 } else {
1829 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1830 }
1831 if (*dummy1 == '#') {
1832 // found comment, skipping rest of line
1833 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1834 if (!sequential) { // here we need it!
1835 file->seekg(file_position, ios::beg); // rewind to start position
1836 }
1837 return 0;
1838 }
1839 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1840 switch(type) {
1841 case (row_int):
1842 *((int *)value) = atoi(dummy1);
1843 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1844 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1845 value = (void *)((long)value + sizeof(int));
1846 //value += sizeof(int);
1847 break;
1848 case(row_double):
1849 case(grid):
1850 case(lower_trigrid):
1851 case(upper_trigrid):
1852 *((double *)value) = atof(dummy1);
1853 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1854 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1855 value = (void *)((long)value + sizeof(double));
1856 //value += sizeof(double);
1857 break;
1858 case(double_type):
1859 *((double *)value) = atof(dummy1);
1860 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1861 //value += sizeof(double);
1862 break;
1863 case(int_type):
1864 *((int *)value) = atoi(dummy1);
1865 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1866 //value += sizeof(int);
1867 break;
1868 default:
1869 case(string_type):
1870 if (value != NULL) {
1871 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1872 maxlength = MAXSTRINGSIZE;
1873 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1874 strncpy((char *)value, dummy1, length); // copy as much
1875 ((char *)value)[length] = '\0'; // and set end marker
1876 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1877 //value += sizeof(char);
1878 } else {
1879 }
1880 break;
1881 }
1882 }
1883 while (*dummy == '\t')
1884 dummy++;
1885 }
1886 }
1887 }
1888 }
1889 }
1890 if ((type >= row_int) && (verbose))
1891 fprintf(stderr,"\n");
1892 if (!sequential) {
1893 file->clear();
1894 file->seekg(file_position, ios::beg); // rewind to start position
1895 }
1896 //fprintf(stderr, "End of Parsing\n\n");
1897
1898 return (found); // true if found, false if not
1899}
1900
1901
1902/** Reads parameter from a parsed file.
1903 * The file is either parsed for a certain keyword or if null is given for
1904 * the value in row yth and column xth. If the keyword was necessity#critical,
1905 * then an error is thrown and the programme aborted.
1906 * \warning value is modified (both in contents and position)!
1907 * \param verbose 1 - print found value to stderr, 0 - don't
1908 * \param *FileBuffer pointer to buffer structure
1909 * \param name Name of value in file (at least 3 chars!)
1910 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1911 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1912 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1913 * counted from this unresetted position!)
1914 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1915 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1916 * \param type Type of the Parameter to be read
1917 * \param value address of the value to be read (must have been allocated)
1918 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1919 * \param critical necessity of this keyword being specified (optional, critical)
1920 * \return 1 - found, 0 - not found
1921 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1922 */
1923int ParseForParameter(const int verbose, struct ConfigFileBuffer * const FileBuffer, const char * const name, const int sequential, const int xth, const int yth, const int type, void * value, const int repetition, const int critical) {
1924 int i = 0;
1925 int j = 0; // loop variables
1926 int length = 0;
1927 int maxlength = -1;
1928 int OldCurrentLine = FileBuffer->CurrentLine;
1929 char *dummy1 = NULL;
1930 char *dummy = NULL; // pointers in the line that is read in per step
1931
1932 //fprintf(stderr,"Parsing for %s\n",name);
1933 if (repetition == 0)
1934 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1935 return 0;
1936
1937 int line = 0; // marks line where parameter was found
1938 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1939 while((found != repetition)) {
1940 dummy1 = dummy = NULL;
1941 do {
1942 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1943 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1944 if ((critical) && (found == 0)) {
1945 //Error(InitReading, name);
1946 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1947 exit(255);
1948 } else {
1949 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1950 return 0;
1951 }
1952 }
1953 if (dummy1 == NULL) {
1954 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1955 } else {
1956 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1957 }
1958 line++;
1959 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1960
1961 // Seek for possible end of keyword on line if given ...
1962 if (name != NULL) {
1963 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1964 if (dummy == NULL) {
1965 dummy = strchr(dummy1, ' '); // if not found seek for space
1966 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1967 dummy++;
1968 }
1969 if (dummy == NULL) {
1970 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1971 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1972 //Error(FileOpenParams, NULL);
1973 } else {
1974 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1975 }
1976 } else dummy = dummy1;
1977 // ... and check if it is the keyword!
1978 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1979 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1980 found++; // found the parameter!
1981 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1982
1983 if (found == repetition) {
1984 for (i=0;i<xth;i++) { // i = rows
1985 if (type >= grid) {
1986 // grid structure means that grid starts on the next line, not right after keyword
1987 dummy1 = dummy = NULL;
1988 do {
1989 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1990 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1991 if ((critical) && (found == 0)) {
1992 //Error(InitReading, name);
1993 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1994 exit(255);
1995 } else {
1996 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1997 return 0;
1998 }
1999 }
2000 if (dummy1 == NULL) {
2001 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
2002 } else {
2003 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
2004 }
2005 line++;
2006 } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
2007 dummy = dummy1;
2008 } else { // simple int, strings or doubles start in the same line
2009 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
2010 dummy++;
2011 }
2012
2013 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
2014 // check for lower triangular area and upper triangular area
2015 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
2016 *((double *)value) = 0.0;
2017 fprintf(stderr,"%f\t",*((double *)value));
2018 value = (void *)((long)value + sizeof(double));
2019 //value += sizeof(double);
2020 } else {
2021 // otherwise we must skip all interjacent tabs and spaces and find next value
2022 dummy1 = dummy;
2023 dummy = strchr(dummy1, '\t'); // seek for tab or space
2024 if (dummy == NULL)
2025 dummy = strchr(dummy1, ' '); // if not found seek for space
2026 if (dummy == NULL) { // if still zero returned ...
2027 dummy = strchr(dummy1, '\n'); // ... at line end then
2028 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
2029 if (critical) {
2030 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
2031 //return 0;
2032 exit(255);
2033 //Error(FileOpenParams, NULL);
2034 } else {
2035 if (!sequential) { // here we need it!
2036 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
2037 }
2038 return 0;
2039 }
2040 }
2041 } else {
2042 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
2043 }
2044 if (*dummy1 == '#') {
2045 // found comment, skipping rest of line
2046 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
2047 if (!sequential) { // here we need it!
2048 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
2049 }
2050 return 0;
2051 }
2052 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
2053 switch(type) {
2054 case (row_int):
2055 *((int *)value) = atoi(dummy1);
2056 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
2057 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
2058 value = (void *)((long)value + sizeof(int));
2059 //value += sizeof(int);
2060 break;
2061 case(row_double):
2062 case(grid):
2063 case(lower_trigrid):
2064 case(upper_trigrid):
2065 *((double *)value) = atof(dummy1);
2066 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
2067 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
2068 value = (void *)((long)value + sizeof(double));
2069 //value += sizeof(double);
2070 break;
2071 case(double_type):
2072 *((double *)value) = atof(dummy1);
2073 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
2074 //value += sizeof(double);
2075 break;
2076 case(int_type):
2077 *((int *)value) = atoi(dummy1);
2078 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
2079 //value += sizeof(int);
2080 break;
2081 default:
2082 case(string_type):
2083 if (value != NULL) {
2084 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
2085 maxlength = MAXSTRINGSIZE;
2086 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
2087 strncpy((char *)value, dummy1, length); // copy as much
2088 ((char *)value)[length] = '\0'; // and set end marker
2089 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
2090 //value += sizeof(char);
2091 } else {
2092 }
2093 break;
2094 }
2095 }
2096 while (*dummy == '\t')
2097 dummy++;
2098 }
2099 }
2100 }
2101 }
2102 }
2103 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
2104 if (!sequential) {
2105 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
2106 }
2107 //fprintf(stderr, "End of Parsing\n\n");
2108
2109 return (found); // true if found, false if not
2110}
2111
2112/** Reading of Thermostat related values from parameter file.
2113 * \param *fb file buffer containing the config file
2114 */
2115void config::ParseThermostats(class ConfigFileBuffer * const fb)
2116{
2117 char * const thermo = new char[12];
2118 const int verbose = 0;
2119
2120 // read desired Thermostat from file along with needed additional parameters
2121 if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
2122 if (strcmp(thermo, Thermostats->ThermostatNames[0]) == 0) { // None
2123 if (Thermostats->ThermostatImplemented[0] == 1) {
2124 Thermostats->Thermostat = None;
2125 } else {
2126 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2127 Thermostats->Thermostat = None;
2128 }
2129 } else if (strcmp(thermo, Thermostats->ThermostatNames[1]) == 0) { // Woodcock
2130 if (Thermostats->ThermostatImplemented[1] == 1) {
2131 Thermostats->Thermostat = Woodcock;
2132 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &Thermostats->ScaleTempStep, 1, critical); // read scaling frequency
2133 } else {
2134 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2135 Thermostats->Thermostat = None;
2136 }
2137 } else if (strcmp(thermo, Thermostats->ThermostatNames[2]) == 0) { // Gaussian
2138 if (Thermostats->ThermostatImplemented[2] == 1) {
2139 Thermostats->Thermostat = Gaussian;
2140 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &Thermostats->ScaleTempStep, 1, critical); // read collision rate
2141 } else {
2142 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2143 Thermostats->Thermostat = None;
2144 }
2145 } else if (strcmp(thermo, Thermostats->ThermostatNames[3]) == 0) { // Langevin
2146 if (Thermostats->ThermostatImplemented[3] == 1) {
2147 Thermostats->Thermostat = Langevin;
2148 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->TempFrequency, 1, critical); // read gamma
2149 if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &Thermostats->alpha, 1, optional)) {
2150 DoLog(2) && (Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << Thermostats->alpha << "." << endl);
2151 } else {
2152 Thermostats->alpha = 1.;
2153 }
2154 } else {
2155 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2156 Thermostats->Thermostat = None;
2157 }
2158 } else if (strcmp(thermo, Thermostats->ThermostatNames[4]) == 0) { // Berendsen
2159 if (Thermostats->ThermostatImplemented[4] == 1) {
2160 Thermostats->Thermostat = Berendsen;
2161 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->TempFrequency, 1, critical); // read \tau_T
2162 } else {
2163 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2164 Thermostats->Thermostat = None;
2165 }
2166 } else if (strcmp(thermo, Thermostats->ThermostatNames[5]) == 0) { // Nose-Hoover
2167 if (Thermostats->ThermostatImplemented[5] == 1) {
2168 Thermostats->Thermostat = NoseHoover;
2169 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->HooverMass, 1, critical); // read Hoovermass
2170 Thermostats->alpha = 0.;
2171 } else {
2172 DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
2173 Thermostats->Thermostat = None;
2174 }
2175 } else {
2176 DoLog(1) && (Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl);
2177 Thermostats->Thermostat = None;
2178 }
2179 } else {
2180 if ((Thermostats->TargetTemp != 0))
2181 DoLog(2) && (Log() << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
2182 Thermostats->Thermostat = None;
2183 }
2184 delete[](thermo);
2185};
2186
Note: See TracBrowser for help on using the repository browser.