forked from Colvars/colvars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolvarbias_restraint.h
363 lines (263 loc) · 10.9 KB
/
colvarbias_restraint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
// -*- c++ -*-
// This file is part of the Collective Variables module (Colvars).
// The original version of Colvars and its updates are located at:
// https://github.com/Colvars/colvars
// Please update all Colvars source files before making any changes.
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.
#ifndef COLVARBIAS_RESTRAINT_H
#define COLVARBIAS_RESTRAINT_H
#include "colvarbias.h"
/// \brief Most general definition of a colvar restraint:
/// see derived classes for specific types
/// (implementation of \link colvarbias \endlink)
class colvarbias_restraint
: public virtual colvarbias,
public virtual colvarbias_ti
{
public:
/// Retrieve colvar values and calculate their biasing forces
virtual int update();
/// Load new configuration - force constant and/or centers only
virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
/// Calculate change in energy from using alternate configuration
virtual cvm::real energy_difference(std::string const & /* conf */) { return 0.0; }
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
// virtual std::ostream & write_state_data(std::ostream &os);
// virtual std::istream & read_state_data(std::istream &os);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
/// \brief Constructor
colvarbias_restraint(char const *key);
virtual int init(std::string const &conf);
virtual ~colvarbias_restraint();
protected:
/// \brief Potential function for the i-th colvar
virtual cvm::real restraint_potential(size_t i) const = 0;
/// \brief Force function for the i-th colvar
virtual colvarvalue const restraint_force(size_t i) const = 0;
/// \brief Derivative of the potential function with respect to the force constant
virtual cvm::real d_restraint_potential_dk(size_t i) const = 0;
};
/// Definition and parsing of the restraint centers
class colvarbias_restraint_centers
: public virtual colvarbias_restraint
{
public:
colvarbias_restraint_centers(char const *key);
virtual int init(std::string const &conf);
virtual int change_configuration(std::string const &conf);
protected:
/// \brief Restraint centers
std::vector<colvarvalue> colvar_centers;
};
/// Definition and parsing of the force constant
class colvarbias_restraint_k
: public virtual colvarbias_restraint
{
public:
colvarbias_restraint_k(char const *key);
virtual int init(std::string const &conf);
virtual int change_configuration(std::string const &conf);
protected:
/// \brief Restraint force constant
cvm::real force_k;
/// \brief Whether the force constant should be positive
bool check_positive_k;
};
/// Options to change the restraint configuration over time (shared between centers and k moving)
class colvarbias_restraint_moving
: public virtual colvarparse, public virtual colvardeps {
public:
colvarbias_restraint_moving(char const *key);
// Note: despite the diamond inheritance, most of this function gets only executed once
virtual int init(std::string const &conf);
virtual int update() { return COLVARS_OK; }
virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
protected:
/// \brief Moving target?
bool b_chg_centers;
/// \brief Changing force constant?
bool b_chg_force_k;
/// \brief Number of stages over which to perform the change
/// If zero, perform a continuous change
int target_nstages;
/// \brief Number of current stage of the perturbation
int stage;
/// \brief Lambda-schedule for custom varying force constant
std::vector<cvm::real> lambda_schedule;
/// \brief Number of steps required to reach the target force constant
/// or restraint centers
cvm::step_number target_nsteps;
/// \brief Accumulated work (computed when outputAccumulatedWork == true)
cvm::real acc_work;
};
/// Options to change the restraint centers over time
class colvarbias_restraint_centers_moving
: public virtual colvarbias_restraint_centers,
public virtual colvarbias_restraint_moving
{
public:
colvarbias_restraint_centers_moving(char const *key);
virtual int init(std::string const &conf);
virtual int update();
virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
protected:
/// \brief New restraint centers
std::vector<colvarvalue> target_centers;
/// \brief Initial value of the restraint centers
std::vector<colvarvalue> initial_centers;
/// \brief Increment of the restraint centers at each step
std::vector<colvarvalue> centers_incr;
/// \brief Update the centers by interpolating between initial and target
virtual int update_centers(cvm::real lambda);
/// Whether to write the current restraint centers to the trajectory file
bool b_output_centers;
/// Update the accumulated work
int update_acc_work();
};
/// Options to change the restraint force constant over time
class colvarbias_restraint_k_moving
: public virtual colvarbias_restraint_k,
public virtual colvarbias_restraint_moving
{
public:
colvarbias_restraint_k_moving(char const *key);
virtual int init(std::string const &conf);
virtual int update();
virtual int change_configuration(std::string const & /* conf */) { return COLVARS_NOT_IMPLEMENTED; }
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
protected:
/// \brief Restraint force constant (target value)
cvm::real target_force_k;
/// \brief Restraint force constant (starting value)
cvm::real starting_force_k;
/// \brief Exponent for varying the force constant
cvm::real force_k_exp;
/// \brief Intermediate quantity to compute the restraint free energy
/// (in TI, would be the accumulating FE derivative)
cvm::real restraint_FE;
/// \brief Equilibration steps for restraint FE calculation through TI
cvm::real target_equil_steps;
/// \brief Increment of the force constant at each step
cvm::real force_k_incr;
/// Update the accumulated work
int update_acc_work();
};
/// \brief Harmonic bias restraint
/// (implementation of \link colvarbias_restraint \endlink)
class colvarbias_restraint_harmonic
: public colvarbias_restraint_centers_moving,
public colvarbias_restraint_k_moving
{
public:
colvarbias_restraint_harmonic(char const *key);
virtual int init(std::string const &conf);
virtual int update();
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
virtual std::ostream & write_state_data(std::ostream &os);
virtual std::istream & read_state_data(std::istream &os);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
virtual int change_configuration(std::string const &conf);
virtual cvm::real energy_difference(std::string const &conf);
protected:
virtual cvm::real restraint_potential(size_t i) const;
virtual colvarvalue const restraint_force(size_t i) const;
virtual cvm::real d_restraint_potential_dk(size_t i) const;
};
/// \brief Wall restraint
/// (implementation of \link colvarbias_restraint \endlink)
class colvarbias_restraint_harmonic_walls
: public colvarbias_restraint_k_moving
{
public:
colvarbias_restraint_harmonic_walls(char const *key);
virtual int init(std::string const &conf);
virtual int update();
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
virtual std::ostream & write_state_data(std::ostream &os);
virtual std::istream & read_state_data(std::istream &os);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
protected:
/// \brief Location of the lower walls
std::vector<colvarvalue> lower_walls;
/// \brief Location of the upper walls
std::vector<colvarvalue> upper_walls;
/// \brief If both walls are defined, use this k for the lower
cvm::real lower_wall_k;
/// \brief If both walls are defined, use this k for the upper
cvm::real upper_wall_k;
virtual cvm::real colvar_distance(size_t i) const;
virtual cvm::real restraint_potential(size_t i) const;
virtual colvarvalue const restraint_force(size_t i) const;
virtual cvm::real d_restraint_potential_dk(size_t i) const;
};
/// \brief Linear bias restraint
/// (implementation of \link colvarbias_restraint \endlink)
class colvarbias_restraint_linear
: public colvarbias_restraint_centers_moving,
public colvarbias_restraint_k_moving
{
public:
colvarbias_restraint_linear(char const *key);
virtual int init(std::string const &conf);
virtual int update();
virtual int change_configuration(std::string const &conf);
virtual cvm::real energy_difference(std::string const &conf);
virtual std::string const get_state_params() const;
virtual int set_state_params(std::string const &conf);
virtual std::ostream & write_state_data(std::ostream &os);
virtual std::istream & read_state_data(std::istream &os);
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
protected:
virtual cvm::real restraint_potential(size_t i) const;
virtual colvarvalue const restraint_force(size_t i) const;
virtual cvm::real d_restraint_potential_dk(size_t i) const;
};
/// Restrain the 1D histogram of a set of variables (or of a multidimensional one)
// TODO this could be reimplemented more cleanly as a derived class of both restraint and histogram
class colvarbias_restraint_histogram : public colvarbias {
public:
colvarbias_restraint_histogram(char const *key);
int init(std::string const &conf);
~colvarbias_restraint_histogram();
virtual int update();
virtual int write_output_files();
virtual std::ostream & write_traj_label(std::ostream &os);
virtual std::ostream & write_traj(std::ostream &os);
protected:
/// Probability density
cvm::vector1d<cvm::real> p;
/// Reference probability density
cvm::vector1d<cvm::real> ref_p;
/// Difference between probability density and reference
cvm::vector1d<cvm::real> p_diff;
/// Lower boundary of the grid
cvm::real lower_boundary;
/// Upper boundary of the grid
cvm::real upper_boundary;
/// Resolution of the grid
cvm::real width;
/// Width of the Gaussians
cvm::real gaussian_width;
/// Restraint force constant
cvm::real force_k;
/// Write the histogram to a file
bool b_write_histogram;
};
#endif