source: src/config.cpp@ 8d1dd4

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 8d1dd4 was 8d1dd4, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Removed obsolete load methods from config class

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