Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    r68f03d r35b698  
    55 */
    66
     7#include "Helpers/MemDebug.hpp"
     8
    79#include <stdio.h>
    810#include <cstring>
    911
    10 #include "World.hpp"
    1112#include "atom.hpp"
    1213#include "bond.hpp"
     14#include "bondgraph.hpp"
    1315#include "config.hpp"
     16#include "ConfigFileBuffer.hpp"
    1417#include "element.hpp"
    1518#include "helpers.hpp"
     19#include "info.hpp"
    1620#include "lists.hpp"
    1721#include "log.hpp"
     
    2024#include "molecule.hpp"
    2125#include "periodentafel.hpp"
     26#include "ThermoStatContainer.hpp"
    2227#include "World.hpp"
    23 
    24 /******************************** Functions for class ConfigFileBuffer **********************/
    25 
    26 /** Structure containing compare function for Ion_Type sorting.
    27  */
    28 struct IonTypeCompare {
    29   bool operator()(const char* s1, const char *s2) const {
    30     char number1[8];
    31     char number2[8];
    32     const char *dummy1, *dummy2;
    33     //Log() << Verbose(0) << s1 << "  " << s2 << endl;
    34     dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    35     dummy2 = strchr(dummy1, '_');
    36     strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    37     number1[dummy2-dummy1]='\0';
    38     dummy1 = strchr(s2, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    39     dummy2 = strchr(dummy1, '_');
    40     strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    41     number2[dummy2-dummy1]='\0';
    42     if (atoi(number1) != atoi(number2))
    43       return (atoi(number1) < atoi(number2));
    44     else {
    45       dummy1 = strchr(s1, '_')+sizeof(char);
    46       dummy1 = strchr(dummy1, '_')+sizeof(char);
    47       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    48       strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    49       number1[dummy2-dummy1]='\0';
    50       dummy1 = strchr(s2, '_')+sizeof(char);
    51       dummy1 = strchr(dummy1, '_')+sizeof(char);
    52       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    53       strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    54       number2[dummy2-dummy1]='\0';
    55       return (atoi(number1) < atoi(number2));
    56     }
    57   }
    58 };
    59 
    60 /** Constructor for ConfigFileBuffer class.
    61  */
    62 ConfigFileBuffer::ConfigFileBuffer() : buffer(NULL), LineMapping(NULL), CurrentLine(0), NoLines(0)
    63 {
    64 };
    65 
    66 /** Constructor for ConfigFileBuffer class with filename to be parsed.
    67  * \param *filename file name
    68  */
    69 ConfigFileBuffer::ConfigFileBuffer(const char * const filename) : buffer(NULL), LineMapping(NULL), CurrentLine(0), NoLines(0)
    70 {
    71   ifstream *file = NULL;
    72   char line[MAXSTRINGSIZE];
    73 
    74   // prescan number of lines
    75   file= new ifstream(filename);
    76   if (file == NULL) {
    77     DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
    78     return;
    79   }
    80   NoLines = 0; // we're overcounting by one
    81   long file_position = file->tellg(); // mark current position
    82   do {
    83     file->getline(line, 256);
    84     NoLines++;
    85   } while (!file->eof());
    86   file->clear();
    87   file->seekg(file_position, ios::beg);
    88   DoLog(1) && (Log() << Verbose(1) << NoLines-1 << " lines were recognized." << endl);
    89 
    90   // allocate buffer's 1st dimension
    91   if (buffer != NULL) {
    92     DoeLog(1) && (eLog()<< Verbose(1) << "FileBuffer->buffer is not NULL!" << endl);
    93     return;
    94   } else
    95     buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
    96 
    97   // scan each line and put into buffer
    98   int lines=0;
    99   int i;
    100   do {
    101     buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
    102     file->getline(buffer[lines], MAXSTRINGSIZE-1);
    103     i = strlen(buffer[lines]);
    104     buffer[lines][i] = '\n';
    105     buffer[lines][i+1] = '\0';
    106     lines++;
    107   } while((!file->eof()) && (lines < NoLines));
    108   DoLog(1) && (Log() << Verbose(1) << lines-1 << " lines were read into the buffer." << endl);
    109 
    110   // close and exit
    111   file->close();
    112   file->clear();
    113   delete(file);
    114 }
    115 
    116 /** Destructor for ConfigFileBuffer class.
    117  */
    118 ConfigFileBuffer::~ConfigFileBuffer()
    119 {
    120   for(int i=0;i<NoLines;++i)
    121     Free(&buffer[i]);
    122   Free(&buffer);
    123   Free(&LineMapping);
    124 }
    125 
    126 
    127 /** Create trivial mapping.
    128  */
    129 void ConfigFileBuffer::InitMapping()
    130 {
    131   LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
    132   for (int i=0;i<NoLines;i++)
    133     LineMapping[i] = i;
    134 }
    135 
    136 /** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
    137  * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
    138  * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
    139  * points to first Ion_Type entry.
    140  * \param *FileBuffer pointer to buffer structure
    141  * \param NoAtoms of subsequent lines to look at
    142  */
    143 void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
    144 {
    145   map<const char *, int, IonTypeCompare> IonTypeLineMap;
    146   if (LineMapping == NULL) {
    147     DoeLog(0) && (eLog()<< Verbose(0) << "map pointer is NULL: " << LineMapping << endl);
    148     performCriticalExit();
    149     return;
    150   }
    151 
    152   // put all into hashed map
    153   for (int i=0; i<NoAtoms; ++i) {
    154     IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
    155   }
    156 
    157   // fill map
    158   int nr=0;
    159   for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
    160     if (CurrentLine+nr < NoLines)
    161       LineMapping[CurrentLine+(nr++)] = runner->second;
    162     else {
    163       DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl);
    164       performCriticalExit();
    165     }
    166   }
    167 }
    16828
    16929/************************************* Functions for class config ***************************/
     
    17131/** Constructor for config file class.
    17232 */
    173 config::config() : BG(NULL), PsiType(0), MaxPsiDouble(0), PsiMaxNoUp(0), PsiMaxNoDown(0), MaxMinStopStep(1), InitMaxMinStopStep(1), ProcPEGamma(8), ProcPEPsi(1), configpath(NULL),
    174     configname(NULL), FastParsing(false), Deltat(0.01), basis(""), databasepath(NULL), DoConstrainedMD(0), MaxOuterStep(0), Thermostat(4), ThermostatImplemented(NULL),
    175     ThermostatNames(NULL), TempFrequency(2.5), alpha(0.), HooverMass(0.), TargetTemp(0.00095004455), ScaleTempStep(25),  mainname(NULL), defaultpath(NULL), pseudopotpath(NULL),
     33config::config() : BG(NULL), Thermostats(0), PsiType(0), MaxPsiDouble(0), PsiMaxNoUp(0), PsiMaxNoDown(0), MaxMinStopStep(1), InitMaxMinStopStep(1), ProcPEGamma(8), ProcPEPsi(1),
     34    configname(NULL), FastParsing(false), Deltat(0.01), basis(""), databasepath(NULL), DoConstrainedMD(0), MaxOuterStep(0), mainname(NULL), defaultpath(NULL), pseudopotpath(NULL),
    17635    DoOutVis(0), DoOutMes(1), DoOutNICS(0), DoOutOrbitals(0), DoOutCurrent(0), DoFullCurrent(0), DoPerturbation(0), DoWannier(0), CommonWannier(0), SawtoothStart(0.01),
    17736    VectorPlane(0), VectorCut(0.), UseAddGramSch(1), Seed(1), OutVisStep(10), OutSrcStep(5), MaxPsiStep(0), EpsWannier(1e-7), MaxMinStep(100), RelEpsTotalEnergy(1e-7),
     
    17938    MaxLevel(5), RiemannTensor(0), LevRFactor(0), RiemannLevel(0), Lev0Factor(2), RTActualUse(0), AddPsis(0), RCut(20.), StructOpt(0), IsAngstroem(1), RelativeCoord(0),
    18039    MaxTypes(0) {
    181   mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
    182   defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
    183   pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
    184   databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
    185   configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
    186   configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
     40  mainname = new char[MAXSTRINGSIZE];
     41  defaultpath = new char[MAXSTRINGSIZE];
     42  pseudopotpath = new char[MAXSTRINGSIZE];
     43  databasepath = new char[MAXSTRINGSIZE];
     44  configname = new char[MAXSTRINGSIZE];
     45  Thermostats = new ThermoStatContainer();
    18746  strcpy(mainname,"pcp");
    18847  strcpy(defaultpath,"not specified");
    18948  strcpy(pseudopotpath,"not specified");
    190   configpath[0]='\0';
    19149  configname[0]='\0';
    19250  basis = "3-21G";
    193 
    194   InitThermostats();
    19551};
    19652
     
    19955config::~config()
    20056{
    201   Free(&mainname);
    202   Free(&defaultpath);
    203   Free(&pseudopotpath);
    204   Free(&databasepath);
    205   Free(&configpath);
    206   Free(&configname);
    207   Free(&ThermostatImplemented);
    208   for (int j=0;j<MaxThermostats;j++)
    209     Free(&ThermostatNames[j]);
    210   Free(&ThermostatNames);
     57  delete[](mainname);
     58  delete[](defaultpath);
     59  delete[](pseudopotpath);
     60  delete[](databasepath);
     61  delete[](configname);
     62  if (Thermostats != NULL)
     63    delete(Thermostats);
    21164
    21265  if (BG != NULL)
    21366    delete(BG);
    21467};
    215 
    216 /** Initialises variables in class config for Thermostats.
    217  */
    218 void config::InitThermostats()
    219 {
    220   ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
    221   ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
    222   for (int j=0;j<MaxThermostats;j++)
    223     ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
    224 
    225   strcpy(ThermostatNames[0],"None");
    226   ThermostatImplemented[0] = 1;
    227   strcpy(ThermostatNames[1],"Woodcock");
    228   ThermostatImplemented[1] = 1;
    229   strcpy(ThermostatNames[2],"Gaussian");
    230   ThermostatImplemented[2] = 1;
    231   strcpy(ThermostatNames[3],"Langevin");
    232   ThermostatImplemented[3] = 1;
    233   strcpy(ThermostatNames[4],"Berendsen");
    234   ThermostatImplemented[4] = 1;
    235   strcpy(ThermostatNames[5],"NoseHoover");
    236   ThermostatImplemented[5] = 1;
    237 };
    238 
    239 /** Readin of Thermostat related values from parameter file.
    240  * \param *fb file buffer containing the config file
    241  */
    242 void config::ParseThermostats(class ConfigFileBuffer * const fb)
    243 {
    244   char * const thermo = Malloc<char>(12, "IonsInitRead: thermo");
    245   const int verbose = 0;
    246 
    247   // read desired Thermostat from file along with needed additional parameters
    248   if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
    249     if (strcmp(thermo, ThermostatNames[0]) == 0) { // None
    250       if (ThermostatImplemented[0] == 1) {
    251         Thermostat = None;
    252       } else {
    253         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    254         Thermostat = None;
    255       }
    256     } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock
    257       if (ThermostatImplemented[1] == 1) {
    258         Thermostat = Woodcock;
    259         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
    260       } else {
    261         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    262         Thermostat = None;
    263       }
    264     } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian
    265       if (ThermostatImplemented[2] == 1) {
    266         Thermostat = Gaussian;
    267         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
    268       } else {
    269         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    270         Thermostat = None;
    271       }
    272     } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin
    273       if (ThermostatImplemented[3] == 1) {
    274         Thermostat = Langevin;
    275         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
    276         if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
    277           DoLog(2) && (Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl);
    278         } else {
    279           alpha = 1.;
    280         }
    281       } else {
    282         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    283         Thermostat = None;
    284       }
    285     } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen
    286       if (ThermostatImplemented[4] == 1) {
    287         Thermostat = Berendsen;
    288         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
    289       } else {
    290         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    291         Thermostat = None;
    292       }
    293     } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover
    294       if (ThermostatImplemented[5] == 1) {
    295         Thermostat = NoseHoover;
    296         ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
    297         alpha = 0.;
    298       } else {
    299         DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    300         Thermostat = None;
    301       }
    302     } else {
    303       DoLog(1) && (Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl);
    304       Thermostat = None;
    305     }
    306   } else {
    307     if ((MaxOuterStep > 0) && (TargetTemp != 0))
    308       DoLog(2) && (Log() << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
    309     Thermostat = None;
    310   }
    311   Free(thermo);
    312 };
    313 
    31468
    31569/** Displays menu for editing each entry of the config file.
     
    626380};
    627381
    628 /** Retrieves the path in the given config file name.
    629  * \param filename config file string
    630  */
    631 void config::RetrieveConfigPathAndName(const string filename)
    632 {
    633   char *ptr = NULL;
    634   char *buffer = new char[MAXSTRINGSIZE];
    635   strncpy(buffer, filename.c_str(), MAXSTRINGSIZE);
    636   int last = -1;
    637   for(last=MAXSTRINGSIZE;last--;) {
    638     if (buffer[last] == '/')
    639       break;
    640   }
    641   if (last == -1) { // no path in front, set to local directory.
    642     strcpy(configpath, "./");
    643     ptr = buffer;
    644   } else {
    645     strncpy(configpath, buffer, last+1);
    646     ptr = &buffer[last+1];
    647     if (last < 254)
    648       configpath[last+1]='\0';
    649   }
    650   strcpy(configname, ptr);
    651   DoLog(0) && (Log() << Verbose(0) << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl);
    652   delete[](buffer);
    653 };
    654 
    655 /** Initializes ConfigFileBuffer from a file.
    656  * \param *file input file stream being the opened config file
    657  * \param *FileBuffer pointer to FileBuffer on return, should point to NULL
    658  */
    659 void PrepareFileBuffer(const char * const filename, struct ConfigFileBuffer *&FileBuffer)
    660 {
    661   if (FileBuffer != NULL) {
    662     DoeLog(2) && (eLog()<< Verbose(2) << "deleting present FileBuffer in PrepareFileBuffer()." << endl);
    663     delete(FileBuffer);
    664   }
    665   FileBuffer = new ConfigFileBuffer(filename);
    666 
    667   FileBuffer->InitMapping();
    668 };
    669 
    670382/** Loads a molecule from a ConfigFileBuffer.
    671383 * \param *mol molecule to load
     
    861573  file->close();
    862574  delete(file);
    863   RetrieveConfigPathAndName(filename);
    864575
    865576  // ParseParameterFile
    866   struct ConfigFileBuffer *FileBuffer = NULL;
    867   PrepareFileBuffer(filename,FileBuffer);
     577  class ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
    868578
    869579  /* Oeffne Hauptparameterdatei */
     
    874584  int verbose = 0;
    875585 
     586  //TODO: This is actually sensible?: if (MaxOuterStep > 0)
    876587  ParseThermostats(FileBuffer);
    877588 
     
    938649  ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
    939650  ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
    940   ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
     651  ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
    941652  //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
    942653  if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
     
    1098809    return;
    1099810  }
    1100   RetrieveConfigPathAndName(filename);
    1101811  // ParseParameters
    1102812
     
    1147857  ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
    1148858  ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
    1149   ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
    1150   ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
     859  ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(Thermostats->TargetTemp), 1, optional);
     860  ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(Thermostats->ScaleTempStep), 1, optional);
    1151861  config::EpsWannier = 1e-8;
    1152862
     
    13361046    *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
    13371047    *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
    1338     *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
    1339     switch(Thermostat) {
     1048    *output << "Thermostat\t" << Thermostats->ThermostatNames[Thermostats->Thermostat] << "\t";
     1049    switch(Thermostats->Thermostat) {
    13401050      default:
    13411051      case None:
    13421052        break;
    13431053      case Woodcock:
    1344         *output << ScaleTempStep;
     1054        *output << Thermostats->ScaleTempStep;
    13451055        break;
    13461056      case Gaussian:
    1347         *output << ScaleTempStep;
     1057        *output << Thermostats->ScaleTempStep;
    13481058        break;
    13491059      case Langevin:
    1350         *output << TempFrequency << "\t" << alpha;
     1060        *output << Thermostats->TempFrequency << "\t" << Thermostats->alpha;
    13511061        break;
    13521062      case Berendsen:
    1353         *output << TempFrequency;
     1063        *output << Thermostats->TempFrequency;
    13541064        break;
    13551065      case NoseHoover:
    1356         *output << HooverMass;
     1066        *output << Thermostats->HooverMass;
    13571067        break;
    13581068    };
     
    13691079    *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
    13701080    *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
    1371     *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
     1081    *output << "TargetTemp\t" << Thermostats->TargetTemp << "\t# Target temperature" << endl;
    13721082    *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
    13731083    *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
     
    14801190    // output of atoms
    14811191    AtomNo = 0;
    1482     mol->ActOnAllAtoms( &atom::OutputMPQCLine, output, (const Vector *)center, &AtomNo );
     1192    mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
    14831193    delete(center);
    14841194    *output << "\t}" << endl;
     
    15221232    // output of atoms
    15231233    AtomNo = 0;
    1524     mol->ActOnAllAtoms( &atom::OutputMPQCLine, output, (const Vector *)center, &AtomNo );
     1234    mol->ActOnAllAtoms( &atom::OutputMPQCLine, (ostream * const) output, (const Vector *)center, &AtomNo );
    15251235    delete(center);
    15261236    *output << "\t}" << endl;
     
    15471257  int AtomNo = -1;
    15481258  int MolNo = 0;
    1549   atom *Walker = NULL;
    15501259  FILE *f = NULL;
    15511260
     
    15601269  fprintf(f, "# Created by MoleCuilder\n");
    15611270
    1562   for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
    1563     Walker = (*Runner)->start;
    1564     int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1271  for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
     1272    int *elementNo = new int[MAX_ELEMENTS];
     1273    for (int i=0;i<MAX_ELEMENTS;i++)
     1274      elementNo[i] = 0;
    15651275    AtomNo = 0;
    1566     while (Walker->next != (*Runner)->end) {
    1567       Walker = Walker->next;
    1568       sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
    1569       elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1276    for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
     1277      sprintf(name, "%2s%2d",(*iter)->type->symbol, elementNo[(*iter)->type->Z]);
     1278      elementNo[(*iter)->type->Z] = (elementNo[(*iter)->type->Z]+1) % 100;   // confine to two digits
    15701279      fprintf(f,
    15711280             "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
    1572              Walker->nr,                /* atom serial number */
     1281             (*iter)->nr,                /* atom serial number */
    15731282             name,         /* atom name */
    1574              (*Runner)->name,      /* residue name */
     1283             (*MolRunner)->name,      /* residue name */
    15751284             'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    15761285             MolNo,         /* residue sequence number */
    1577              Walker->node->at(0),                 /* position X in Angstroem */
    1578              Walker->node->at(1),                 /* position Y in Angstroem */
    1579              Walker->node->at(2),                 /* position Z in Angstroem */
    1580              (double)Walker->type->Valence,         /* occupancy */
    1581              (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1286             (*iter)->node->at(0),                 /* position X in Angstroem */
     1287             (*iter)->node->at(1),                 /* position Y in Angstroem */
     1288             (*iter)->node->at(2),                 /* position Z in Angstroem */
     1289             (double)(*iter)->type->Valence,         /* occupancy */
     1290             (double)(*iter)->type->NoValenceOrbitals,          /* temperature factor */
    15821291             "0",            /* segment identifier */
    1583              Walker->type->symbol,    /* element symbol */
     1292             (*iter)->type->symbol,    /* element symbol */
    15841293             "0");           /* charge */
    15851294      AtomNo++;
    15861295    }
    1587     Free(&elementNo);
     1296    delete[](elementNo);
    15881297    MolNo++;
    15891298  }
     
    16011310{
    16021311  int AtomNo = -1;
    1603   atom *Walker = NULL;
    16041312  FILE *f = NULL;
    16051313
    1606   int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1314  int *elementNo = new int[MAX_ELEMENTS];
     1315  for (int i=0;i<MAX_ELEMENTS;i++)
     1316    elementNo[i] = 0;
    16071317  char name[MAXSTRINGSIZE];
    16081318  strncpy(name, filename, MAXSTRINGSIZE-1);
     
    16111321  if (f == NULL) {
    16121322    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
    1613     Free(&elementNo);
     1323    delete[](elementNo);
    16141324    return false;
    16151325  }
    16161326  fprintf(f, "# Created by MoleCuilder\n");
    16171327
    1618   Walker = mol->start;
    16191328  AtomNo = 0;
    1620   while (Walker->next != mol->end) {
    1621     Walker = Walker->next;
    1622     sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
    1623     elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1329  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1330    sprintf(name, "%2s%2d",(*iter)->type->symbol, elementNo[(*iter)->type->Z]);
     1331    elementNo[(*iter)->type->Z] = (elementNo[(*iter)->type->Z]+1) % 100;   // confine to two digits
    16241332    fprintf(f,
    16251333           "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
    1626            Walker->nr,                /* atom serial number */
     1334           (*iter)->nr,                /* atom serial number */
    16271335           name,         /* atom name */
    16281336           mol->name,      /* residue name */
    16291337           'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    16301338           0,         /* residue sequence number */
    1631            Walker->node->at(0),                 /* position X in Angstroem */
    1632            Walker->node->at(1),                 /* position Y in Angstroem */
    1633            Walker->node->at(2),                 /* position Z in Angstroem */
    1634            (double)Walker->type->Valence,         /* occupancy */
    1635            (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1339           (*iter)->node->at(0),                 /* position X in Angstroem */
     1340           (*iter)->node->at(1),                 /* position Y in Angstroem */
     1341           (*iter)->node->at(2),                 /* position Z in Angstroem */
     1342           (double)(*iter)->type->Valence,         /* occupancy */
     1343           (double)(*iter)->type->NoValenceOrbitals,          /* temperature factor */
    16361344           "0",            /* segment identifier */
    1637            Walker->type->symbol,    /* element symbol */
     1345           (*iter)->type->symbol,    /* element symbol */
    16381346           "0");           /* charge */
    16391347    AtomNo++;
    16401348  }
    16411349  fclose(f);
    1642   Free(&elementNo);
     1350  delete[](elementNo);
    16431351
    16441352  return true;
     
    16531361bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
    16541362{
    1655   atom *Walker = NULL;
    16561363  ofstream *output = NULL;
    16571364  stringstream * const fname = new stringstream;
     
    16661373
    16671374  // scan maximum number of neighbours
    1668   Walker = mol->start;
    16691375  int MaxNeighbours = 0;
    1670   while (Walker->next != mol->end) {
    1671     Walker = Walker->next;
    1672     const int count = Walker->ListOfBonds.size();
     1376  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1377    const int count = (*iter)->ListOfBonds.size();
    16731378    if (MaxNeighbours < count)
    16741379      MaxNeighbours = count;
    16751380  }
    1676   *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
    1677 
    1678   Walker = mol->start;
    1679   while (Walker->next != mol->end) {
    1680     Walker = Walker->next;
    1681     *output << Walker->nr << "\t";
    1682     *output << Walker->getName() << "\t";
     1381  *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
     1382
     1383  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1384    *output << (*iter)->nr << "\t";
     1385    *output << (*iter)->getName() << "\t";
    16831386    *output << mol->name << "\t";
    16841387    *output << 0 << "\t";
    1685     *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
    1686     *output << static_cast<double>(Walker->type->Valence) << "\t";
    1687     *output << Walker->type->symbol << "\t";
    1688     for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
    1689       *output << (*runner)->GetOtherAtom(Walker)->nr << "\t";
    1690     for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1388    *output << (*iter)->node->at(0) << "\t" << (*iter)->node->at(1) << "\t" << (*iter)->node->at(2) << "\t";
     1389    *output << static_cast<double>((*iter)->type->Valence) << "\t";
     1390    *output << (*iter)->type->symbol << "\t";
     1391    for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
     1392      *output << (*runner)->GetOtherAtom(*iter)->nr << "\t";
     1393    for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
    16911394      *output << "-\t";
    16921395    *output << endl;
     
    17081411bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
    17091412{
    1710   atom *Walker = NULL;
     1413  Info FunctionInfo(__func__);
    17111414  ofstream *output = NULL;
    17121415  stringstream * const fname = new stringstream;
     
    17231426  int MaxNeighbours = 0;
    17241427  for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1725     Walker = (*MolWalker)->start;
    1726     while (Walker->next != (*MolWalker)->end) {
    1727       Walker = Walker->next;
    1728       const int count = Walker->ListOfBonds.size();
     1428    for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     1429      const int count = (*iter)->ListOfBonds.size();
    17291430      if (MaxNeighbours < count)
    17301431        MaxNeighbours = count;
    17311432    }
    17321433  }
    1733   *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
     1434  *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
    17341435
    17351436  // create global to local id map
    1736   int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap");
     1437  map<int, int> LocalNotoGlobalNoMap;
    17371438  {
    1738     int MolCounter = 0;
    1739     int AtomNo = 0;
     1439    unsigned int MolCounter = 0;
     1440    int AtomNo = 1;
    17401441    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1741       LocalNotoGlobalNoMap[MolCounter] = Calloc<int>(MolList->CountAllAtoms(), "config::SaveTREMOLO - *LocalNotoGlobalNoMap[]");
    1742 
    1743       (*MolWalker)->SetIndexedArrayForEachAtomTo( LocalNotoGlobalNoMap[MolCounter], &atom::nr, IncrementalAbsoluteValue, &AtomNo);
    1744 
     1442      for(molecule::iterator AtomRunner = (*MolWalker)->begin(); AtomRunner != (*MolWalker)->end(); ++AtomRunner) {
     1443        LocalNotoGlobalNoMap.insert( pair<int,int>((*AtomRunner)->getId(), AtomNo++) );
     1444      }
    17451445      MolCounter++;
    17461446    }
     1447    ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
    17471448  }
    17481449
     
    17521453    int AtomNo = 0;
    17531454    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1754       Walker = (*MolWalker)->start;
    1755       while (Walker->next != (*MolWalker)->end) {
    1756         Walker = Walker->next;
    1757         *output << AtomNo+1 << "\t";
    1758         *output << Walker->getName() << "\t";
     1455      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     1456        *output << LocalNotoGlobalNoMap[ (*iter)->getId() ] << "\t";
     1457        *output << (*iter)->getName() << "\t";
    17591458        *output << (*MolWalker)->name << "\t";
    17601459        *output << MolCounter+1 << "\t";
    1761         *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
    1762         *output << (double)Walker->type->Valence << "\t";
    1763         *output << Walker->type->symbol << "\t";
    1764         for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
    1765           *output << LocalNotoGlobalNoMap[MolCounter][ (*runner)->GetOtherAtom(Walker)->nr ]+1 << "\t";
    1766         for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1460        *output << (*iter)->node->at(0) << "\t" << (*iter)->node->at(1) << "\t" << (*iter)->node->at(2) << "\t";
     1461        *output << (double)(*iter)->type->Valence << "\t";
     1462        *output << (*iter)->type->symbol << "\t";
     1463        for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
     1464          *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom((*iter))->getId() ] << "\t";
     1465        for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
    17671466          *output << "-\t";
    17681467        *output << endl;
     
    17781477  delete(output);
    17791478  delete(fname);
    1780   for(size_t i=0;i<MolList->ListOfMolecules.size(); i++)
    1781     Free(&LocalNotoGlobalNoMap[i]);
    1782   Free(&LocalNotoGlobalNoMap);
    17831479
    17841480  return true;
     
    17951491  char filename[MAXSTRINGSIZE];
    17961492  ofstream output;
    1797   molecule *mol = World::getInstance().createMolecule();
    1798   mol->SetNameFromFilename(ConfigFileName);
    1799 
    1800   if (!strcmp(configpath, GetDefaultPath())) {
    1801     eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
    1802   }
    1803 
     1493  molecule *mol = NULL;
    18041494
    18051495  // first save as PDB data
     
    18081498  if (output == NULL)
    18091499    strcpy(filename,"main_pcp_linux");
    1810   Log() << Verbose(0) << "Saving as pdb input ";
     1500  Log() << Verbose(0) << "Saving as pdb input ... " << endl;
    18111501  if (SavePDB(filename, molecules))
    1812     Log() << Verbose(0) << "done." << endl;
     1502    Log() << Verbose(0) << "\t... done." << endl;
    18131503  else
    1814     Log() << Verbose(0) << "failed." << endl;
     1504    Log() << Verbose(0) << "\t... failed." << endl;
    18151505
    18161506  // then save as tremolo data file
     
    18191509  if (output == NULL)
    18201510    strcpy(filename,"main_pcp_linux");
    1821   Log() << Verbose(0) << "Saving as tremolo data input ";
     1511  Log() << Verbose(0) << "Saving as tremolo data input ... " << endl;
    18221512  if (SaveTREMOLO(filename, molecules))
    1823     Log() << Verbose(0) << "done." << endl;
     1513    Log() << Verbose(0) << "\t... done." << endl;
    18241514  else
    1825     Log() << Verbose(0) << "failed." << endl;
     1515    Log() << Verbose(0) << "\t... failed." << endl;
    18261516
    18271517  // translate each to its center and merge all molecules in MoleculeListClass into this molecule
    18281518  int N = molecules->ListOfMolecules.size();
    1829   int *src = new int[N];
    1830   N=0;
    1831   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1832     src[N++] = (*ListRunner)->IndexNr;
    1833     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1834   }
    1835   molecules->SimpleMultiAdd(mol, src, N);
    1836   delete[](src);
    1837 
    1838   // ... and translate back
    1839   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1840     (*ListRunner)->Center.Scale(-1.);
    1841     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1842     (*ListRunner)->Center.Scale(-1.);
     1519  if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
     1520    int *src = new int[N];
     1521    N=0;
     1522    for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1523      src[N++] = (*ListRunner)->IndexNr;
     1524      (*ListRunner)->Translate(&(*ListRunner)->Center);
     1525    }
     1526    mol = World::getInstance().createMolecule();
     1527    mol->SetNameFromFilename(ConfigFileName);
     1528    molecules->SimpleMultiMerge(mol, src, N);
     1529    mol->doCountAtoms();
     1530    mol->CountElements();
     1531    //mol->CalculateOrbitals(*this);
     1532    delete[](src);
     1533  } else {
     1534    if (!molecules->ListOfMolecules.empty()) {
     1535      mol = *(molecules->ListOfMolecules.begin());
     1536      mol->doCountAtoms();
     1537      //mol->CalculateOrbitals(*this);
     1538    } else {
     1539      DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
     1540    }
    18431541  }
    18441542
    18451543  Log() << Verbose(0) << "Storing configuration ... " << endl;
    18461544  // get correct valence orbitals
    1847   mol->CalculateOrbitals(*this);
    1848   InitMaxMinStopStep = MaxMinStopStep = MaxPsiDouble;
    18491545  if (ConfigFileName != NULL) { // test the file name
    18501546    strcpy(filename, ConfigFileName);
     
    18591555  output.close();
    18601556  output.clear();
    1861   Log() << Verbose(0) << "Saving of config file ";
     1557  Log() << Verbose(0) << "Saving of config file ... " << endl;
    18621558  if (Save(filename, periode, mol))
    1863     Log() << Verbose(0) << "successful." << endl;
     1559    Log() << Verbose(0) << "\t... successful." << endl;
    18641560  else
    1865     Log() << Verbose(0) << "failed." << endl;
     1561    Log() << Verbose(0) << "\t... failed." << endl;
    18661562
    18671563  // and save to xyz file
     
    18761572    output.open(filename, ios::trunc);
    18771573  }
    1878   Log() << Verbose(0) << "Saving of XYZ file ";
     1574  Log() << Verbose(0) << "Saving of XYZ file ... " << endl;
    18791575  if (mol->MDSteps <= 1) {
    18801576    if (mol->OutputXYZ(&output))
    1881       Log() << Verbose(0) << "successful." << endl;
     1577      Log() << Verbose(0) << "\t... successful." << endl;
    18821578    else
    1883       Log() << Verbose(0) << "failed." << endl;
     1579      Log() << Verbose(0) << "\t... failed." << endl;
    18841580  } else {
    18851581    if (mol->OutputTrajectoriesXYZ(&output))
    1886       Log() << Verbose(0) << "successful." << endl;
     1582      Log() << Verbose(0) << "\t... successful." << endl;
    18871583    else
    1888       Log() << Verbose(0) << "failed." << endl;
     1584      Log() << Verbose(0) << "\t... failed." << endl;
    18891585  }
    18901586  output.close();
     
    18961592  if (output == NULL)
    18971593    strcpy(filename,"main_pcp_linux");
    1898   Log() << Verbose(0) << "Saving as mpqc input ";
     1594  Log() << Verbose(0) << "Saving as mpqc input .. " << endl;
    18991595  if (SaveMPQC(filename, mol))
    1900     Log() << Verbose(0) << "done." << endl;
     1596    Log() << Verbose(0) << "\t... done." << endl;
    19011597  else
    1902     Log() << Verbose(0) << "failed." << endl;
    1903 
    1904   if (!strcmp(configpath, GetDefaultPath())) {
    1905     eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
    1906   }
    1907 
    1908   World::getInstance().destroyMolecule(mol);
     1598    Log() << Verbose(0) << "\t... failed." << endl;
     1599
     1600  // don't destroy molecule as it contains all our atoms
     1601  //World::getInstance().destroyMolecule(mol);
    19091602};
    19101603
     
    19381631  char *dummy1 = NULL;
    19391632  char *dummy = NULL;
    1940   char * const free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");    // pointers in the line that is read in per step
     1633  char free_dummy[MAXSTRINGSIZE];    // pointers in the line that is read in per step
    19411634  dummy1 = free_dummy;
    19421635
     
    19541647      if (file->eof()) {
    19551648        if ((critical) && (found == 0)) {
    1956           Free(free_dummy);
    19571649          //Error(InitReading, name);
    19581650          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    19621654          file->clear();
    19631655          file->seekg(file_position, ios::beg);  // rewind to start position
    1964           Free(free_dummy);
    19651656          return 0;
    19661657        }
     
    19931684        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    19941685        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    1995         //Free((void **)&free_dummy);
    19961686        //Error(FileOpenParams, NULL);
    19971687      } else {
     
    20141704              if (file->eof()) {
    20151705                if ((critical) && (found == 0)) {
    2016                   Free(free_dummy);
    20171706                  //Error(InitReading, name);
    20181707                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    20221711                  file->clear();
    20231712                  file->seekg(file_position, ios::beg);  // rewind to start position
    2024                   Free(free_dummy);
    20251713                  return 0;
    20261714                }
     
    20631751                  if (critical) {
    20641752                    if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
    2065                     Free(free_dummy);
    20661753                    //return 0;
    20671754                    exit(255);
     
    20711758                    file->clear();
    20721759                    file->seekg(file_position, ios::beg);  // rewind to start position
    2073                     Free(free_dummy);
    20741760                    return 0;
    20751761                  }
     
    20841770                  file->seekg(file_position, ios::beg);  // rewind to start position
    20851771                }
    2086                 Free(free_dummy);
    20871772                return 0;
    20881773              }
     
    21401825  if ((type >= row_int) && (verbose))
    21411826    fprintf(stderr,"\n");
    2142   Free(free_dummy);
    21431827  if (!sequential) {
    21441828    file->clear();
     
    22211905        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    22221906        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    2223         //Free(&free_dummy);
    22241907        //Error(FileOpenParams, NULL);
    22251908      } else {
     
    23612044  return (found); // true if found, false if not
    23622045}
     2046
     2047/** Reading of Thermostat related values from parameter file.
     2048 * \param *fb file buffer containing the config file
     2049 */
     2050void config::ParseThermostats(class ConfigFileBuffer * const fb)
     2051{
     2052  char * const thermo = new char[12];
     2053  const int verbose = 0;
     2054
     2055  // read desired Thermostat from file along with needed additional parameters
     2056  if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
     2057    if (strcmp(thermo, Thermostats->ThermostatNames[0]) == 0) { // None
     2058      if (Thermostats->ThermostatImplemented[0] == 1) {
     2059        Thermostats->Thermostat = None;
     2060      } else {
     2061        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2062        Thermostats->Thermostat = None;
     2063      }
     2064    } else if (strcmp(thermo, Thermostats->ThermostatNames[1]) == 0) { // Woodcock
     2065      if (Thermostats->ThermostatImplemented[1] == 1) {
     2066        Thermostats->Thermostat = Woodcock;
     2067        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &Thermostats->ScaleTempStep, 1, critical); // read scaling frequency
     2068      } else {
     2069        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2070        Thermostats->Thermostat = None;
     2071      }
     2072    } else if (strcmp(thermo, Thermostats->ThermostatNames[2]) == 0) { // Gaussian
     2073      if (Thermostats->ThermostatImplemented[2] == 1) {
     2074        Thermostats->Thermostat = Gaussian;
     2075        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &Thermostats->ScaleTempStep, 1, critical); // read collision rate
     2076      } else {
     2077        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2078        Thermostats->Thermostat = None;
     2079      }
     2080    } else if (strcmp(thermo, Thermostats->ThermostatNames[3]) == 0) { // Langevin
     2081      if (Thermostats->ThermostatImplemented[3] == 1) {
     2082        Thermostats->Thermostat = Langevin;
     2083        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->TempFrequency, 1, critical); // read gamma
     2084        if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &Thermostats->alpha, 1, optional)) {
     2085          DoLog(2) && (Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << Thermostats->alpha << "." << endl);
     2086        } else {
     2087          Thermostats->alpha = 1.;
     2088        }
     2089      } else {
     2090        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2091        Thermostats->Thermostat = None;
     2092      }
     2093    } else if (strcmp(thermo, Thermostats->ThermostatNames[4]) == 0) { // Berendsen
     2094      if (Thermostats->ThermostatImplemented[4] == 1) {
     2095        Thermostats->Thermostat = Berendsen;
     2096        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->TempFrequency, 1, critical); // read \tau_T
     2097      } else {
     2098        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2099        Thermostats->Thermostat = None;
     2100      }
     2101    } else if (strcmp(thermo, Thermostats->ThermostatNames[5]) == 0) { // Nose-Hoover
     2102      if (Thermostats->ThermostatImplemented[5] == 1) {
     2103        Thermostats->Thermostat = NoseHoover;
     2104        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &Thermostats->HooverMass, 1, critical); // read Hoovermass
     2105        Thermostats->alpha = 0.;
     2106      } else {
     2107        DoLog(1) && (Log() << Verbose(1) << "Warning: " << Thermostats->ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
     2108        Thermostats->Thermostat = None;
     2109      }
     2110    } else {
     2111      DoLog(1) && (Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl);
     2112      Thermostats->Thermostat = None;
     2113    }
     2114  } else {
     2115    if ((Thermostats->TargetTemp != 0))
     2116      DoLog(2) && (Log() << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
     2117    Thermostats->Thermostat = None;
     2118  }
     2119  delete[](thermo);
     2120};
     2121
Note: See TracChangeset for help on using the changeset viewer.