version 1.31 | version 1.32 |
---|
| |
#include "colvarbias_meta.h" | #include "colvarbias_meta.h" |
#include "colvarbias_restraint.h" | #include "colvarbias_restraint.h" |
#include "colvarscript.h" | #include "colvarscript.h" |
| #include "colvaratoms.h" |
| |
| |
colvarmodule::colvarmodule(colvarproxy *proxy_in) | colvarmodule::colvarmodule(colvarproxy *proxy_in) |
| |
| |
size_t i; | size_t i; |
| |
for (i = 0; i < biases.size(); i++) { | |
biases[i]->enable(colvardeps::f_cvb_active); | |
if (cvm::debug()) | |
biases[i]->print_state(); | |
} | |
| |
size_t n_hist_dep_biases = 0; | size_t n_hist_dep_biases = 0; |
std::vector<std::string> hist_dep_biases_names; | std::vector<std::string> hist_dep_biases_names; |
for (i = 0; i < biases.size(); i++) { | for (i = 0; i < biases.size(); i++) { |
| |
} | } |
| |
| |
colvarbias * colvarmodule::bias_by_name(std::string const &name) { | colvarbias * colvarmodule::bias_by_name(std::string const &name) |
| { |
colvarmodule *cv = cvm::main(); | colvarmodule *cv = cvm::main(); |
for (std::vector<colvarbias *>::iterator bi = cv->biases.begin(); | for (std::vector<colvarbias *>::iterator bi = cv->biases.begin(); |
bi != cv->biases.end(); | bi != cv->biases.end(); |
| |
} | } |
| |
| |
colvar *colvarmodule::colvar_by_name(std::string const &name) { | colvar *colvarmodule::colvar_by_name(std::string const &name) |
| { |
colvarmodule *cv = cvm::main(); | colvarmodule *cv = cvm::main(); |
for (std::vector<colvar *>::iterator cvi = cv->colvars.begin(); | for (std::vector<colvar *>::iterator cvi = cv->colvars.begin(); |
cvi != cv->colvars.end(); | cvi != cv->colvars.end(); |
| |
} | } |
| |
| |
| cvm::atom_group *colvarmodule::atom_group_by_name(std::string const &name) |
| { |
| colvarmodule *cv = cvm::main(); |
| for (std::vector<cvm::atom_group *>::iterator agi = cv->named_atom_groups.begin(); |
| agi != cv->named_atom_groups.end(); |
| agi++) { |
| if ((*agi)->name == name) { |
| return (*agi); |
| } |
| } |
| return NULL; |
| } |
| |
| |
int colvarmodule::change_configuration(std::string const &bias_name, | int colvarmodule::change_configuration(std::string const &bias_name, |
std::string const &conf) | std::string const &conf) |
{ | { |
| |
cvm::log("Calculating collective variables.\n"); | cvm::log("Calculating collective variables.\n"); |
// calculate collective variables and their gradients | // calculate collective variables and their gradients |
| |
| // First, we need to decide which biases are awake |
| // so they can activate colvars as needed |
| std::vector<colvarbias *>::iterator bi; |
| for (bi = biases.begin(); bi != biases.end(); bi++) { |
| int tsf = (*bi)->get_time_step_factor(); |
| if (tsf > 0 && (step_absolute() % tsf == 0)) { |
| (*bi)->enable(colvardeps::f_cvb_awake); |
| } else { |
| (*bi)->disable(colvardeps::f_cvb_awake); |
| } |
| } |
| |
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 iteration | // Determine which colvars are active at this iteration |
variables_active()->resize(0); | variables_active()->clear(); |
variables_active()->reserve(variables()->size()); | variables_active()->reserve(variables()->size()); |
for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { | for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { |
// This is a dynamic feature - the next call should be to enable() | // Wake up or put to sleep variables |
// or disable() when dynamic dependency resolution is fully implemented | int tsf = (*cvi)->get_time_step_factor(); |
(*cvi)->set_enabled(colvardeps::f_cv_active, | if (tsf > 0 && (step_absolute() % tsf == 0)) { |
step_absolute() % (*cvi)->get_time_step_factor() == 0); | (*cvi)->enable(colvardeps::f_cv_awake); |
| } else { |
| (*cvi)->disable(colvardeps::f_cv_awake); |
| } |
| |
| if ((*cvi)->is_enabled()) { |
variables_active()->push_back(*cvi); | variables_active()->push_back(*cvi); |
} | } |
| } |
| |
// 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) { |
| |
// 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 |
| |
variables_active_smp()->resize(0); | variables_active_smp()->clear(); |
variables_active_smp_items()->resize(0); | variables_active_smp_items()->clear(); |
| |
variables_active_smp()->reserve(variables_active()->size()); | variables_active_smp()->reserve(variables_active()->size()); |
variables_active_smp_items()->reserve(variables_active()->size()); | variables_active_smp_items()->reserve(variables_active()->size()); |
| |
total_bias_energy = 0.0; | total_bias_energy = 0.0; |
| |
// update the list of active biases | // update the list of active biases |
biases_active()->resize(0); | // which may have changed based on f_cvb_awake in calc_colvars() |
| biases_active()->clear(); |
biases_active()->reserve(biases.size()); | biases_active()->reserve(biases.size()); |
for (bi = biases.begin(); bi != biases.end(); bi++) { | for (bi = biases.begin(); bi != biases.end(); bi++) { |
if ((*bi)->is_enabled()) { | if ((*bi)->is_enabled()) { |
| |
"of colvars (if they have any).\n"); | "of colvars (if they have any).\n"); |
cvm::increase_depth(); | cvm::increase_depth(); |
for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { | for (cvi = variables()->begin(); cvi != variables()->end(); cvi++) { |
// Here we call even inactive colvars, so they accumulate biasing forces | // Inactive colvars will only reset their forces and return 0 energy |
// as well as update their extended-system dynamics | |
total_colvar_energy += (*cvi)->update_forces_energy(); | total_colvar_energy += (*cvi)->update_forces_energy(); |
if (cvm::get_error()) { | if (cvm::get_error()) { |
return COLVARS_ERROR; | return COLVARS_ERROR; |
| |
} | } |
| |
| |
void cvm::error(std::string const &message, int code) | int colvarmodule::error(std::string const &message, int code) |
{ | { |
set_error_bits(code); | set_error_bits(code); |
proxy->error(message); | proxy->error(message); |
| return get_error(); |
} | } |
| |
| |
void cvm::fatal_error(std::string const &message) | int colvarmodule::fatal_error(std::string const &message) |
{ | { |
// TODO once all non-fatal errors have been set to be handled by error(), | // TODO once all non-fatal errors have been set to be handled by error(), |
// set DELETE_COLVARS here for VMD to handle it | // set DELETE_COLVARS here for VMD to handle it |
set_error_bits(FATAL_ERROR); | set_error_bits(FATAL_ERROR); |
proxy->fatal_error(message); | proxy->fatal_error(message); |
| return get_error(); |
} | } |
| |
| |