version 1.15 | version 1.16 |
---|
| |
// -*- 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. |
| |
#ifndef COLVARBIAS_H | #ifndef COLVARBIAS_H |
#define COLVARBIAS_H | #define COLVARBIAS_H |
| |
| |
| |
| |
/// \brief Collective variable bias, base class | /// \brief Collective variable bias, base class |
class colvarbias : public colvarparse, public colvardeps { | class colvarbias |
| : public virtual colvarparse, public virtual colvardeps { |
public: | public: |
| |
/// Name of this bias | /// Name of this bias |
| |
/// Add a new collective variable to this bias | /// Add a new collective variable to this bias |
int add_colvar(std::string const &cv_name); | int add_colvar(std::string const &cv_name); |
| |
| /// How many variables are defined for this bias |
| inline size_t num_variables() const |
| { |
| return colvars.size(); |
| } |
| |
| /// Access the variables vector |
| inline std::vector<colvar *> *variables() |
| { |
| return &colvars; |
| } |
| |
| /// Access the i-th variable |
| inline colvar * variables(int i) const |
| { |
| return colvars[i]; |
| } |
| |
/// Retrieve colvar values and calculate their biasing forces | /// Retrieve colvar values and calculate their biasing forces |
/// Return bias energy | /// Return bias energy |
virtual int update(); | virtual int update(); |
| |
// TODO: move update_bias here (share with metadynamics) | /// \brief Compute the energy of the bias with alternative values of the |
| /// collective variables (suitable for bias exchange) |
| virtual int calc_energy(std::vector<colvarvalue> const &values = |
| std::vector<colvarvalue>(0)) |
| { |
| cvm::error("Error: calc_energy() not implemented.\n", COLVARS_NOT_IMPLEMENTED); |
| return COLVARS_NOT_IMPLEMENTED; |
| } |
| |
| /// Send forces to the collective variables |
| virtual void communicate_forces(); |
| |
/// Load new configuration - force constant and/or centers only | /// Load new configuration - force constant and/or centers only |
virtual void change_configuration(std::string const &conf); | virtual int change_configuration(std::string const &conf); |
| |
/// Calculate change in energy from using alternate configuration | /// Calculate change in energy from using alternate configuration |
virtual cvm::real energy_difference(std::string const &conf); | virtual cvm::real energy_difference(std::string const &conf); |
| |
/// Give the total number of bins for a given bias. | /// Give the total number of bins for a given bias. |
| // FIXME this is currently 1D only |
virtual int bin_num(); | virtual int bin_num(); |
/// Calculate the bin index for a given bias. | /// Calculate the bin index for a given bias. |
| // FIXME this is currently 1D only |
virtual int current_bin(); | virtual int current_bin(); |
//// Give the count at a given bin index. | //// Give the count at a given bin index. |
| // FIXME this is currently 1D only |
virtual int bin_count(int bin_index); | virtual int bin_count(int bin_index); |
//// Share information between replicas, whatever it may be. | //// Share information between replicas, whatever it may be. |
virtual int replica_share(); | virtual int replica_share(); |
| |
/// Perform analysis tasks | /// Perform analysis tasks |
virtual void analyze() {} | virtual void analyze() {} |
| |
/// Send forces to the collective variables | |
void communicate_forces(); | |
| |
/// \brief Constructor | /// \brief Constructor |
colvarbias(char const *key); | colvarbias(char const *key); |
| |
| |
/// \brief Set to zero all mutable data | /// \brief Set to zero all mutable data |
virtual int reset(); | virtual int reset(); |
| |
protected: | private: |
| |
/// Default constructor | /// Default constructor |
colvarbias(); | colvarbias(); |
| |
private: | |
| |
/// Copy constructor | /// Copy constructor |
colvarbias(colvarbias &); | colvarbias(colvarbias &); |
| |
| |
/// Destructor | /// Destructor |
virtual ~colvarbias(); | virtual ~colvarbias(); |
| |
/// Read the bias configuration from a restart file | /// Write the values of specific mutable properties to a string |
virtual std::istream & read_restart(std::istream &is) = 0; | virtual std::string const get_state_params() const; |
| |
| /// Read the values of specific mutable properties from a string |
| virtual int set_state_params(std::string const &state_conf); |
| |
/// Write the bias configuration to a restart file | /// Write all mutable data not already written by get_state_params() |
virtual std::ostream & write_restart(std::ostream &os) = 0; | virtual std::ostream & write_state_data(std::ostream &os) |
| { |
| return os; |
| } |
| |
| /// Read all mutable data not already set by set_state_params() |
| virtual std::istream & read_state_data(std::istream &is) |
| { |
| return is; |
| } |
| |
| /// Read a keyword from the state data (typically a header) |
| std::istream & read_state_data_key(std::istream &is, char const *key); |
| |
| /// Write the bias configuration to a restart file or other stream |
| virtual std::ostream & write_state(std::ostream &os); |
| |
| /// Read the bias configuration from a restart file or other stream |
| virtual std::istream & read_state(std::istream &is); |
| |
/// Write a label to the trajectory file (comment line) | /// Write a label to the trajectory file (comment line) |
virtual std::ostream & write_traj_label(std::ostream &os); | virtual std::ostream & write_traj_label(std::ostream &os); |
| |
/// (Re)initialize the output files (does not write them yet) | |
virtual int setup_output() { return COLVARS_OK; } | |
| |
/// Output quantities such as the bias energy to the trajectory file | /// Output quantities such as the bias energy to the trajectory file |
virtual std::ostream & write_traj(std::ostream &os); | virtual std::ostream & write_traj(std::ostream &os); |
| |
/// Write output files (if defined, e.g. in analysis mode) | /// (Re)initialize the output files (does not write them yet) |
| virtual int setup_output() |
| { |
| return COLVARS_OK; |
| } |
| |
| /// Write any output files that this bias may have (e.g. PMF files) |
virtual int write_output_files() | virtual int write_output_files() |
{ | { |
return COLVARS_OK; | return COLVARS_OK; |
} | } |
| |
inline cvm::real get_energy() { | /// Use this prefix for all output files |
| std::string output_prefix; |
| |
| /// If this bias is communicating with other replicas through files, send it to them |
| virtual int write_state_to_replicas() |
| { |
| return COLVARS_OK; |
| } |
| |
| inline cvm::real get_energy() |
| { |
return bias_energy; | return bias_energy; |
} | } |
| |
| |
static std::vector<feature *> cvb_features; | static std::vector<feature *> cvb_features; |
| |
/// \brief Implementation of the feature list accessor for colvarbias | /// \brief Implementation of the feature list accessor for colvarbias |
virtual std::vector<feature *> &features() { | virtual std::vector<feature *> &features() |
| { |
return cvb_features; | return cvb_features; |
} | } |
| |
protected: | protected: |
| |
/// \brief Pointers to collective variables to which the bias is | /// \brief Pointers to collective variables to which the bias is |
| |
/// through each colvar object | /// through each colvar object |
std::vector<colvar *> colvars; | std::vector<colvar *> colvars; |
| |
/// \brief Current forces from this bias to the colvars | /// \brief Current forces from this bias to the variables |
std::vector<colvarvalue> colvar_forces; | std::vector<colvarvalue> colvar_forces; |
| |
/// \brief Current energy of this bias (colvar_forces should be obtained by deriving this) | /// \brief Current energy of this bias (colvar_forces should be obtained by deriving this) |
| |
/// (for history-dependent biases) | /// (for history-dependent biases) |
bool has_data; | bool has_data; |
| |
| /// \brief Step number read from the last state file |
| size_t state_file_step; |
| |
}; | }; |
| |
#endif | #endif |