source: src/config.cpp@ 88104f

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 88104f was 88104f, checked in by Frederik Heber <heber@…>, 15 years ago

Placed class ConfigFileBuffer into its own module.

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