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