diff --git a/structure.cpp b/structure.cpp
index a6ac35d474d61ccf565f613758f77b5ee7853b33..fbbc200dbbd577ad7cab97ee35550e2c2090c51a 100644
--- a/structure.cpp
+++ b/structure.cpp
@@ -194,11 +194,29 @@ bool Structure::operator==(const Structure& st) const
 int Structure::next_structure(std::ifstream &ifs) {
   std::string line;
   std::getline(ifs,line);
-  if(line.empty()) return 1;
+  if(line.empty()) return 0;
 
+  std::getline(ifs,line);
+  std::getline(ifs,line);
+  // the second line could be energy or
+  // a scalling factors eweight fweight sweight
+  std::stringstream stream(line);
+  std::string temp;
+  size_t count = 0;
+  while(stream >> temp) { ++count;}
+  // optional if second line is a weight
+  if (count==3)
+    std::getline(ifs,line);
+
+  for (size_t i=0; i<6;++i)
+    std::getline(ifs,line);
+
+
+  int natoms=0;
   while(std::getline(ifs,line)) {
+    natoms++;
     if(line.empty()) break;
     if(line == "\r") break;     // detects windows newline
   }
-  return 0;
+  return natoms;
 }
diff --git a/structure.h b/structure.h
index 62bb1a1c6bbff4db343a49cb4be7fb069ce575a9..a819087a898fbfcbc0f9d6f24a2ed2344b469195 100644
--- a/structure.h
+++ b/structure.h
@@ -257,8 +257,8 @@ struct Structure {
     bool operator==(const Structure& st) const;
 
     // move iterator forward to the next structure
-    // return 0 if success
-    // return 1 if there is no more structures
+    // return number of atoms in the structure
+    // return 0 if there is no more structures
     static int next_structure(std::ifstream &ifs);
 
     private: