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