Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
colvarbias.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARBIAS_H
4 #define COLVARBIAS_H
5 
6 #include "colvar.h"
7 #include "colvarparse.h"
8 #include "colvardeps.h"
9 
10 
13  : public virtual colvarparse, public virtual colvardeps {
14 public:
15 
17  std::string name;
18 
20  std::string bias_type;
21 
23  int rank;
24 
26  int add_colvar(std::string const &cv_name);
27 
29  inline size_t num_variables() const
30  {
31  return colvars.size();
32  }
33 
35  inline std::vector<colvar *> *variables()
36  {
37  return &colvars;
38  }
39 
41  inline colvar * variables(int i) const
42  {
43  return colvars[i];
44  }
45 
48  virtual int update();
49 
52  virtual int calc_energy(std::vector<colvarvalue> const &values =
53  std::vector<colvarvalue>(0))
54  {
55  cvm::error("Error: calc_energy() not implemented.\n", COLVARS_NOT_IMPLEMENTED);
56  return COLVARS_NOT_IMPLEMENTED;
57  }
58 
60  virtual void communicate_forces();
61 
63  virtual int change_configuration(std::string const &conf);
64 
66  virtual cvm::real energy_difference(std::string const &conf);
67 
69  // FIXME this is currently 1D only
70  virtual int bin_num();
72  // FIXME this is currently 1D only
73  virtual int current_bin();
75  // FIXME this is currently 1D only
76  virtual int bin_count(int bin_index);
78  virtual int replica_share();
79 
81  virtual void analyze() {}
82 
84  colvarbias(char const *key);
85 
87  virtual int init(std::string const &conf);
88 
90  virtual int reset();
91 
92 private:
93 
95  colvarbias();
96 
99 
100 public:
101 
103  virtual int clear();
104 
106  virtual ~colvarbias();
107 
109  virtual std::string const get_state_params() const;
110 
112  virtual int set_state_params(std::string const &state_conf);
113 
115  virtual std::ostream & write_state_data(std::ostream &os)
116  {
117  return os;
118  }
119 
121  virtual std::istream & read_state_data(std::istream &is)
122  {
123  return is;
124  }
125 
127  std::istream & read_state_data_key(std::istream &is, char const *key);
128 
130  virtual std::ostream & write_state(std::ostream &os);
131 
133  virtual std::istream & read_state(std::istream &is);
134 
136  virtual std::ostream & write_traj_label(std::ostream &os);
137 
139  virtual std::ostream & write_traj(std::ostream &os);
140 
142  virtual int setup_output()
143  {
144  return COLVARS_OK;
145  }
146 
148  virtual int write_output_files()
149  {
150  return COLVARS_OK;
151  }
152 
154  std::string output_prefix;
155 
158  {
159  return COLVARS_OK;
160  }
161 
162  inline cvm::real get_energy()
163  {
164  return bias_energy;
165  }
166 
168  static std::vector<feature *> cvb_features;
169 
171  virtual std::vector<feature *> &features()
172  {
173  return cvb_features;
174  }
175 
176 protected:
177 
181  std::vector<colvar *> colvars;
182 
184  std::vector<colvarvalue> colvar_forces;
185 
188 
191 
194  bool has_data;
195 
198 
199 };
200 
201 #endif
virtual std::istream & read_state_data(std::istream &is)
Read all mutable data not already set by set_state_params()
Definition: colvarbias.h:121
virtual int update()
Definition: colvarbias.cpp:172
virtual int write_output_files()
Write any output files that this bias may have (e.g. PMF files)
Definition: colvarbias.h:148
bool b_output_energy
Whether to write the current bias energy from this bias to the trajectory file.
Definition: colvarbias.h:190
static std::vector< feature * > cvb_features
Implementation of the feature list for colvarbias.
Definition: colvarbias.h:168
virtual void analyze()
Perform analysis tasks.
Definition: colvarbias.h:81
std::vector< colvar * > colvars
Pointers to collective variables to which the bias is applied; current values and metric functions wi...
Definition: colvarbias.h:181
virtual int bin_num()
Give the total number of bins for a given bias.
Definition: colvarbias.cpp:218
std::vector< colvarvalue > colvar_forces
Current forces from this bias to the variables.
Definition: colvarbias.h:184
virtual int set_state_params(std::string const &state_conf)
Read the values of specific mutable properties from a string.
Definition: colvarbias.cpp:249
virtual int write_state_to_replicas()
If this bias is communicating with other replicas through files, send it to them. ...
Definition: colvarbias.h:157
colvar * variables(int i) const
Access the i-th variable.
Definition: colvarbias.h:41
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias.cpp:361
virtual int current_bin()
Calculate the bin index for a given bias.
Definition: colvarbias.cpp:223
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias.cpp:209
bool has_data
Whether this bias has already accumulated information (for history-dependent biases) ...
Definition: colvarbias.h:194
std::string bias_type
Type of this bias.
Definition: colvarbias.h:20
virtual std::string const get_state_params() const
Write the values of specific mutable properties to a string.
Definition: colvarbias.cpp:240
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:85
std::vector< colvar * > * variables()
Access the variables vector.
Definition: colvarbias.h:35
Collective variable bias, base class.
Definition: colvarbias.h:12
virtual int clear()
Delete everything.
Definition: colvarbias.cpp:104
std::string name
Name of this bias.
Definition: colvarbias.h:17
virtual std::ostream & write_state_data(std::ostream &os)
Write all mutable data not already written by get_state_params()
Definition: colvarbias.h:115
virtual std::istream & read_state(std::istream &is)
Read the bias configuration from a restart file or other stream.
Definition: colvarbias.cpp:293
virtual std::vector< feature * > & features()
Implementation of the feature list accessor for colvarbias.
Definition: colvarbias.h:171
size_t num_variables() const
How many variables are defined for this bias.
Definition: colvarbias.h:29
cvm::real bias_energy
Current energy of this bias (colvar_forces should be obtained by deriving this)
Definition: colvarbias.h:187
virtual int setup_output()
(Re)initialize the output files (does not write them yet)
Definition: colvarbias.h:142
virtual std::ostream & write_state(std::ostream &os)
Write the bias configuration to a restart file or other stream.
Definition: colvarbias.cpp:272
static void error(std::string const &message, int code=COLVARS_ERROR)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:1536
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias.cpp:351
virtual int reset()
Set to zero all mutable data.
Definition: colvarbias.cpp:83
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:19
A collective variable (main class); to be defined, it needs at least one object of a derived class of...
Definition: colvar.h:41
virtual void communicate_forces()
Send forces to the collective variables.
Definition: colvarbias.cpp:189
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias.cpp:201
Parsing functions for collective variables.
Base class containing parsing functions; all objects which need to parse input inherit from this...
Definition: colvarparse.h:18
void init()
Set the object ready to parse a new configuration string.
Definition: colvarparse.h:71
int add_colvar(std::string const &cv_name)
Add a new collective variable to this bias.
Definition: colvarbias.cpp:135
size_t state_file_step
Step number read from the last state file.
Definition: colvarbias.h:197
int rank
If there is more than one bias of this type, record its rank.
Definition: colvarbias.h:23
std::string output_prefix
Use this prefix for all output files.
Definition: colvarbias.h:154
virtual ~colvarbias()
Destructor.
Definition: colvarbias.cpp:98
virtual int calc_energy(std::vector< colvarvalue > const &values=std::vector< colvarvalue >(0))
Compute the energy of the bias with alternative values of the collective variables (suitable for bias...
Definition: colvarbias.h:52
std::istream & read_state_data_key(std::istream &is, char const *key)
Read a keyword from the state data (typically a header)
Definition: colvarbias.cpp:332