Collective Variables Module - Developer Documentation
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  public virtual colvarbias_ti
14 {
15 
16 public:
17 
19  virtual int update();
20 
22  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
23 
25  virtual cvm::real energy_difference(std::string const &conf) { return 0.0; }
26 
27  virtual std::string const get_state_params() const;
28  virtual int set_state_params(std::string const &conf);
29  // virtual std::ostream & write_state_data(std::ostream &os);
30  // virtual std::istream & read_state_data(std::istream &os);
31  virtual std::ostream & write_state(std::ostream &os);
32  virtual std::istream & read_state(std::istream &is);
33 
34  virtual std::ostream & write_traj_label(std::ostream &os);
35  virtual std::ostream & write_traj(std::ostream &os);
36 
38  colvarbias_restraint(char const *key);
39 
40  virtual int init(std::string const &conf);
41  virtual ~colvarbias_restraint();
42 
43 
44 protected:
45 
47  virtual cvm::real restraint_potential(size_t i) const = 0;
48 
50  virtual colvarvalue const restraint_force(size_t i) const = 0;
51 
53  virtual cvm::real d_restraint_potential_dk(size_t i) const = 0;
54 };
55 
56 
59  : public virtual colvarbias_restraint
60 {
61 public:
62 
63  colvarbias_restraint_centers(char const *key);
64  virtual int init(std::string const &conf);
65  virtual int change_configuration(std::string const &conf);
66 
67 protected:
68 
70  std::vector<colvarvalue> colvar_centers;
71 };
72 
73 
76  : public virtual colvarbias_restraint
77 {
78 public:
79 
80  colvarbias_restraint_k(char const *key);
81  virtual int init(std::string const &conf);
82  virtual int change_configuration(std::string const &conf);
83 
84 protected:
87 };
88 
89 
92  : public virtual colvarparse, public virtual colvardeps {
93 public:
94 
95  colvarbias_restraint_moving(char const *key);
96  // Note: despite the diamond inheritance, most of this function gets only executed once
97  virtual int init(std::string const &conf);
98  virtual int update() { return COLVARS_OK; }
99  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
100 
101  virtual std::string const get_state_params() const;
102  virtual int set_state_params(std::string const &conf);
103 
104 protected:
105 
108 
111 
115 
117  int stage;
118 
120  std::vector<cvm::real> lambda_schedule;
121 
125 };
126 
127 
130  : public virtual colvarbias_restraint_centers,
131  public virtual colvarbias_restraint_moving
132 {
133 public:
134 
135  colvarbias_restraint_centers_moving(char const *key);
136  virtual int init(std::string const &conf);
137  virtual int update();
138  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
139 
140  virtual std::string const get_state_params() const;
141  virtual int set_state_params(std::string const &conf);
142  virtual std::ostream & write_traj_label(std::ostream &os);
143  virtual std::ostream & write_traj(std::ostream &os);
144 
145 protected:
146 
148  std::vector<colvarvalue> target_centers;
149 
151  std::vector<colvarvalue> initial_centers;
152 
155  std::vector<colvarvalue> centers_incr;
156 
158  virtual int update_centers(cvm::real lambda);
159 
162 
165 
168 
170  int update_acc_work();
171 };
172 
173 
176  : public virtual colvarbias_restraint_k,
177  public virtual colvarbias_restraint_moving
178 {
179 public:
180 
181  colvarbias_restraint_k_moving(char const *key);
182  virtual int init(std::string const &conf);
183  virtual int update();
184  virtual int change_configuration(std::string const &conf) { return COLVARS_NOT_IMPLEMENTED; }
185 
186  virtual std::string const get_state_params() const;
187  virtual int set_state_params(std::string const &conf);
188  virtual std::ostream & write_traj_label(std::ostream &os);
189  virtual std::ostream & write_traj(std::ostream &os);
190 
191 protected:
192 
195 
198 
201 
205 
208 };
209 
210 
216 {
217 public:
218  colvarbias_restraint_harmonic(char const *key);
219  virtual int init(std::string const &conf);
220  virtual int update();
221  virtual std::string const get_state_params() const;
222  virtual int set_state_params(std::string const &conf);
223  virtual std::ostream & write_state_data(std::ostream &os);
224  virtual std::istream & read_state_data(std::istream &os);
225  virtual std::ostream & write_traj_label(std::ostream &os);
226  virtual std::ostream & write_traj(std::ostream &os);
227  virtual int change_configuration(std::string const &conf);
228  virtual cvm::real energy_difference(std::string const &conf);
229 
230 protected:
231 
232  virtual cvm::real restraint_potential(size_t i) const;
233  virtual colvarvalue const restraint_force(size_t i) const;
234  virtual cvm::real d_restraint_potential_dk(size_t i) const;
235 };
236 
237 
242 {
243 public:
244 
245  colvarbias_restraint_harmonic_walls(char const *key);
246  virtual int init(std::string const &conf);
247  virtual int update();
248  virtual void communicate_forces();
249  virtual std::string const get_state_params() const;
250  virtual int set_state_params(std::string const &conf);
251  virtual std::ostream & write_state_data(std::ostream &os);
252  virtual std::istream & read_state_data(std::istream &os);
253  virtual std::ostream & write_traj_label(std::ostream &os);
254  virtual std::ostream & write_traj(std::ostream &os);
255 
256 protected:
257 
259  std::vector<colvarvalue> lower_walls;
260 
262  std::vector<colvarvalue> upper_walls;
263 
266 
269 
270  virtual cvm::real colvar_distance(size_t i) const;
271  virtual cvm::real restraint_potential(size_t i) const;
272  virtual colvarvalue const restraint_force(size_t i) const;
273  virtual cvm::real d_restraint_potential_dk(size_t i) const;
274 };
275 
276 
282 {
283 
284 public:
285  colvarbias_restraint_linear(char const *key);
286  virtual int init(std::string const &conf);
287  virtual int update();
288  virtual int change_configuration(std::string const &conf);
289  virtual cvm::real energy_difference(std::string const &conf);
290 
291  virtual std::string const get_state_params() const;
292  virtual int set_state_params(std::string const &conf);
293  virtual std::ostream & write_state_data(std::ostream &os);
294  virtual std::istream & read_state_data(std::istream &os);
295  virtual std::ostream & write_traj_label(std::ostream &os);
296  virtual std::ostream & write_traj(std::ostream &os);
297 
298 protected:
299 
300  virtual cvm::real restraint_potential(size_t i) const;
301  virtual colvarvalue const restraint_force(size_t i) const;
302  virtual cvm::real d_restraint_potential_dk(size_t i) const;
303 };
304 
305 
307 // TODO this could be reimplemented more cleanly as a derived class of both restraint and histogram
309 
310 public:
311 
312  colvarbias_restraint_histogram(char const *key);
313  int init(std::string const &conf);
315 
316  virtual int update();
317 
318  virtual std::istream & read_restart(std::istream &is);
319  virtual std::ostream & write_restart(std::ostream &os);
320  virtual std::ostream & write_traj_label(std::ostream &os);
321  virtual std::ostream & write_traj(std::ostream &os);
322 
323 protected:
324 
327 
330 
333 
336 
339 
342 
345 
348 
351 };
352 
353 
354 #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
bool b_chg_centers
Moving target?
Definition: colvarbias_restraint.h:107
cvm::real lower_wall_k
If both walls are defined, use this k for the lower.
Definition: colvarbias_restraint.h:265
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:22
virtual std::string const get_state_params() const
Write the values of specific mutable properties to a string.
Definition: colvarbias_restraint.cpp:61
bool b_chg_force_k
Changing force constant?
Definition: colvarbias_restraint.h:110
std::vector< cvm::real > lambda_schedule
Lambda-schedule for custom varying force constant.
Definition: colvarbias_restraint.h:120
cvm::real acc_work
Accumulated work.
Definition: colvarbias_restraint.h:167
Wall restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:240
std::vector< colvarvalue > lower_walls
Location of the lower walls.
Definition: colvarbias_restraint.h:259
virtual std::ostream & write_state(std::ostream &os)
Write the bias configuration to a restart file or other stream.
Definition: colvarbias_restraint.cpp:698
virtual cvm::real restraint_potential(size_t i) const =0
Potential function for the i-th colvar.
cvm::real starting_force_k
Restraint force constant (starting value)
Definition: colvarbias_restraint.h:197
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.h:25
Definition and parsing of the restraint centers.
Definition: colvarbias_restraint.h:58
cvm::real target_force_k
Restraint force constant (target value)
Definition: colvarbias_restraint.h:194
cvm::real gaussian_width
Width of the Gaussians.
Definition: colvarbias_restraint.h:344
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:79
cvm::real force_k_exp
Exponent for varying the force constant.
Definition: colvarbias_restraint.h:200
std::vector< colvarvalue > centers_incr
Amplitude of the restraint centers&#39; increment at each step towards the new values (calculated from ta...
Definition: colvarbias_restraint.h:155
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:76
cvm::vector1d< cvm::real > p
Probability density.
Definition: colvarbias_restraint.h:326
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:86
Linear bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:279
Definition and parsing of the force constant.
Definition: colvarbias_restraint.h:75
colvarbias_restraint(char const *key)
Constructor.
Definition: colvarbias_restraint.cpp:12
Collective variable bias, base class.
Definition: colvarbias.h:12
std::vector< colvarvalue > colvar_centers
Restraint centers.
Definition: colvarbias_restraint.h:70
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:347
int target_nstages
Number of stages over which to perform the change If zero, perform a continuous change.
Definition: colvarbias_restraint.h:114
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:34
bool b_output_centers
Whether to write the current restraint centers to the trajectory file.
Definition: colvarbias_restraint.h:161
cvm::real lower_boundary
Lower boundary of the grid.
Definition: colvarbias_restraint.h:335
Options to change the restraint force constant over time.
Definition: colvarbias_restraint.h:175
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 int set_state_params(std::string const &conf)
Read the values of specific mutable properties from a string.
Definition: colvarbias_restraint.cpp:67
cvm::real upper_boundary
Upper boundary of the grid.
Definition: colvarbias_restraint.h:338
Restrain the 1D histogram of a set of variables (or of a multidimensional one)
Definition: colvarbias_restraint.h:308
cvm::real target_equil_steps
Equilibration steps for restraint FE calculation through TI.
Definition: colvarbias_restraint.h:207
Options to change the restraint centers over time.
Definition: colvarbias_restraint.h:129
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:138
cvm::vector1d< cvm::real > p_diff
Difference between probability density and reference.
Definition: colvarbias_restraint.h:332
bool b_write_histogram
Write the histogram to a file.
Definition: colvarbias_restraint.h:350
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:23
long target_nsteps
Number of steps required to reach the target force constant or restraint centers. ...
Definition: colvarbias_restraint.h:124
std::vector< colvarvalue > initial_centers
Initial value of the restraint centers.
Definition: colvarbias_restraint.h:151
virtual void communicate_forces()
Send forces to the collective variables.
Definition: colvarbias.cpp:211
int stage
Number of current stage of the perturbation.
Definition: colvarbias_restraint.h:117
Options to change the restraint configuration over time (shared between centers and k moving) ...
Definition: colvarbias_restraint.h:91
std::vector< colvarvalue > target_centers
New restraint centers.
Definition: colvarbias_restraint.h:148
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:61
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:184
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:268
cvm::real restraint_FE
Intermediate quantity to compute the restraint free energy (in TI, would be the accumulating FE deriv...
Definition: colvarbias_restraint.h:204
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:73
cvm::real width
Resolution of the grid.
Definition: colvarbias_restraint.h:341
virtual std::istream & read_state(std::istream &is)
Read the bias configuration from a restart file or other stream.
Definition: colvarbias_restraint.cpp:658
bool b_output_acc_work
Whether to write the current accumulated work to the trajectory file.
Definition: colvarbias_restraint.h:164
cvm::vector1d< cvm::real > ref_p
Reference probability density.
Definition: colvarbias_restraint.h:329
std::vector< colvarvalue > upper_walls
Location of the upper walls.
Definition: colvarbias_restraint.h:262
Harmonic bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:213
virtual int update()
Retrieve colvar values and calculate their biasing forces.
Definition: colvarbias_restraint.cpp:32
Base class for unconstrained thermodynamic-integration FE estimator.
Definition: colvarbias.h:222