version 1.21 | version 1.22 |
---|
| |
// -*- 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_abf.h" | #include "colvarbias_abf.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); |
| |
| provide(f_cvb_calc_pmf); |
| enable(f_cvb_calc_pmf); |
| |
// TODO relax this in case of VMD plugin | // TODO relax this in case of VMD plugin |
if (cvm::temperature() == 0.0) | if (cvm::temperature() == 0.0) |
cvm::log("WARNING: ABF should not be run without a thermostat or at 0 Kelvin!\n"); | cvm::log("WARNING: ABF should not be run without a thermostat or at 0 Kelvin!\n"); |
| |
delete [] system_force; | delete [] system_force; |
system_force = NULL; | system_force = NULL; |
} | } |
| |
if (cvm::n_abf_biases > 0) | |
cvm::n_abf_biases -= 1; | |
} | } |
| |
| |
| |
} | } |
| |
// update the output prefix; TODO: move later to setup_output() function | // update the output prefix; TODO: move later to setup_output() function |
if ( cvm::n_abf_biases == 1 && cvm::n_meta_biases == 0 ) { | if (cvm::num_biases_feature(colvardeps::f_cvb_calc_pmf) == 1) { |
// This is the only ABF bias | // This is the only bias computing PMFs |
output_prefix = cvm::output_prefix; | output_prefix = cvm::output_prefix(); |
} else { | } else { |
output_prefix = cvm::output_prefix + "." + this->name; | output_prefix = cvm::output_prefix() + "." + this->name; |
} | } |
| |
if (output_freq && (cvm::step_absolute() % output_freq) == 0) { | if (output_freq && (cvm::step_absolute() % output_freq) == 0) { |
| |
} | } |
| |
| |
std::ostream & colvarbias_abf::write_restart(std::ostream& os) | std::ostream & colvarbias_abf::write_state_data(std::ostream& os) |
{ | { |
| |
std::ios::fmtflags flags(os.flags()); | std::ios::fmtflags flags(os.flags()); |
| |
os << "abf {\n" | |
<< " configuration {\n" | |
<< " name " << this->name << "\n"; | |
os << " }\n"; | |
| |
os.setf(std::ios::fmtflags(0), std::ios::floatfield); // default floating-point format | os.setf(std::ios::fmtflags(0), std::ios::floatfield); // default floating-point format |
os << "\nsamples\n"; | os << "\nsamples\n"; |
samples->write_raw(os, 8); | samples->write_raw(os, 8); |
| |
z_gradients->write_raw(os, 8); | z_gradients->write_raw(os, 8); |
} | } |
| |
os << "}\n\n"; | |
| |
os.flags(flags); | os.flags(flags); |
return os; | return os; |
} | } |
| |
| |
std::istream & colvarbias_abf::read_restart(std::istream& is) | std::istream & colvarbias_abf::read_state_data(std::istream& is) |
{ | { |
if ( input_prefix.size() > 0 ) { | if ( input_prefix.size() > 0 ) { |
cvm::error("ERROR: cannot provide both inputPrefix and a colvars state file.\n", INPUT_ERROR); | cvm::error("ERROR: cannot provide both inputPrefix and a colvars state file.\n", INPUT_ERROR); |
} | } |
| |
size_t const start_pos = is.tellg(); | if (! read_state_data_key(is, "samples")) { |
| |
cvm::log("Restarting ABF bias \""+ | |
this->name+"\".\n"); | |
std::string key, brace, conf; | |
| |
if ( !(is >> key) || !(key == "abf") || | |
!(is >> brace) || !(brace == "{") || | |
!(is >> colvarparse::read_block("configuration", conf)) ) { | |
cvm::log("Error: in reading restart configuration for ABF bias \""+ | |
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; | |
} | |
| |
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 " | |
"\"abf\" block has wrong name(" + name + ")\n"); | |
if ( name == "" ) { | |
cvm::error("Error: \"abf\" block in the restart file has no name.\n"); | |
} | |
| |
if ( !(is >> key) || !(key == "samples")) { | |
cvm::log("Error: in reading restart configuration for ABF bias \""+ | |
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 (! samples->read_raw(is)) { | if (! samples->read_raw(is)) { |
is.clear(); | |
is.seekg(start_pos, std::ios::beg); | |
is.setstate(std::ios::failbit); | |
return is; | return is; |
} | } |
| |
if ( !(is >> key) || !(key == "gradient")) { | if (! read_state_data_key(is, "gradient")) { |
cvm::log("Error: in reading restart configuration for ABF bias \""+ | |
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 (! gradients->read_raw(is)) { | if (! gradients->read_raw(is)) { |
is.clear(); | |
is.seekg(start_pos, std::ios::beg); | |
is.setstate(std::ios::failbit); | |
return is; | return is; |
} | } |
| |
if (z_gradients) { | if (z_gradients) { |
if ( !(is >> key) || !(key == "z_samples")) { | |
cvm::log("Error: in reading restart configuration for ABF bias \""+ | if (! read_state_data_key(is, "z_samples")) { |
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 (! z_samples->read_raw(is)) { | if (! z_samples->read_raw(is)) { |
is.clear(); | |
is.seekg(start_pos, std::ios::beg); | |
is.setstate(std::ios::failbit); | |
return is; | return is; |
} | } |
| |
if ( !(is >> key) || !(key == "z_gradient")) { | if (! read_state_data_key(is, "z_gradient")) { |
cvm::log("Error: in reading restart configuration for ABF bias \""+ | |
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 (! z_gradients->read_raw(is)) { | if (! z_gradients->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; |
} | } |