source: src/config.cpp@ e2373df

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 e2373df was 056e70, checked in by Frederik Heber <heber@…>, 14 years ago

Suffixed getters and setters for AtomInfo trajecories with AtStep.

  • AtomInfo:: getters are now const members
  • added lots of ASSERTS to getters with time step to assure no out-of-bounds access.
  • Property mode set to 100644
File size: 74.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file config.cpp
9 *
10 * Function implementations for the class config.
11 *
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "CodePatterns/MemDebug.hpp"
20
21#include <stdio.h>
22#include <cstring>
23
24//#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
25#include "atom.hpp"
26#include "bond.hpp"
27#include "bondgraph.hpp"
28#include "config.hpp"
29#include "ConfigFileBuffer.hpp"
30#include "element.hpp"
31#include "Helpers/helpers.hpp"
32#include "CodePatterns/Info.hpp"
33#include "lists.hpp"
34#include "CodePatterns/Verbose.hpp"
35#include "CodePatterns/Log.hpp"
36#include "molecule.hpp"
37#include "molecule.hpp"
38#include "periodentafel.hpp"
39#include "ThermoStatContainer.hpp"
40#include "World.hpp"
41#include "LinearAlgebra/RealSpaceMatrix.hpp"
42#include "Box.hpp"
43
44/************************************* Functions for class config ***************************/
45
46/** Constructor for config file class.
47 */
48config::config() :
49 BG(NULL),
50 Thermostats(0),
51 PsiType(0),
52 MaxPsiDouble(0),
53 PsiMaxNoUp(0),
54 PsiMaxNoDown(0),
55 MaxMinStopStep(1),
56 InitMaxMinStopStep(1),
57 ProcPEGamma(8),
58 ProcPEPsi(1),
59 configname(NULL),
60 FastParsing(false),
61 Deltat(0.01),
62 databasepath(NULL),
63 DoConstrainedMD(0),
64 MaxOuterStep(0),
65 mainname(NULL),
66 defaultpath(NULL),
67 pseudopotpath(NULL),
68 DoOutVis(0),
69 DoOutMes(1),
70 DoOutNICS(0),
71 DoOutOrbitals(0),
72 DoOutCurrent(0),
73 DoFullCurrent(0),
74 DoPerturbation(0),
75 DoWannier(0),
76 CommonWannier(0),
77 SawtoothStart(0.01),
78 VectorPlane(0),
79 VectorCut(0.),
80 UseAddGramSch(1),
81 Seed(1),
82 OutVisStep(10),
83 OutSrcStep(5),
84 MaxPsiStep(0),
85 EpsWannier(1e-7),
86 MaxMinStep(100),
87 RelEpsTotalEnergy(1e-7),
88 RelEpsKineticEnergy(1e-5),
89 MaxMinGapStopStep(0),
90 MaxInitMinStep(100),
91 InitRelEpsTotalEnergy(1e-5),
92 InitRelEpsKineticEnergy(1e-4),
93 InitMaxMinGapStopStep(0),
94 ECut(128.),
95 MaxLevel(5),
96 RiemannTensor(0),
97 LevRFactor(0),
98 RiemannLevel(0),
99 Lev0Factor(2),
100 RTActualUse(0),
101 AddPsis(0),
102 RCut(20.),
103 StructOpt(0),
104 IsAngstroem(1),
105 RelativeCoord(0),
106 MaxTypes(0)
107{
108 mainname = new char[MAXSTRINGSIZE];
109 defaultpath = new char[MAXSTRINGSIZE];
110 pseudopotpath = new char[MAXSTRINGSIZE];
111 databasepath = new char[MAXSTRINGSIZE];
112 configname = new char[MAXSTRINGSIZE];
113 Thermostats = new ThermoStatContainer();
114 strcpy(mainname,"pcp");
115 strcpy(defaultpath,"not specified");
116 strcpy(pseudopotpath,"not specified");
117 configname[0]='\0';
118};
119
120/** Destructor for config file class.
121 */
122config::~config()
123{
124 delete[](mainname);
125 delete[](defaultpath);
126 delete[](pseudopotpath);
127 delete[](databasepath);
128 delete[](configname);
129 if (Thermostats != NULL)
130 delete(Thermostats);
131
132 if (BG != NULL)
133 delete(BG);
134};
135
136/** Displays menu for editing each entry of the config file.
137 * Nothing fancy here, just lots of Log() << Verbose(0)s for the menu and a switch/case
138 * for each entry of the config file structure.
139 */
140void config::Edit()
141{
142 char choice;
143
144 do {
145 DoLog(0) && (Log() << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl);
146 DoLog(0) && (Log() << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl);
147 DoLog(0) && (Log() << Verbose(0) << " B - Default path (for runtime files)" << endl);
148 DoLog(0) && (Log() << Verbose(0) << " C - Path of pseudopotential files" << endl);
149 DoLog(0) && (Log() << Verbose(0) << " D - Number of coefficient sharing processes" << endl);
150 DoLog(0) && (Log() << Verbose(0) << " E - Number of wave function sharing processes" << endl);
151 DoLog(0) && (Log() << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl);
152 DoLog(0) && (Log() << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl);
153 DoLog(0) && (Log() << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl);
154 DoLog(0) && (Log() << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl);
155 DoLog(0) && (Log() << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl);
156 DoLog(0) && (Log() << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl);
157 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);
158 DoLog(0) && (Log() << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl);
159 DoLog(0) && (Log() << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl);
160 DoLog(0) && (Log() << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl);
161 DoLog(0) && (Log() << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl);
162 DoLog(0) && (Log() << Verbose(0) << " Q - Initial integer value of random number generator" << endl);
163 DoLog(0) && (Log() << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl);
164 DoLog(0) && (Log() << Verbose(0) << " T - Output visual after ...th step" << endl);
165 DoLog(0) && (Log() << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl);
166 DoLog(0) && (Log() << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl);
167 DoLog(0) && (Log() << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl);
168 DoLog(0) && (Log() << Verbose(0) << " Z - Maximum number of minimization iterations" << endl);
169 DoLog(0) && (Log() << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl);
170 DoLog(0) && (Log() << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl);
171 DoLog(0) && (Log() << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl);
172 DoLog(0) && (Log() << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl);
173 DoLog(0) && (Log() << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl);
174 DoLog(0) && (Log() << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl);
175 DoLog(0) && (Log() << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl);
176// Log() << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
177 DoLog(0) && (Log() << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl);
178 DoLog(0) && (Log() << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl);
179 DoLog(0) && (Log() << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl);
180 DoLog(0) && (Log() << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl);
181 DoLog(0) && (Log() << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl);
182 DoLog(0) && (Log() << Verbose(0) << " p - Number of Riemann levels" << endl);
183 DoLog(0) && (Log() << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl);
184 DoLog(0) && (Log() << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl);
185 DoLog(0) && (Log() << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl);
186 DoLog(0) && (Log() << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl);
187 DoLog(0) && (Log() << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl);
188 DoLog(0) && (Log() << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl);
189 DoLog(0) && (Log() << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl);
190 DoLog(0) && (Log() << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl);
191 DoLog(0) && (Log() << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl);
192 DoLog(0) && (Log() << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl);
193 DoLog(0) && (Log() << Verbose(0) << "=========================================================" << endl);
194 DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
195 cin >> choice;
196
197 switch (choice) {
198 case 'A': // mainname
199 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::mainname << "\t new: ");
200 cin >> config::mainname;
201 break;
202 case 'B': // defaultpath
203 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::defaultpath << "\t new: ");
204 cin >> config::defaultpath;
205 break;
206 case 'C': // pseudopotpath
207 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ");
208 cin >> config::pseudopotpath;
209 break;
210
211 case 'D': // ProcPEGamma
212 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ");
213 cin >> config::ProcPEGamma;
214 break;
215 case 'E': // ProcPEPsi
216 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ");
217 cin >> config::ProcPEPsi;
218 break;
219 case 'F': // DoOutVis
220 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ");
221 cin >> config::DoOutVis;
222 break;
223 case 'G': // DoOutMes
224 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ");
225 cin >> config::DoOutMes;
226 break;
227 case 'H': // DoOutOrbitals
228 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ");
229 cin >> config::DoOutOrbitals;
230 break;
231 case 'I': // DoOutCurrent
232 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ");
233 cin >> config::DoOutCurrent;
234 break;
235 case 'J': // DoFullCurrent
236 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ");
237 cin >> config::DoFullCurrent;
238 break;
239 case 'K': // DoPerturbation
240 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ");
241 cin >> config::DoPerturbation;
242 break;
243 case 'L': // CommonWannier
244 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ");
245 cin >> config::CommonWannier;
246 break;
247 case 'M': // SawtoothStart
248 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ");
249 cin >> config::SawtoothStart;
250 break;
251 case 'N': // VectorPlane
252 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ");
253 cin >> config::VectorPlane;
254 break;
255 case 'O': // VectorCut
256 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorCut << "\t new: ");
257 cin >> config::VectorCut;
258 break;
259 case 'P': // UseAddGramSch
260 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ");
261 cin >> config::UseAddGramSch;
262 break;
263 case 'Q': // Seed
264 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Seed << "\t new: ");
265 cin >> config::Seed;
266 break;
267
268 case 'R': // MaxOuterStep
269 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ");
270 cin >> config::MaxOuterStep;
271 break;
272 case 'T': // OutVisStep
273 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ");
274 cin >> config::OutVisStep;
275 break;
276 case 'U': // OutSrcStep
277 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ");
278 cin >> config::OutSrcStep;
279 break;
280 case 'X': // MaxPsiStep
281 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ");
282 cin >> config::MaxPsiStep;
283 break;
284 case 'Y': // EpsWannier
285 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ");
286 cin >> config::EpsWannier;
287 break;
288
289 case 'Z': // MaxMinStep
290 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ");
291 cin >> config::MaxMinStep;
292 break;
293 case 'a': // RelEpsTotalEnergy
294 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ");
295 cin >> config::RelEpsTotalEnergy;
296 break;
297 case 'b': // RelEpsKineticEnergy
298 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ");
299 cin >> config::RelEpsKineticEnergy;
300 break;
301 case 'c': // MaxMinStopStep
302 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ");
303 cin >> config::MaxMinStopStep;
304 break;
305 case 'e': // MaxInitMinStep
306 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ");
307 cin >> config::MaxInitMinStep;
308 break;
309 case 'f': // InitRelEpsTotalEnergy
310 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ");
311 cin >> config::InitRelEpsTotalEnergy;
312 break;
313 case 'g': // InitRelEpsKineticEnergy
314 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ");
315 cin >> config::InitRelEpsKineticEnergy;
316 break;
317 case 'h': // InitMaxMinStopStep
318 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ");
319 cin >> config::InitMaxMinStopStep;
320 break;
321
322// case 'j': // BoxLength
323// Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
324// double * const cell_size = World::getInstance().getDomain();
325// for (int i=0;i<6;i++) {
326// Log() << Verbose(0) << "Cell size" << i << ": ";
327// cin >> cell_size[i];
328// }
329// break;
330
331 case 'k': // ECut
332 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ECut << "\t new: ");
333 cin >> config::ECut;
334 break;
335 case 'l': // MaxLevel
336 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ");
337 cin >> config::MaxLevel;
338 break;
339 case 'm': // RiemannTensor
340 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ");
341 cin >> config::RiemannTensor;
342 break;
343 case 'n': // LevRFactor
344 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ");
345 cin >> config::LevRFactor;
346 break;
347 case 'o': // RiemannLevel
348 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ");
349 cin >> config::RiemannLevel;
350 break;
351 case 'p': // Lev0Factor
352 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ");
353 cin >> config::Lev0Factor;
354 break;
355 case 'r': // RTActualUse
356 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ");
357 cin >> config::RTActualUse;
358 break;
359 case 's': // PsiType
360 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiType << "\t new: ");
361 cin >> config::PsiType;
362 break;
363 case 't': // MaxPsiDouble
364 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ");
365 cin >> config::MaxPsiDouble;
366 break;
367 case 'u': // PsiMaxNoUp
368 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ");
369 cin >> config::PsiMaxNoUp;
370 break;
371 case 'v': // PsiMaxNoDown
372 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ");
373 cin >> config::PsiMaxNoDown;
374 break;
375 case 'w': // AddPsis
376 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::AddPsis << "\t new: ");
377 cin >> config::AddPsis;
378 break;
379
380 case 'x': // RCut
381 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RCut << "\t new: ");
382 cin >> config::RCut;
383 break;
384 case 'y': // StructOpt
385 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::StructOpt << "\t new: ");
386 cin >> config::StructOpt;
387 break;
388 case 'z': // IsAngstroem
389 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ");
390 cin >> config::IsAngstroem;
391 break;
392 case 'i': // RelativeCoord
393 DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ");
394 cin >> config::RelativeCoord;
395 break;
396 };
397 } while (choice != 'q');
398};
399
400/** Tests whether a given configuration file adhears to old or new syntax.
401 * \param *filename filename of config file to be tested
402 * \param *periode pointer to a periodentafel class with all elements
403 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
404 */
405int config::TestSyntax(const char * const filename, const periodentafel * const periode) const
406{
407 int test;
408 ifstream file(filename);
409
410 // search file for keyword: ProcPEGamma (new syntax)
411 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
412 file.close();
413 return 1;
414 }
415 // search file for keyword: ProcsGammaPsi (old syntax)
416 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
417 file.close();
418 return 0;
419 }
420 file.close();
421 return -1;
422}
423
424/** Returns private config::IsAngstroem.
425 * \return IsAngstroem
426 */
427bool config::GetIsAngstroem() const
428{
429 return (IsAngstroem == 1);
430};
431
432/** Returns private config::*defaultpath.
433 * \return *defaultpath
434 */
435char * config::GetDefaultPath() const
436{
437 return defaultpath;
438};
439
440
441/** Returns private config::*defaultpath.
442 * \return *defaultpath
443 */
444void config::SetDefaultPath(const char * const path)
445{
446 strcpy(defaultpath, path);
447};
448
449/** Loads a molecule from a ConfigFileBuffer.
450 * \param *mol molecule to load
451 * \param *FileBuffer ConfigFileBuffer to use
452 * \param *periode periodentafel for finding elements
453 * \param FastParsing whether to parse trajectories or not
454 */
455void LoadMolecule(molecule * const &mol, struct ConfigFileBuffer * const &FileBuffer, const periodentafel * const periode, const bool FastParsing)
456{
457 int MaxTypes = 0;
458 const element *elementhash[MAX_ELEMENTS];
459 char name[MAX_ELEMENTS];
460 char keyword[MAX_ELEMENTS];
461 int Z = -1;
462 int No[MAX_ELEMENTS];
463 int verbose = 0;
464 Vector tempVector;
465 int _fixedion;
466 double value[3];
467
468 if (mol == NULL) {
469 DoeLog(0) && (eLog()<< Verbose(0) << "Molecule is not allocated in LoadMolecule(), exit.");
470 performCriticalExit();
471 }
472
473 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
474 if (MaxTypes == 0) {
475 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms according to MaxTypes in this config file." << endl);
476 //performCriticalExit();
477 } else {
478 // prescan number of ions per type
479 DoLog(0) && (Log() << Verbose(0) << "Prescanning ions per type: " << endl);
480 int NoAtoms = 0;
481 for (int i=0; i < MaxTypes; i++) {
482 sprintf(name,"Ion_Type%i",i+1);
483 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
484 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
485 elementhash[i] = periode->FindElement(Z);
486 DoLog(1) && (Log() << Verbose(1) << i << ". Z = " << elementhash[i]->getAtomicNumber() << " with " << No[i] << " ions." << endl);
487 NoAtoms += No[i];
488 }
489 int repetition = 0; // which repeated keyword shall be read
490
491 // sort the lines via the LineMapping
492 sprintf(name,"Ion_Type%i",MaxTypes);
493 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
494 DoeLog(0) && (eLog()<< Verbose(0) << "There are no atoms in the config file!" << endl);
495 performCriticalExit();
496 return;
497 }
498 FileBuffer->CurrentLine++;
499 //Log() << Verbose(0) << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
500 FileBuffer->MapIonTypesInBuffer(NoAtoms);
501 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
502 // Log() << Verbose(0) << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
503 //}
504
505 map<int, atom *> AtomList[MaxTypes];
506 map<int, atom *> LinearList;
507 atom *neues = NULL;
508 Vector position;
509 if (!FastParsing) {
510 // parse in trajectories
511 bool status = true;
512 while (status) {
513 DoLog(0) && (Log() << Verbose(0) << "Currently parsing MD step " << repetition << "." << endl);
514 for (int i=0; i < MaxTypes; i++) {
515 sprintf(name,"Ion_Type%i",i+1);
516 for(int j=0;j<No[i];j++) {
517 sprintf(keyword,"%s_%i",name, j+1);
518 if (repetition == 0) {
519 neues = World::getInstance().createAtom();
520 AtomList[i][j] = neues;
521 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
522 neues->setType(elementhash[i]); // find element type
523 } else
524 neues = AtomList[i][j];
525 status = (status &&
526 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &position[0], 1, (repetition == 0) ? critical : optional) &&
527 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &position[1], 1, (repetition == 0) ? critical : optional) &&
528 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &position[2], 1, (repetition == 0) ? critical : optional) &&
529 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &_fixedion, 1, (repetition == 0) ? critical : optional));
530 if (!status)
531 break;
532
533 // check size of vectors
534 if (neues->getTrajectorySize() <= (unsigned int)(repetition)) {
535 //Log() << Verbose(0) << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
536 neues->ResizeTrajectory(repetition+1);
537 neues->ResizeTrajectory(repetition+1);
538 neues->ResizeTrajectory(repetition+1);
539 }
540 neues->setFixedIon(_fixedion);
541 neues->setPositionAtStep(repetition,position);
542
543 // parse velocities if present
544 tempVector.Zero();
545 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &tempVector[0], 1,optional))
546 tempVector[0] = 0.;
547 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &tempVector[1], 1,optional))
548 tempVector[1] = 0.;
549 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &tempVector[2], 1,optional))
550 tempVector[2] = 0.;
551 neues->setAtomicVelocityAtStep(repetition, tempVector);
552
553 // parse forces if present
554 tempVector.Zero();
555 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &tempVector[0], 1,optional))
556 tempVector[0] = 0.;
557 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &tempVector[1], 1,optional))
558 tempVector[1] = 0.;
559 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &tempVector[2], 1,optional))
560 tempVector[2] = 0.;
561 neues->setAtomicForceAtStep(repetition, tempVector);
562
563 // Log() << Verbose(0) << "Parsed position of step " << (repetition) << ": (";
564 // Log() << Verbose(0) << neues->getPosition(repetition) << " "; // next step
565 // Log() << Verbose(0) << neues->getAtomicVelocity(repetition) << " "; // next step
566 // Log() << Verbose(0) << neues->getAtomicForce(repetition) << " "; // next step
567 // Log() << Verbose(0) << ")" << endl;
568 }
569 }
570 repetition++;
571 }
572 repetition--;
573 DoLog(0) && (Log() << Verbose(0) << "Found " << repetition << " trajectory steps." << endl);
574 if (repetition <= 1) // if onyl one step, desactivate use of trajectories
575 mol->MDSteps = 0;
576 else
577 mol->MDSteps = repetition;
578 } else {
579 // 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)
580 repetition = 0;
581 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
582 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
583 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
584 repetition++;
585 DoLog(0) && (Log() << Verbose(0) << "I found " << repetition << " times the keyword Ion_Type1_1." << endl);
586 // parse in molecule coordinates
587 for (int i=0; i < MaxTypes; i++) {
588 sprintf(name,"Ion_Type%i",i+1);
589 for(int j=0;j<No[i];j++) {
590 sprintf(keyword,"%s_%i",name, j+1);
591 if (repetition == 0) {
592 neues = World::getInstance().createAtom();
593 AtomList[i][j] = neues;
594 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
595 neues->setType(elementhash[i]); // find element type
596 } else
597 neues = AtomList[i][j];
598 // then parse for each atom the coordinates as often as present
599 tempVector.Zero();
600 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &tempVector[0], repetition,critical);
601 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &tempVector[1], repetition,critical);
602 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &tempVector[2], repetition,critical);
603 neues->setPosition(tempVector);
604 // fixed ion
605 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &_fixedion, repetition,critical);
606 neues->setFixedIon(_fixedion);
607 // and velocity
608 tempVector.Zero();
609 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &tempVector[0], repetition,optional))
610 tempVector[0] = 0.;
611 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &tempVector[1], repetition,optional))
612 tempVector[1] = 0.;
613 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &tempVector[2], repetition,optional))
614 tempVector[2] = 0.;
615 neues->setAtomicVelocity(tempVector);
616 // here we don't care if forces are present (last in trajectories is always equal to current position)
617 neues->setType(elementhash[i]); // find element type
618 mol->AddAtom(neues);
619 }
620 }
621 }
622 // put atoms into the molecule in their original order
623 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
624 mol->AddAtom(runner->second);
625 }
626 }
627};
628
629/** Stores all elements of config structure from which they can be re-read.
630 * \param *filename name of file
631 * \param *periode pointer to a periodentafel class with all elements
632 * \param *mol pointer to molecule containing all atoms of the molecule
633 */
634bool config::Save(const char * const filename, const periodentafel * const periode, molecule * const mol) const
635{
636 bool result = true;
637 const RealSpaceMatrix &domain = World::getInstance().getDomain().getM();
638 ofstream * const output = new ofstream(filename, ios::out);
639 if (output != NULL) {
640 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
641 *output << endl;
642 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
643 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
644 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
645 *output << endl;
646 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
647 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
648 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
649 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
650 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
651 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
652 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
653 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
654 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
655 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
656 *output << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t";
657 *output << Thermostats->activeThermostat->writeParams();
658 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
659 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
660 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
661 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
662 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
663 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
664 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
665 *output << endl;
666 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
667 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
668 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
669 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
670 *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
671 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
672 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
673 *output << endl;
674 *output << "# Values specifying when to stop" << endl;
675 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
676 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
677 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
678 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
679 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
680 *output << endl;
681 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
682 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
683 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
684 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
685 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
686 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
687 *output << endl;
688 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
689 *output << domain.at(0,0) << "\t" << endl;
690 *output << domain.at(1,0) << "\t" << domain.at(1,1) << "\t" << endl;
691 *output << domain.at(2,0) << "\t" << domain.at(2,1) << "\t" << domain.at(2,2) << "\t" << endl;
692 // FIXME
693 *output << endl;
694 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
695 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
696 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
697 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
698 switch (config::RiemannTensor) {
699 case 0: //UseNoRT
700 break;
701 case 1: // UseRT
702 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
703 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
704 break;
705 }
706 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
707 // write out both types for easier changing afterwards
708 // switch (PsiType) {
709 // case 0:
710 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
711 // break;
712 // case 1:
713 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
714 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
715 // break;
716 // }
717 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
718 *output << endl;
719 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
720 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
721 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
722 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
723 *output << "MaxTypes\t" << mol->getElementCount() << "\t# maximum number of different ion types" << endl;
724 *output << endl;
725 result = result && mol->Checkout(output);
726 if (mol->MDSteps <=1 )
727 result = result && mol->Output(output);
728 else
729 result = result && mol->OutputTrajectories(output);
730 output->close();
731 output->clear();
732 delete(output);
733 return result;
734 } else {
735 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file:" << filename << endl);
736 return false;
737 }
738};
739
740/** Stores all elements in a MPQC input file.
741 * Note that this format cannot be parsed again.
742 * \param *filename name of file (without ".in" suffix!)
743 * \param *mol pointer to molecule containing all atoms of the molecule
744 */
745bool config::SaveMPQC(const char * const filename, const molecule * const mol) const
746{
747 Vector *center = NULL;
748 ofstream *output = NULL;
749
750 // first without hessian
751 {
752 stringstream * const fname = new stringstream;;
753 *fname << filename << ".in";
754 output = new ofstream(fname->str().c_str(), ios::out);
755 if (output == NULL) {
756 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file:" << fname << endl);
757 delete(fname);
758 return false;
759 }
760 *output << "% Created by MoleCuilder" << endl;
761 *output << "mpqc: (" << endl;
762 *output << "\tsavestate = no" << endl;
763 *output << "\tdo_gradient = yes" << endl;
764 *output << "\tmole<MBPT2>: (" << endl;
765 *output << "\t\tmaxiter = 200" << endl;
766 *output << "\t\tbasis = $:basis" << endl;
767 *output << "\t\tmolecule = $:molecule" << endl;
768 *output << "\t\treference<CLHF>: (" << endl;
769 *output << "\t\t\tbasis = $:basis" << endl;
770 *output << "\t\t\tmolecule = $:molecule" << endl;
771 *output << "\t\t)" << endl;
772 *output << "\t)" << endl;
773 *output << ")" << endl;
774 *output << "molecule<Molecule>: (" << endl;
775 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
776 *output << "\t{ atoms geometry } = {" << endl;
777 center = mol->DetermineCenterOfAll();
778 // output of atoms
779 for(molecule::const_iterator iter = mol->begin(); iter!=mol->end();++iter){
780 (*iter)->OutputMPQCLine(output,center);
781 }
782 delete(center);
783 *output << "\t}" << endl;
784 *output << ")" << endl;
785 *output << "basis<GaussianBasisSet>: (" << endl;
786 *output << "\tname = \"3-21G\"" << endl;
787 *output << "\tmolecule = $:molecule" << endl;
788 *output << ")" << endl;
789 output->close();
790 delete(output);
791 delete(fname);
792 }
793
794 // second with hessian
795 {
796 stringstream * const fname = new stringstream;
797 *fname << filename << ".hess.in";
798 output = new ofstream(fname->str().c_str(), ios::out);
799 if (output == NULL) {
800 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc hessian output file:" << fname << endl);
801 delete(fname);
802 return false;
803 }
804 *output << "% Created by MoleCuilder" << endl;
805 *output << "mpqc: (" << endl;
806 *output << "\tsavestate = no" << endl;
807 *output << "\tdo_gradient = yes" << endl;
808 *output << "\tmole<CLHF>: (" << endl;
809 *output << "\t\tmaxiter = 200" << endl;
810 *output << "\t\tbasis = $:basis" << endl;
811 *output << "\t\tmolecule = $:molecule" << endl;
812 *output << "\t)" << endl;
813 *output << "\tfreq<MolecularFrequencies>: (" << endl;
814 *output << "\t\tmolecule=$:molecule" << endl;
815 *output << "\t)" << endl;
816 *output << ")" << endl;
817 *output << "molecule<Molecule>: (" << endl;
818 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
819 *output << "\t{ atoms geometry } = {" << endl;
820 center = mol->DetermineCenterOfAll();
821 // output of atoms
822 for(molecule::const_iterator iter = mol->begin(); iter!=mol->end();++iter){
823 (*iter)->OutputMPQCLine(output,center);
824 }
825 delete(center);
826 *output << "\t}" << endl;
827 *output << ")" << endl;
828 *output << "basis<GaussianBasisSet>: (" << endl;
829 *output << "\tname = \"3-21G\"" << endl;
830 *output << "\tmolecule = $:molecule" << endl;
831 *output << ")" << endl;
832 output->close();
833 delete(output);
834 delete(fname);
835 }
836
837 return true;
838};
839
840/** Stores all atoms from all molecules in a PDB input file.
841 * Note that this format cannot be parsed again.
842 * \param *filename name of file (without ".in" suffix!)
843 * \param *MolList pointer to MoleculeListClass containing all atoms
844 */
845bool config::SavePDB(const char * const filename, const MoleculeListClass * const MolList) const
846{
847 int AtomNo = -1;
848 int MolNo = 0;
849 FILE *f = NULL;
850
851 char name[MAXSTRINGSIZE];
852 strncpy(name, filename, MAXSTRINGSIZE-1);
853 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
854 f = fopen(name, "w" );
855 if (f == NULL) {
856 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
857 return false;
858 }
859 fprintf(f, "# Created by MoleCuilder\n");
860
861 for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
862 int *elementNo = new int[MAX_ELEMENTS];
863 for (int i=0;i<MAX_ELEMENTS;i++)
864 elementNo[i] = 0;
865 AtomNo = 0;
866 for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
867 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->getAtomicNumber()]);
868 elementNo[(*iter)->getType()->getAtomicNumber()] = (elementNo[(*iter)->getType()->getAtomicNumber()]+1) % 100; // confine to two digits
869 fprintf(f,
870 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
871 (*iter)->nr, /* atom serial number */
872 name, /* atom name */
873 (*MolRunner)->name, /* residue name */
874 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
875 MolNo, /* residue sequence number */
876 (*iter)->at(0), /* position X in Angstroem */
877 (*iter)->at(1), /* position Y in Angstroem */
878 (*iter)->at(2), /* position Z in Angstroem */
879 (double)(*iter)->getType()->getValence(), /* occupancy */
880 (double)(*iter)->getType()->getNoValenceOrbitals(), /* temperature factor */
881 "0", /* segment identifier */
882 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
883 "0"); /* charge */
884 AtomNo++;
885 }
886 delete[](elementNo);
887 MolNo++;
888 }
889 fclose(f);
890
891 return true;
892};
893
894/** Stores all atoms in a PDB input file.
895 * Note that this format cannot be parsed again.
896 * \param *filename name of file (without ".in" suffix!)
897 * \param *mol pointer to molecule
898 */
899bool config::SavePDB(const char * const filename, const molecule * const mol) const
900{
901 int AtomNo = -1;
902 FILE *f = NULL;
903
904 int *elementNo = new int[MAX_ELEMENTS];
905 for (int i=0;i<MAX_ELEMENTS;i++)
906 elementNo[i] = 0;
907 char name[MAXSTRINGSIZE];
908 strncpy(name, filename, MAXSTRINGSIZE-1);
909 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
910 f = fopen(name, "w" );
911 if (f == NULL) {
912 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
913 delete[](elementNo);
914 return false;
915 }
916 fprintf(f, "# Created by MoleCuilder\n");
917
918 AtomNo = 0;
919 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
920 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->getAtomicNumber()]);
921 elementNo[(*iter)->getType()->getAtomicNumber()] = (elementNo[(*iter)->getType()->getAtomicNumber()]+1) % 100; // confine to two digits
922 fprintf(f,
923 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
924 (*iter)->nr, /* atom serial number */
925 name, /* atom name */
926 mol->name, /* residue name */
927 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
928 0, /* residue sequence number */
929 (*iter)->at(0), /* position X in Angstroem */
930 (*iter)->at(1), /* position Y in Angstroem */
931 (*iter)->at(2), /* position Z in Angstroem */
932 (double)(*iter)->getType()->getValence(), /* occupancy */
933 (double)(*iter)->getType()->getNoValenceOrbitals(), /* temperature factor */
934 "0", /* segment identifier */
935 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
936 "0"); /* charge */
937 AtomNo++;
938 }
939 fclose(f);
940 delete[](elementNo);
941
942 return true;
943};
944
945/** Stores all atoms in a TREMOLO data input file.
946 * Note that this format cannot be parsed again.
947 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
948 * \param *filename name of file (without ".in" suffix!)
949 * \param *mol pointer to molecule
950 */
951bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
952{
953 ofstream *output = NULL;
954 stringstream * const fname = new stringstream;
955
956 *fname << filename << ".data";
957 output = new ofstream(fname->str().c_str(), ios::out);
958 if (output == NULL) {
959 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
960 delete(fname);
961 return false;
962 }
963
964 // scan maximum number of neighbours
965 int MaxNeighbours = 0;
966 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
967 const int count = (*iter)->ListOfBonds.size();
968 if (MaxNeighbours < count)
969 MaxNeighbours = count;
970 }
971 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
972
973 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
974 *output << (*iter)->nr << "\t";
975 *output << (*iter)->getName() << "\t";
976 *output << mol->name << "\t";
977 *output << 0 << "\t";
978 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
979 *output << static_cast<double>((*iter)->getType()->getValence()) << "\t";
980 *output << (*iter)->getType()->getSymbol() << "\t";
981 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
982 *output << (*runner)->GetOtherAtom(*iter)->nr << "\t";
983 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
984 *output << "-\t";
985 *output << endl;
986 }
987 output->flush();
988 output->close();
989 delete(output);
990 delete(fname);
991
992 return true;
993};
994
995/** Stores all atoms from all molecules in a TREMOLO data input file.
996 * Note that this format cannot be parsed again.
997 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
998 * \param *filename name of file (without ".in" suffix!)
999 * \param *MolList pointer to MoleculeListClass containing all atoms
1000 */
1001bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
1002{
1003 Info FunctionInfo(__func__);
1004 ofstream *output = NULL;
1005 stringstream * const fname = new stringstream;
1006
1007 *fname << filename << ".data";
1008 output = new ofstream(fname->str().c_str(), ios::out);
1009 if (output == NULL) {
1010 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
1011 delete(fname);
1012 return false;
1013 }
1014
1015 // scan maximum number of neighbours
1016 int MaxNeighbours = 0;
1017 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1018 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1019 const int count = (*iter)->ListOfBonds.size();
1020 if (MaxNeighbours < count)
1021 MaxNeighbours = count;
1022 }
1023 }
1024 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
1025
1026 // create global to local id map
1027 map<int, int> LocalNotoGlobalNoMap;
1028 {
1029 unsigned int MolCounter = 0;
1030 int AtomNo = 1;
1031 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1032 for(molecule::iterator AtomRunner = (*MolWalker)->begin(); AtomRunner != (*MolWalker)->end(); ++AtomRunner) {
1033 LocalNotoGlobalNoMap.insert( pair<int,int>((*AtomRunner)->getId(), AtomNo++) );
1034 }
1035 MolCounter++;
1036 }
1037 ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
1038 }
1039
1040 // write the file
1041 {
1042 int MolCounter = 0;
1043 int AtomNo = 0;
1044 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1045 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1046 *output << LocalNotoGlobalNoMap[ (*iter)->getId() ] << "\t";
1047 *output << (*iter)->getName() << "\t";
1048 *output << (*MolWalker)->name << "\t";
1049 *output << MolCounter+1 << "\t";
1050 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
1051 *output << (double)(*iter)->getType()->getValence() << "\t";
1052 *output << (*iter)->getType()->getSymbol() << "\t";
1053 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
1054 *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom((*iter))->getId() ] << "\t";
1055 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
1056 *output << "-\t";
1057 *output << endl;
1058 AtomNo++;
1059 }
1060 MolCounter++;
1061 }
1062 }
1063
1064 // store & free
1065 output->flush();
1066 output->close();
1067 delete(output);
1068 delete(fname);
1069
1070 return true;
1071};
1072
1073
1074/** Tries given filename or standard on saving the config file.
1075 * \param *ConfigFileName name of file
1076 * \param *periode pointer to periodentafel structure with all the elements
1077 * \param *molecules list of molecules structure with all the atoms and coordinates
1078 */
1079void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
1080{
1081 char filename[MAXSTRINGSIZE];
1082 ofstream output;
1083 molecule *mol = NULL;
1084
1085 // first save as PDB data
1086 if (ConfigFileName != NULL)
1087 strcpy(filename, ConfigFileName);
1088 if (output == NULL)
1089 strcpy(filename,"main_pcp_linux");
1090 Log() << Verbose(0) << "Saving as pdb input ... " << endl;
1091 if (SavePDB(filename, molecules))
1092 Log() << Verbose(0) << "\t... done." << endl;
1093 else
1094 Log() << Verbose(0) << "\t... failed." << endl;
1095
1096 // then save as tremolo data file
1097 if (ConfigFileName != NULL)
1098 strcpy(filename, ConfigFileName);
1099 if (output == NULL)
1100 strcpy(filename,"main_pcp_linux");
1101 Log() << Verbose(0) << "Saving as tremolo data input ... " << endl;
1102 if (SaveTREMOLO(filename, molecules))
1103 Log() << Verbose(0) << "\t... done." << endl;
1104 else
1105 Log() << Verbose(0) << "\t... failed." << endl;
1106
1107 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1108 int N = molecules->ListOfMolecules.size();
1109 if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
1110 int *src = new int[N];
1111 N=0;
1112 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1113 src[N++] = (*ListRunner)->IndexNr;
1114 }
1115 mol = World::getInstance().createMolecule();
1116 mol->SetNameFromFilename(ConfigFileName);
1117 //mol->CalculateOrbitals(*this);
1118 delete[](src);
1119 } else {
1120 if (!molecules->ListOfMolecules.empty()) {
1121 mol = *(molecules->ListOfMolecules.begin());
1122 mol->doCountAtoms();
1123 //mol->CalculateOrbitals(*this);
1124 } else {
1125 DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
1126 }
1127 }
1128
1129 Log() << Verbose(0) << "Storing configuration ... " << endl;
1130 // get correct valence orbitals
1131 if (ConfigFileName != NULL) { // test the file name
1132 strcpy(filename, ConfigFileName);
1133 output.open(filename, ios::trunc);
1134 } else if (strlen(configname) != 0) {
1135 strcpy(filename, configname);
1136 output.open(configname, ios::trunc);
1137 } else {
1138 strcpy(filename, DEFAULTCONFIG);
1139 output.open(DEFAULTCONFIG, ios::trunc);
1140 }
1141 output.close();
1142 output.clear();
1143 Log() << Verbose(0) << "Saving of config file ... " << endl;
1144 if (Save(filename, periode, mol))
1145 Log() << Verbose(0) << "\t... successful." << endl;
1146 else
1147 Log() << Verbose(0) << "\t... failed." << endl;
1148
1149 // and save to xyz file
1150 if (ConfigFileName != NULL) {
1151 strcpy(filename, ConfigFileName);
1152 strcat(filename, ".xyz");
1153 output.open(filename, ios::trunc);
1154 }
1155 if (output == NULL) {
1156 strcpy(filename,"main_pcp_linux");
1157 strcat(filename, ".xyz");
1158 output.open(filename, ios::trunc);
1159 }
1160 Log() << Verbose(0) << "Saving of XYZ file ... " << endl;
1161 if (mol->MDSteps <= 1) {
1162 if (mol->OutputXYZ(&output))
1163 Log() << Verbose(0) << "\t... successful." << endl;
1164 else
1165 Log() << Verbose(0) << "\t... failed." << endl;
1166 } else {
1167 if (mol->OutputTrajectoriesXYZ(&output))
1168 Log() << Verbose(0) << "\t... successful." << endl;
1169 else
1170 Log() << Verbose(0) << "\t... failed." << endl;
1171 }
1172 output.close();
1173 output.clear();
1174
1175 // and save as MPQC configuration
1176 if (ConfigFileName != NULL)
1177 strcpy(filename, ConfigFileName);
1178 if (output == NULL)
1179 strcpy(filename,"main_pcp_linux");
1180 Log() << Verbose(0) << "Saving as mpqc input .. " << endl;
1181 if (SaveMPQC(filename, mol))
1182 Log() << Verbose(0) << "\t... done." << endl;
1183 else
1184 Log() << Verbose(0) << "\t... failed." << endl;
1185
1186 // don't destroy molecule as it contains all our atoms
1187 //World::getInstance().destroyMolecule(mol);
1188};
1189
1190/** Reads parameter from a parsed file.
1191 * The file is either parsed for a certain keyword or if null is given for
1192 * the value in row yth and column xth. If the keyword was necessity#critical,
1193 * then an error is thrown and the programme aborted.
1194 * \warning value is modified (both in contents and position)!
1195 * \param verbose 1 - print found value to stderr, 0 - don't
1196 * \param *file file to be parsed
1197 * \param name Name of value in file (at least 3 chars!)
1198 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1199 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1200 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1201 * counted from this unresetted position!)
1202 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1203 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1204 * \param type Type of the Parameter to be read
1205 * \param value address of the value to be read (must have been allocated)
1206 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1207 * \param critical necessity of this keyword being specified (optional, critical)
1208 * \return 1 - found, 0 - not found
1209 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1210 */
1211int 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) {
1212 int i = 0;
1213 int j = 0; // loop variables
1214 int length = 0;
1215 int maxlength = -1;
1216 long file_position = file->tellg(); // mark current position
1217 char *dummy1 = NULL;
1218 char *dummy = NULL;
1219 char free_dummy[MAXSTRINGSIZE]; // pointers in the line that is read in per step
1220 dummy1 = free_dummy;
1221
1222 //fprintf(stderr,"Parsing for %s\n",name);
1223 if (repetition == 0)
1224 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1225 return 0;
1226
1227 int line = 0; // marks line where parameter was found
1228 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1229 while((found != repetition)) {
1230 dummy1 = dummy = free_dummy;
1231 do {
1232 file->getline(dummy1, 256); // Read the whole line
1233 if (file->eof()) {
1234 if ((critical) && (found == 0)) {
1235 //Error(InitReading, name);
1236 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1237 exit(255);
1238 } else {
1239 //if (!sequential)
1240 file->clear();
1241 file->seekg(file_position, ios::beg); // rewind to start position
1242 return 0;
1243 }
1244 }
1245 line++;
1246 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1247
1248 // C++ getline removes newline at end, thus re-add
1249 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1250 i = strlen(dummy1);
1251 dummy1[i] = '\n';
1252 dummy1[i+1] = '\0';
1253 }
1254 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1255
1256 if (dummy1 == NULL) {
1257 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1258 } else {
1259 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1260 }
1261 // Seek for possible end of keyword on line if given ...
1262 if (name != NULL) {
1263 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1264 if (dummy == NULL) {
1265 dummy = strchr(dummy1, ' '); // if not found seek for space
1266 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1267 dummy++;
1268 }
1269 if (dummy == NULL) {
1270 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1271 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1272 //Error(FileOpenParams, NULL);
1273 } else {
1274 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1275 }
1276 } else dummy = dummy1;
1277 // ... and check if it is the keyword!
1278 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1279 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1280 found++; // found the parameter!
1281 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1282
1283 if (found == repetition) {
1284 for (i=0;i<xth;i++) { // i = rows
1285 if (type >= grid) {
1286 // grid structure means that grid starts on the next line, not right after keyword
1287 dummy1 = dummy = free_dummy;
1288 do {
1289 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1290 if (file->eof()) {
1291 if ((critical) && (found == 0)) {
1292 //Error(InitReading, name);
1293 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1294 exit(255);
1295 } else {
1296 //if (!sequential)
1297 file->clear();
1298 file->seekg(file_position, ios::beg); // rewind to start position
1299 return 0;
1300 }
1301 }
1302 line++;
1303 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1304 if (dummy1 == NULL){
1305 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1306 } else {
1307 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1308 }
1309 } else { // simple int, strings or doubles start in the same line
1310 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1311 dummy++;
1312 }
1313 // C++ getline removes newline at end, thus re-add
1314 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1315 j = strlen(dummy1);
1316 dummy1[j] = '\n';
1317 dummy1[j+1] = '\0';
1318 }
1319
1320 int start = (type >= grid) ? 0 : yth-1 ;
1321 for (j=start;j<yth;j++) { // j = columns
1322 // check for lower triangular area and upper triangular area
1323 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1324 *((double *)value) = 0.0;
1325 fprintf(stderr,"%f\t",*((double *)value));
1326 value = (void *)((long)value + sizeof(double));
1327 //value += sizeof(double);
1328 } else {
1329 // otherwise we must skip all interjacent tabs and spaces and find next value
1330 dummy1 = dummy;
1331 dummy = strchr(dummy1, '\t'); // seek for tab or space
1332 if (dummy == NULL)
1333 dummy = strchr(dummy1, ' '); // if not found seek for space
1334 if (dummy == NULL) { // if still zero returned ...
1335 dummy = strchr(dummy1, '\n'); // ... at line end then
1336 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1337 if (critical) {
1338 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1339 //return 0;
1340 exit(255);
1341 //Error(FileOpenParams, NULL);
1342 } else {
1343 //if (!sequential)
1344 file->clear();
1345 file->seekg(file_position, ios::beg); // rewind to start position
1346 return 0;
1347 }
1348 }
1349 } else {
1350 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1351 }
1352 if (*dummy1 == '#') {
1353 // found comment, skipping rest of line
1354 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1355 if (!sequential) { // here we need it!
1356 file->seekg(file_position, ios::beg); // rewind to start position
1357 }
1358 return 0;
1359 }
1360 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1361 switch(type) {
1362 case (row_int):
1363 *((int *)value) = atoi(dummy1);
1364 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1365 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1366 value = (void *)((long)value + sizeof(int));
1367 //value += sizeof(int);
1368 break;
1369 case(row_double):
1370 case(grid):
1371 case(lower_trigrid):
1372 case(upper_trigrid):
1373 *((double *)value) = atof(dummy1);
1374 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1375 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1376 value = (void *)((long)value + sizeof(double));
1377 //value += sizeof(double);
1378 break;
1379 case(double_type):
1380 *((double *)value) = atof(dummy1);
1381 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1382 //value += sizeof(double);
1383 break;
1384 case(int_type):
1385 *((int *)value) = atoi(dummy1);
1386 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1387 //value += sizeof(int);
1388 break;
1389 default:
1390 case(string_type):
1391 if (value != NULL) {
1392 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1393 maxlength = MAXSTRINGSIZE;
1394 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1395 strncpy((char *)value, dummy1, length); // copy as much
1396 ((char *)value)[length] = '\0'; // and set end marker
1397 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1398 //value += sizeof(char);
1399 } else {
1400 }
1401 break;
1402 }
1403 }
1404 while (*dummy == '\t')
1405 dummy++;
1406 }
1407 }
1408 }
1409 }
1410 }
1411 if ((type >= row_int) && (verbose))
1412 fprintf(stderr,"\n");
1413 if (!sequential) {
1414 file->clear();
1415 file->seekg(file_position, ios::beg); // rewind to start position
1416 }
1417 //fprintf(stderr, "End of Parsing\n\n");
1418
1419 return (found); // true if found, false if not
1420}
1421
1422
1423/** Reads parameter from a parsed file.
1424 * The file is either parsed for a certain keyword or if null is given for
1425 * the value in row yth and column xth. If the keyword was necessity#critical,
1426 * then an error is thrown and the programme aborted.
1427 * \warning value is modified (both in contents and position)!
1428 * \param verbose 1 - print found value to stderr, 0 - don't
1429 * \param *FileBuffer pointer to buffer structure
1430 * \param name Name of value in file (at least 3 chars!)
1431 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1432 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1433 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1434 * counted from this unresetted position!)
1435 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1436 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1437 * \param type Type of the Parameter to be read
1438 * \param value address of the value to be read (must have been allocated)
1439 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1440 * \param critical necessity of this keyword being specified (optional, critical)
1441 * \return 1 - found, 0 - not found
1442 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1443 */
1444int 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) {
1445 int i = 0;
1446 int j = 0; // loop variables
1447 int length = 0;
1448 int maxlength = -1;
1449 int OldCurrentLine = FileBuffer->CurrentLine;
1450 char *dummy1 = NULL;
1451 char *dummy = NULL; // pointers in the line that is read in per step
1452
1453 //fprintf(stderr,"Parsing for %s\n",name);
1454 if (repetition == 0)
1455 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1456 return 0;
1457
1458 int line = 0; // marks line where parameter was found
1459 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1460 while((found != repetition)) {
1461 dummy1 = dummy = NULL;
1462 do {
1463 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1464 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1465 if ((critical) && (found == 0)) {
1466 //Error(InitReading, name);
1467 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1468 exit(255);
1469 } else {
1470 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1471 return 0;
1472 }
1473 }
1474 if (dummy1 == NULL) {
1475 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1476 } else {
1477 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1478 }
1479 line++;
1480 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1481
1482 // Seek for possible end of keyword on line if given ...
1483 if (name != NULL) {
1484 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1485 if (dummy == NULL) {
1486 dummy = strchr(dummy1, ' '); // if not found seek for space
1487 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1488 dummy++;
1489 }
1490 if (dummy == NULL) {
1491 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1492 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1493 //Error(FileOpenParams, NULL);
1494 } else {
1495 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1496 }
1497 } else dummy = dummy1;
1498 // ... and check if it is the keyword!
1499 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1500 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1501 found++; // found the parameter!
1502 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1503
1504 if (found == repetition) {
1505 for (i=0;i<xth;i++) { // i = rows
1506 if (type >= grid) {
1507 // grid structure means that grid starts on the next line, not right after keyword
1508 dummy1 = dummy = NULL;
1509 do {
1510 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1511 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1512 if ((critical) && (found == 0)) {
1513 //Error(InitReading, name);
1514 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1515 exit(255);
1516 } else {
1517 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1518 return 0;
1519 }
1520 }
1521 if (dummy1 == NULL) {
1522 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1523 } else {
1524 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1525 }
1526 line++;
1527 } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
1528 dummy = dummy1;
1529 } else { // simple int, strings or doubles start in the same line
1530 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1531 dummy++;
1532 }
1533
1534 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
1535 // check for lower triangular area and upper triangular area
1536 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1537 *((double *)value) = 0.0;
1538 fprintf(stderr,"%f\t",*((double *)value));
1539 value = (void *)((long)value + sizeof(double));
1540 //value += sizeof(double);
1541 } else {
1542 // otherwise we must skip all interjacent tabs and spaces and find next value
1543 dummy1 = dummy;
1544 dummy = strchr(dummy1, '\t'); // seek for tab or space
1545 if (dummy == NULL)
1546 dummy = strchr(dummy1, ' '); // if not found seek for space
1547 if (dummy == NULL) { // if still zero returned ...
1548 dummy = strchr(dummy1, '\n'); // ... at line end then
1549 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1550 if (critical) {
1551 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1552 //return 0;
1553 exit(255);
1554 //Error(FileOpenParams, NULL);
1555 } else {
1556 if (!sequential) { // here we need it!
1557 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1558 }
1559 return 0;
1560 }
1561 }
1562 } else {
1563 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1564 }
1565 if (*dummy1 == '#') {
1566 // found comment, skipping rest of line
1567 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1568 if (!sequential) { // here we need it!
1569 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1570 }
1571 return 0;
1572 }
1573 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1574 switch(type) {
1575 case (row_int):
1576 *((int *)value) = atoi(dummy1);
1577 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1578 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1579 value = (void *)((long)value + sizeof(int));
1580 //value += sizeof(int);
1581 break;
1582 case(row_double):
1583 case(grid):
1584 case(lower_trigrid):
1585 case(upper_trigrid):
1586 *((double *)value) = atof(dummy1);
1587 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1588 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1589 value = (void *)((long)value + sizeof(double));
1590 //value += sizeof(double);
1591 break;
1592 case(double_type):
1593 *((double *)value) = atof(dummy1);
1594 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1595 //value += sizeof(double);
1596 break;
1597 case(int_type):
1598 *((int *)value) = atoi(dummy1);
1599 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1600 //value += sizeof(int);
1601 break;
1602 default:
1603 case(string_type):
1604 if (value != NULL) {
1605 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1606 maxlength = MAXSTRINGSIZE;
1607 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1608 strncpy((char *)value, dummy1, length); // copy as much
1609 ((char *)value)[length] = '\0'; // and set end marker
1610 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1611 //value += sizeof(char);
1612 } else {
1613 }
1614 break;
1615 }
1616 }
1617 while (*dummy == '\t')
1618 dummy++;
1619 }
1620 }
1621 }
1622 }
1623 }
1624 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1625 if (!sequential) {
1626 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1627 }
1628 //fprintf(stderr, "End of Parsing\n\n");
1629
1630 return (found); // true if found, false if not
1631}
1632
1633/** Reading of Thermostat related values from parameter file.
1634 * \param *fb file buffer containing the config file
1635 */
1636void config::ParseThermostats(class ConfigFileBuffer * const fb)
1637{
1638 char * const thermo = new char[12];
1639 const int verbose = 0;
1640
1641 // read desired Thermostat from file along with needed additional parameters
1642 if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
1643 Thermostats->makeActive(thermo,fb);
1644 } else {
1645 if ((Thermostats->TargetTemp != 0))
1646 DoLog(2) && (Log() << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
1647 Thermostats->chooseNone();
1648 }
1649 delete[](thermo);
1650};
1651
Note: See TracBrowser for help on using the repository browser.