Changes in src/config.cpp [ce5ac3:042f82]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/config.cpp
rce5ac3 r042f82 1 1 /** \file config.cpp 2 * 2 * 3 3 * Function implementations for the class config. 4 * 4 * 5 5 */ 6 6 7 7 #include "molecules.hpp" 8 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 } 8 158 9 159 /************************************* Functions for class config ***************************/ … … 14 164 { 15 165 mainname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname"); 16 defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname"); 17 pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname"); 18 configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname"); 19 configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname"); 20 ThermostatImplemented = (int *) Malloc((MaxThermostats)*(sizeof(int)), "IonsInitRead: *ThermostatImplemented"); 21 ThermostatNames = (char **) Malloc((MaxThermostats)*(sizeof(char *)), "IonsInitRead: *ThermostatNames"); 22 for (int j=0;j<MaxThermostats;j++) 23 ThermostatNames[j] = (char *) MallocString(12*(sizeof(char)), "IonsInitRead: ThermostatNames[]"); 24 Thermostat = 4; 25 alpha = 0.; 26 ScaleTempStep = 25; 27 TempFrequency = 2.5; 166 defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: defaultpath"); 167 pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: pseudopotpath"); 168 databasepath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: databasepath"); 169 configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configpath"); 170 configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configname"); 28 171 strcpy(mainname,"pcp"); 29 172 strcpy(defaultpath,"not specified"); … … 31 174 configpath[0]='\0'; 32 175 configname[0]='\0'; 33 basis="3-21G"; 34 35 36 strcpy(ThermostatNames[0],"None"); 37 ThermostatImplemented[0] = 1; 38 strcpy(ThermostatNames[1],"Woodcock"); 39 ThermostatImplemented[1] = 1; 40 strcpy(ThermostatNames[2],"Gaussian"); 41 ThermostatImplemented[2] = 1; 42 strcpy(ThermostatNames[3],"Langevin"); 43 ThermostatImplemented[3] = 1; 44 strcpy(ThermostatNames[4],"Berendsen"); 45 ThermostatImplemented[4] = 1; 46 strcpy(ThermostatNames[5],"NoseHoover"); 47 ThermostatImplemented[5] = 1; 176 basis = "3-21G"; 48 177 49 178 FastParsing = false; … … 58 187 DoFullCurrent=0; 59 188 DoWannier=0; 60 DoConstrainedMD=0;61 189 CommonWannier=0; 62 190 SawtoothStart=0.01; … … 65 193 UseAddGramSch=1; 66 194 Seed=1; 195 67 196 MaxOuterStep=0; 68 Deltat= 0.01;197 Deltat=1; 69 198 OutVisStep=10; 70 199 OutSrcStep=5; … … 73 202 MaxPsiStep=0; 74 203 EpsWannier=1e-7; 75 204 76 205 MaxMinStep=100; 77 206 RelEpsTotalEnergy=1e-7; … … 84 213 InitMaxMinStopStep=1; 85 214 InitMaxMinGapStopStep=0; 86 215 87 216 //BoxLength[NDIM*NDIM]; 88 217 89 218 ECut=128.; 90 219 MaxLevel=5; … … 99 228 PsiMaxNoDown=0; 100 229 AddPsis=0; 101 230 102 231 RCut=20.; 103 232 StructOpt=0; … … 115 244 Free((void **)&defaultpath, "config::~config: *defaultpath"); 116 245 Free((void **)&pseudopotpath, "config::~config: *pseudopotpath"); 246 Free((void **)&databasepath, "config::~config: *databasepath"); 117 247 Free((void **)&configpath, "config::~config: *configpath"); 118 248 Free((void **)&configname, "config::~config: *configname"); 119 249 }; 120 250 121 /** Readin of Thermostat related values from parameter file.122 * \param *source parameter file123 */124 void config::InitThermostats(ifstream *source)125 {126 char *thermo = MallocString(12, "IonsInitRead: thermo");127 int verbose = 0;128 129 // read desired Thermostat from file along with needed additional parameters130 if (ParseForParameter(verbose,source,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {131 if (strcmp(thermo, ThermostatNames[0]) == 0) { // None132 if (ThermostatImplemented[0] == 1) {133 Thermostat = None;134 } else {135 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;136 Thermostat = None;137 }138 } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock139 if (ThermostatImplemented[1] == 1) {140 Thermostat = Woodcock;141 ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency142 } else {143 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;144 Thermostat = None;145 }146 } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian147 if (ThermostatImplemented[2] == 1) {148 Thermostat = Gaussian;149 ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate150 } else {151 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;152 Thermostat = None;153 }154 } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin155 if (ThermostatImplemented[3] == 1) {156 Thermostat = Langevin;157 ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma158 if (ParseForParameter(verbose,source,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {159 cout << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl;160 } else {161 alpha = 1.;162 }163 } else {164 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;165 Thermostat = None;166 }167 } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen168 if (ThermostatImplemented[4] == 1) {169 Thermostat = Berendsen;170 ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T171 } else {172 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;173 Thermostat = None;174 }175 } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover176 if (ThermostatImplemented[5] == 1) {177 Thermostat = NoseHoover;178 ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass179 alpha = 0.;180 } else {181 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;182 Thermostat = None;183 }184 } else {185 cout << Verbose(1) << " Warning: thermostat name was not understood!" << endl;186 Thermostat = None;187 }188 } else {189 if ((MaxOuterStep > 0) && (TargetTemp != 0))190 cout << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl;191 Thermostat = None;192 }193 Free((void **)&thermo, "InitThermostats: thermo");194 };195 196 197 251 /** Displays menu for editing each entry of the config file. 198 252 * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case 199 253 * for each entry of the config file structure. 200 254 */ 201 void config::Edit( molecule *mol)255 void config::Edit() 202 256 { 203 257 char choice; 204 258 205 259 do { 206 260 cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl; … … 235 289 cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl; 236 290 cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl; 237 cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;291 // cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl; 238 292 cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl; 239 293 cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl; … … 255 309 cout << Verbose(0) << "INPUT: "; 256 310 cin >> choice; 257 311 258 312 switch (choice) { 259 313 case 'A': // mainname … … 380 434 cin >> config::InitMaxMinStopStep; 381 435 break; 382 383 case 'j': // BoxLength384 cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;385 for (int i=0;i<6;i++) {386 cout << Verbose(0) << "Cell size" << i << ": ";387 cin >> mol->cell_size[i];388 }389 break;390 436 437 // case 'j': // BoxLength 438 // cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl; 439 // for (int i=0;i<6;i++) { 440 // cout << Verbose(0) << "Cell size" << i << ": "; 441 // cin >> mol->cell_size[i]; 442 // } 443 // break; 444 391 445 case 'k': // ECut 392 446 cout << Verbose(0) << "Old: " << config::ECut << "\t new: "; … … 462 516 * \param *periode pointer to a periodentafel class with all elements 463 517 * \param *mol pointer to molecule containing all atoms of the molecule 464 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax 518 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax 465 519 */ 466 520 int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol) … … 468 522 int test; 469 523 ifstream file(filename); 470 524 471 525 // search file for keyword: ProcPEGamma (new syntax) 472 526 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) { … … 539 593 * \param *file input file stream being the opened config file 540 594 * \param *periode pointer to a periodentafel class with all elements 541 * \param *mol pointer to molecule containing all atoms of the molecule 595 * \param *mol pointer to molecule containing all atoms of the molecule 542 596 */ 543 597 void config::Load(char *filename, periodentafel *periode, molecule *mol) 544 598 { 545 ifstream *file = new ifstream(filename);546 if (file == NULL) {547 cerr << "ERROR: config file " << filename << " missing!" << endl;548 return;549 }550 599 RetrieveConfigPathAndName(filename); 551 // ParseParameters 552 600 601 // ParseParameterFile 602 struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename); 603 FileBuffer->InitMapping(); 604 553 605 /* Oeffne Hauptparameterdatei */ 554 606 int di; … … 562 614 int verbose = 0; 563 615 double value[3]; 564 565 InitThermostats(file); 566 616 567 617 /* Namen einlesen */ 568 618 569 ParseForParameter(verbose, file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);570 ParseForParameter(verbose, file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);571 ParseForParameter(verbose, file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);572 ParseForParameter(verbose, file,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);573 ParseForParameter(verbose, file,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);574 575 if (!ParseForParameter(verbose, file,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))619 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical); 620 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical); 621 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical); 622 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical); 623 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical); 624 625 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional)) 576 626 config::Seed = 1; 577 627 578 if(!ParseForParameter(verbose, file,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {628 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) { 579 629 config::DoOutOrbitals = 0; 580 630 } else { … … 582 632 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1; 583 633 } 584 ParseForParameter(verbose, file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);634 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical); 585 635 if (config::DoOutVis < 0) config::DoOutVis = 0; 586 636 if (config::DoOutVis > 1) config::DoOutVis = 1; 587 if (!ParseForParameter(verbose, file,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))637 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional)) 588 638 config::VectorPlane = -1; 589 if (!ParseForParameter(verbose, file,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))639 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional)) 590 640 config::VectorCut = 0.; 591 ParseForParameter(verbose, file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);641 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical); 592 642 if (config::DoOutMes < 0) config::DoOutMes = 0; 593 643 if (config::DoOutMes > 1) config::DoOutMes = 1; 594 if (!ParseForParameter(verbose, file,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))644 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional)) 595 645 config::DoOutCurrent = 0; 596 646 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0; 597 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1; 598 ParseForParameter(verbose, file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);647 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1; 648 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical); 599 649 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0; 600 650 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2; 601 if(!ParseForParameter(verbose, file,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {651 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) { 602 652 config::DoWannier = 0; 603 653 } else { … … 605 655 if (config::DoWannier > 1) config::DoWannier = 1; 606 656 } 607 if(!ParseForParameter(verbose, file,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {657 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) { 608 658 config::CommonWannier = 0; 609 659 } else { … … 611 661 if (config::CommonWannier > 4) config::CommonWannier = 4; 612 662 } 613 if(!ParseForParameter(verbose, file,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {663 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) { 614 664 config::SawtoothStart = 0.01; 615 665 } else { … … 617 667 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.; 618 668 } 619 620 if (ParseForParameter(verbose,file,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional)) 621 if (config::DoConstrainedMD < 0) 622 config::DoConstrainedMD = 0; 623 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical); 624 if (!ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional)) 669 670 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical); 671 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional)) 625 672 config::Deltat = 1; 626 ParseForParameter(verbose, file,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);627 ParseForParameter(verbose, file,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);628 ParseForParameter(verbose, file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);629 //ParseForParameter(verbose, file,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);630 if (!ParseForParameter(verbose, file,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))673 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional); 674 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional); 675 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional); 676 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional); 677 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional)) 631 678 config::EpsWannier = 1e-8; 632 679 633 680 // stop conditions 634 681 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1; 635 ParseForParameter(verbose, file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);682 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical); 636 683 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3; 637 638 ParseForParameter(verbose, file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);639 ParseForParameter(verbose, file,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);640 ParseForParameter(verbose, file,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);641 ParseForParameter(verbose, file,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);642 ParseForParameter(verbose, file,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);684 685 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical); 686 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical); 687 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical); 688 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical); 689 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical); 643 690 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep; 644 691 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1; 645 692 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1; 646 647 ParseForParameter(verbose, file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);648 ParseForParameter(verbose, file,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);649 ParseForParameter(verbose, file,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);650 ParseForParameter(verbose, file,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);651 ParseForParameter(verbose, file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);693 694 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical); 695 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical); 696 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical); 697 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical); 698 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical); 652 699 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep; 653 700 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1; 654 701 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1; 655 702 656 703 // Unit cell and magnetic field 657 ParseForParameter(verbose, file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */704 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */ 658 705 mol->cell_size[0] = BoxLength[0]; 659 706 mol->cell_size[1] = BoxLength[3]; … … 662 709 mol->cell_size[4] = BoxLength[7]; 663 710 mol->cell_size[5] = BoxLength[8]; 664 if (1) fprintf(stderr,"\n");665 666 ParseForParameter(verbose, file,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);667 ParseForParameter(verbose, file,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);668 if (!ParseForParameter(verbose, file,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))711 //if (1) fprintf(stderr,"\n"); 712 713 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional); 714 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional); 715 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional)) 669 716 config::DoFullCurrent = 0; 670 717 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0; 671 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2; 718 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2; 672 719 if (config::DoOutNICS < 0) config::DoOutNICS = 0; 673 if (config::DoOutNICS > 2) config::DoOutNICS = 2; 720 if (config::DoOutNICS > 2) config::DoOutNICS = 2; 674 721 if (config::DoPerturbation == 0) { 675 722 config::DoFullCurrent = 0; … … 677 724 } 678 725 679 ParseForParameter(verbose, file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);680 ParseForParameter(verbose, file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);681 ParseForParameter(verbose, file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);726 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical); 727 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical); 728 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical); 682 729 if (config::Lev0Factor < 2) { 683 730 config::Lev0Factor = 2; 684 731 } 685 ParseForParameter(verbose, file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);732 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical); 686 733 if (di >= 0 && di < 2) { 687 734 config::RiemannTensor = di; 688 735 } else { 689 736 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT"); 690 exit(1); 737 exit(1); 691 738 } 692 739 switch (config::RiemannTensor) { … … 702 749 config::MaxLevel = 3; 703 750 } 704 ParseForParameter(verbose, file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);751 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical); 705 752 if (config::RiemannLevel < 2) { 706 753 config::RiemannLevel = 2; 707 } 754 } 708 755 if (config::RiemannLevel > config::MaxLevel-1) { 709 756 config::RiemannLevel = config::MaxLevel-1; 710 757 } 711 ParseForParameter(verbose, file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);758 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical); 712 759 if (config::LevRFactor < 2) { 713 760 config::LevRFactor = 2; 714 } 761 } 715 762 config::Lev0Factor = 2; 716 763 config::RTActualUse = 2; 717 764 break; 718 765 } 719 ParseForParameter(verbose, file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);766 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical); 720 767 if (di >= 0 && di < 2) { 721 768 config::PsiType = di; 722 769 } else { 723 770 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown"); 724 exit(1); 771 exit(1); 725 772 } 726 773 switch (config::PsiType) { 727 774 case 0: // SpinDouble 728 ParseForParameter(verbose, file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);729 ParseForParameter(verbose, file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);775 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical); 776 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional); 730 777 break; 731 778 case 1: // SpinUpDown 732 779 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2; 733 ParseForParameter(verbose, file,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);734 ParseForParameter(verbose, file,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);735 ParseForParameter(verbose, file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);780 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical); 781 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical); 782 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional); 736 783 break; 737 784 } 738 785 739 786 // IonsInitRead 740 741 ParseForParameter(verbose, file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);742 ParseForParameter(verbose, file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);743 ParseForParameter(verbose, file,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);744 if (!ParseForParameter(verbose, file,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))787 788 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical); 789 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical); 790 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical); 791 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional)) 745 792 config::RelativeCoord = 0; 746 if (!ParseForParameter(verbose, file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))793 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional)) 747 794 config::StructOpt = 0; 748 795 if (MaxTypes == 0) { … … 751 798 // prescan number of ions per type 752 799 cout << Verbose(0) << "Prescanning ions per type: " << endl; 800 int NoAtoms = 0; 753 801 for (int i=0; i < config::MaxTypes; i++) { 754 802 sprintf(name,"Ion_Type%i",i+1); 755 ParseForParameter(verbose, file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);756 ParseForParameter(verbose, file, name, 0, 2, 1, int_type, &Z, 1, critical);803 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical); 804 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical); 757 805 elementhash[i] = periode->FindElement(Z); 758 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl; 806 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl; 807 NoAtoms += No[i]; 759 808 } 760 809 int repetition = 0; // which repeated keyword shall be read 761 810 811 // sort the lines via the LineMapping 812 sprintf(name,"Ion_Type%i",config::MaxTypes); 813 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) { 814 cerr << "There are no atoms in the config file!" << endl; 815 return; 816 } 817 FileBuffer->CurrentLine++; 818 //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]]; 819 FileBuffer->MapIonTypesInBuffer(NoAtoms); 820 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) { 821 // cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]]; 822 //} 823 762 824 map<int, atom *> AtomList[config::MaxTypes]; 825 map<int, atom *> LinearList; 763 826 if (!FastParsing) { 764 827 // parse in trajectories … … 774 837 neues = new atom(); 775 838 AtomList[i][j] = neues; 839 LinearList[FileBuffer->CurrentLine] = neues; 776 840 neues->type = elementhash[i]; // find element type 777 mol->AddAtom(neues);778 841 } else 779 842 neues = AtomList[i][j]; 780 status = (status && 781 ParseForParameter(verbose, file, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&782 ParseForParameter(verbose, file, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&783 ParseForParameter(verbose, file, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&784 ParseForParameter(verbose, file, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));843 status = (status && 844 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) && 845 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) && 846 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) && 847 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional)); 785 848 if (!status) break; 786 849 787 850 // check size of vectors 788 851 if (mol->Trajectories[neues].R.size() <= (unsigned int)(repetition)) { … … 792 855 mol->Trajectories[neues].F.resize(repetition+10); 793 856 } 794 857 795 858 // put into trajectories list 796 859 for (int d=0;d<NDIM;d++) 797 860 mol->Trajectories[neues].R.at(repetition).x[d] = neues->x.x[d]; 798 861 799 862 // parse velocities if present 800 if(!ParseForParameter(verbose, file, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))863 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional)) 801 864 neues->v.x[0] = 0.; 802 if(!ParseForParameter(verbose, file, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))865 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional)) 803 866 neues->v.x[1] = 0.; 804 if(!ParseForParameter(verbose, file, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))867 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional)) 805 868 neues->v.x[2] = 0.; 806 869 for (int d=0;d<NDIM;d++) 807 870 mol->Trajectories[neues].U.at(repetition).x[d] = neues->v.x[d]; 808 871 809 872 // parse forces if present 810 if(!ParseForParameter(verbose, file, keyword, 0, 8, 1, double_type, &value[0], 1,optional))873 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional)) 811 874 value[0] = 0.; 812 if(!ParseForParameter(verbose, file, keyword, 0, 9, 1, double_type, &value[1], 1,optional))875 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional)) 813 876 value[1] = 0.; 814 if(!ParseForParameter(verbose, file, keyword, 1, 10, 1, double_type, &value[2], 1,optional))877 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional)) 815 878 value[2] = 0.; 816 879 for (int d=0;d<NDIM;d++) 817 880 mol->Trajectories[neues].F.at(repetition).x[d] = value[d]; 818 819 // cout << "Parsed position of step " << (repetition) << ": ("; 881 882 // cout << "Parsed position of step " << (repetition) << ": ("; 820 883 // for (int d=0;d<NDIM;d++) 821 884 // cout << mol->Trajectories[neues].R.at(repetition).x[d] << " "; // next step … … 831 894 repetition++; 832 895 } 896 // put atoms into the molecule in their original order 897 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) { 898 mol->AddAtom(runner->second); 899 } 833 900 repetition--; 834 901 cout << "Found " << repetition << " trajectory steps." << endl; … … 837 904 // 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) 838 905 repetition = 0; 839 while ( ParseForParameter(verbose, file, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&840 ParseForParameter(verbose, file, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&841 ParseForParameter(verbose, file, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))906 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) && 907 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) && 908 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional)) 842 909 repetition++; 843 910 cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl; … … 849 916 atom *neues = new atom(); 850 917 // then parse for each atom the coordinates as often as present 851 ParseForParameter(verbose, file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);852 ParseForParameter(verbose, file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);853 ParseForParameter(verbose, file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);854 ParseForParameter(verbose, file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);855 if(!ParseForParameter(verbose, file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))918 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical); 919 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical); 920 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical); 921 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical); 922 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional)) 856 923 neues->v.x[0] = 0.; 857 if(!ParseForParameter(verbose, file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))924 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional)) 858 925 neues->v.x[1] = 0.; 859 if(!ParseForParameter(verbose, file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))926 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional)) 860 927 neues->v.x[2] = 0.; 861 928 // here we don't care if forces are present (last in trajectories is always equal to current position) … … 866 933 } 867 934 } 868 file->close(); 869 delete(file); 935 delete(FileBuffer); 870 936 }; 871 937 … … 873 939 * \param *file input file stream being the opened config file with old pcp syntax 874 940 * \param *periode pointer to a periodentafel class with all elements 875 * \param *mol pointer to molecule containing all atoms of the molecule 941 * \param *mol pointer to molecule containing all atoms of the molecule 876 942 */ 877 943 void config::LoadOld(char *filename, periodentafel *periode, molecule *mol) … … 884 950 RetrieveConfigPathAndName(filename); 885 951 // ParseParameters 886 952 887 953 /* Oeffne Hauptparameterdatei */ 888 954 int l, i, di; … … 894 960 int Z, No, AtomNo, found; 895 961 int verbose = 0; 896 962 897 963 /* Namen einlesen */ 898 964 … … 926 992 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional); 927 993 config::EpsWannier = 1e-8; 928 994 929 995 // stop conditions 930 996 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1; 931 997 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical); 932 998 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3; 933 999 934 1000 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical); 935 1001 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical); … … 939 1005 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1; 940 1006 config::MaxMinGapStopStep = 1; 941 1007 942 1008 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical); 943 1009 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical); … … 970 1036 } else { 971 1037 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT"); 972 exit(1); 1038 exit(1); 973 1039 } 974 1040 switch (config::RiemannTensor) { … … 987 1053 if (config::RiemannLevel < 2) { 988 1054 config::RiemannLevel = 2; 989 } 1055 } 990 1056 if (config::RiemannLevel > config::MaxLevel-1) { 991 1057 config::RiemannLevel = config::MaxLevel-1; … … 994 1060 if (config::LevRFactor < 2) { 995 1061 config::LevRFactor = 2; 996 } 1062 } 997 1063 config::Lev0Factor = 2; 998 1064 config::RTActualUse = 2; … … 1004 1070 } else { 1005 1071 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown"); 1006 exit(1); 1072 exit(1); 1007 1073 } 1008 1074 switch (config::PsiType) { … … 1018 1084 break; 1019 1085 } 1020 1086 1021 1087 // IonsInitRead 1022 1088 1023 1089 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical); 1024 1090 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical); … … 1027 1093 1028 1094 // Routine from builder.cpp 1029 1030 1031 for (i=MAX_ELEMENTS;i--;) 1095 1096 1097 for (i=MAX_ELEMENTS;i--;) 1032 1098 elementhash[i] = NULL; 1033 1099 cout << Verbose(0) << "Parsing Ions ..." << endl; … … 1040 1106 } 1041 1107 if (found > 0) { 1042 if (zeile.find("Ions_Data") == 0) 1108 if (zeile.find("Ions_Data") == 0) 1043 1109 getline(*file,zeile,'\n'); // read next line and parse this one 1044 1110 istringstream input(zeile); … … 1069 1135 No++; 1070 1136 } 1071 } 1137 } 1072 1138 file->close(); 1073 1139 delete(file); … … 1077 1143 * \param *filename name of file 1078 1144 * \param *periode pointer to a periodentafel class with all elements 1079 * \param *mol pointer to molecule containing all atoms of the molecule 1145 * \param *mol pointer to molecule containing all atoms of the molecule 1080 1146 */ 1081 1147 bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const … … 1102 1168 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl; 1103 1169 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl; 1104 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;1105 *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";1106 switch(Thermostat) {1107 default:1108 case None:1109 break;1110 case Woodcock:1111 *output << ScaleTempStep;1112 break;1113 case Gaussian:1114 *output << ScaleTempStep;1115 break;1116 case Langevin:1117 *output << TempFrequency << "\t" << alpha;1118 break;1119 case Berendsen:1120 *output << TempFrequency;1121 break;1122 case NoseHoover:1123 *output << HooverMass;1124 break;1125 };1126 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;1127 1170 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl; 1128 1171 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl; … … 1207 1250 * Note that this format cannot be parsed again. 1208 1251 * \param *filename name of file (without ".in" suffix!) 1209 * \param *mol pointer to molecule containing all atoms of the molecule 1252 * \param *mol pointer to molecule containing all atoms of the molecule 1210 1253 */ 1211 1254 bool config::SaveMPQC(const char *filename, molecule *mol) const … … 1218 1261 ofstream *output = NULL; 1219 1262 stringstream *fname = NULL; 1220 1263 1221 1264 // first without hessian 1222 1265 fname = new stringstream; … … 1227 1270 *output << "\tsavestate = no" << endl; 1228 1271 *output << "\tdo_gradient = yes" << endl; 1229 *output << "\tmole< CLHF>: (" << endl;1272 *output << "\tmole<MBPT2>: (" << endl; 1230 1273 *output << "\t\tmaxiter = 200" << endl; 1231 1274 *output << "\t\tbasis = $:basis" << endl; 1232 1275 *output << "\t\tmolecule = $:molecule" << endl; 1276 *output << "\t\treference<CLHF>: (" << endl; 1277 *output << "\t\t\tbasis = $:basis" << endl; 1278 *output << "\t\t\tmolecule = $:molecule" << endl; 1279 *output << "\t\t)" << endl; 1233 1280 *output << "\t)" << endl; 1234 1281 *output << ")" << endl; … … 1258 1305 *output << ")" << endl; 1259 1306 *output << "basis<GaussianBasisSet>: (" << endl; 1260 *output << "\tname = \"" 1307 *output << "\tname = \""<< basis << "\"" << endl; 1261 1308 *output << "\tmolecule = $:molecule" << endl; 1262 1309 *output << ")" << endl; … … 1313 1360 delete(output); 1314 1361 delete(fname); 1315 1362 1316 1363 return true; 1317 1364 }; … … 1323 1370 * \warning value is modified (both in contents and position)! 1324 1371 * \param verbose 1 - print found value to stderr, 0 - don't 1325 * \param file file to be parsed1372 * \param *file file to be parsed 1326 1373 * \param name Name of value in file (at least 3 chars!) 1327 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning 1374 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning 1328 1375 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read - 1329 1376 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now … … 1345 1392 dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy"); 1346 1393 1347 //fprintf(stderr,"Parsing for %s\n",name); 1394 //fprintf(stderr,"Parsing for %s\n",name); 1348 1395 if (repetition == 0) 1349 1396 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!"); … … 1366 1413 file->clear(); 1367 1414 file->seekg(file_position, ios::beg); // rewind to start position 1368 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy"); 1415 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy"); 1369 1416 return 0; 1370 1417 } … … 1372 1419 line++; 1373 1420 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines 1374 1421 1375 1422 // C++ getline removes newline at end, thus re-add 1376 1423 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) { … … 1398 1445 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name); 1399 1446 //Free((void **)&free_dummy); 1400 //Error(FileOpenParams, NULL); 1447 //Error(FileOpenParams, NULL); 1401 1448 } else { 1402 1449 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1); … … 1407 1454 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) { 1408 1455 found++; // found the parameter! 1409 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy); 1410 1456 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy); 1457 1411 1458 if (found == repetition) { 1412 1459 for (i=0;i<xth;i++) { // i = rows … … 1447 1494 dummy1[j+1] = '\0'; 1448 1495 } 1449 1496 1450 1497 int start = (type >= grid) ? 0 : yth-1 ; 1451 1498 for (j=start;j<yth;j++) { // j = columns … … 1470 1517 //return 0; 1471 1518 exit(255); 1472 //Error(FileOpenParams, NULL); 1519 //Error(FileOpenParams, NULL); 1473 1520 } else { 1474 1521 //if (!sequential) … … 1485 1532 // found comment, skipping rest of line 1486 1533 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 1487 if (!sequential) { // here we need it! 1534 if (!sequential) { // here we need it! 1488 1535 file->seekg(file_position, ios::beg); // rewind to start position 1489 1536 } … … 1500 1547 //value += sizeof(int); 1501 1548 break; 1502 case(row_double): 1549 case(row_double): 1503 1550 case(grid): 1504 1551 case(lower_trigrid): … … 1541 1588 } 1542 1589 } 1543 } 1590 } 1544 1591 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n"); 1545 1592 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy"); … … 1549 1596 } 1550 1597 //fprintf(stderr, "End of Parsing\n\n"); 1551 1598 1552 1599 return (found); // true if found, false if not 1553 1600 } 1601 1602 1603 /** Reads parameter from a parsed file. 1604 * The file is either parsed for a certain keyword or if null is given for 1605 * the value in row yth and column xth. If the keyword was necessity#critical, 1606 * then an error is thrown and the programme aborted. 1607 * \warning value is modified (both in contents and position)! 1608 * \param verbose 1 - print found value to stderr, 0 - don't 1609 * \param *FileBuffer pointer to buffer structure 1610 * \param name Name of value in file (at least 3 chars!) 1611 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning 1612 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read - 1613 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now 1614 * counted from this unresetted position!) 1615 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!) 1616 * \param yth In grid case specifying column number, otherwise the yth \a name matching line 1617 * \param type Type of the Parameter to be read 1618 * \param value address of the value to be read (must have been allocated) 1619 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply 1620 * \param critical necessity of this keyword being specified (optional, critical) 1621 * \return 1 - found, 0 - not found 1622 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++ 1623 */ 1624 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) { 1625 int i,j; // loop variables 1626 int length = 0, maxlength = -1; 1627 int OldCurrentLine = FileBuffer->CurrentLine; 1628 char *dummy1, *dummy; // pointers in the line that is read in per step 1629 1630 //fprintf(stderr,"Parsing for %s\n",name); 1631 if (repetition == 0) 1632 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!"); 1633 return 0; 1634 1635 int line = 0; // marks line where parameter was found 1636 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found 1637 while((found != repetition)) { 1638 dummy1 = dummy = NULL; 1639 do { 1640 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ]; 1641 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) { 1642 if ((critical) && (found == 0)) { 1643 //Error(InitReading, name); 1644 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); 1645 exit(255); 1646 } else { 1647 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1648 return 0; 1649 } 1650 } 1651 if (dummy1 == NULL) { 1652 if (verbose) fprintf(stderr,"Error reading line %i\n",line); 1653 } else { 1654 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1); 1655 } 1656 line++; 1657 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines 1658 1659 // Seek for possible end of keyword on line if given ... 1660 if (name != NULL) { 1661 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer 1662 if (dummy == NULL) { 1663 dummy = strchr(dummy1, ' '); // if not found seek for space 1664 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary 1665 dummy++; 1666 } 1667 if (dummy == NULL) { 1668 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword) 1669 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name); 1670 //Free((void **)&free_dummy); 1671 //Error(FileOpenParams, NULL); 1672 } else { 1673 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1); 1674 } 1675 } else dummy = dummy1; 1676 // ... and check if it is the keyword! 1677 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name)); 1678 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) { 1679 found++; // found the parameter! 1680 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy); 1681 1682 if (found == repetition) { 1683 for (i=0;i<xth;i++) { // i = rows 1684 if (type >= grid) { 1685 // grid structure means that grid starts on the next line, not right after keyword 1686 dummy1 = dummy = NULL; 1687 do { 1688 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ]; 1689 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) { 1690 if ((critical) && (found == 0)) { 1691 //Error(InitReading, name); 1692 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); 1693 exit(255); 1694 } else { 1695 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1696 return 0; 1697 } 1698 } 1699 if (dummy1 == NULL) { 1700 if (verbose) fprintf(stderr,"Error reading line %i\n", line); 1701 } else { 1702 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1); 1703 } 1704 line++; 1705 } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n')); 1706 dummy = dummy1; 1707 } else { // simple int, strings or doubles start in the same line 1708 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces 1709 dummy++; 1710 } 1711 1712 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns 1713 // check for lower triangular area and upper triangular area 1714 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) { 1715 *((double *)value) = 0.0; 1716 fprintf(stderr,"%f\t",*((double *)value)); 1717 value = (void *)((long)value + sizeof(double)); 1718 //value += sizeof(double); 1719 } else { 1720 // otherwise we must skip all interjacent tabs and spaces and find next value 1721 dummy1 = dummy; 1722 dummy = strchr(dummy1, '\t'); // seek for tab or space 1723 if (dummy == NULL) 1724 dummy = strchr(dummy1, ' '); // if not found seek for space 1725 if (dummy == NULL) { // if still zero returned ... 1726 dummy = strchr(dummy1, '\n'); // ... at line end then 1727 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet 1728 if (critical) { 1729 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 1730 //return 0; 1731 exit(255); 1732 //Error(FileOpenParams, NULL); 1733 } else { 1734 if (!sequential) { // here we need it! 1735 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1736 } 1737 return 0; 1738 } 1739 } 1740 } else { 1741 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy); 1742 } 1743 if (*dummy1 == '#') { 1744 // found comment, skipping rest of line 1745 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 1746 if (!sequential) { // here we need it! 1747 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1748 } 1749 return 0; 1750 } 1751 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy); 1752 switch(type) { 1753 case (row_int): 1754 *((int *)value) = atoi(dummy1); 1755 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name); 1756 if (verbose) fprintf(stderr,"%i\t",*((int *)value)); 1757 value = (void *)((long)value + sizeof(int)); 1758 //value += sizeof(int); 1759 break; 1760 case(row_double): 1761 case(grid): 1762 case(lower_trigrid): 1763 case(upper_trigrid): 1764 *((double *)value) = atof(dummy1); 1765 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name); 1766 if (verbose) fprintf(stderr,"%lg\t",*((double *)value)); 1767 value = (void *)((long)value + sizeof(double)); 1768 //value += sizeof(double); 1769 break; 1770 case(double_type): 1771 *((double *)value) = atof(dummy1); 1772 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value)); 1773 //value += sizeof(double); 1774 break; 1775 case(int_type): 1776 *((int *)value) = atoi(dummy1); 1777 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value)); 1778 //value += sizeof(int); 1779 break; 1780 default: 1781 case(string_type): 1782 if (value != NULL) { 1783 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array 1784 maxlength = MAXSTRINGSIZE; 1785 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum 1786 strncpy((char *)value, dummy1, length); // copy as much 1787 ((char *)value)[length] = '\0'; // and set end marker 1788 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length); 1789 //value += sizeof(char); 1790 } else { 1791 } 1792 break; 1793 } 1794 } 1795 while (*dummy == '\t') 1796 dummy++; 1797 } 1798 } 1799 } 1800 } 1801 } 1802 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n"); 1803 if (!sequential) { 1804 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1805 } 1806 //fprintf(stderr, "End of Parsing\n\n"); 1807 1808 return (found); // true if found, false if not 1809 }
Note:
See TracChangeset
for help on using the changeset viewer.