source: src/config.cpp@ c89fb4

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

Shortened constructors [Meyers, "Effective C++" item 12]

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