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