Index: src/Parser/Psi3Parser.cpp
===================================================================
--- src/Parser/Psi3Parser.cpp	(revision 1bef077d3656c91b027c4cf35ca7eb3e79969644)
+++ src/Parser/Psi3Parser.cpp	(revision 032f31cf80e8ee3e35032df0bfd39da32b7db018)
@@ -64,154 +64,92 @@
 void FormatParser< psi3 >::load(istream *file)
 {
-//  bool Psi3Section = false;
-//  bool MoleculeSection = false;
-//  bool GeometrySection = false;
-//  bool BasisSection = false;
-//  bool AuxBasisSection = false;
-//  char line[MAXSTRINGSIZE];
-//  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-//  boost::char_separator<char> sep("[]");
-//  boost::char_separator<char> angularsep("<>");
-//  boost::char_separator<char> equalitysep(" =");
-//  boost::char_separator<char> whitesep(" \t");
-//  ConvertTo<double> toDouble;
-//
-//  molecule *newmol = World::getInstance().createMolecule();
-//  newmol->ActiveFlag = true;
-//  // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
-//  World::getInstance().getMolecules()->insert(newmol);
-//  while (file->good()) {
-//    file->getline(line, MAXSTRINGSIZE-1);
-//    std::string linestring(line);
-//    if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
-//      GeometrySection = false;
-//    }
-//    if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap
-//      Psi3Section = false;
-//      MoleculeSection = false;
-//      BasisSection = false;
-//      AuxBasisSection = false;
-//    }
-//    if (MoleculeSection) {
-//      if (GeometrySection) { // we have an atom
-//        tokenizer tokens(linestring, sep);
-//  //      if (tokens.size() != 2)
-//  //        throw Psi3ParseException;
-//        tokenizer::iterator tok_iter = tokens.begin();
-//        ASSERT(tok_iter != tokens.end(),
-//            "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
-//        std::stringstream whitespacefilter(*tok_iter++);
-//        std::string element;
-//        whitespacefilter >> ws >> element;
-//        ASSERT(tok_iter != tokens.end(),
-//            "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
-//        std::string vector = *tok_iter;
-//        tokenizer vectorcomponents(vector, whitesep);
-//        Vector X;
-//  //      if (vectorcomponents.size() != NDIM)
-//  //        throw Psi3ParseException;
-//        tok_iter = vectorcomponents.begin();
-//        for (int i=0; i<NDIM; ++i) {
-//          X[i] = toDouble(*tok_iter++);
-//        }
-//        // create atom
-//        atom *newAtom = World::getInstance().createAtom();
-//        newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
-//        newAtom->setPosition(X);
-//        newmol->AddAtom(newAtom);
-//        DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
-//      }
-//    }
-//    if (Psi3Section) {
-//      if (linestring.find("mole<") != string::npos) { // get theory
-//        tokenizer tokens(linestring, angularsep);
-//        tokenizer::iterator tok_iter = tokens.begin();
-//        ++tok_iter;
-//        ASSERT(tok_iter != tokens.end(),
-//            "FormatParser< psi3 >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
-//        std::string value(*tok_iter);
-//        std::stringstream linestream("theory = "+value);
-//        linestream >> getParams();
-//      } else if (linestring.find("integrals<") != string::npos) { // get theory
-//        tokenizer tokens(linestring, angularsep);
-//        tokenizer::iterator tok_iter = tokens.begin();
-//        ++tok_iter;
-//        ASSERT(tok_iter != tokens.end(),
-//            "FormatParser< psi3 >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
-//        std::string value(*tok_iter);
-//        std::stringstream linestream("integration = "+value);
-//        linestream >> getParams();
-//      } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){
-//        // molecule and basis must not be parsed in this section
-//        tokenizer tokens(linestring, equalitysep);
-//        tokenizer::iterator tok_iter = tokens.begin();
-//        ASSERT(tok_iter != tokens.end(),
-//            "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!");
-//        std::stringstream whitespacefilter(*tok_iter);
-//        std::string key;
-//        whitespacefilter >> ws >> key;
-//        if (getParams().haveParameter(key)) {
-//          std::stringstream linestream(linestring);
-//          linestream >> getParams();
-//        } else { // unknown keys are simply ignored as long as parser is incomplete
-//          DoLog(2) && (Log() << Verbose(2) << "INFO: '"+key+"' is unknown and ignored." << std::endl);
-//        }
-//      }
-//    }
-//    if (BasisSection) {
-//      tokenizer tokens(linestring, equalitysep);
-//      tokenizer::iterator tok_iter = tokens.begin();
-//      ASSERT(tok_iter != tokens.end(),
-//          "FormatParser< psi3 >::load() - missing token for BasisSection in line "+linestring+"!");
-//      std::string key(*tok_iter++);
-//      ASSERT(tok_iter != tokens.end(),
-//          "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
-//      std::string value(*tok_iter);
-//      tok_iter++;
-//      // TODO: use exception instead of ASSERT
-//      ASSERT(tok_iter == tokens.end(),
-//          "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+".");
-//      if (key == "name") {
-//        std::stringstream linestream("basis = "+value);
-//        linestream >> getParams();
-//      }
-//    }
-//    if (AuxBasisSection) {
-//      tokenizer tokens(linestring, equalitysep);
-//      tokenizer::iterator tok_iter = tokens.begin();
-//      ASSERT(tok_iter != tokens.end(),
-//          "FormatParser< psi3 >::load() - missing token for AuxBasisSection in line "+linestring+"!");
-//      std::string key(*tok_iter++);
-//      ASSERT(tok_iter != tokens.end(),
-//          "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
-//      std::string value(*tok_iter);
-//      tok_iter++;
-//      // TODO: use exception instead of ASSERT
-//      ASSERT(tok_iter == tokens.end(),
-//          "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+".");
-//      if (key == "name") {
-//        std::stringstream linestream("aux_basis = "+value);
-//        linestream >> getParams();
-//      }
-//    }
-//    // set some scan flags
-//    if (linestring.find("psi3:") != string::npos) {
-//      Psi3Section = true;
-//    }
-//    if (linestring.find("molecule<Molecule>:") != string::npos) {
-//      MoleculeSection = true;
-//    }
-//    if (linestring.find("atoms geometry") != string::npos) {
-//      GeometrySection = true;
-//    }
-//    if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) {
-//      BasisSection = true;
-//    }
-//    if (linestring.find("abasis<") != string::npos) {
-//      AuxBasisSection = true;
-//    }
-//  }
-//  // refresh atom::nr and atom::name
-//  newmol->getAtomCount();
+  bool Psi3Section = false;
+  bool GeometrySection = false;
+  char line[MAXSTRINGSIZE];
+  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+  boost::char_separator<char> sep("()");
+  boost::char_separator<char> angularsep("<>");
+  boost::char_separator<char> equalitysep(" =");
+  boost::char_separator<char> whitesep(" \t");
+  ConvertTo<double> toDouble;
+
+  molecule *newmol = World::getInstance().createMolecule();
+  newmol->ActiveFlag = true;
+  // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
+  World::getInstance().getMolecules()->insert(newmol);
+  while (file->good()) {
+    file->getline(line, MAXSTRINGSIZE-1);
+    std::string linestring(line);
+    LOG(3, "INFO: Current line is: " << line);
+    if ((linestring.find(")") != string::npos) && (linestring.find("(") == string::npos)) {
+      LOG(3, "INFO: Line contains ')' and no '(' (end of section): " << line);
+      // ends a section which do not overlap
+      if (GeometrySection)
+        GeometrySection = false;
+      else
+        Psi3Section = false;
+    }
+    if (GeometrySection) { // we have an atom
+      tokenizer tokens(linestring, sep);
+//      if (tokens.size() != 2)
+//        throw Psi3ParseException;
+      tokenizer::iterator tok_iter = tokens.begin();
+      ASSERT(tok_iter != tokens.end(),
+          "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
+      std::stringstream whitespacefilter(*++tok_iter);
+      std::string element;
+      whitespacefilter >> ws >> element;
+      LOG(2, "INFO: element of atom is " << element);
+      ASSERT(tok_iter != tokens.end(),
+          "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
+      std::string vector = *tok_iter;
+      tokenizer vectorcomponents(vector, whitesep);
+      Vector X;
+//      if (vectorcomponents.size() != NDIM)
+//        throw Psi3ParseException;
+      tok_iter = vectorcomponents.begin();
+      ++tok_iter;
+      for (int i=0; i<NDIM; ++i) {
+        LOG(4, "INFO: Current value is " << *tok_iter << ".");
+        X[i] = toDouble(*tok_iter++);
+      }
+      LOG(2, "INFO: position of atom is " << X);
+      // create atom
+      atom *newAtom = World::getInstance().createAtom();
+      newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
+      newAtom->setPosition(X);
+      newmol->AddAtom(newAtom);
+      DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
+    }
+    if ((Psi3Section) && (!GeometrySection)) {
+      if (linestring.find("=") != string::npos) { // get param value
+        tokenizer tokens(linestring, equalitysep);
+        tokenizer::iterator tok_iter = tokens.begin();
+        ASSERT(tok_iter != tokens.end(),
+            "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!");
+        std::stringstream whitespacefilter(*tok_iter);
+        std::string key;
+        whitespacefilter >> ws >> key;
+        //LOG(2, "INFO: key to check is: " << key);
+        if (getParams().haveParameter(key)) {
+          //LOG(2, "INFO: Line submitted to parameter is: " << linestring);
+          std::stringstream linestream(linestring);
+          linestream >> getParams();
+        } else { // unknown keys are simply ignored as long as parser is incomplete
+          LOG(3, "INFO: '"+key+"' is unknown and ignored.");
+        }
+      }
+    }
+    if ((linestring.find("geometry") != string::npos) && (linestring.find("(") != string::npos)) {
+      LOG(3, "INFO: Line contains geometry and '(': " << line);
+      GeometrySection = true;
+    }
+    if ((linestring.find("psi:") != string::npos) && (linestring.find("(") != string::npos)) {
+      LOG(3, "INFO: Line contains psi: and '(': " << line);
+      Psi3Section = true;
+    }
+  }
+  // refresh atom::nr and atom::name
+  newmol->getAtomCount();
 }
 
