source: src/config.cpp@ 44de80

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 44de80 was 8f4df1, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

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