source: src/config.cpp@ 1434c9

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

Merge branch 'stable' into PcpAndMpqcParser

Conflicts:

molecuilder/src/Makefile.am

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