Skip to content
Snippets Groups Projects
Commit 1a12c85d authored by mkirsz's avatar mkirsz
Browse files

Added dump to Structure

parent ee7f5f41
No related branches found
No related tags found
1 merge request!8Develop
Pipeline #48250 passed
Pipeline: Tadah.MLIP

#48252

    ......@@ -271,6 +271,12 @@ struct Structure {
    std::vector<Atom>::const_iterator begin() const;
    std::vector<Atom>::const_iterator end() const;
    /** Method to dump class content to a file */
    void dump_to_file(std::ostream &file, size_t prec=12) const;
    /** Method to dump class content to a file */
    void dump_to_file(const std::string& filepath, size_t prec=12) const;
    private:
    const static size_t w=15; // controls output width
    const static size_t p=6; // controls output precision
    ......
    ......@@ -241,3 +241,52 @@ std::vector<Atom>::const_iterator Structure::begin() const {
    std::vector<Atom>::const_iterator Structure::end() const {
    return atoms.cend();
    }
    void Structure::dump_to_file(std::ostream& file, size_t prec) const {
    const int n = 5;
    file << label << std::endl;
    file << std::fixed << std::setprecision(prec);
    file << eweight << " " << fweight << " " << sweight << std::endl;
    file << energy << std::endl;
    file
    << std::setw(prec+n) << cell(0,0) << " "
    << std::setw(prec+n) << cell(0,1) << " "
    << std::setw(prec+n) << cell(0,2) << " " << std::endl
    << std::setw(prec+n) << cell(1,0) << " "
    << std::setw(prec+n) << cell(1,1) << " "
    << std::setw(prec+n) << cell(1,2) << " " << std::endl
    << std::setw(prec+n) << cell(2,0) << " "
    << std::setw(prec+n) << cell(2,1) << " "
    << std::setw(prec+n) << cell(2,2) << " " << std::endl;
    file
    << std::setw(prec+n) << stress(0,0) << " "
    << std::setw(prec+n) << stress(0,1) << " "
    << std::setw(prec+n) << stress(0,2) << " " << std::endl
    << std::setw(prec+n) << stress(1,0) << " "
    << std::setw(prec+n) << stress(1,1) << " "
    << std::setw(prec+n) << stress(1,2) << " " << std::endl
    << std::setw(prec+n) << stress(2,0) << " "
    << std::setw(prec+n) << stress(2,1) << " "
    << std::setw(prec+n) << stress(2,2) << " " << std::endl;
    for (const auto& a : atoms) {
    file << std::setw(2) << a.symbol << " "
    << std::setw(prec+n) << a.position[0] << " "
    << std::setw(prec+n) << a.position[1] << " "
    << std::setw(prec+n) << a.position[2] << " "
    << std::setw(prec+n) << a.force[0] << " "
    << std::setw(prec+n) << a.force[1] << " "
    << std::setw(prec+n) << a.force[2] << std::endl;
    }
    file << std::endl;
    }
    void Structure::dump_to_file(const std::string& filepath, size_t prec) const {
    std::ofstream file(filepath, std::ios::app); // Open in append mode
    if (!file.is_open()) {
    std::cerr << "Error: Could not open file for writing: " << filepath << std::endl;
    return;
    }
    dump_to_file(file,prec);
    file.close();
    }
    ......@@ -254,46 +254,8 @@ void StructureDB::dump_to_file(const std::string& filepath, size_t prec) const {
    std::cerr << "Error: Could not open file for writing: " << filepath << std::endl;
    return;
    }
    const int n = 5;
    for (const auto &s : structures) {
    file << s.label << std::endl;
    file << std::fixed << std::setprecision(prec);
    file << s.eweight << " " << s.fweight << " " << s.sweight << std::endl;
    file << s.energy << std::endl;
    file
    << std::setw(prec+n) << s.cell(0,0) << " "
    << std::setw(prec+n) << s.cell(0,1) << " "
    << std::setw(prec+n) << s.cell(0,2) << " " << std::endl
    << std::setw(prec+n) << s.cell(1,0) << " "
    << std::setw(prec+n) << s.cell(1,1) << " "
    << std::setw(prec+n) << s.cell(1,2) << " " << std::endl
    << std::setw(prec+n) << s.cell(2,0) << " "
    << std::setw(prec+n) << s.cell(2,1) << " "
    << std::setw(prec+n) << s.cell(2,2) << " " << std::endl;
    file
    << std::setw(prec+n) << s.stress(0,0) << " "
    << std::setw(prec+n) << s.stress(0,1) << " "
    << std::setw(prec+n) << s.stress(0,2) << " " << std::endl
    << std::setw(prec+n) << s.stress(1,0) << " "
    << std::setw(prec+n) << s.stress(1,1) << " "
    << std::setw(prec+n) << s.stress(1,2) << " " << std::endl
    << std::setw(prec+n) << s.stress(2,0) << " "
    << std::setw(prec+n) << s.stress(2,1) << " "
    << std::setw(prec+n) << s.stress(2,2) << " " << std::endl;
    for (const auto& a : s.atoms) {
    file << std::setw(2) << a.symbol << " "
    << std::setw(prec+n) << a.position[0] << " "
    << std::setw(prec+n) << a.position[1] << " "
    << std::setw(prec+n) << a.position[2] << " "
    << std::setw(prec+n) << a.force[0] << " "
    << std::setw(prec+n) << a.force[1] << " "
    << std::setw(prec+n) << a.force[2] << std::endl;
    }
    file << std::endl;
    s.dump_to_file(file,prec);
    }
    file.close();
    }
    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