source: src/config.cpp@ fa7989

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

Merged MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs() into FragmenationSubgraphDissectionAction.

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