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