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