Collective Variables Module - Developer Documentation
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 int clear_state_data();
107 
109  virtual ~colvarbias();
110 
112  virtual std::string const get_state_params() const;
113 
115  virtual int set_state_params(std::string const &state_conf);
116 
118  virtual std::ostream & write_state_data(std::ostream &os)
119  {
120  return os;
121  }
122 
124  virtual std::istream & read_state_data(std::istream &is)
125  {
126  return is;
127  }
128 
130  std::istream & read_state_data_key(std::istream &is, char const *key);
131 
133  virtual std::ostream & write_state(std::ostream &os);
134 
136  virtual std::istream & read_state(std::istream &is);
137 
139  virtual std::ostream & write_traj_label(std::ostream &os);
140 
142  virtual std::ostream & write_traj(std::ostream &os);
143 
145  virtual int setup_output()
146  {
147  return COLVARS_OK;
148  }
149 
151  virtual int write_output_files()
152  {
153  return COLVARS_OK;
154  }
155 
157  std::string output_prefix;
158 
161  {
162  return COLVARS_OK;
163  }
164 
165  inline cvm::real get_energy()
166  {
167  return bias_energy;
168  }
169 
171  static std::vector<feature *> cvb_features;
172 
174  virtual const std::vector<feature *> &features()
175  {
176  return cvb_features;
177  }
178  virtual std::vector<feature *> &modify_features()
179  {
180  return cvb_features;
181  }
182  static void delete_features() {
183  for (size_t i=0; i < cvb_features.size(); i++) {
184  delete cvb_features[i];
185  }
186  cvb_features.clear();
187  }
188 
189 protected:
190 
194  std::vector<colvar *> colvars;
195 
197  std::vector<colvarvalue> colvar_forces;
198 
200  std::vector<colvarvalue> previous_colvar_forces;
201 
204 
207 
210  bool has_data;
211 
214 
215 };
216 
217 
219 class colvar_grid_count;
220 
222 class colvarbias_ti : public virtual colvarbias {
223 public:
224 
225  colvarbias_ti(char const *key);
226  virtual ~colvarbias_ti();
227 
228  virtual int clear_state_data();
229 
230  virtual int init(std::string const &conf);
231  virtual int init_grids();
232  virtual int update();
233 
236  virtual int update_system_forces(std::vector<colvarvalue> const
237  *subtract_forces);
238 
239  virtual std::string const get_state_params() const;
240  virtual int set_state_params(std::string const &state_conf);
241  virtual std::ostream & write_state_data(std::ostream &os);
242  virtual std::istream & read_state_data(std::istream &is);
243  virtual int write_output_files();
244 
245 protected:
246 
248  std::vector<colvarvalue> ti_system_forces;
249 
252 
255 
258  std::vector<int> ti_bin;
259 };
260 
261 #endif
virtual std::istream & read_state_data(std::istream &is)
Read all mutable data not already set by set_state_params()
Definition: colvarbias.h:124
virtual int update()
Definition: colvarbias.cpp:194
virtual int write_output_files()
Write any output files that this bias may have (e.g. PMF files)
Definition: colvarbias.h:151
bool b_output_energy
Whether to write the current bias energy from this bias to the trajectory file.
Definition: colvarbias.h:206
virtual std::string const get_state_params() const
Write the values of specific mutable properties to a string.
Definition: colvarbias.cpp:271
static std::vector< feature * > cvb_features
Implementation of the feature list for colvarbias.
Definition: colvarbias.h:171
colvar_grid_count * ti_count
Histogram of sampled data.
Definition: colvarbias.h:254
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:194
virtual int bin_num()
Give the total number of bins for a given bias.
Definition: colvarbias.cpp:249
std::vector< colvarvalue > colvar_forces
Current forces from this bias to the variables.
Definition: colvarbias.h:197
virtual int set_state_params(std::string const &state_conf)
Read the values of specific mutable properties from a string.
Definition: colvarbias.cpp:280
virtual int write_state_to_replicas()
If this bias is communicating with other replicas through files, send it to them. ...
Definition: colvarbias.h:160
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias.cpp:392
colvar_grid_gradient * ti_avg_forces
Averaged system forces.
Definition: colvarbias.h:251
virtual int current_bin()
Calculate the bin index for a given bias.
Definition: colvarbias.cpp:254
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias.cpp:240
bool has_data
Whether this bias has already accumulated information (for history-dependent biases) ...
Definition: colvarbias.h:210
std::string bias_type
Type of this bias.
Definition: colvarbias.h:20
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:76
static int error(std::string const &message, int code=COLVARS_ERROR)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:1587
std::vector< colvar * > * variables()
Access the variables vector.
Definition: colvarbias.h:35
Collective variable bias, base class.
Definition: colvarbias.h:12
std::vector< int > ti_bin
Definition: colvarbias.h:258
virtual int clear()
Delete everything.
Definition: colvarbias.cpp:115
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:118
virtual std::istream & read_state(std::istream &is)
Read the bias configuration from a restart file or other stream.
Definition: colvarbias.cpp:324
cvm::real bias_energy
Current energy of this bias (colvar_forces should be obtained by deriving this)
Definition: colvarbias.h:203
std::vector< colvarvalue > previous_colvar_forces
Forces last applied by this bias to the variables.
Definition: colvarbias.h:200
virtual int setup_output()
(Re)initialize the output files (does not write them yet)
Definition: colvarbias.h:145
virtual std::ostream & write_state(std::ostream &os)
Write the bias configuration to a restart file or other stream.
Definition: colvarbias.cpp:303
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias.cpp:382
virtual int reset()
Set to zero all mutable data.
Definition: colvarbias.cpp:94
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:23
A collective variable (main class); to be defined, it needs at least one object of a derived class of...
Definition: colvar.h:42
virtual void communicate_forces()
Send forces to the collective variables.
Definition: colvarbias.cpp:211
std::vector< colvarvalue > ti_system_forces
Forces exerted from the system to the associated variables.
Definition: colvarbias.h:248
colvar * variables(int i) const
Access the i-th variable.
Definition: colvarbias.h:41
Colvar_grid derived class to hold counters in discrete n-dim colvar space.
Definition: colvargrid.h:1146
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias.cpp:232
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:61
int add_colvar(std::string const &cv_name)
Add a new collective variable to this bias.
Definition: colvarbias.cpp:155
virtual int clear_state_data()
Delete only the allocatable data (save memory)
Definition: colvarbias.cpp:148
size_t state_file_step
Step number read from the last state file.
Definition: colvarbias.h:213
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:157
virtual ~colvarbias()
Destructor.
Definition: colvarbias.cpp:109
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
Class for accumulating the gradient of a scalar function on a grid.
Definition: colvargrid.h:1378
virtual const std::vector< feature * > & features()
Implementation of the feature list accessor for colvarbias.
Definition: colvarbias.h:174
Base class for unconstrained thermodynamic-integration FE estimator.
Definition: colvarbias.h:222
size_t num_variables() const
How many variables are defined for this bias.
Definition: colvarbias.h:29
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:363