<commit_before>
#include <stdio.h>
#include <string>
#include "statesaver.h"

using namespace std;

StateSaver::StateSaver(QMTopology& qmtop, string &filein, string & fileout){
    Open(qmtop, filein, fileout);
}

void StateSaver::Open(QMTopology &qmtop, string &filein, string & fileout) {
    _qmtop = &qmtop;
    _out.open(fileout.c_str(),ios::binary|ios::out);
    _in.open(filein.c_str(), ios::in | ios::binary);
    _mode = 'b';
}

StateSaver::StateSaver(QMTopology& qmtop, string & file, const char & mode){
    Open(qmtop, file, mode);
}

void StateSaver::Open(QMTopology &qmtop, string &file, const char & mode) {
    _qmtop = &qmtop;
    _mode = mode;
    if (mode == 'w') {_out.open( file.c_str(),ios::binary|ios::out);}
    else if (mode == 'r') {_in.open(file.c_str(), ios::in | ios::binary);}
    else {
        throw runtime_error(string("Open mode not available" ) + mode );
    }
}

//void StateSaver::Open(string file)

void StateSaver::Save() {
    
    streampos start = _out.tellp();
    _startpos.push_back(start);
    Write_TimeStep();
    Write_PBCs();
    Write_Molecules();
    Write_QMBeads();
    Write_QMNeighbourlist();
    //Write NBL
    //_out.close();
    //_out = datafile(datafile.c_str(), ios::binary|ios::out);
}

void StateSaver::Close(){
    if (_mode == 'w' || _mode == 'b'){
        vector <streampos>::iterator itb=_startpos.begin();
        for ( ;itb !=_startpos.end(); ++itb){
            write<streampos>(*itb);
        }
        write<int>(_startpos.size());
        _out.close();
    }
    if (_mode == 'r' || _mode == 'b'){
        _in.close();
    }
}

void StateSaver::Load() {
    _qmtop->Cleanup();
    _qmtop->nblist().Cleanup();
    _qmtop->CreateResidue("dummy");

    Read_PBCs();
    Read_TimeStep();
    Read_Molecules();
    Read_QMBeads();
    Read_QMNeighbourlist();
}

void StateSaver::Write_TimeStep(){
    write<double>(_qmtop->getTime());
    write<int>(_qmtop->getStep());
}
<commit_msg>removed bug: writing time step, then PBCs; but reading PBCs then time step ;)<commit_after>
#include <stdio.h>
#include <string>
#include "statesaver.h"

using namespace std;

StateSaver::StateSaver(QMTopology& qmtop, string &filein, string & fileout){
    Open(qmtop, filein, fileout);
}

void StateSaver::Open(QMTopology &qmtop, string &filein, string & fileout) {
    _qmtop = &qmtop;
    _out.open(fileout.c_str(),ios::binary|ios::out);
    _in.open(filein.c_str(), ios::in | ios::binary);
    _mode = 'b';
}

StateSaver::StateSaver(QMTopology& qmtop, string & file, const char & mode){
    Open(qmtop, file, mode);
}

void StateSaver::Open(QMTopology &qmtop, string &file, const char & mode) {
    _qmtop = &qmtop;
    _mode = mode;
    if (mode == 'w') {_out.open( file.c_str(),ios::binary|ios::out);}
    else if (mode == 'r') {_in.open(file.c_str(), ios::in | ios::binary);}
    else {
        throw runtime_error(string("Open mode not available" ) + mode );
    }
}

//void StateSaver::Open(string file)

void StateSaver::Save() {
    
    streampos start = _out.tellp();
    _startpos.push_back(start);
    Write_TimeStep();
    Write_PBCs();
    Write_Molecules();
    Write_QMBeads();
    Write_QMNeighbourlist();
    //Write NBL
    //_out.close();
    //_out = datafile(datafile.c_str(), ios::binary|ios::out);
}

void StateSaver::Close(){
    if (_mode == 'w' || _mode == 'b'){
        vector <streampos>::iterator itb=_startpos.begin();
        for ( ;itb !=_startpos.end(); ++itb){
            write<streampos>(*itb);
        }
        write<int>(_startpos.size());
        _out.close();
    }
    if (_mode == 'r' || _mode == 'b'){
        _in.close();
    }
}

void StateSaver::Load() {
    _qmtop->Cleanup();
    _qmtop->nblist().Cleanup();
    _qmtop->CreateResidue("dummy");

    Read_TimeStep();
    Read_PBCs();
    Read_Molecules();
    Read_QMBeads();
    Read_QMNeighbourlist();
}

void StateSaver::Write_TimeStep(){
    write<double>(_qmtop->getTime());
    write<int>(_qmtop->getStep());
}

{'fraction_non_alphanumeric': 0.18293910417715148, 'fraction_numerical': 0.0, 'mean_word_length': 3.496606334841629, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5971979', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1523, 'n_words': 277}