source: src/config.cpp@ 5f8660a

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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