version 1.4 | version 1.5 |
---|
| |
// -*- 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_RESTRAINT_H | #ifndef COLVARBIAS_RESTRAINT_H |
#define COLVARBIAS_RESTRAINT_H | #define COLVARBIAS_RESTRAINT_H |
| |
#include "colvarbias.h" | #include "colvarbias.h" |
| |
/// \brief Bias restraint, optionally moving towards a target | /// \brief Most general definition of a colvar restraint: |
| /// see derived classes for specific types |
/// (implementation of \link colvarbias \endlink) | /// (implementation of \link colvarbias \endlink) |
class colvarbias_restraint : public colvarbias { | class colvarbias_restraint |
| : public virtual colvarbias |
| { |
| |
public: | public: |
| |
/// Retrieve colvar values and calculate their biasing forces | /// Retrieve colvar values and calculate their biasing forces |
virtual int update(); | virtual int update(); |
| |
// TODO the following can be supplanted by a new call to init() | |
/// 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) { return COLVARS_NOT_IMPLEMENTED; } |
| |
/// 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) { return 0.0; } |
| |
/// Read the bias configuration from a restart file | |
virtual std::istream & read_restart(std::istream &is); | |
| |
/// Write the bias configuration to a restart file | virtual std::string const get_state_params() const; |
virtual std::ostream & write_restart(std::ostream &os); | virtual int set_state_params(std::string const &conf); |
| // virtual std::ostream & write_state_data(std::ostream &os); |
| // virtual std::istream & read_state_data(std::istream &os); |
| virtual std::ostream & write_state(std::ostream &os); |
| virtual std::istream & read_state(std::istream &is); |
| |
/// 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); |
| |
/// 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); |
| |
/// \brief Constructor | /// \brief Constructor |
| |
| |
protected: | protected: |
| |
/// \brief Potential function | /// \brief Potential function for the i-th colvar |
virtual cvm::real restraint_potential(cvm::real k, colvar const *x, | virtual cvm::real restraint_potential(size_t i) const = 0; |
colvarvalue const &xcenter) const = 0; | |
| |
/// \brief Force function | |
virtual colvarvalue restraint_force(cvm::real k, colvar const *x, | |
colvarvalue const &xcenter) const = 0; | |
| |
///\brief Unit scaling | /// \brief Force function for the i-th colvar |
virtual cvm::real restraint_convert_k(cvm::real k, cvm::real dist_measure) const = 0; | virtual colvarvalue const restraint_force(size_t i) const = 0; |
| |
| /// \brief Derivative of the potential function with respect to the force constant |
| virtual cvm::real d_restraint_potential_dk(size_t i) const = 0; |
| }; |
| |
| |
| /// Definition and parsing of the restraint centers |
| class colvarbias_restraint_centers |
| : public virtual colvarbias_restraint |
| { |
| public: |
| |
| colvarbias_restraint_centers(char const *key); |
| virtual int init(std::string const &conf); |
| virtual int change_configuration(std::string const &conf); |
| |
| protected: |
| |
/// \brief Restraint centers | /// \brief Restraint centers |
std::vector<colvarvalue> colvar_centers; | std::vector<colvarvalue> colvar_centers; |
| |
/// \brief Restraint centers without wrapping or constraints applied | /// \brief Restraint centers outside the domain of the colvars (no wrapping or constraints applied) |
std::vector<colvarvalue> colvar_centers_raw; | std::vector<colvarvalue> colvar_centers_raw; |
| }; |
| |
| |
| /// Definition and parsing of the force constant |
| class colvarbias_restraint_k |
| : public virtual colvarbias_restraint |
| { |
| public: |
| |
| colvarbias_restraint_k(char const *key); |
| virtual int init(std::string const &conf); |
| virtual int change_configuration(std::string const &conf); |
| |
| protected: |
| /// \brief Restraint force constant |
| cvm::real force_k; |
| }; |
| |
| |
| /// Options to change the restraint configuration over time (shared between centers and k moving) |
| class colvarbias_restraint_moving |
| : public virtual colvarparse { |
| public: |
| |
| colvarbias_restraint_moving(char const *key); |
| // Note: despite the diamond inheritance, most of this function gets only executed once |
| virtual int init(std::string const &conf); |
| virtual int update() { return COLVARS_OK; } |
| virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; } |
| |
| virtual std::string const get_state_params() const; |
| virtual int set_state_params(std::string const &conf); |
| |
| protected: |
| |
/// \brief Moving target? | /// \brief Moving target? |
bool b_chg_centers; | bool b_chg_centers; |
| |
| /// \brief Changing force constant? |
| bool b_chg_force_k; |
| |
| /// \brief Number of stages over which to perform the change |
| /// If zero, perform a continuous change |
| int target_nstages; |
| |
| /// \brief Number of current stage of the perturbation |
| int stage; |
| |
| /// \brief Lambda-schedule for custom varying force constant |
| std::vector<cvm::real> lambda_schedule; |
| |
| /// \brief Number of steps required to reach the target force constant |
| /// or restraint centers |
| long target_nsteps; |
| }; |
| |
| |
| /// Options to change the restraint centers over time |
| class colvarbias_restraint_centers_moving |
| : public virtual colvarbias_restraint_centers, |
| public virtual colvarbias_restraint_moving |
| { |
| public: |
| |
| colvarbias_restraint_centers_moving(char const *key); |
| virtual int init(std::string const &conf); |
| virtual int update(); |
| virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; } |
| |
| virtual std::string const get_state_params() const; |
| virtual int set_state_params(std::string const &conf); |
| virtual std::ostream & write_traj_label(std::ostream &os); |
| virtual std::ostream & write_traj(std::ostream &os); |
| |
| protected: |
| |
/// \brief New restraint centers | /// \brief New restraint centers |
std::vector<colvarvalue> target_centers; | std::vector<colvarvalue> target_centers; |
| |
| |
/// \brief Accumulated work | /// \brief Accumulated work |
cvm::real acc_work; | cvm::real acc_work; |
| |
/// \brief Restraint force constant | /// Update the accumulated work |
cvm::real force_k; | int update_acc_work(); |
| }; |
| |
/// \brief Changing force constant? | |
bool b_chg_force_k; | /// Options to change the restraint force constant over time |
| class colvarbias_restraint_k_moving |
| : public virtual colvarbias_restraint_k, |
| public virtual colvarbias_restraint_moving |
| { |
| public: |
| |
| colvarbias_restraint_k_moving(char const *key); |
| virtual int init(std::string const &conf); |
| virtual int update(); |
| virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; } |
| |
| virtual std::string const get_state_params() const; |
| virtual int set_state_params(std::string const &conf); |
| virtual std::ostream & write_traj_label(std::ostream &os); |
| virtual std::ostream & write_traj(std::ostream &os); |
| |
| protected: |
| |
/// \brief Restraint force constant (target value) | /// \brief Restraint force constant (target value) |
cvm::real target_force_k; | cvm::real target_force_k; |
| |
/// \brief Restraint force constant (starting value) | /// \brief Restraint force constant (starting value) |
cvm::real starting_force_k; | cvm::real starting_force_k; |
| |
/// \brief Lambda-schedule for custom varying force constant | |
std::vector<cvm::real> lambda_schedule; | |
| |
/// \brief Exponent for varying the force constant | /// \brief Exponent for varying the force constant |
cvm::real force_k_exp; | cvm::real force_k_exp; |
| |
| |
/// (in TI, would be the accumulating FE derivative) | /// (in TI, would be the accumulating FE derivative) |
cvm::real restraint_FE; | cvm::real restraint_FE; |
| |
| |
/// \brief Equilibration steps for restraint FE calculation through TI | /// \brief Equilibration steps for restraint FE calculation through TI |
cvm::real target_equil_steps; | cvm::real target_equil_steps; |
| }; |
| |
/// \brief Number of stages over which to perform the change | |
/// If zero, perform a continuous change | |
int target_nstages; | |
| |
/// \brief Number of current stage of the perturbation | /// \brief Harmonic bias restraint |
int stage; | /// (implementation of \link colvarbias_restraint \endlink) |
| class colvarbias_restraint_harmonic |
| : public colvarbias_restraint_centers_moving, |
| public colvarbias_restraint_k_moving |
| { |
| public: |
| colvarbias_restraint_harmonic(char const *key); |
| virtual int init(std::string const &conf); |
| virtual int update(); |
| virtual std::string const get_state_params() const; |
| virtual int set_state_params(std::string const &conf); |
| virtual std::ostream & write_traj_label(std::ostream &os); |
| virtual std::ostream & write_traj(std::ostream &os); |
| virtual int change_configuration(std::string const &conf); |
| virtual cvm::real energy_difference(std::string const &conf); |
| |
/// \brief Number of steps required to reach the target force constant | protected: |
/// or restraint centers | |
long target_nsteps; | virtual cvm::real restraint_potential(size_t i) const; |
| virtual colvarvalue const restraint_force(size_t i) const; |
| virtual cvm::real d_restraint_potential_dk(size_t i) const; |
}; | }; |
| |
| |
/// \brief Harmonic bias restraint | /// \brief Wall restraint |
/// (implementation of \link colvarbias_restraint \endlink) | /// (implementation of \link colvarbias_restraint \endlink) |
class colvarbias_restraint_harmonic : public colvarbias_restraint { | class colvarbias_restraint_harmonic_walls |
| : public colvarbias_restraint_k_moving |
| { |
public: | public: |
| |
colvarbias_restraint_harmonic(char const *key); | colvarbias_restraint_harmonic_walls(char const *key); |
virtual int init(std::string const &conf); | virtual int init(std::string const &conf); |
// no additional members, destructor not needed | virtual int update(); |
| virtual void communicate_forces(); |
| virtual std::string const get_state_params() const; |
| virtual int set_state_params(std::string const &conf); |
| virtual std::ostream & write_traj_label(std::ostream &os); |
| virtual std::ostream & write_traj(std::ostream &os); |
| |
protected: | protected: |
| |
/// \brief Potential function | /// \brief Location of the lower walls |
virtual cvm::real restraint_potential(cvm::real k, colvar const *x, | std::vector<colvarvalue> lower_walls; |
colvarvalue const &xcenter) const; | |
| |
/// \brief Force function | |
virtual colvarvalue restraint_force(cvm::real k, colvar const *x, | |
colvarvalue const &xcenter) const; | |
| |
///\brief Unit scaling | /// \brief Location of the upper walls |
virtual cvm::real restraint_convert_k(cvm::real k, cvm::real dist_measure) const; | std::vector<colvarvalue> upper_walls; |
| |
| virtual cvm::real colvar_distance(size_t i) const; |
| virtual cvm::real restraint_potential(size_t i) const; |
| virtual colvarvalue const restraint_force(size_t i) const; |
| virtual cvm::real d_restraint_potential_dk(size_t i) const; |
}; | }; |
| |
| |
/// \brief Linear bias restraint | /// \brief Linear bias restraint |
/// (implementation of \link colvarbias_restraint \endlink) | /// (implementation of \link colvarbias_restraint \endlink) |
class colvarbias_restraint_linear : public colvarbias_restraint { | class colvarbias_restraint_linear |
| : public colvarbias_restraint_centers_moving, |
| public colvarbias_restraint_k_moving |
| { |
| |
public: | public: |
colvarbias_restraint_linear(char const *key); | colvarbias_restraint_linear(char const *key); |
virtual int init(std::string const &conf); | virtual int init(std::string const &conf); |
// no additional members, destructor not needed | virtual int update(); |
| virtual int change_configuration(std::string const &conf); |
protected: | virtual cvm::real energy_difference(std::string const &conf); |
| |
/// \brief Potential function | |
virtual cvm::real restraint_potential(cvm::real k, colvar const *x, | |
colvarvalue const &xcenter) const; | |
| |
/// \brief Force function | virtual std::string const get_state_params() const; |
virtual colvarvalue restraint_force(cvm::real k, colvar const *x, | virtual int set_state_params(std::string const &conf); |
colvarvalue const &xcenter) const; | virtual std::ostream & write_traj_label(std::ostream &os); |
| virtual std::ostream & write_traj(std::ostream &os); |
| |
///\brief Unit scaling | protected: |
virtual cvm::real restraint_convert_k(cvm::real k, cvm::real dist_measure) const; | |
| |
| virtual cvm::real restraint_potential(size_t i) const; |
| virtual colvarvalue const restraint_force(size_t i) const; |
| virtual cvm::real d_restraint_potential_dk(size_t i) const; |
}; | }; |
| |
| |