Index: src/config.cpp
===================================================================
--- src/config.cpp	(revision b1f2549d14a74c382543b97323d3b0bbeeda3d56)
+++ src/config.cpp	(revision 3a9fe9f11fb9af6d172ca93d62a1b7bdfb61f183)
@@ -8,4 +8,5 @@
 #include "config.hpp"
 #include "element.hpp"
+#include "helpers.hpp"
 #include "memoryallocator.hpp"
 #include "molecule.hpp"
@@ -696,220 +697,42 @@
 };
 
-
-/** Initializes config file structure by loading elements from a give file.
+/** Initializes ConfigFileBuffer from a file.
  * \param *file input file stream being the opened config file
- * \param *periode pointer to a periodentafel class with all elements
- * \param *mol pointer to molecule containing all atoms of the molecule
- */
-void config::Load(char *filename, periodentafel *periode, molecule *mol)
+ * \param *FileBuffer pointer to FileBuffer on return, should point to NULL
+ */
+void PrepareFileBuffer(char *filename, struct ConfigFileBuffer *&FileBuffer)
 {
-  ifstream *file = new ifstream(filename);
-  if (file == NULL) {
-    cerr << "ERROR: config file " << filename << " missing!" << endl;
-    return;
-  }
-  file->close();
-  delete(file);
-  RetrieveConfigPathAndName(filename);
-
-  // ParseParameterFile
-  struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
+  if (FileBuffer != NULL) {
+    cerr << Verbose(1) << "WARNING: deleting present FileBuffer in PrepareFileBuffer()." << endl;
+    delete(FileBuffer);
+  }
+  FileBuffer = new ConfigFileBuffer(filename);
+
   FileBuffer->InitMapping();
-
-  /* Oeffne Hauptparameterdatei */
-  int di;
-  double BoxLength[9];
-  string zeile;
-  string dummy;
+};
+
+/** Loads a molecule from a ConfigFileBuffer.
+ * \param *mol molecule to load
+ * \param *FileBuffer ConfigFileBuffer to use
+ * \param *periode periodentafel for finding elements
+ * \param FastParsing whether to parse trajectories or not
+ */
+void LoadMolecule(molecule *&mol, struct ConfigFileBuffer *&FileBuffer, periodentafel *periode, bool FastParsing)
+{
+  int MaxTypes = 0;
   element *elementhash[MAX_ELEMENTS];
   char name[MAX_ELEMENTS];
   char keyword[MAX_ELEMENTS];
-  int Z, No[MAX_ELEMENTS];
+  int Z = -1;
+  int No[MAX_ELEMENTS];
   int verbose = 0;
   double value[3];
-  
-  InitThermostats(FileBuffer);
-  
-  /* Namen einlesen */
-
-  ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
-  ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
-  ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
-
-  if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
-    config::Seed = 1;
-
-  if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
-    config::DoOutOrbitals = 0;
-  } else {
-    if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
-    if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
-  }
-  ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
-  if (config::DoOutVis < 0) config::DoOutVis = 0;
-  if (config::DoOutVis > 1) config::DoOutVis = 1;
-  if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
-    config::VectorPlane = -1;
-  if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
-    config::VectorCut = 0.;
-  ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
-  if (config::DoOutMes < 0) config::DoOutMes = 0;
-  if (config::DoOutMes > 1) config::DoOutMes = 1;
-  if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
-    config::DoOutCurrent = 0;
-  if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
-  if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
-  ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
-  if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
-  if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
-  if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
-    config::DoWannier = 0;
-  } else {
-    if (config::DoWannier < 0) config::DoWannier = 0;
-    if (config::DoWannier > 1) config::DoWannier = 1;
-  }
-  if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
-    config::CommonWannier = 0;
-  } else {
-    if (config::CommonWannier < 0) config::CommonWannier = 0;
-    if (config::CommonWannier > 4) config::CommonWannier = 4;
-  }
-  if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
-    config::SawtoothStart = 0.01;
-  } else {
-    if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
-    if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
-  }
-  
-  if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
-    if (config::DoConstrainedMD < 0) 
-      config::DoConstrainedMD = 0;
-  ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
-  if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
-    config::Deltat = 1;
-  ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
-  ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
-  ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
-  //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
-  if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
-    config::EpsWannier = 1e-8;
-
-  // stop conditions
-  //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
-  ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
-  if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
-
-  ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
-  if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
-  if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
-  if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
-
-  ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
-  if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
-  if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
-  if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
-
-  // Unit cell and magnetic field
-  ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
-  mol->cell_size[0] = BoxLength[0];
-  mol->cell_size[1] = BoxLength[3];
-  mol->cell_size[2] = BoxLength[4];
-  mol->cell_size[3] = BoxLength[6];
-  mol->cell_size[4] = BoxLength[7];
-  mol->cell_size[5] = BoxLength[8];
-  //if (1) fprintf(stderr,"\n");
-
-  ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
-  ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
-  if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
-    config::DoFullCurrent = 0;
-  if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
-  if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
-  if (config::DoOutNICS < 0) config::DoOutNICS = 0;
-  if (config::DoOutNICS > 2) config::DoOutNICS = 2;
-  if (config::DoPerturbation == 0) {
-    config::DoFullCurrent = 0;
-    config::DoOutNICS = 0;
-  }
-
-  ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
-  if (config::Lev0Factor < 2) {
-    config::Lev0Factor = 2;
-  }
-  ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
-  if (di >= 0 && di < 2) {
-    config::RiemannTensor = di;
-  } else {
-    fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
-    exit(1);
-  }
-  switch (config::RiemannTensor) {
-    case 0: //UseNoRT
-      if (config::MaxLevel < 2) {
-        config::MaxLevel = 2;
-      }
-      config::LevRFactor = 2;
-      config::RTActualUse = 0;
-      break;
-    case 1: // UseRT
-      if (config::MaxLevel < 3) {
-        config::MaxLevel = 3;
-      }
-      ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
-      if (config::RiemannLevel < 2) {
-        config::RiemannLevel = 2;
-      }
-      if (config::RiemannLevel > config::MaxLevel-1) {
-        config::RiemannLevel = config::MaxLevel-1;
-      }
-      ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
-      if (config::LevRFactor < 2) {
-        config::LevRFactor = 2;
-      }
-      config::Lev0Factor = 2;
-      config::RTActualUse = 2;
-      break;
-  }
-  ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
-  if (di >= 0 && di < 2) {
-    config::PsiType = di;
-  } else {
-    fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
-    exit(1);
-  }
-  switch (config::PsiType) {
-  case 0: // SpinDouble
-    ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
-    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
-    break;
-  case 1: // SpinUpDown
-    if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
-    ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
-    ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
-    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
-    break;
-  }
-
-  // IonsInitRead
-
-  ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
-  ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
-  if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
-    config::RelativeCoord = 0;
-  if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
-    config::StructOpt = 0;
+
+  if (mol == NULL) {
+    cerr << "Molecule is not allocated in LoadMolecule(), exit.";
+    performCriticalExit();
+  }
+
+  ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
   if (MaxTypes == 0) {
     cerr << "There are no atoms according to MaxTypes in this config file." << endl;
@@ -918,5 +741,5 @@
     cout << Verbose(0) << "Prescanning ions per type: " << endl;
     int NoAtoms = 0;
-    for (int i=0; i < config::MaxTypes; i++) {
+    for (int i=0; i < MaxTypes; i++) {
       sprintf(name,"Ion_Type%i",i+1);
       ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
@@ -929,5 +752,5 @@
 
     // sort the lines via the LineMapping
-    sprintf(name,"Ion_Type%i",config::MaxTypes);
+    sprintf(name,"Ion_Type%i",MaxTypes);
     if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
       cerr << "There are no atoms in the config file!" << endl;
@@ -941,5 +764,5 @@
     //}
 
-    map<int, atom *> AtomList[config::MaxTypes];
+    map<int, atom *> AtomList[MaxTypes];
     map<int, atom *> LinearList;
     atom *neues = NULL;
@@ -949,5 +772,5 @@
       while (status) {
         cout << "Currently parsing MD step " << repetition << "." << endl;
-        for (int i=0; i < config::MaxTypes; i++) {
+        for (int i=0; i < MaxTypes; i++) {
           sprintf(name,"Ion_Type%i",i+1);
           for(int j=0;j<No[i];j++) {
@@ -1028,5 +851,5 @@
       cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
       // parse in molecule coordinates
-      for (int i=0; i < config::MaxTypes; i++) {
+      for (int i=0; i < MaxTypes; i++) {
         sprintf(name,"Ion_Type%i",i+1);
         for(int j=0;j<No[i];j++) {
@@ -1061,4 +884,220 @@
     }
   }
+};
+
+
+/** Initializes config file structure by loading elements from a give file.
+ * \param *file input file stream being the opened config file
+ * \param *periode pointer to a periodentafel class with all elements
+ * \param *mol pointer to molecule containing all atoms of the molecule
+ */
+void config::Load(char *filename, periodentafel *periode, molecule *mol)
+{
+  ifstream *file = new ifstream(filename);
+  if (file == NULL) {
+    cerr << "ERROR: config file " << filename << " missing!" << endl;
+    return;
+  }
+  file->close();
+  delete(file);
+  RetrieveConfigPathAndName(filename);
+
+  // ParseParameterFile
+  struct ConfigFileBuffer *FileBuffer = NULL;
+  PrepareFileBuffer(filename,FileBuffer);
+
+  /* Oeffne Hauptparameterdatei */
+  int di;
+  double BoxLength[9];
+  string zeile;
+  string dummy;
+  int verbose = 0;
+  
+  InitThermostats(FileBuffer);
+  
+  /* Namen einlesen */
+
+  ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
+  ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
+  ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
+
+  if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
+    config::Seed = 1;
+
+  if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
+    config::DoOutOrbitals = 0;
+  } else {
+    if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
+    if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
+  }
+  ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
+  if (config::DoOutVis < 0) config::DoOutVis = 0;
+  if (config::DoOutVis > 1) config::DoOutVis = 1;
+  if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
+    config::VectorPlane = -1;
+  if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
+    config::VectorCut = 0.;
+  ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
+  if (config::DoOutMes < 0) config::DoOutMes = 0;
+  if (config::DoOutMes > 1) config::DoOutMes = 1;
+  if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
+    config::DoOutCurrent = 0;
+  if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
+  if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
+  ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
+  if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
+  if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
+  if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
+    config::DoWannier = 0;
+  } else {
+    if (config::DoWannier < 0) config::DoWannier = 0;
+    if (config::DoWannier > 1) config::DoWannier = 1;
+  }
+  if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
+    config::CommonWannier = 0;
+  } else {
+    if (config::CommonWannier < 0) config::CommonWannier = 0;
+    if (config::CommonWannier > 4) config::CommonWannier = 4;
+  }
+  if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
+    config::SawtoothStart = 0.01;
+  } else {
+    if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
+    if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
+  }
+  
+  if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
+    if (config::DoConstrainedMD < 0) 
+      config::DoConstrainedMD = 0;
+  ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
+  if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
+    config::Deltat = 1;
+  ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
+  ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
+  ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
+  //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
+  if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
+    config::EpsWannier = 1e-8;
+
+  // stop conditions
+  //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
+  ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
+  if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
+
+  ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
+  if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
+  if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
+  if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
+
+  ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
+  if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
+  if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
+  if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
+
+  // Unit cell and magnetic field
+  ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
+  mol->cell_size[0] = BoxLength[0];
+  mol->cell_size[1] = BoxLength[3];
+  mol->cell_size[2] = BoxLength[4];
+  mol->cell_size[3] = BoxLength[6];
+  mol->cell_size[4] = BoxLength[7];
+  mol->cell_size[5] = BoxLength[8];
+  //if (1) fprintf(stderr,"\n");
+
+  ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
+  ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
+  if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
+    config::DoFullCurrent = 0;
+  if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
+  if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
+  if (config::DoOutNICS < 0) config::DoOutNICS = 0;
+  if (config::DoOutNICS > 2) config::DoOutNICS = 2;
+  if (config::DoPerturbation == 0) {
+    config::DoFullCurrent = 0;
+    config::DoOutNICS = 0;
+  }
+
+  ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
+  if (config::Lev0Factor < 2) {
+    config::Lev0Factor = 2;
+  }
+  ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
+  if (di >= 0 && di < 2) {
+    config::RiemannTensor = di;
+  } else {
+    fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
+    exit(1);
+  }
+  switch (config::RiemannTensor) {
+    case 0: //UseNoRT
+      if (config::MaxLevel < 2) {
+        config::MaxLevel = 2;
+      }
+      config::LevRFactor = 2;
+      config::RTActualUse = 0;
+      break;
+    case 1: // UseRT
+      if (config::MaxLevel < 3) {
+        config::MaxLevel = 3;
+      }
+      ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
+      if (config::RiemannLevel < 2) {
+        config::RiemannLevel = 2;
+      }
+      if (config::RiemannLevel > config::MaxLevel-1) {
+        config::RiemannLevel = config::MaxLevel-1;
+      }
+      ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
+      if (config::LevRFactor < 2) {
+        config::LevRFactor = 2;
+      }
+      config::Lev0Factor = 2;
+      config::RTActualUse = 2;
+      break;
+  }
+  ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
+  if (di >= 0 && di < 2) {
+    config::PsiType = di;
+  } else {
+    fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
+    exit(1);
+  }
+  switch (config::PsiType) {
+  case 0: // SpinDouble
+    ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
+    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
+    break;
+  case 1: // SpinUpDown
+    if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
+    ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
+    ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
+    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
+    break;
+  }
+
+  // IonsInitRead
+
+  ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
+  ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
+  if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
+    config::RelativeCoord = 0;
+  if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
+    config::StructOpt = 0;
+
+  LoadMolecule(mol, FileBuffer, periode, FastParsing);
+
   delete(FileBuffer);
 };
@@ -1536,5 +1575,5 @@
  * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
  */
-int config::ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
+int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
   int i,j;  // loop variables
   int length = 0, maxlength = -1;
@@ -1774,5 +1813,5 @@
  * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
  */
-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) {
+int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
   int i,j;  // loop variables
   int length = 0, maxlength = -1;
Index: src/config.hpp
===================================================================
--- src/config.hpp	(revision b1f2549d14a74c382543b97323d3b0bbeeda3d56)
+++ src/config.hpp	(revision 3a9fe9f11fb9af6d172ca93d62a1b7bdfb61f183)
@@ -126,7 +126,4 @@
 
 
-  int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
-  int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
-
   public:
   config();
@@ -146,3 +143,8 @@
 };
 
+int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
+int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
+void LoadMolecule(molecule *&mol, struct ConfigFileBuffer *&FileBuffer, periodentafel *periode, bool FastParsing);
+void PrepareFileBuffer(char *filename, struct ConfigFileBuffer *&FileBuffer);
+
 #endif /* CONFIG_HPP_ */
