| version 1.28 | version 1.29 |
|---|
| |
| // -*- 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 <sstream> | #include <sstream> |
| #include <string.h> | #include <string.h> |
| | |
| |
| "variable module twice.\n"); | "variable module twice.\n"); |
| return; | return; |
| } | } |
| | |
| | depth_s = 0; |
| | |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| cvm::log("Initializing the collective variables module, version "+ | cvm::log("Initializing the collective variables module, version "+ |
| cvm::to_str(COLVARS_VERSION)+".\n"); | cvm::to_str(COLVARS_VERSION)+".\n"); |
| |
| } | } |
| | |
| | |
| | colvarmodule * colvarmodule::main() |
| | { |
| | return proxy->colvars; |
| | } |
| | |
| | |
| | std::vector<colvar *> *colvarmodule::variables() |
| | { |
| | return &colvars; |
| | } |
| | |
| | |
| | std::vector<colvar *> *colvarmodule::variables_active() |
| | { |
| | return &colvars_active; |
| | } |
| | |
| | |
| | std::vector<colvar *> *colvarmodule::variables_active_smp() |
| | { |
| | return &colvars_smp; |
| | } |
| | |
| | |
| | std::vector<int> *colvarmodule::variables_active_smp_items() |
| | { |
| | return &colvars_smp_items; |
| | } |
| | |
| | |
| | std::vector<colvarbias *> *colvarmodule::biases_active() |
| | { |
| | return &(biases_active_); |
| | } |
| | |
| | |
| | size_t colvarmodule::size() const |
| | { |
| | return colvars.size() + biases.size(); |
| | } |
| | |
| | |
| int colvarmodule::read_config_file(char const *config_filename) | int colvarmodule::read_config_file(char const *config_filename) |
| { | { |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| |
| } | } |
| | |
| | |
| | std::istream & colvarmodule::getline(std::istream &is, std::string &line) |
| | { |
| | std::string l; |
| | if (std::getline(is, l)) { |
| | size_t const sz = l.size(); |
| | if (sz > 0) { |
| | if (l[sz-1] == '\r' ) { |
| | line = l.substr(0, sz-1); |
| | } else { |
| | line = l; |
| | } |
| | } else { |
| | line.clear(); |
| | } |
| | } |
| | return is; |
| | } |
| | |
| | |
| int colvarmodule::parse_config(std::string &conf) | int colvarmodule::parse_config(std::string &conf) |
| { | { |
| | extra_conf.clear(); |
| | |
| // parse global options | // parse global options |
| if (catch_input_errors(parse_global_params(conf))) { | if (catch_input_errors(parse_global_params(conf))) { |
| return get_error(); | return get_error(); |
| |
| return get_error(); | return get_error(); |
| } | } |
| | |
| | if (extra_conf.size()) { |
| | catch_input_errors(parse_global_params(extra_conf)); |
| | catch_input_errors(parse_colvars(extra_conf)); |
| | catch_input_errors(parse_biases(extra_conf)); |
| | extra_conf.clear(); |
| | if (get_error() != COLVARS_OK) return get_error(); |
| | } |
| | |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| cvm::log("Collective variables module (re)initialized.\n"); | cvm::log("Collective variables module (re)initialized.\n"); |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| |
| } | } |
| | |
| | |
| | int colvarmodule::append_new_config(std::string const &new_conf) |
| | { |
| | extra_conf += new_conf; |
| | return COLVARS_OK; |
| | } |
| | |
| | |
| int colvarmodule::parse_global_params(std::string const &conf) | int colvarmodule::parse_global_params(std::string const &conf) |
| { | { |
| | colvarmodule *cvm = cvm::main(); |
| | |
| std::string index_file_name; | std::string index_file_name; |
| if (parse->get_keyval(conf, "indexFile", index_file_name)) { | if (parse->get_keyval(conf, "indexFile", index_file_name)) { |
| read_index_file(index_file_name.c_str()); | cvm->read_index_file(index_file_name.c_str()); |
| } | } |
| | |
| if (parse->get_keyval(conf, "smp", proxy->b_smp_active, proxy->b_smp_active)) { | if (parse->get_keyval(conf, "smp", proxy->b_smp_active, proxy->b_smp_active)) { |
| |
| if (colvar_conf.size()) { | if (colvar_conf.size()) { |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| cvm::increase_depth(); | cvm::increase_depth(); |
| colvars.push_back(new colvar(colvar_conf)); | colvars.push_back(new colvar()); |
| if (cvm::get_error() || | if (((colvars.back())->init(colvar_conf) != COLVARS_OK) || |
| ((colvars.back())->check_keywords(colvar_conf, "colvar") != COLVARS_OK)) { | ((colvars.back())->check_keywords(colvar_conf, "colvar") != COLVARS_OK)) { |
| cvm::log("Error while constructing colvar number " + | cvm::log("Error while constructing colvar number " + |
| cvm::to_str(colvars.size()) + " : deleting."); | cvm::to_str(colvars.size()) + " : deleting."); |
| |
| | |
| template <class bias_type> | template <class bias_type> |
| int colvarmodule::parse_biases_type(std::string const &conf, | int colvarmodule::parse_biases_type(std::string const &conf, |
| char const *keyword, | char const *keyword) |
| size_t &bias_count) | |
| { | { |
| std::string bias_conf = ""; | std::string bias_conf = ""; |
| size_t conf_saved_pos = 0; | size_t conf_saved_pos = 0; |
| |
| return COLVARS_ERROR; | return COLVARS_ERROR; |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| bias_count++; | |
| } else { | } else { |
| cvm::error("Error: keyword \""+std::string(keyword)+"\" found without configuration.\n", | cvm::error("Error: keyword \""+std::string(keyword)+"\" found without configuration.\n", |
| INPUT_ERROR); | INPUT_ERROR); |
| |
| cvm::log("Initializing the collective variables biases.\n"); | cvm::log("Initializing the collective variables biases.\n"); |
| | |
| /// initialize ABF instances | /// initialize ABF instances |
| parse_biases_type<colvarbias_abf>(conf, "abf", n_abf_biases); | parse_biases_type<colvarbias_abf>(conf, "abf"); |
| | |
| /// initialize adaptive linear biases | /// initialize adaptive linear biases |
| parse_biases_type<colvarbias_alb>(conf, "ALB", n_rest_biases); | parse_biases_type<colvarbias_alb>(conf, "ALB"); |
| | |
| /// initialize harmonic restraints | /// initialize harmonic restraints |
| parse_biases_type<colvarbias_restraint_harmonic>(conf, "harmonic", n_rest_biases); | parse_biases_type<colvarbias_restraint_harmonic>(conf, "harmonic"); |
| | |
| | /// initialize harmonic walls restraints |
| | parse_biases_type<colvarbias_restraint_harmonic_walls>(conf, "harmonicWalls"); |
| | |
| /// initialize histograms | /// initialize histograms |
| parse_biases_type<colvarbias_histogram>(conf, "histogram", n_histo_biases); | parse_biases_type<colvarbias_histogram>(conf, "histogram"); |
| | |
| /// initialize histogram restraints | /// initialize histogram restraints |
| parse_biases_type<colvarbias_restraint_histogram>(conf, "histogramRestraint", n_rest_biases); | parse_biases_type<colvarbias_restraint_histogram>(conf, "histogramRestraint"); |
| | |
| /// initialize linear restraints | /// initialize linear restraints |
| parse_biases_type<colvarbias_restraint_linear>(conf, "linear", n_rest_biases); | parse_biases_type<colvarbias_restraint_linear>(conf, "linear"); |
| | |
| /// initialize metadynamics instances | /// initialize metadynamics instances |
| parse_biases_type<colvarbias_meta>(conf, "metadynamics", n_meta_biases); | parse_biases_type<colvarbias_meta>(conf, "metadynamics"); |
| | |
| if (use_scripted_forces) { | if (use_scripted_forces) { |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| |
| } | } |
| | |
| | |
| | int colvarmodule::num_biases_feature(int feature_id) |
| | { |
| | colvarmodule *cv = cvm::main(); |
| | size_t n = 0; |
| | for (std::vector<colvarbias *>::iterator bi = cv->biases.begin(); |
| | bi != cv->biases.end(); |
| | bi++) { |
| | if ((*bi)->is_enabled(feature_id)) { |
| | n++; |
| | } |
| | } |
| | return n; |
| | } |
| | |
| | |
| | int colvarmodule::num_biases_type(std::string const &type) |
| | { |
| | colvarmodule *cv = cvm::main(); |
| | size_t n = 0; |
| | for (std::vector<colvarbias *>::iterator bi = cv->biases.begin(); |
| | bi != cv->biases.end(); |
| | bi++) { |
| | if ((*bi)->bias_type == type) { |
| | n++; |
| | } |
| | } |
| | return n; |
| | } |
| | |
| | |
| int colvarmodule::catch_input_errors(int result) | int colvarmodule::catch_input_errors(int result) |
| { | { |
| if (result != COLVARS_OK || get_error()) { | if (result != COLVARS_OK || get_error()) { |
| |
| | |
| | |
| colvarbias * colvarmodule::bias_by_name(std::string const &name) { | colvarbias * colvarmodule::bias_by_name(std::string const &name) { |
| for (std::vector<colvarbias *>::iterator bi = biases.begin(); | colvarmodule *cv = cvm::main(); |
| bi != biases.end(); | for (std::vector<colvarbias *>::iterator bi = cv->biases.begin(); |
| | bi != cv->biases.end(); |
| bi++) { | bi++) { |
| if ((*bi)->name == name) { | if ((*bi)->name == name) { |
| return (*bi); | return (*bi); |
| |
| | |
| | |
| colvar *colvarmodule::colvar_by_name(std::string const &name) { | colvar *colvarmodule::colvar_by_name(std::string const &name) { |
| for (std::vector<colvar *>::iterator cvi = colvars.begin(); | colvarmodule *cv = cvm::main(); |
| cvi != colvars.end(); | for (std::vector<colvar *>::iterator cvi = cv->colvars.begin(); |
| | cvi != cv->colvars.end(); |
| cvi++) { | cvi++) { |
| if ((*cvi)->name == name) { | if ((*cvi)->name == name) { |
| return (*cvi); | return (*cvi); |
| |
| int error_code = COLVARS_OK; | int error_code = COLVARS_OK; |
| std::vector<colvar *>::iterator cvi; | std::vector<colvar *>::iterator cvi; |
| | |
| // Determine which colvars are active at this time step | // Determine which colvars are active at this iteration |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | variables_active()->resize(0); |
| (*cvi)->feature_states[colvardeps::f_cv_active]->enabled = (step_absolute() % (*cvi)->get_time_step_factor() == 0); | variables_active()->reserve(variables()->size()); |
| | for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { |
| | (*cvi)->feature_states[colvardeps::f_cv_active]->enabled = |
| | (step_absolute() % (*cvi)->get_time_step_factor() == 0); |
| | variables_active()->push_back(*cvi); |
| } | } |
| | |
| // if SMP support is available, split up the work | // if SMP support is available, split up the work |
| |
| | |
| // first, calculate how much work (currently, how many active CVCs) each colvar has | // first, calculate how much work (currently, how many active CVCs) each colvar has |
| | |
| colvars_smp.resize(0); | variables_active_smp()->resize(0); |
| colvars_smp_items.resize(0); | variables_active_smp_items()->resize(0); |
| | |
| colvars_smp.reserve(colvars.size()); | variables_active_smp()->reserve(variables_active()->size()); |
| colvars_smp_items.reserve(colvars.size()); | variables_active_smp_items()->reserve(variables_active()->size()); |
| | |
| // set up a vector containing all components | // set up a vector containing all components |
| size_t num_colvar_items = 0; | |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | for (cvi = variables_active()->begin(); cvi != variables_active()->end(); cvi++) { |
| | |
| if (!(*cvi)->is_enabled()) continue; | |
| error_code |= (*cvi)->update_cvc_flags(); | error_code |= (*cvi)->update_cvc_flags(); |
| | |
| size_t num_items = (*cvi)->num_active_cvcs(); | size_t num_items = (*cvi)->num_active_cvcs(); |
| colvars_smp.reserve(colvars_smp.size() + num_items); | variables_active_smp()->reserve(variables_active_smp()->size() + num_items); |
| colvars_smp_items.reserve(colvars_smp_items.size() + num_items); | variables_active_smp_items()->reserve(variables_active_smp_items()->size() + num_items); |
| for (size_t icvc = 0; icvc < num_items; icvc++) { | for (size_t icvc = 0; icvc < num_items; icvc++) { |
| colvars_smp.push_back(*cvi); | variables_active_smp()->push_back(*cvi); |
| colvars_smp_items.push_back(icvc); | variables_active_smp_items()->push_back(icvc); |
| } | } |
| | |
| num_colvar_items += num_items; | |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| | |
| |
| error_code |= proxy->smp_colvars_loop(); | error_code |= proxy->smp_colvars_loop(); |
| | |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | for (cvi = variables_active()->begin(); cvi != variables_active()->end(); cvi++) { |
| if (!(*cvi)->is_enabled()) continue; | |
| error_code |= (*cvi)->collect_cvc_data(); | error_code |= (*cvi)->collect_cvc_data(); |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| |
| | |
| // calculate colvars one at a time | // calculate colvars one at a time |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | for (cvi = variables_active()->begin(); cvi != variables_active()->end(); cvi++) { |
| if (!(*cvi)->is_enabled()) continue; | |
| error_code |= (*cvi)->calc(); | error_code |= (*cvi)->calc(); |
| if (cvm::get_error()) { | if (cvm::get_error()) { |
| return COLVARS_ERROR; | return COLVARS_ERROR; |
| |
| std::vector<colvarbias *>::iterator bi; | std::vector<colvarbias *>::iterator bi; |
| int error_code = COLVARS_OK; | int error_code = COLVARS_OK; |
| | |
| | // update the list of active biases |
| | biases_active()->resize(0); |
| | biases_active()->reserve(biases.size()); |
| | for (bi = biases.begin(); bi != biases.end(); bi++) { |
| | if ((*bi)->is_enabled()) { |
| | biases_active()->push_back(*bi); |
| | } |
| | } |
| | |
| // if SMP support is available, split up the work | // if SMP support is available, split up the work |
| if (proxy->smp_enabled() == COLVARS_OK) { | if (proxy->smp_enabled() == COLVARS_OK) { |
| | |
| |
| } | } |
| | |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (bi = biases.begin(); bi != biases.end(); bi++) { | for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) { |
| error_code |= (*bi)->update(); | error_code |= (*bi)->update(); |
| if (cvm::get_error()) { | if (cvm::get_error()) { |
| return COLVARS_ERROR; | return error_code; |
| } | } |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| } | } |
| | |
| cvm::real total_bias_energy = 0.0; | cvm::real total_bias_energy = 0.0; |
| for (bi = biases.begin(); bi != biases.end(); bi++) { | for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) { |
| total_bias_energy += (*bi)->get_energy(); | total_bias_energy += (*bi)->get_energy(); |
| } | } |
| | |
| | if (cvm::debug()) |
| | cvm::log("Adding total bias energy: " + cvm::to_str(total_bias_energy) + "\n"); |
| proxy->add_energy(total_bias_energy); | proxy->add_energy(total_bias_energy); |
| return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); | return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); |
| } | } |
| |
| if (cvm::debug() && biases.size()) | if (cvm::debug() && biases.size()) |
| cvm::log("Collecting forces from all biases.\n"); | cvm::log("Collecting forces from all biases.\n"); |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (bi = biases.begin(); bi != biases.end(); bi++) { | for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) { |
| (*bi)->communicate_forces(); | (*bi)->communicate_forces(); |
| if (cvm::get_error()) { | if (cvm::get_error()) { |
| return COLVARS_ERROR; | return COLVARS_ERROR; |
| |
| cvm::log("Updating the internal degrees of freedom " | cvm::log("Updating the internal degrees of freedom " |
| "of colvars (if they have any).\n"); | "of colvars (if they have any).\n"); |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { |
| // Here we call even inactive colvars, so they accumulate biasing forces | // Here we call even inactive colvars, so they accumulate biasing forces |
| // as well as update their extended-system dynamics | // as well as update their extended-system dynamics |
| total_colvar_energy += (*cvi)->update_forces_energy(); | total_colvar_energy += (*cvi)->update_forces_energy(); |
| |
| } | } |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| | if (cvm::debug()) |
| | cvm::log("Adding total colvar energy: " + cvm::to_str(total_colvar_energy) + "\n"); |
| proxy->add_energy(total_colvar_energy); | proxy->add_energy(total_colvar_energy); |
| | |
| // make collective variables communicate their forces to their | // make collective variables communicate their forces to their |
| |
| if (cvm::debug()) | if (cvm::debug()) |
| cvm::log("Communicating forces from the colvars to the atoms.\n"); | cvm::log("Communicating forces from the colvars to the atoms.\n"); |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (cvi = colvars.begin(); cvi != colvars.end(); cvi++) { | for (cvi = variables_active()->begin(); cvi != variables_active()->end(); cvi++) { |
| if ((*cvi)->is_enabled(colvardeps::f_cv_gradient)) { | if ((*cvi)->is_enabled(colvardeps::f_cv_gradient)) { |
| if (!(*cvi)->is_enabled()) continue; | |
| (*cvi)->communicate_forces(); | (*cvi)->communicate_forces(); |
| if (cvm::get_error()) { | if (cvm::get_error()) { |
| return COLVARS_ERROR; | return COLVARS_ERROR; |
| |
| cvm::log("Performing analysis.\n"); | cvm::log("Performing analysis.\n"); |
| | |
| // perform colvar-specific analysis | // perform colvar-specific analysis |
| for (std::vector<colvar *>::iterator cvi = colvars.begin(); | for (std::vector<colvar *>::iterator cvi = variables_active()->begin(); |
| cvi != colvars.end(); | cvi != variables_active()->end(); |
| cvi++) { | cvi++) { |
| cvm::increase_depth(); | cvm::increase_depth(); |
| (*cvi)->analyze(); | (*cvi)->analyze(); |
| |
| { | { |
| if (this->size() == 0) return cvm::get_error(); | if (this->size() == 0) return cvm::get_error(); |
| // loop over all components of all colvars to reset masses of all groups | // loop over all components of all colvars to reset masses of all groups |
| for (std::vector<colvar *>::iterator cvi = colvars.begin(); | for (std::vector<colvar *>::iterator cvi = variables()->begin(); |
| cvi != colvars.end(); cvi++) { | cvi != variables()->end(); cvi++) { |
| (*cvi)->setup(); | (*cvi)->setup(); |
| } | } |
| return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); | return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); |
| |
| cvm::log("The restart output state file will be \""+restart_out_name+"\".\n"); | cvm::log("The restart output state file will be \""+restart_out_name+"\".\n"); |
| } | } |
| | |
| output_prefix = proxy->output_prefix(); | output_prefix() = proxy->output_prefix(); |
| if (output_prefix.size()) { | if (output_prefix().size()) { |
| cvm::log("The final output state file will be \""+ | cvm::log("The final output state file will be \""+ |
| (output_prefix.size() ? | (output_prefix().size() ? |
| std::string(output_prefix+".colvars.state") : | std::string(output_prefix()+".colvars.state") : |
| std::string("colvars.state"))+"\".\n"); | std::string("colvars.state"))+"\".\n"); |
| // cvm::log (cvm::line_marker); | // cvm::log (cvm::line_marker); |
| } | } |
| | |
| cv_traj_name = | cv_traj_name = |
| (output_prefix.size() ? | (output_prefix().size() ? |
| std::string(output_prefix+".colvars.traj") : | std::string(output_prefix()+".colvars.traj") : |
| std::string("")); | std::string("")); |
| | |
| if (cv_traj_freq && cv_traj_name.size()) { | if (cv_traj_freq && cv_traj_name.size()) { |
| |
| for (std::vector<colvarbias *>::iterator bi = biases.begin(); | for (std::vector<colvarbias *>::iterator bi = biases.begin(); |
| bi != biases.end(); | bi != biases.end(); |
| bi++) { | bi++) { |
| if (!((*bi)->read_restart(is))) { | if (!((*bi)->read_state(is))) { |
| cvm::error("Error: in reading restart configuration for bias \""+ | cvm::error("Error: in reading restart configuration for bias \""+ |
| (*bi)->name+"\".\n", | (*bi)->name+"\".\n", |
| INPUT_ERROR); | INPUT_ERROR); |
| |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| | |
| // update this ahead of time in this special case | // update this ahead of time in this special case |
| output_prefix = proxy->output_prefix(); | output_prefix() = proxy->input_prefix(); |
| cvm::log("All output files will now be saved with the prefix \""+output_prefix+".tmp.*\".\n"); | cvm::log("All output files will now be saved with the prefix \""+output_prefix()+".tmp.*\".\n"); |
| output_prefix = output_prefix+".tmp"; | |
| write_output_files(); | |
| cvm::log(cvm::line_marker); | cvm::log(cvm::line_marker); |
| cvm::log("Please review the important warning above. After that, you may rename:\n\ | cvm::log("Please review the important warning above. After that, you may rename:\n\ |
| \""+output_prefix+".tmp.colvars.state\"\n\ | \""+output_prefix()+".tmp.colvars.state\"\n\ |
| to:\n\ | to:\n\ |
| \""+output_prefix+".colvars.state\"\n"); | \""+ proxy->input_prefix()+".colvars.state\"\n"); |
| | output_prefix() = output_prefix()+".tmp"; |
| | write_output_files(); |
| cvm::error("Exiting with error until issue is addressed.\n", FATAL_ERROR); | cvm::error("Exiting with error until issue is addressed.\n", FATAL_ERROR); |
| } | } |
| | |
| |
| // if this is a simulation run (i.e. not a postprocessing), output data | // if this is a simulation run (i.e. not a postprocessing), output data |
| // must be written to be able to restart the simulation | // must be written to be able to restart the simulation |
| std::string const out_name = | std::string const out_name = |
| (output_prefix.size() ? | (output_prefix().size() ? |
| std::string(output_prefix+".colvars.state") : | std::string(output_prefix()+".colvars.state") : |
| std::string("colvars.state")); | std::string("colvars.state")); |
| cvm::log("Saving collective variables state to \""+out_name+"\".\n"); | cvm::log("Saving collective variables state to \""+out_name+"\".\n"); |
| | |
| |
| bi != biases.end(); | bi != biases.end(); |
| bi++) { | bi++) { |
| (*bi)->write_output_files(); | (*bi)->write_output_files(); |
| | (*bi)->write_state_to_replicas(); |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| | |
| |
| << " version " << std::string(COLVARS_VERSION) << "\n" | << " version " << std::string(COLVARS_VERSION) << "\n" |
| << "}\n\n"; | << "}\n\n"; |
| | |
| | int error_code = COLVARS_OK; |
| | |
| cvm::increase_depth(); | cvm::increase_depth(); |
| for (std::vector<colvar *>::iterator cvi = colvars.begin(); | for (std::vector<colvar *>::iterator cvi = colvars.begin(); |
| cvi != colvars.end(); | cvi != colvars.end(); |
| cvi++) { | cvi++) { |
| (*cvi)->write_restart(os); | (*cvi)->write_restart(os); |
| | error_code |= (*cvi)->write_output_files(); |
| } | } |
| | |
| for (std::vector<colvarbias *>::iterator bi = biases.begin(); | for (std::vector<colvarbias *>::iterator bi = biases.begin(); |
| bi != biases.end(); | bi != biases.end(); |
| bi++) { | bi++) { |
| (*bi)->write_restart(os); | (*bi)->write_state(os); |
| | error_code |= (*bi)->write_state_to_replicas(); |
| | error_code |= (*bi)->write_output_files(); |
| } | } |
| cvm::decrease_depth(); | cvm::decrease_depth(); |
| | |
| | if (error_code != COLVARS_OK) { |
| | // TODO make this function return an int instead |
| | os.setstate(std::ios::failbit); |
| | } |
| | |
| return os; | return os; |
| } | } |
| | |
| |
| | |
| void cvm::log(std::string const &message) | void cvm::log(std::string const &message) |
| { | { |
| size_t const d = depth(); | // allow logging when the module is not fully initialized |
| | size_t const d = (cvm::main() != NULL) ? depth() : 0; |
| if (d > 0) | if (d > 0) |
| proxy->log((std::string(2*d, ' '))+message); | proxy->log((std::string(2*d, ' '))+message); |
| else | else |
| |
| size_t & cvm::depth() | size_t & cvm::depth() |
| { | { |
| // NOTE: do not call log() or error() here, to avoid recursion | // NOTE: do not call log() or error() here, to avoid recursion |
| size_t const nt = proxy->smp_num_threads(); | colvarmodule *cv = cvm::main(); |
| if (proxy->smp_enabled() == COLVARS_OK) { | if (proxy->smp_enabled() == COLVARS_OK) { |
| if (depth_v.size() != nt) { | int const nt = proxy->smp_num_threads(); |
| // update array of depths | if (int(cv->depth_v.size()) != nt) { |
| proxy->smp_lock(); | proxy->smp_lock(); |
| if (depth_v.size() > 0) { depth_s = depth_v[0]; } | // update array of depths |
| depth_v.clear(); | if (cv->depth_v.size() > 0) { cv->depth_s = cv->depth_v[0]; } |
| depth_v.assign(nt, depth_s); | cv->depth_v.clear(); |
| | cv->depth_v.assign(nt, cv->depth_s); |
| proxy->smp_unlock(); | proxy->smp_unlock(); |
| } | } |
| return depth_v[proxy->smp_thread_id()]; | return cv->depth_v[proxy->smp_thread_id()]; |
| } | } |
| return depth_s; | return cv->depth_s; |
| } | } |
| | |
| | |
| |
| FILE_ERROR); | FILE_ERROR); |
| } | } |
| } | } |
| cvm::index_group_names.push_back(group_name); | index_group_names.push_back(group_name); |
| cvm::index_groups.push_back(std::vector<int> ()); | index_groups.push_back(std::vector<int>()); |
| } else { | } else { |
| cvm::error("Error: in parsing index file \""+ | cvm::error("Error: in parsing index file \""+ |
| std::string(filename)+"\".\n", | std::string(filename)+"\".\n", |
| |
| int atom_number = 1; | int atom_number = 1; |
| size_t pos = is.tellg(); | size_t pos = is.tellg(); |
| while ( (is >> atom_number) && (atom_number > 0) ) { | while ( (is >> atom_number) && (atom_number > 0) ) { |
| (cvm::index_groups.back()).push_back(atom_number); | (index_groups.back()).push_back(atom_number); |
| pos = is.tellg(); | pos = is.tellg(); |
| } | } |
| is.clear(); | is.clear(); |
| |
| + std::string(filename) + ".\n", INPUT_ERROR); | + std::string(filename) + ".\n", INPUT_ERROR); |
| } | } |
| // skip comment line | // skip comment line |
| std::getline(xyz_is, line); | cvm::getline(xyz_is, line); |
| std::getline(xyz_is, line); | cvm::getline(xyz_is, line); |
| xyz_is.width(255); | xyz_is.width(255); |
| std::vector<atom_pos>::iterator pos_i = pos.begin(); | std::vector<atom_pos>::iterator pos_i = pos.begin(); |
| | |
| |
| for ( ; pos_i != pos.end() ; pos_i++, index++) { | for ( ; pos_i != pos.end() ; pos_i++, index++) { |
| | |
| while ( next < *index ) { | while ( next < *index ) { |
| std::getline(xyz_is, line); | cvm::getline(xyz_is, line); |
| next++; | next++; |
| } | } |
| xyz_is >> symbol; | xyz_is >> symbol; |
| |
| return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); | return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK); |
| } | } |
| | |
| // static pointers | |
| std::vector<colvar *> colvarmodule::colvars; | |
| std::vector<colvarbias *> colvarmodule::biases; | |
| size_t colvarmodule::n_abf_biases = 0; | |
| size_t colvarmodule::n_rest_biases = 0; | |
| size_t colvarmodule::n_histo_biases = 0; | |
| size_t colvarmodule::n_meta_biases = 0; | |
| colvarproxy *colvarmodule::proxy = NULL; | |
| | |
| | // shared pointer to the proxy object |
| | colvarproxy *colvarmodule::proxy = NULL; |
| | |
| // static runtime data | // static runtime data |
| cvm::real colvarmodule::debug_gradients_step_size = 1.0e-07; | cvm::real colvarmodule::debug_gradients_step_size = 1.0e-07; |
| |
| long colvarmodule::it_restart = 0; | long colvarmodule::it_restart = 0; |
| size_t colvarmodule::restart_out_freq = 0; | size_t colvarmodule::restart_out_freq = 0; |
| size_t colvarmodule::cv_traj_freq = 0; | size_t colvarmodule::cv_traj_freq = 0; |
| size_t colvarmodule::depth_s = 0; | |
| std::vector<size_t> colvarmodule::depth_v(0); | |
| bool colvarmodule::b_analysis = false; | bool colvarmodule::b_analysis = false; |
| std::list<std::string> colvarmodule::index_group_names; | |
| std::list<std::vector<int> > colvarmodule::index_groups; | |
| bool colvarmodule::use_scripted_forces = false; | bool colvarmodule::use_scripted_forces = false; |
| bool colvarmodule::scripting_after_biases = true; | bool colvarmodule::scripting_after_biases = true; |
| std::string colvarmodule::output_prefix = ""; | |
| | |
| // i/o constants | // i/o constants |
| size_t const colvarmodule::it_width = 12; | size_t const colvarmodule::it_width = 12; |