source: src/config.cpp@ 796aa6

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 796aa6 was 389cc8, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Used the formual class instead of single variables inside molecule

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