source: src/config.cpp@ 2be37b

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 2be37b was 51c3e4, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'stable' into StructureRefactoring

Conflicts:

src/atom_trajectoryparticle.cpp

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