Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarbias_restraint.h
1// -*- c++ -*-
2
3// This file is part of the Collective Variables module (Colvars).
4// The original version of Colvars and its updates are located at:
5// https://github.com/Colvars/colvars
6// Please update all Colvars source files before making any changes.
7// If you wish to distribute your changes, please submit them to the
8// Colvars repository at GitHub.
9
10#ifndef COLVARBIAS_RESTRAINT_H
11#define COLVARBIAS_RESTRAINT_H
12
13#include "colvarbias.h"
14
15#ifdef _MSC_VER
16#pragma warning(push)
17#pragma warning(disable : 4250) // Silence diamond inheritance warning
18#endif
19
24 : public virtual colvarbias,
25 public virtual colvarbias_ti
26{
27
28public:
29
31 virtual int update();
32
34 virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
35
37 virtual cvm::real energy_difference(std::string const & /* conf */) { return 0.0; }
38
39 virtual std::string const get_state_params() const;
40 virtual int set_state_params(std::string const &conf);
41 virtual std::ostream & write_traj_label(std::ostream &os);
42 virtual std::ostream & write_traj(std::ostream &os);
43
45 colvarbias_restraint(char const *key);
46
47 virtual int init(std::string const &conf);
48 virtual ~colvarbias_restraint();
49
50
51protected:
52
54 virtual cvm::real restraint_potential(size_t i) const = 0;
55
57 virtual colvarvalue const restraint_force(size_t i) const = 0;
58
60 virtual cvm::real d_restraint_potential_dk(size_t i) const = 0;
61};
62
63
66 : public virtual colvarbias_restraint
67{
68public:
69
70 colvarbias_restraint_centers(char const *key);
71 virtual int init(std::string const &conf);
72 virtual int change_configuration(std::string const &conf);
73
74protected:
75
77 std::vector<colvarvalue> colvar_centers;
78};
79
80
83 : public virtual colvarbias_restraint
84{
85public:
86
87 colvarbias_restraint_k(char const *key);
88 virtual int init(std::string const &conf);
89 virtual int change_configuration(std::string const &conf);
90
91protected:
92
95
98};
99
100
103 : public virtual colvarparse, public virtual colvardeps {
104public:
105
106 colvarbias_restraint_moving(char const *key);
107 // Note: despite the diamond inheritance, most of this function gets only executed once
108 virtual int init(std::string const &conf);
109 virtual int update() { return COLVARS_OK; }
110 virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
111
112 virtual std::string const get_state_params() const;
113 virtual int set_state_params(std::string const &conf);
114
115protected:
116
119
122
125
129
131 int stage;
132
134 std::vector<cvm::real> lambda_schedule;
135
139
142
145};
146
147
150 : public virtual colvarbias_restraint_centers,
151 public virtual colvarbias_restraint_moving
152{
153public:
154
156 virtual int init(std::string const &conf);
157 virtual int update();
158 virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
159
160 virtual std::string const get_state_params() const;
161 virtual int set_state_params(std::string const &conf);
162 virtual std::ostream & write_traj_label(std::ostream &os);
163 virtual std::ostream & write_traj(std::ostream &os);
164
165protected:
166
168 std::vector<colvarvalue> target_centers;
169
171 std::vector<colvarvalue> initial_centers;
172
174 std::vector<colvarvalue> centers_incr;
175
177 virtual int update_centers(cvm::real lambda);
178
181
183 int update_acc_work();
184};
185
186
189 : public virtual colvarbias_restraint_k,
190 public virtual colvarbias_restraint_moving
191{
192public:
193
194 colvarbias_restraint_k_moving(char const *key);
195 virtual int init(std::string const &conf);
196 virtual int update();
197 virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
198
199 virtual std::string const get_state_params() const;
200 virtual int set_state_params(std::string const &conf);
201 virtual std::ostream & write_traj_label(std::ostream &os);
202 virtual std::ostream & write_traj(std::ostream &os);
203
204protected:
205
208
211
214
218
221
224
226 int update_acc_work();
227};
228
229
235{
236public:
237 colvarbias_restraint_harmonic(char const *key);
238 virtual int init(std::string const &conf);
239 virtual int update();
240 virtual std::string const get_state_params() const;
241 virtual int set_state_params(std::string const &conf);
242 virtual std::ostream & write_traj_label(std::ostream &os);
243 virtual std::ostream & write_traj(std::ostream &os);
244 virtual int change_configuration(std::string const &conf);
245 virtual cvm::real energy_difference(std::string const &conf);
246
247protected:
248
249 virtual cvm::real restraint_potential(size_t i) const;
250 virtual colvarvalue const restraint_force(size_t i) const;
251 virtual cvm::real d_restraint_potential_dk(size_t i) const;
252};
253
254
259{
260public:
261
263 virtual int init(std::string const &conf);
264 virtual int update();
265 virtual std::string const get_state_params() const;
266 virtual int set_state_params(std::string const &conf);
267 virtual std::ostream & write_traj_label(std::ostream &os);
268 virtual std::ostream & write_traj(std::ostream &os);
269
270protected:
271
273 std::vector<colvarvalue> lower_walls;
274
276 std::vector<colvarvalue> upper_walls;
277
280
283
284 virtual cvm::real colvar_distance(size_t i) const;
285 virtual cvm::real restraint_potential(size_t i) const;
286 virtual colvarvalue const restraint_force(size_t i) const;
287 virtual cvm::real d_restraint_potential_dk(size_t i) const;
288};
289
290
296{
297
298public:
299 colvarbias_restraint_linear(char const *key);
300 virtual int init(std::string const &conf);
301 virtual int update();
302 virtual int change_configuration(std::string const &conf);
303 virtual cvm::real energy_difference(std::string const &conf);
304
305 virtual std::string const get_state_params() const;
306 virtual int set_state_params(std::string const &conf);
307 virtual std::ostream & write_traj_label(std::ostream &os);
308 virtual std::ostream & write_traj(std::ostream &os);
309
310protected:
311
312 virtual cvm::real restraint_potential(size_t i) const;
313 virtual colvarvalue const restraint_force(size_t i) const;
314 virtual cvm::real d_restraint_potential_dk(size_t i) const;
315};
316
317
319// TODO this could be reimplemented more cleanly as a derived class of both restraint and histogram
321
322public:
323
324 colvarbias_restraint_histogram(char const *key);
325 int init(std::string const &conf);
327
328 virtual int update();
329
330 virtual int write_output_files();
331 virtual std::ostream & write_traj_label(std::ostream &os);
332 virtual std::ostream & write_traj(std::ostream &os);
333
334protected:
335
338
341
344
347
350
353
356
359
362};
363
364#ifdef _MSC_VER
365#pragma warning(pop)
366#endif
367
368#endif
Options to change the restraint centers over time.
Definition: colvarbias_restraint.h:152
std::vector< colvarvalue > target_centers
New restraint centers.
Definition: colvarbias_restraint.h:168
std::vector< colvarvalue > initial_centers
Initial value of the restraint centers.
Definition: colvarbias_restraint.h:171
virtual int update_centers(cvm::real lambda)
Update the centers by interpolating between initial and target.
Definition: colvarbias_restraint.cpp:329
virtual int change_configuration(std::string const &)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:158
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:493
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:280
int update_acc_work()
Update the accumulated work.
Definition: colvarbias_restraint.cpp:410
std::vector< colvarvalue > centers_incr
Increment of the restraint centers at each step.
Definition: colvarbias_restraint.h:174
bool b_output_centers
Whether to write the current restraint centers to the trajectory file.
Definition: colvarbias_restraint.h:180
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:474
Definition and parsing of the restraint centers.
Definition: colvarbias_restraint.h:67
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:105
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:145
std::vector< colvarvalue > colvar_centers
Restraint centers.
Definition: colvarbias_restraint.h:77
Wall restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:259
cvm::real upper_wall_k
If both walls are defined, use this k for the upper.
Definition: colvarbias_restraint.h:282
cvm::real lower_wall_k
If both walls are defined, use this k for the lower.
Definition: colvarbias_restraint.h:279
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1102
std::vector< colvarvalue > lower_walls
Location of the lower walls.
Definition: colvarbias_restraint.h:273
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1093
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:911
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1137
std::vector< colvarvalue > upper_walls
Location of the upper walls.
Definition: colvarbias_restraint.h:276
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1145
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:1110
Harmonic bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:235
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:809
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.cpp:875
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:823
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:868
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:766
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:850
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:816
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:859
Restrain the 1D histogram of a set of variables (or of a multidimensional one)
Definition: colvarbias_restraint.h:320
int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:1311
cvm::real width
Resolution of the grid.
Definition: colvarbias_restraint.h:352
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1547
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1558
cvm::vector1d< cvm::real > p_diff
Difference between probability density and reference.
Definition: colvarbias_restraint.h:343
cvm::vector1d< cvm::real > ref_p
Reference probability density.
Definition: colvarbias_restraint.h:340
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:358
cvm::real lower_boundary
Lower boundary of the grid.
Definition: colvarbias_restraint.h:346
virtual int update()
Definition: colvarbias_restraint.cpp:1426
bool b_write_histogram
Write the histogram to a file.
Definition: colvarbias_restraint.h:361
virtual int write_output_files()
Write any output files that this bias may have (e.g. PMF files)
Definition: colvarbias_restraint.cpp:1516
cvm::vector1d< cvm::real > p
Probability density.
Definition: colvarbias_restraint.h:337
cvm::real gaussian_width
Width of the Gaussians.
Definition: colvarbias_restraint.h:355
cvm::real upper_boundary
Upper boundary of the grid.
Definition: colvarbias_restraint.h:349
Options to change the restraint force constant over time.
Definition: colvarbias_restraint.h:191
cvm::real lambda_exp
Exponent for varying the force constant.
Definition: colvarbias_restraint.h:213
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:741
cvm::real target_equil_steps
Equilibration steps for restraint FE calculation through TI.
Definition: colvarbias_restraint.h:220
cvm::real force_k_incr
Increment of the force constant at each step.
Definition: colvarbias_restraint.h:223
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:532
int update_acc_work()
Update the accumulated work.
Definition: colvarbias_restraint.cpp:674
cvm::real starting_force_k
Restraint force constant (starting value)
Definition: colvarbias_restraint.h:210
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:731
cvm::real target_force_k
Restraint force constant (target value)
Definition: colvarbias_restraint.h:207
virtual int change_configuration(std::string const &)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:197
cvm::real restraint_FE
Intermediate quantity to compute the restraint free energy (in TI, would be the accumulating FE deriv...
Definition: colvarbias_restraint.h:217
Definition and parsing of the force constant.
Definition: colvarbias_restraint.h:84
cvm::real force_k
Restraint force constant.
Definition: colvarbias_restraint.h:94
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:166
bool check_positive_k
Whether the force constant should be positive.
Definition: colvarbias_restraint.h:97
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:177
Linear bias restraint (implementation of colvarbias_restraint)
Definition: colvarbias_restraint.h:296
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:1291
virtual cvm::real restraint_potential(size_t i) const
Potential function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1240
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:1282
virtual colvarvalue const restraint_force(size_t i) const
Force function for the i-th colvar.
Definition: colvarbias_restraint.cpp:1247
virtual int change_configuration(std::string const &conf)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.cpp:1216
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:1168
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:1255
virtual cvm::real energy_difference(std::string const &conf)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.cpp:1223
Options to change the restraint configuration over time (shared between centers and k moving)
Definition: colvarbias_restraint.h:103
int stage
Number of current stage of the perturbation.
Definition: colvarbias_restraint.h:131
bool b_chg_centers
Moving target?
Definition: colvarbias_restraint.h:118
std::vector< cvm::real > lambda_schedule
Lambda-schedule for custom varying force constant.
Definition: colvarbias_restraint.h:134
bool b_decoupling
Perform decoupling of the restraint?
Definition: colvarbias_restraint.h:124
cvm::real acc_work
Accumulated work (computed when outputAccumulatedWork == true)
Definition: colvarbias_restraint.h:144
cvm::step_number target_nsteps
Number of steps required to reach the target force constant or restraint centers.
Definition: colvarbias_restraint.h:138
cvm::step_number first_step
Timestep at which the restraint starts moving.
Definition: colvarbias_restraint.h:141
bool b_chg_force_k
Changing force constant?
Definition: colvarbias_restraint.h:121
int target_nstages
Number of stages over which to perform the change If zero, perform a continuous change.
Definition: colvarbias_restraint.h:128
Most general definition of a colvar restraint: see derived classes for specific types (implementation...
Definition: colvarbias_restraint.h:26
virtual cvm::real d_restraint_potential_dk(size_t i) const =0
Derivative of the potential function with respect to the force constant.
virtual int set_state_params(std::string const &conf)
Read the values of specific mutable properties from a string.
Definition: colvarbias_restraint.cpp:80
virtual colvarvalue const restraint_force(size_t i) const =0
Force function for the i-th colvar.
virtual cvm::real energy_difference(std::string const &)
Calculate change in energy from using alternate configuration.
Definition: colvarbias_restraint.h:37
virtual int update()
Retrieve colvar values and calculate their biasing forces.
Definition: colvarbias_restraint.cpp:45
virtual std::string const get_state_params() const
Write the values of specific mutable properties to a string.
Definition: colvarbias_restraint.cpp:74
virtual int init(std::string const &conf)
Parse config string and (re)initialize.
Definition: colvarbias_restraint.cpp:28
virtual cvm::real restraint_potential(size_t i) const =0
Potential function for the i-th colvar.
virtual std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvarbias_restraint.cpp:86
virtual std::ostream & write_traj(std::ostream &os)
Output quantities such as the bias energy to the trajectory file.
Definition: colvarbias_restraint.cpp:92
virtual int change_configuration(std::string const &)
Load new configuration - force constant and/or centers only.
Definition: colvarbias_restraint.h:34
Base class for unconstrained thermodynamic-integration FE estimator.
Definition: colvarbias.h:333
Collective variable bias, base class.
Definition: colvarbias.h:23
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:37
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:92
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43