| version 1.2 | version 1.3 |
|---|
| |
| // -*- c++ -*- | // -*- c++ -*- |
| | |
| | // This file is part of the Collective Variables module (Colvars). |
| | // The original version of Colvars and its updates are located at: |
| | // https://github.com/colvars/colvars |
| | // Please update all Colvars source files before making any changes. |
| | // If you wish to distribute your changes, please submit them to the |
| | // Colvars repository at GitHub. |
| | |
| #include "colvarmodule.h" | #include "colvarmodule.h" |
| #include "colvar.h" | #include "colvar.h" |
| #include "colvarbias_histogram.h" | #include "colvarbias_histogram.h" |
| |
| { | { |
| colvarbias::init(conf); | colvarbias::init(conf); |
| | |
| | provide(f_cvb_scalar_variables); |
| | enable(f_cvb_scalar_variables); |
| | |
| provide(f_cvb_history_dependent); | provide(f_cvb_history_dependent); |
| enable(f_cvb_history_dependent); | enable(f_cvb_history_dependent); |
| | |
| |
| delete grid; | delete grid; |
| grid = NULL; | grid = NULL; |
| } | } |
| | |
| if (cvm::n_histo_biases > 0) | |
| cvm::n_histo_biases -= 1; | |
| } | } |
| | |
| | |
| |
| // At the first timestep, we need to assign out_name since | // At the first timestep, we need to assign out_name since |
| // output_prefix is unset during the constructor | // output_prefix is unset during the constructor |
| if (cvm::step_relative() == 0) { | if (cvm::step_relative() == 0) { |
| out_name = cvm::output_prefix + "." + this->name + ".dat"; | out_name = cvm::output_prefix() + "." + this->name + ".dat"; |
| cvm::log("Histogram " + this->name + " will be written to file \"" + out_name + "\""); | cvm::log("Histogram " + this->name + " will be written to file \"" + out_name + "\""); |
| } | } |
| } | } |
| | |
| if (out_name_dx.size() == 0) { | if (out_name_dx.size() == 0) { |
| if (cvm::step_relative() == 0) { | if (cvm::step_relative() == 0) { |
| out_name_dx = cvm::output_prefix + "." + this->name + ".dx"; | out_name_dx = cvm::output_prefix() + "." + this->name + ".dx"; |
| cvm::log("Histogram " + this->name + " will be written to file \"" + out_name_dx + "\""); | cvm::log("Histogram " + this->name + " will be written to file \"" + out_name_dx + "\""); |
| } | } |
| } | } |
| |
| } | } |
| | |
| | |
| std::istream & colvarbias_histogram::read_restart(std::istream& is) | std::istream & colvarbias_histogram::read_state_data(std::istream& is) |
| { | { |
| size_t const start_pos = is.tellg(); | if (! read_state_data_key(is, "grid")) { |
| | |
| cvm::log("Restarting collective variable histogram \""+ | |
| this->name+"\".\n"); | |
| std::string key, brace, conf; | |
| | |
| if ( !(is >> key) || !(key == "histogram") || | |
| !(is >> brace) || !(brace == "{") || | |
| !(is >> colvarparse::read_block("configuration", conf)) ) { | |
| cvm::log("Error: in reading restart configuration for histogram \""+ | |
| this->name+"\" at position "+ | |
| cvm::to_str(is.tellg())+" in stream.\n"); | |
| is.clear(); | |
| is.seekg(start_pos, std::ios::beg); | |
| is.setstate(std::ios::failbit); | |
| return is; | |
| } | |
| | |
| int id = -1; | |
| std::string name = ""; | |
| if ( (colvarparse::get_keyval(conf, "name", name, std::string(""), colvarparse::parse_silent)) && | |
| (name != this->name) ) | |
| cvm::error("Error: in the restart file, the " | |
| "\"histogram\" block has a wrong name: different system?\n"); | |
| if ( (id == -1) && (name == "") ) { | |
| cvm::error("Error: \"histogram\" block in the restart file " | |
| "has no name.\n"); | |
| } | |
| | |
| if ( !(is >> key) || !(key == "grid")) { | |
| cvm::error("Error: in reading restart configuration for histogram \""+ | |
| this->name+"\" at position "+ | |
| cvm::to_str(is.tellg())+" in stream.\n"); | |
| is.clear(); | |
| is.seekg(start_pos, std::ios::beg); | |
| is.setstate(std::ios::failbit); | |
| return is; | return is; |
| } | } |
| if (! grid->read_raw(is)) { | if (! grid->read_raw(is)) { |
| is.clear(); | |
| is.seekg(start_pos, std::ios::beg); | |
| is.setstate(std::ios::failbit); | |
| return is; | return is; |
| } | } |
| | |
| is >> brace; | |
| if (brace != "}") { | |
| cvm::error("Error: corrupt restart information for ABF bias \""+ | |
| this->name+"\": no matching brace at position "+ | |
| cvm::to_str(is.tellg())+" in the restart file.\n"); | |
| is.setstate(std::ios::failbit); | |
| } | |
| return is; | return is; |
| } | } |
| | |
| std::ostream & colvarbias_histogram::write_restart(std::ostream& os) | |
| | std::ostream & colvarbias_histogram::write_state_data(std::ostream& os) |
| { | { |
| std::ios::fmtflags flags(os.flags()); | std::ios::fmtflags flags(os.flags()); |
| os.setf(std::ios::fmtflags(0), std::ios::floatfield); | os.setf(std::ios::fmtflags(0), std::ios::floatfield); |
| | |
| os << "histogram {\n" | |
| << " configuration {\n" | |
| << " name " << this->name << "\n"; | |
| os << " }\n"; | |
| | |
| os << "grid\n"; | os << "grid\n"; |
| grid->write_raw(os, 8); | grid->write_raw(os, 8); |
| | |
| os << "}\n\n"; | |
| | |
| os.flags(flags); | os.flags(flags); |
| return os; | return os; |
| } | } |