Skip to content
Snippets Groups Projects
Commit 5f0b80d5 authored by Marcin Kirsz's avatar Marcin Kirsz
Browse files

Return number of atoms in a structure

parent b0c86f77
No related branches found
No related tags found
No related merge requests found
Pipeline #37201 passed
Pipeline: Tadah.MLIP

#37202

    ...@@ -194,11 +194,29 @@ bool Structure::operator==(const Structure& st) const ...@@ -194,11 +194,29 @@ bool Structure::operator==(const Structure& st) const
    int Structure::next_structure(std::ifstream &ifs) { int Structure::next_structure(std::ifstream &ifs) {
    std::string line; std::string line;
    std::getline(ifs,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)) { while(std::getline(ifs,line)) {
    natoms++;
    if(line.empty()) break; if(line.empty()) break;
    if(line == "\r") break; // detects windows newline if(line == "\r") break; // detects windows newline
    } }
    return 0; return natoms;
    } }
    ...@@ -257,8 +257,8 @@ struct Structure { ...@@ -257,8 +257,8 @@ struct Structure {
    bool operator==(const Structure& st) const; bool operator==(const Structure& st) const;
    // move iterator forward to the next structure // move iterator forward to the next structure
    // return 0 if success // return number of atoms in the structure
    // return 1 if there is no more structures // return 0 if there is no more structures
    static int next_structure(std::ifstream &ifs); static int next_structure(std::ifstream &ifs);
    private: private:
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment