Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
colvarbias_restraint.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARBIAS_RESTRAINT_H
4 #define COLVARBIAS_RESTRAINT_H
5 
6 #include "colvarbias.h"
7 
12  : public virtual colvarbias
13 {
14 
15 public:
16 
18  virtual int update();
19 
21  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
22 
24  virtual cvm::real energy_difference(std::string const &conf) { return 0.0; }
25 
26  virtual std::string const get_state_params() const;
27  virtual int set_state_params(std::string const &conf);
28  // virtual std::ostream & write_state_data(std::ostream &os);
29  // virtual std::istream & read_state_data(std::istream &os);
30  virtual std::ostream & write_state(std::ostream &os);
31  virtual std::istream & read_state(std::istream &is);
32 
33  virtual std::ostream & write_traj_label(std::ostream &os);
34  virtual std::ostream & write_traj(std::ostream &os);
35 
37  colvarbias_restraint(char const *key);
38 
39  virtual int init(std::string const &conf);
40  virtual ~colvarbias_restraint();
41 
42 
43 protected:
44 
46  virtual cvm::real restraint_potential(size_t i) const = 0;
47 
49  virtual colvarvalue const restraint_force(size_t i) const = 0;
50 
52  virtual cvm::real d_restraint_potential_dk(size_t i) const = 0;
53 };
54 
55 
58  : public virtual colvarbias_restraint
59 {
60 public:
61 
62  colvarbias_restraint_centers(char const *key);
63  virtual int init(std::string const &conf);
64  virtual int change_configuration(std::string const &conf);
65 
66 protected:
67 
69  std::vector<colvarvalue> colvar_centers;
70 
72  std::vector<colvarvalue> colvar_centers_raw;
73 };
74 
75 
78  : public virtual colvarbias_restraint
79 {
80 public:
81 
82  colvarbias_restraint_k(char const *key);
83  virtual int init(std::string const &conf);
84  virtual int change_configuration(std::string const &conf);
85 
86 protected:
89 };
90 
91 
94  : public virtual colvarparse {
95 public:
96 
97  colvarbias_restraint_moving(char const *key);
98  // Note: despite the diamond inheritance, most of this function gets only executed once
99  virtual int init(std::string const &conf);
100  virtual int update() { return COLVARS_OK; }
101  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
102 
103  virtual std::string const get_state_params() const;
104  virtual int set_state_params(std::string const &conf);
105 
106 protected:
107 
110 
113 
117 
119  int stage;
120 
122  std::vector<cvm::real> lambda_schedule;
123 
127 };
128 
129 
132  : public virtual colvarbias_restraint_centers,
133  public virtual colvarbias_restraint_moving
134 {
135 public:
136 
137  colvarbias_restraint_centers_moving(char const *key);
138  virtual int init(std::string const &conf);
139  virtual int update();
140  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
141 
142  virtual std::string const get_state_params() const;
143  virtual int set_state_params(std::string const &conf);
144  virtual std::ostream & write_traj_label(std::ostream &os);
145  virtual std::ostream & write_traj(std::ostream &os);
146 
147 protected:
148 
150  std::vector<colvarvalue> target_centers;
151 
154  std::vector<colvarvalue> centers_incr;
155 
158 
161 
164 
166  int update_acc_work();
167 };
168 
169 
172  : public virtual colvarbias_restraint_k,
173  public virtual colvarbias_restraint_moving
174 {
175 public:
176 
177  colvarbias_restraint_k_moving(char const *key);
178  virtual int init(std::string const &conf);
179  virtual int update();
180  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
181 
182  virtual std::string const get_state_params() const;
183  virtual int set_state_params(std::string const &conf);
184  virtual std::ostream & write_traj_label(std::ostream &os);
185  virtual std::ostream & write_traj(std::ostream &os);
186 
187 protected:
188 
191 
194 
197 
201 
204 };
205 
206 
212 {
213 public:
214  colvarbias_restraint_harmonic(char const *key);
215  virtual int init(std::string const &conf);
216  virtual int update();
217  virtual std::string const get_state_params() const;
218  virtual int set_state_params(std::string const &conf);
219  virtual std::ostream & write_traj_label(std::ostream &os);
220  virtual std::ostream & write_traj(std::ostream &os);
221  virtual int change_configuration(std::string const &conf);
222  virtual cvm::real energy_difference(std::string const &conf);
223 
224 protected:
225 
226  virtual cvm::real restraint_potential(size_t i) const;
227  virtual colvarvalue const restraint_force(size_t i) const;
228  virtual cvm::real d_restraint_potential_dk(size_t i) const;
229 };
230 
231 
236 {
237 public:
238 
239  colvarbias_restraint_harmonic_walls(char const *key);
240  virtual int init(std::string const &conf);
241  virtual int update();
242  virtual void communicate_forces();
243  virtual std::string const get_state_params() const;
244  virtual int set_state_params(std::string const &conf);
245  virtual std::ostream & write_traj_label(std::ostream &os);
246  virtual std::ostream & write_traj(std::ostream &os);
247 
248 protected:
249 
251  std::vector<colvarvalue> lower_walls;
252 
254  std::vector<colvarvalue> upper_walls;
255 
258 
261 
262  virtual cvm::real colvar_distance(size_t i) const;
263  virtual cvm::real restraint_potential(size_t i) const;
264  virtual colvarvalue const restraint_force(size_t i) const;
265  virtual cvm::real d_restraint_potential_dk(size_t i) const;
266 };
267 
268 
274 {
275 
276 public:
277  colvarbias_restraint_linear(char const *key);
278  virtual int init(std::string const &conf);
279  virtual int update();
280  virtual int change_configuration(std::string const &conf);
281  virtual cvm::real energy_difference(std::string const &conf);
282 
283  virtual std::string const get_state_params() const;
284  virtual int set_state_params(std::string const &conf);
285  virtual std::ostream & write_traj_label(std::ostream &os);
286  virtual std::ostream & write_traj(std::ostream &os);
287 
288 protected:
289 
290  virtual cvm::real restraint_potential(size_t i) const;
291  virtual colvarvalue const restraint_force(size_t i) const;
292  virtual cvm::real d_restraint_potential_dk(size_t i) const;
293 };
294 
295 
297 // TODO this could be reimplemented more cleanly as a derived class of both restraint and histogram
299 
300 public:
301 
302  colvarbias_restraint_histogram(char const *key);
303  int init(std::string const &conf);
305 
306  virtual int update();
307 
308  virtual std::istream & read_restart(std::istream &is);
309  virtual std::ostream & write_restart(std::ostream &os);
310  virtual std::ostream & write_traj_label(std::ostream &os);
311  virtual std::ostream & write_traj(std::ostream &os);
312 
313 protected:
314 
317 
320 
323 
326 
329 
332 
335 
338 
341 };
342 
343 
344 #endif
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:781
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:623
bool b_chg_centers
Moving target?
Definition: colvarbias_restraint.h:109
cvm::real lower_wall_k
If both walls are defined, use this k for the lower.
Definition: colvarbias_restraint.h:257
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:21
bool b_chg_force_k
Changing force constant?
Definition: colvarbias_restraint.h:112
std::vector< cvm::real > lambda_schedule
Lambda-schedule for custom varying force constant.
Definition: colvarbias_restraint.h:122
cvm::real acc_work
Accumulated work.
Definition: colvarbias_restraint.h:163
Wall restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:234
std::vector< colvarvalue > lower_walls
Location of the lower walls.
Definition: colvarbias_restraint.h:251
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1159
virtual std::ostream & write_state(std::ostream &os)
Write the bias configuration to a restart file or other stream.
Definition: colvarbias_restraint.cpp:677
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.cpp:1106
virtual cvm::real restraint_potential(size_t i) const =0
Potential function for the i-th colvar.
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:629
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1417
virtual cvm::real d_restraint_potential_dk(size_t i) const
Derivative of the potential function with respect to the force constant.
Definition: colvarbias_restraint.cpp:1135
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1038
cvm::real starting_force_k
Restraint force constant (starting value)
Definition: colvarbias_restraint.h:193
int update_acc_work()
Update the accumulated work.
Definition: colvarbias_restraint.cpp:351
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.h:24
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:997
Definition and parsing of the restraint centers.
Definition: colvarbias_restraint.h:57
cvm::real target_force_k
Restraint force constant (target value)
Definition: colvarbias_restraint.h:190
cvm::real gaussian_width
Width of the Gaussians.
Definition: colvarbias_restraint.h:334
virtual cvm::real d_restraint_potential_dk(size_t i) const =0
Derivative of the potential function with respect to the force constant.
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:74
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1123
cvm::real force_k_exp
Exponent for varying the force constant.
Definition: colvarbias_restraint.h:196
std::vector< colvarvalue > centers_incr
Amplitude of the restraint centers' increment at each step (or stage) towards the new values (calcula...
Definition: colvarbias_restraint.h:154
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:85
cvm::vector1d< cvm::real > p
Probability density.
Definition: colvarbias_restraint.h:316
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:88
Linear bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:271
virtual int update()
Definition: colvarbias_restraint.cpp:1284
Definition and parsing of the force constant.
Definition: colvarbias_restraint.h:77
colvarbias_restraint(char const *key)
Constructor.
Definition: colvarbias_restraint.cpp:9
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:742
Collective variable bias, base class.
Definition: colvarbias.h:12
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:988
std::vector< colvarvalue > colvar_centers
Restraint centers.
Definition: colvarbias_restraint.h:69
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:337
int target_nstages
Number of stages over which to perform the change If zero, perform a continuous change.
Definition: colvarbias_restraint.h:116
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:34
virtual void communicate_forces()
Send forces to the collective variables.
Definition: colvarbias_restraint.cpp:943
bool b_output_centers
Whether to write the current restraint centers to the trajectory file.
Definition: colvarbias_restraint.h:157
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:799
cvm::real lower_boundary
Lower boundary of the grid.
Definition: colvarbias_restraint.h:325
Options to change the restraint force constant over time.
Definition: colvarbias_restraint.h:171
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:790
virtual std::string const get_state_params() const
Write the values of specific mutable properties to a string.
Definition: colvarbias_restraint.cpp:56
virtual int set_state_params(std::string const &conf)
Read the values of specific mutable properties from a string.
Definition: colvarbias_restraint.cpp:62
cvm::real upper_boundary
Upper boundary of the grid.
Definition: colvarbias_restraint.h:328
Restrain the 1D histogram of a set of variables (or of a multidimensional one)
Definition: colvarbias_restraint.h:298
cvm::real target_equil_steps
Equilibration steps for restraint FE calculation through TI.
Definition: colvarbias_restraint.h:203
Options to change the restraint centers over time.
Definition: colvarbias_restraint.h:131
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.cpp:806
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:140
cvm::vector1d< cvm::real > p_diff
Difference between probability density and reference.
Definition: colvarbias_restraint.h:322
bool b_write_histogram
Write the histogram to a file.
Definition: colvarbias_restraint.h:340
std::vector< colvarvalue > colvar_centers_raw
Restraint centers outside the domain of the colvars (no wrapping or constraints applied) ...
Definition: colvarbias_restraint.h:72
virtual cvm::real d_restraint_potential_dk(size_t i) const
Derivative of the potential function with respect to the force constant.
Definition: colvarbias_restraint.cpp:1005
virtual cvm::real d_restraint_potential_dk(size_t i) const
Derivative of the potential function with respect to the force constant.
Definition: colvarbias_restraint.cpp:756
long target_nsteps
Number of steps required to reach the target force constant or restraint centers. ...
Definition: colvarbias_restraint.h:126
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1030
int stage
Number of current stage of the perturbation.
Definition: colvarbias_restraint.h:119
Options to change the restraint configuration over time (shared between centers and k moving) ...
Definition: colvarbias_restraint.h:93
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1168
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:1099
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:749
std::vector< colvarvalue > target_centers
New restraint centers.
Definition: colvarbias_restraint.h:150
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1406
Most general definition of a colvar restraint: see derived classes for specific types (implementation...
Definition: colvarbias_restraint.h:11
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
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:418
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:437
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:180
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:164
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1129
virtual colvarvalue const restraint_force(size_t i) const =0
Force function for the i-th colvar.
cvm::real upper_wall_k
If both walls are defined, use this k for the upper.
Definition: colvarbias_restraint.h:260
cvm::real restraint_FE
Intermediate quantity to compute the restraint free energy (in TI, would be the accumulating FE deriv...
Definition: colvarbias_restraint.h:200
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:68
cvm::real width
Resolution of the grid.
Definition: colvarbias_restraint.h:331
virtual std::istream & read_state(std::istream &is)
Read the bias configuration from a restart file or other stream.
Definition: colvarbias_restraint.cpp:637
bool b_output_acc_work
Whether to write the current accumulated work to the trajectory file.
Definition: colvarbias_restraint.h:160
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e. for floating point numbers it can be used with library functions)
Definition: colvarmodule.h:90
cvm::vector1d< cvm::real > ref_p
Reference probability density.
Definition: colvarbias_restraint.h:319
std::vector< colvarvalue > upper_walls
Location of the upper walls.
Definition: colvarbias_restraint.h:254
Harmonic bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:209
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:131
virtual int update()
Retrieve colvar values and calculate their biasing forces.
Definition: colvarbias_restraint.cpp:27