source: src/config.cpp@ 14c57a

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 Candidate_v1.7.0 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 14c57a was 14c57a, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made all parts of the programm use the new thermostat structure

  • Property mode set to 100644
File size: 74.3 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/** Stores all elements of config structure from which they can be re-read.
625 * \param *filename name of file
626 * \param *periode pointer to a periodentafel class with all elements
627 * \param *mol pointer to molecule containing all atoms of the molecule
628 */
629bool config::Save(const char * const filename, const periodentafel * const periode, molecule * const mol) const
630{
631 bool result = true;
632 const Matrix &domain = World::getInstance().getDomain().getM();
633 ofstream * const output = new ofstream(filename, ios::out);
634 if (output != NULL) {
635 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
636 *output << endl;
637 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
638 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
639 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
640 *output << endl;
641 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
642 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
643 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
644 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
645 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
646 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
647 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
648 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
649 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
650 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
651 *output << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t";
652 *output << Thermostats->activeThermostat->writeParams();
653 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
654 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
655 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
656 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
657 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
658 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
659 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
660 *output << endl;
661 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
662 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
663 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
664 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
665 *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
666 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
667 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
668 *output << endl;
669 *output << "# Values specifying when to stop" << endl;
670 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
671 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
672 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
673 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
674 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
675 *output << endl;
676 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
677 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
678 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
679 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
680 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
681 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
682 *output << endl;
683 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
684 *output << domain.at(0,0) << "\t" << endl;
685 *output << domain.at(1,0) << "\t" << domain.at(1,1) << "\t" << endl;
686 *output << domain.at(2,0) << "\t" << domain.at(2,1) << "\t" << domain.at(2,2) << "\t" << endl;
687 // FIXME
688 *output << endl;
689 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
690 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
691 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
692 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
693 switch (config::RiemannTensor) {
694 case 0: //UseNoRT
695 break;
696 case 1: // UseRT
697 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
698 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
699 break;
700 }
701 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
702 // write out both types for easier changing afterwards
703 // switch (PsiType) {
704 // case 0:
705 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
706 // break;
707 // case 1:
708 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
709 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
710 // break;
711 // }
712 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
713 *output << endl;
714 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
715 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
716 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
717 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
718 *output << "MaxTypes\t" << mol->getElementCount() << "\t# maximum number of different ion types" << endl;
719 *output << endl;
720 result = result && mol->Checkout(output);
721 if (mol->MDSteps <=1 )
722 result = result && mol->Output(output);
723 else
724 result = result && mol->OutputTrajectories(output);
725 output->close();
726 output->clear();
727 delete(output);
728 return result;
729 } else {
730 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file:" << filename << endl);
731 return false;
732 }
733};
734
735/** Stores all elements in a MPQC input file.
736 * Note that this format cannot be parsed again.
737 * \param *filename name of file (without ".in" suffix!)
738 * \param *mol pointer to molecule containing all atoms of the molecule
739 */
740bool config::SaveMPQC(const char * const filename, const molecule * const mol) const
741{
742 int AtomNo = -1;
743 Vector *center = NULL;
744 ofstream *output = NULL;
745
746 // first without hessian
747 {
748 stringstream * const fname = new stringstream;;
749 *fname << filename << ".in";
750 output = new ofstream(fname->str().c_str(), ios::out);
751 if (output == NULL) {
752 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file:" << fname << endl);
753 delete(fname);
754 return false;
755 }
756 *output << "% Created by MoleCuilder" << endl;
757 *output << "mpqc: (" << endl;
758 *output << "\tsavestate = no" << endl;
759 *output << "\tdo_gradient = yes" << endl;
760 *output << "\tmole<MBPT2>: (" << endl;
761 *output << "\t\tmaxiter = 200" << endl;
762 *output << "\t\tbasis = $:basis" << endl;
763 *output << "\t\tmolecule = $:molecule" << endl;
764 *output << "\t\treference<CLHF>: (" << endl;
765 *output << "\t\t\tbasis = $:basis" << endl;
766 *output << "\t\t\tmolecule = $:molecule" << endl;
767 *output << "\t\t)" << endl;
768 *output << "\t)" << endl;
769 *output << ")" << endl;
770 *output << "molecule<Molecule>: (" << endl;
771 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
772 *output << "\t{ atoms geometry } = {" << endl;
773 center = mol->DetermineCenterOfAll();
774 // output of atoms
775 AtomNo = 0;
776 mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
777 delete(center);
778 *output << "\t}" << endl;
779 *output << ")" << endl;
780 *output << "basis<GaussianBasisSet>: (" << endl;
781 *output << "\tname = \"" << basis << "\"" << endl;
782 *output << "\tmolecule = $:molecule" << endl;
783 *output << ")" << endl;
784 output->close();
785 delete(output);
786 delete(fname);
787 }
788
789 // second with hessian
790 {
791 stringstream * const fname = new stringstream;
792 *fname << filename << ".hess.in";
793 output = new ofstream(fname->str().c_str(), ios::out);
794 if (output == NULL) {
795 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc hessian output file:" << fname << endl);
796 delete(fname);
797 return false;
798 }
799 *output << "% Created by MoleCuilder" << endl;
800 *output << "mpqc: (" << endl;
801 *output << "\tsavestate = no" << endl;
802 *output << "\tdo_gradient = yes" << endl;
803 *output << "\tmole<CLHF>: (" << endl;
804 *output << "\t\tmaxiter = 200" << endl;
805 *output << "\t\tbasis = $:basis" << endl;
806 *output << "\t\tmolecule = $:molecule" << endl;
807 *output << "\t)" << endl;
808 *output << "\tfreq<MolecularFrequencies>: (" << endl;
809 *output << "\t\tmolecule=$:molecule" << endl;
810 *output << "\t)" << endl;
811 *output << ")" << endl;
812 *output << "molecule<Molecule>: (" << endl;
813 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
814 *output << "\t{ atoms geometry } = {" << endl;
815 center = mol->DetermineCenterOfAll();
816 // output of atoms
817 AtomNo = 0;
818 mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
819 delete(center);
820 *output << "\t}" << endl;
821 *output << ")" << endl;
822 *output << "basis<GaussianBasisSet>: (" << endl;
823 *output << "\tname = \"3-21G\"" << endl;
824 *output << "\tmolecule = $:molecule" << endl;
825 *output << ")" << endl;
826 output->close();
827 delete(output);
828 delete(fname);
829 }
830
831 return true;
832};
833
834/** Stores all atoms from all molecules in a PDB input file.
835 * Note that this format cannot be parsed again.
836 * \param *filename name of file (without ".in" suffix!)
837 * \param *MolList pointer to MoleculeListClass containing all atoms
838 */
839bool config::SavePDB(const char * const filename, const MoleculeListClass * const MolList) const
840{
841 int AtomNo = -1;
842 int MolNo = 0;
843 FILE *f = NULL;
844
845 char name[MAXSTRINGSIZE];
846 strncpy(name, filename, MAXSTRINGSIZE-1);
847 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
848 f = fopen(name, "w" );
849 if (f == NULL) {
850 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
851 return false;
852 }
853 fprintf(f, "# Created by MoleCuilder\n");
854
855 for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
856 int *elementNo = new int[MAX_ELEMENTS];
857 for (int i=0;i<MAX_ELEMENTS;i++)
858 elementNo[i] = 0;
859 AtomNo = 0;
860 for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
861 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->Z]);
862 elementNo[(*iter)->getType()->Z] = (elementNo[(*iter)->getType()->Z]+1) % 100; // confine to two digits
863 fprintf(f,
864 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
865 (*iter)->nr, /* atom serial number */
866 name, /* atom name */
867 (*MolRunner)->name, /* residue name */
868 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
869 MolNo, /* residue sequence number */
870 (*iter)->at(0), /* position X in Angstroem */
871 (*iter)->at(1), /* position Y in Angstroem */
872 (*iter)->at(2), /* position Z in Angstroem */
873 (double)(*iter)->getType()->Valence, /* occupancy */
874 (double)(*iter)->getType()->NoValenceOrbitals, /* temperature factor */
875 "0", /* segment identifier */
876 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
877 "0"); /* charge */
878 AtomNo++;
879 }
880 delete[](elementNo);
881 MolNo++;
882 }
883 fclose(f);
884
885 return true;
886};
887
888/** Stores all atoms in a PDB input file.
889 * Note that this format cannot be parsed again.
890 * \param *filename name of file (without ".in" suffix!)
891 * \param *mol pointer to molecule
892 */
893bool config::SavePDB(const char * const filename, const molecule * const mol) const
894{
895 int AtomNo = -1;
896 FILE *f = NULL;
897
898 int *elementNo = new int[MAX_ELEMENTS];
899 for (int i=0;i<MAX_ELEMENTS;i++)
900 elementNo[i] = 0;
901 char name[MAXSTRINGSIZE];
902 strncpy(name, filename, MAXSTRINGSIZE-1);
903 strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
904 f = fopen(name, "w" );
905 if (f == NULL) {
906 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
907 delete[](elementNo);
908 return false;
909 }
910 fprintf(f, "# Created by MoleCuilder\n");
911
912 AtomNo = 0;
913 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
914 sprintf(name, "%2s%2d",(*iter)->getType()->getSymbol().c_str(), elementNo[(*iter)->getType()->Z]);
915 elementNo[(*iter)->getType()->Z] = (elementNo[(*iter)->getType()->Z]+1) % 100; // confine to two digits
916 fprintf(f,
917 "ATOM %6u %-4s %4s%c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n",
918 (*iter)->nr, /* atom serial number */
919 name, /* atom name */
920 mol->name, /* residue name */
921 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */
922 0, /* residue sequence number */
923 (*iter)->at(0), /* position X in Angstroem */
924 (*iter)->at(1), /* position Y in Angstroem */
925 (*iter)->at(2), /* position Z in Angstroem */
926 (double)(*iter)->getType()->Valence, /* occupancy */
927 (double)(*iter)->getType()->NoValenceOrbitals, /* temperature factor */
928 "0", /* segment identifier */
929 (*iter)->getType()->getSymbol().c_str(), /* element symbol */
930 "0"); /* charge */
931 AtomNo++;
932 }
933 fclose(f);
934 delete[](elementNo);
935
936 return true;
937};
938
939/** Stores all atoms in a TREMOLO data input file.
940 * Note that this format cannot be parsed again.
941 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
942 * \param *filename name of file (without ".in" suffix!)
943 * \param *mol pointer to molecule
944 */
945bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
946{
947 ofstream *output = NULL;
948 stringstream * const fname = new stringstream;
949
950 *fname << filename << ".data";
951 output = new ofstream(fname->str().c_str(), ios::out);
952 if (output == NULL) {
953 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
954 delete(fname);
955 return false;
956 }
957
958 // scan maximum number of neighbours
959 int MaxNeighbours = 0;
960 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
961 const int count = (*iter)->ListOfBonds.size();
962 if (MaxNeighbours < count)
963 MaxNeighbours = count;
964 }
965 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
966
967 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
968 *output << (*iter)->nr << "\t";
969 *output << (*iter)->getName() << "\t";
970 *output << mol->name << "\t";
971 *output << 0 << "\t";
972 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
973 *output << static_cast<double>((*iter)->getType()->Valence) << "\t";
974 *output << (*iter)->getType()->getSymbol() << "\t";
975 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
976 *output << (*runner)->GetOtherAtom(*iter)->nr << "\t";
977 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
978 *output << "-\t";
979 *output << endl;
980 }
981 output->flush();
982 output->close();
983 delete(output);
984 delete(fname);
985
986 return true;
987};
988
989/** Stores all atoms from all molecules in a TREMOLO data input file.
990 * Note that this format cannot be parsed again.
991 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
992 * \param *filename name of file (without ".in" suffix!)
993 * \param *MolList pointer to MoleculeListClass containing all atoms
994 */
995bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
996{
997 Info FunctionInfo(__func__);
998 ofstream *output = NULL;
999 stringstream * const fname = new stringstream;
1000
1001 *fname << filename << ".data";
1002 output = new ofstream(fname->str().c_str(), ios::out);
1003 if (output == NULL) {
1004 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
1005 delete(fname);
1006 return false;
1007 }
1008
1009 // scan maximum number of neighbours
1010 int MaxNeighbours = 0;
1011 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1012 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1013 const int count = (*iter)->ListOfBonds.size();
1014 if (MaxNeighbours < count)
1015 MaxNeighbours = count;
1016 }
1017 }
1018 *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
1019
1020 // create global to local id map
1021 map<int, int> LocalNotoGlobalNoMap;
1022 {
1023 unsigned int MolCounter = 0;
1024 int AtomNo = 1;
1025 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1026 for(molecule::iterator AtomRunner = (*MolWalker)->begin(); AtomRunner != (*MolWalker)->end(); ++AtomRunner) {
1027 LocalNotoGlobalNoMap.insert( pair<int,int>((*AtomRunner)->getId(), AtomNo++) );
1028 }
1029 MolCounter++;
1030 }
1031 ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
1032 }
1033
1034 // write the file
1035 {
1036 int MolCounter = 0;
1037 int AtomNo = 0;
1038 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
1039 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
1040 *output << LocalNotoGlobalNoMap[ (*iter)->getId() ] << "\t";
1041 *output << (*iter)->getName() << "\t";
1042 *output << (*MolWalker)->name << "\t";
1043 *output << MolCounter+1 << "\t";
1044 *output << (*iter)->at(0) << "\t" << (*iter)->at(1) << "\t" << (*iter)->at(2) << "\t";
1045 *output << (double)(*iter)->getType()->Valence << "\t";
1046 *output << (*iter)->getType()->getSymbol() << "\t";
1047 for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
1048 *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom((*iter))->getId() ] << "\t";
1049 for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
1050 *output << "-\t";
1051 *output << endl;
1052 AtomNo++;
1053 }
1054 MolCounter++;
1055 }
1056 }
1057
1058 // store & free
1059 output->flush();
1060 output->close();
1061 delete(output);
1062 delete(fname);
1063
1064 return true;
1065};
1066
1067
1068/** Tries given filename or standard on saving the config file.
1069 * \param *ConfigFileName name of file
1070 * \param *periode pointer to periodentafel structure with all the elements
1071 * \param *molecules list of molecules structure with all the atoms and coordinates
1072 */
1073void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
1074{
1075 char filename[MAXSTRINGSIZE];
1076 ofstream output;
1077 molecule *mol = NULL;
1078
1079 // first save as PDB data
1080 if (ConfigFileName != NULL)
1081 strcpy(filename, ConfigFileName);
1082 if (output == NULL)
1083 strcpy(filename,"main_pcp_linux");
1084 Log() << Verbose(0) << "Saving as pdb input ... " << endl;
1085 if (SavePDB(filename, molecules))
1086 Log() << Verbose(0) << "\t... done." << endl;
1087 else
1088 Log() << Verbose(0) << "\t... failed." << endl;
1089
1090 // then save as tremolo data file
1091 if (ConfigFileName != NULL)
1092 strcpy(filename, ConfigFileName);
1093 if (output == NULL)
1094 strcpy(filename,"main_pcp_linux");
1095 Log() << Verbose(0) << "Saving as tremolo data input ... " << endl;
1096 if (SaveTREMOLO(filename, molecules))
1097 Log() << Verbose(0) << "\t... done." << endl;
1098 else
1099 Log() << Verbose(0) << "\t... failed." << endl;
1100
1101 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1102 int N = molecules->ListOfMolecules.size();
1103 if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
1104 int *src = new int[N];
1105 N=0;
1106 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1107 src[N++] = (*ListRunner)->IndexNr;
1108 }
1109 mol = World::getInstance().createMolecule();
1110 mol->SetNameFromFilename(ConfigFileName);
1111 //mol->CalculateOrbitals(*this);
1112 delete[](src);
1113 } else {
1114 if (!molecules->ListOfMolecules.empty()) {
1115 mol = *(molecules->ListOfMolecules.begin());
1116 mol->doCountAtoms();
1117 //mol->CalculateOrbitals(*this);
1118 } else {
1119 DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
1120 }
1121 }
1122
1123 Log() << Verbose(0) << "Storing configuration ... " << endl;
1124 // get correct valence orbitals
1125 if (ConfigFileName != NULL) { // test the file name
1126 strcpy(filename, ConfigFileName);
1127 output.open(filename, ios::trunc);
1128 } else if (strlen(configname) != 0) {
1129 strcpy(filename, configname);
1130 output.open(configname, ios::trunc);
1131 } else {
1132 strcpy(filename, DEFAULTCONFIG);
1133 output.open(DEFAULTCONFIG, ios::trunc);
1134 }
1135 output.close();
1136 output.clear();
1137 Log() << Verbose(0) << "Saving of config file ... " << endl;
1138 if (Save(filename, periode, mol))
1139 Log() << Verbose(0) << "\t... successful." << endl;
1140 else
1141 Log() << Verbose(0) << "\t... failed." << endl;
1142
1143 // and save to xyz file
1144 if (ConfigFileName != NULL) {
1145 strcpy(filename, ConfigFileName);
1146 strcat(filename, ".xyz");
1147 output.open(filename, ios::trunc);
1148 }
1149 if (output == NULL) {
1150 strcpy(filename,"main_pcp_linux");
1151 strcat(filename, ".xyz");
1152 output.open(filename, ios::trunc);
1153 }
1154 Log() << Verbose(0) << "Saving of XYZ file ... " << endl;
1155 if (mol->MDSteps <= 1) {
1156 if (mol->OutputXYZ(&output))
1157 Log() << Verbose(0) << "\t... successful." << endl;
1158 else
1159 Log() << Verbose(0) << "\t... failed." << endl;
1160 } else {
1161 if (mol->OutputTrajectoriesXYZ(&output))
1162 Log() << Verbose(0) << "\t... successful." << endl;
1163 else
1164 Log() << Verbose(0) << "\t... failed." << endl;
1165 }
1166 output.close();
1167 output.clear();
1168
1169 // and save as MPQC configuration
1170 if (ConfigFileName != NULL)
1171 strcpy(filename, ConfigFileName);
1172 if (output == NULL)
1173 strcpy(filename,"main_pcp_linux");
1174 Log() << Verbose(0) << "Saving as mpqc input .. " << endl;
1175 if (SaveMPQC(filename, mol))
1176 Log() << Verbose(0) << "\t... done." << endl;
1177 else
1178 Log() << Verbose(0) << "\t... failed." << endl;
1179
1180 // don't destroy molecule as it contains all our atoms
1181 //World::getInstance().destroyMolecule(mol);
1182};
1183
1184/** Reads parameter from a parsed file.
1185 * The file is either parsed for a certain keyword or if null is given for
1186 * the value in row yth and column xth. If the keyword was necessity#critical,
1187 * then an error is thrown and the programme aborted.
1188 * \warning value is modified (both in contents and position)!
1189 * \param verbose 1 - print found value to stderr, 0 - don't
1190 * \param *file file to be parsed
1191 * \param name Name of value in file (at least 3 chars!)
1192 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1193 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1194 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1195 * counted from this unresetted position!)
1196 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1197 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1198 * \param type Type of the Parameter to be read
1199 * \param value address of the value to be read (must have been allocated)
1200 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1201 * \param critical necessity of this keyword being specified (optional, critical)
1202 * \return 1 - found, 0 - not found
1203 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1204 */
1205int 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) {
1206 int i = 0;
1207 int j = 0; // loop variables
1208 int length = 0;
1209 int maxlength = -1;
1210 long file_position = file->tellg(); // mark current position
1211 char *dummy1 = NULL;
1212 char *dummy = NULL;
1213 char free_dummy[MAXSTRINGSIZE]; // pointers in the line that is read in per step
1214 dummy1 = free_dummy;
1215
1216 //fprintf(stderr,"Parsing for %s\n",name);
1217 if (repetition == 0)
1218 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1219 return 0;
1220
1221 int line = 0; // marks line where parameter was found
1222 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1223 while((found != repetition)) {
1224 dummy1 = dummy = free_dummy;
1225 do {
1226 file->getline(dummy1, 256); // Read the whole line
1227 if (file->eof()) {
1228 if ((critical) && (found == 0)) {
1229 //Error(InitReading, name);
1230 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1231 exit(255);
1232 } else {
1233 //if (!sequential)
1234 file->clear();
1235 file->seekg(file_position, ios::beg); // rewind to start position
1236 return 0;
1237 }
1238 }
1239 line++;
1240 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1241
1242 // C++ getline removes newline at end, thus re-add
1243 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1244 i = strlen(dummy1);
1245 dummy1[i] = '\n';
1246 dummy1[i+1] = '\0';
1247 }
1248 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1249
1250 if (dummy1 == NULL) {
1251 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1252 } else {
1253 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1254 }
1255 // Seek for possible end of keyword on line if given ...
1256 if (name != NULL) {
1257 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1258 if (dummy == NULL) {
1259 dummy = strchr(dummy1, ' '); // if not found seek for space
1260 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1261 dummy++;
1262 }
1263 if (dummy == NULL) {
1264 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1265 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1266 //Error(FileOpenParams, NULL);
1267 } else {
1268 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1269 }
1270 } else dummy = dummy1;
1271 // ... and check if it is the keyword!
1272 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1273 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1274 found++; // found the parameter!
1275 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1276
1277 if (found == repetition) {
1278 for (i=0;i<xth;i++) { // i = rows
1279 if (type >= grid) {
1280 // grid structure means that grid starts on the next line, not right after keyword
1281 dummy1 = dummy = free_dummy;
1282 do {
1283 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1284 if (file->eof()) {
1285 if ((critical) && (found == 0)) {
1286 //Error(InitReading, name);
1287 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1288 exit(255);
1289 } else {
1290 //if (!sequential)
1291 file->clear();
1292 file->seekg(file_position, ios::beg); // rewind to start position
1293 return 0;
1294 }
1295 }
1296 line++;
1297 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1298 if (dummy1 == NULL){
1299 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1300 } else {
1301 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1302 }
1303 } else { // simple int, strings or doubles start in the same line
1304 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1305 dummy++;
1306 }
1307 // C++ getline removes newline at end, thus re-add
1308 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1309 j = strlen(dummy1);
1310 dummy1[j] = '\n';
1311 dummy1[j+1] = '\0';
1312 }
1313
1314 int start = (type >= grid) ? 0 : yth-1 ;
1315 for (j=start;j<yth;j++) { // j = columns
1316 // check for lower triangular area and upper triangular area
1317 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1318 *((double *)value) = 0.0;
1319 fprintf(stderr,"%f\t",*((double *)value));
1320 value = (void *)((long)value + sizeof(double));
1321 //value += sizeof(double);
1322 } else {
1323 // otherwise we must skip all interjacent tabs and spaces and find next value
1324 dummy1 = dummy;
1325 dummy = strchr(dummy1, '\t'); // seek for tab or space
1326 if (dummy == NULL)
1327 dummy = strchr(dummy1, ' '); // if not found seek for space
1328 if (dummy == NULL) { // if still zero returned ...
1329 dummy = strchr(dummy1, '\n'); // ... at line end then
1330 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1331 if (critical) {
1332 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1333 //return 0;
1334 exit(255);
1335 //Error(FileOpenParams, NULL);
1336 } else {
1337 //if (!sequential)
1338 file->clear();
1339 file->seekg(file_position, ios::beg); // rewind to start position
1340 return 0;
1341 }
1342 }
1343 } else {
1344 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1345 }
1346 if (*dummy1 == '#') {
1347 // found comment, skipping rest of line
1348 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1349 if (!sequential) { // here we need it!
1350 file->seekg(file_position, ios::beg); // rewind to start position
1351 }
1352 return 0;
1353 }
1354 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1355 switch(type) {
1356 case (row_int):
1357 *((int *)value) = atoi(dummy1);
1358 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1359 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1360 value = (void *)((long)value + sizeof(int));
1361 //value += sizeof(int);
1362 break;
1363 case(row_double):
1364 case(grid):
1365 case(lower_trigrid):
1366 case(upper_trigrid):
1367 *((double *)value) = atof(dummy1);
1368 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1369 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1370 value = (void *)((long)value + sizeof(double));
1371 //value += sizeof(double);
1372 break;
1373 case(double_type):
1374 *((double *)value) = atof(dummy1);
1375 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1376 //value += sizeof(double);
1377 break;
1378 case(int_type):
1379 *((int *)value) = atoi(dummy1);
1380 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1381 //value += sizeof(int);
1382 break;
1383 default:
1384 case(string_type):
1385 if (value != NULL) {
1386 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1387 maxlength = MAXSTRINGSIZE;
1388 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1389 strncpy((char *)value, dummy1, length); // copy as much
1390 ((char *)value)[length] = '\0'; // and set end marker
1391 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1392 //value += sizeof(char);
1393 } else {
1394 }
1395 break;
1396 }
1397 }
1398 while (*dummy == '\t')
1399 dummy++;
1400 }
1401 }
1402 }
1403 }
1404 }
1405 if ((type >= row_int) && (verbose))
1406 fprintf(stderr,"\n");
1407 if (!sequential) {
1408 file->clear();
1409 file->seekg(file_position, ios::beg); // rewind to start position
1410 }
1411 //fprintf(stderr, "End of Parsing\n\n");
1412
1413 return (found); // true if found, false if not
1414}
1415
1416
1417/** Reads parameter from a parsed file.
1418 * The file is either parsed for a certain keyword or if null is given for
1419 * the value in row yth and column xth. If the keyword was necessity#critical,
1420 * then an error is thrown and the programme aborted.
1421 * \warning value is modified (both in contents and position)!
1422 * \param verbose 1 - print found value to stderr, 0 - don't
1423 * \param *FileBuffer pointer to buffer structure
1424 * \param name Name of value in file (at least 3 chars!)
1425 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1426 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1427 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1428 * counted from this unresetted position!)
1429 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1430 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1431 * \param type Type of the Parameter to be read
1432 * \param value address of the value to be read (must have been allocated)
1433 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1434 * \param critical necessity of this keyword being specified (optional, critical)
1435 * \return 1 - found, 0 - not found
1436 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1437 */
1438int 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) {
1439 int i = 0;
1440 int j = 0; // loop variables
1441 int length = 0;
1442 int maxlength = -1;
1443 int OldCurrentLine = FileBuffer->CurrentLine;
1444 char *dummy1 = NULL;
1445 char *dummy = NULL; // pointers in the line that is read in per step
1446
1447 //fprintf(stderr,"Parsing for %s\n",name);
1448 if (repetition == 0)
1449 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1450 return 0;
1451
1452 int line = 0; // marks line where parameter was found
1453 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1454 while((found != repetition)) {
1455 dummy1 = dummy = NULL;
1456 do {
1457 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1458 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1459 if ((critical) && (found == 0)) {
1460 //Error(InitReading, name);
1461 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1462 exit(255);
1463 } else {
1464 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1465 return 0;
1466 }
1467 }
1468 if (dummy1 == NULL) {
1469 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1470 } else {
1471 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1472 }
1473 line++;
1474 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1475
1476 // Seek for possible end of keyword on line if given ...
1477 if (name != NULL) {
1478 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1479 if (dummy == NULL) {
1480 dummy = strchr(dummy1, ' '); // if not found seek for space
1481 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1482 dummy++;
1483 }
1484 if (dummy == NULL) {
1485 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1486 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1487 //Error(FileOpenParams, NULL);
1488 } else {
1489 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1490 }
1491 } else dummy = dummy1;
1492 // ... and check if it is the keyword!
1493 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1494 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1495 found++; // found the parameter!
1496 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1497
1498 if (found == repetition) {
1499 for (i=0;i<xth;i++) { // i = rows
1500 if (type >= grid) {
1501 // grid structure means that grid starts on the next line, not right after keyword
1502 dummy1 = dummy = NULL;
1503 do {
1504 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1505 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1506 if ((critical) && (found == 0)) {
1507 //Error(InitReading, name);
1508 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1509 exit(255);
1510 } else {
1511 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1512 return 0;
1513 }
1514 }
1515 if (dummy1 == NULL) {
1516 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1517 } else {
1518 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1519 }
1520 line++;
1521 } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
1522 dummy = dummy1;
1523 } else { // simple int, strings or doubles start in the same line
1524 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1525 dummy++;
1526 }
1527
1528 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
1529 // check for lower triangular area and upper triangular area
1530 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1531 *((double *)value) = 0.0;
1532 fprintf(stderr,"%f\t",*((double *)value));
1533 value = (void *)((long)value + sizeof(double));
1534 //value += sizeof(double);
1535 } else {
1536 // otherwise we must skip all interjacent tabs and spaces and find next value
1537 dummy1 = dummy;
1538 dummy = strchr(dummy1, '\t'); // seek for tab or space
1539 if (dummy == NULL)
1540 dummy = strchr(dummy1, ' '); // if not found seek for space
1541 if (dummy == NULL) { // if still zero returned ...
1542 dummy = strchr(dummy1, '\n'); // ... at line end then
1543 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1544 if (critical) {
1545 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1546 //return 0;
1547 exit(255);
1548 //Error(FileOpenParams, NULL);
1549 } else {
1550 if (!sequential) { // here we need it!
1551 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1552 }
1553 return 0;
1554 }
1555 }
1556 } else {
1557 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1558 }
1559 if (*dummy1 == '#') {
1560 // found comment, skipping rest of line
1561 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1562 if (!sequential) { // here we need it!
1563 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1564 }
1565 return 0;
1566 }
1567 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1568 switch(type) {
1569 case (row_int):
1570 *((int *)value) = atoi(dummy1);
1571 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1572 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1573 value = (void *)((long)value + sizeof(int));
1574 //value += sizeof(int);
1575 break;
1576 case(row_double):
1577 case(grid):
1578 case(lower_trigrid):
1579 case(upper_trigrid):
1580 *((double *)value) = atof(dummy1);
1581 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1582 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1583 value = (void *)((long)value + sizeof(double));
1584 //value += sizeof(double);
1585 break;
1586 case(double_type):
1587 *((double *)value) = atof(dummy1);
1588 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1589 //value += sizeof(double);
1590 break;
1591 case(int_type):
1592 *((int *)value) = atoi(dummy1);
1593 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1594 //value += sizeof(int);
1595 break;
1596 default:
1597 case(string_type):
1598 if (value != NULL) {
1599 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1600 maxlength = MAXSTRINGSIZE;
1601 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1602 strncpy((char *)value, dummy1, length); // copy as much
1603 ((char *)value)[length] = '\0'; // and set end marker
1604 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1605 //value += sizeof(char);
1606 } else {
1607 }
1608 break;
1609 }
1610 }
1611 while (*dummy == '\t')
1612 dummy++;
1613 }
1614 }
1615 }
1616 }
1617 }
1618 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1619 if (!sequential) {
1620 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1621 }
1622 //fprintf(stderr, "End of Parsing\n\n");
1623
1624 return (found); // true if found, false if not
1625}
1626
1627/** Reading of Thermostat related values from parameter file.
1628 * \param *fb file buffer containing the config file
1629 */
1630void config::ParseThermostats(class ConfigFileBuffer * const fb)
1631{
1632 char * const thermo = new char[12];
1633 const int verbose = 0;
1634
1635 // read desired Thermostat from file along with needed additional parameters
1636 if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
1637 Thermostats->makeActive(thermo,fb);
1638 } else {
1639 if ((Thermostats->TargetTemp != 0))
1640 DoLog(2) && (Log() << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
1641 Thermostats->chooseNone();
1642 }
1643 delete[](thermo);
1644};
1645
Note: See TracBrowser for help on using the repository browser.