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