Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarproxy_system.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 COLVARPROXY_SYSTEM_H
11#define COLVARPROXY_SYSTEM_H
12
13
16
17public:
18
21
23 virtual ~colvarproxy_system();
24
32 std::string units;
33
35 virtual int set_unit_system(std::string const &units, bool check_only);
36
39 {
40 return l * angstrom_value_;
41 }
42
45 {
46 return l / angstrom_value_;
47 }
48
50 inline cvm::real boltzmann() const
51 {
52 return boltzmann_;
53 }
54
57 {
59 }
60
62 virtual int set_target_temperature(cvm::real T);
63
65 inline double dt() const
66 {
67 return timestep_;
68 }
69
72
74 inline int time_step_factor() const
75 {
76 return time_step_factor_;
77 }
78
80 virtual int set_time_step_factor(int fact);
81
83 virtual cvm::real rand_gaussian(void);
84
86 virtual void add_energy(cvm::real energy);
87
89 inline bool & use_internal_pbc() { return use_internal_pbc_; }
90
93 cvm::atom_pos const &pos2) const;
94
97 cvm::atom_pos const &pos2) const;
98
113 cvm::atom_pos const &pos2,
114 cvm::rvector const &a,
115 cvm::rvector const &b,
116 cvm::rvector const &c,
117 cvm::rvector const &a_r,
118 cvm::rvector const &b_r,
119 cvm::rvector const &c_r,
120 bool a_p = false,
121 bool b_p = false,
122 bool c_p = false);
123
125 void update_pbc_lattice();
126
128 void reset_pbc_lattice();
129
132 virtual void request_total_force(bool yesno);
133
135 virtual bool total_forces_enabled() const;
136
139 virtual bool total_forces_same_step() const;
140
143 virtual int get_molid(int &molid);
144
146 virtual int get_alch_lambda(cvm::real* lambda);
147
149 void set_alch_lambda(cvm::real lambda);
150
152 virtual int send_alch_lambda();
153
155 virtual int request_alch_energy_freq(int const /* freq */) {
156 return COLVARS_OK;
157 }
158
160 virtual int get_dE_dlambda(cvm::real* dE_dlambda);
161
163 virtual int apply_force_dE_dlambda(cvm::real* force);
164
166 virtual int get_d2E_dlambda2(cvm::real* d2E_dlambda2);
167
170
173 cvm::error_static("Error: accessing the reweighting factor of accelerated MD "
174 "is not yet implemented in the MD engine.\n",
175 COLVARS_NOT_IMPLEMENTED);
176 return 1.0;
177 }
178 virtual bool accelMD_enabled() const {
179 return false;
180 }
181
182protected:
183
186
189
192
195
197 double timestep_;
198
201
207
210
213
215 bool use_internal_pbc_ = false;
216
223 boundaries_non_periodic,
224 boundaries_pbc_ortho,
225 boundaries_pbc_triclinic,
226 boundaries_unsupported
227 };
228
231
233 cvm::rvector unit_cell_x, unit_cell_y, unit_cell_z;
234
236 cvm::rvector reciprocal_cell_x, reciprocal_cell_y, reciprocal_cell_z;
237};
238
239
241 cvm::atom_pos const &pos2) const
242{
243 if (boundaries_type == boundaries_unsupported) {
244 cvm::error_static("Error: unsupported boundary conditions.\n", COLVARS_INPUT_ERROR);
245 return cvm::rvector({0.0, 0.0, 0.0});
246 }
247
248 if (boundaries_type == boundaries_non_periodic) {
249 return pos2 - pos1;
250 }
251
252 // Periodicity flags are hard-coded, because this is the only case supported so far other than
253 // the two above
254 return position_distance_kernel(pos1, pos2, unit_cell_x, unit_cell_y, unit_cell_z,
255 reciprocal_cell_x, reciprocal_cell_y, reciprocal_cell_z,
256 true, true, true);
257}
258
259
261 cvm::atom_pos const &pos2,
262 cvm::rvector const &a,
263 cvm::rvector const &b,
264 cvm::rvector const &c,
265 cvm::rvector const &a_r,
266 cvm::rvector const &b_r,
267 cvm::rvector const &c_r,
268 bool a_p,
269 bool b_p,
270 bool c_p)
271{
272 cvm::rvector diff = (pos2 - pos1);
273
274 cvm::real const x_shift = std::floor(a_r * diff + 0.5);
275 cvm::real const y_shift = std::floor(b_r * diff + 0.5);
276 cvm::real const z_shift = std::floor(c_r * diff + 0.5);
277
278 if (a_p) {
279 diff.x -= x_shift * a.x + y_shift * b.x + z_shift * c.x;
280 }
281
282 if (b_p) {
283 diff.y -= x_shift * a.y + y_shift * b.y + z_shift * c.y;
284 }
285
286 if (c_p) {
287 diff.z -= x_shift * a.z + y_shift * b.z + z_shift * c.z;
288 }
289
290 return diff;
291}
292
293
294#endif
vector of real numbers with three components
Definition: colvartypes.h:728
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:770
Methods for accessing the simulation system (PBCs, integrator, etc)
Definition: colvarproxy_system.h:15
bool use_internal_pbc_
Use the PBC functions from the Colvars library (as opposed to MD engine)
Definition: colvarproxy_system.h:215
virtual ~colvarproxy_system()
Destructor.
Definition: colvarproxy_system.cpp:34
bool total_force_requested
Whether the total forces have been requested.
Definition: colvarproxy_system.h:212
virtual void add_energy(cvm::real energy)
Pass restraint energy value for current timestep to MD engine.
Definition: colvarproxy_system.cpp:70
static cvm::rvector position_distance_kernel(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2, cvm::rvector const &a, cvm::rvector const &b, cvm::rvector const &c, cvm::rvector const &a_r, cvm::rvector const &b_r, cvm::rvector const &c_r, bool a_p=false, bool b_p=false, bool c_p=false)
Definition: colvarproxy_system.h:260
virtual int set_target_temperature(cvm::real T)
Set the current target temperature of the simulation (K units)
Definition: colvarproxy_system.cpp:44
virtual int set_unit_system(std::string const &units, bool check_only)
Request to set the units used internally by Colvars.
Definition: colvarproxy_system.cpp:37
cvm::real target_temperature_
Most up to date target temperature (K units); default to 0.0 if undefined.
Definition: colvarproxy_system.h:194
Boundaries_type
Definition: colvarproxy_system.h:222
cvm::real boltzmann_
Boltzmann constant in internal Colvars units.
Definition: colvarproxy_system.h:191
int time_step_factor() const
Time step of the simulation (fs units)
Definition: colvarproxy_system.h:74
virtual int apply_force_dE_dlambda(cvm::real *force)
Apply a scalar force on dE_dlambda (back-end distributes it onto atoms)
Definition: colvarproxy_system.cpp:173
cvm::real boltzmann() const
Boltzmann constant, with unit the same as energy / K.
Definition: colvarproxy_system.h:50
cvm::real angstrom_to_internal(cvm::real l) const
Convert a length from Angstrom to internal.
Definition: colvarproxy_system.h:38
void update_pbc_lattice()
Recompute PBC reciprocal lattice (assumes XYZ periodicity)
Definition: colvarproxy_system.cpp:93
void reset_pbc_lattice()
Set the lattice vectors to zero.
Definition: colvarproxy_system.cpp:119
virtual cvm::real get_accelMD_factor() const
Get weight factor from accelMD.
Definition: colvarproxy_system.h:172
bool & use_internal_pbc()
Use the PBC functions from the Colvars library (as opposed to MD engine)
Definition: colvarproxy_system.h:89
colvarproxy_system()
Constructor.
Definition: colvarproxy_system.cpp:18
virtual bool total_forces_enabled() const
Are total forces being used?
Definition: colvarproxy_system.cpp:81
double dt() const
Time step of the simulation (fs units)
Definition: colvarproxy_system.h:65
cvm::rvector reciprocal_cell_x
Reciprocal lattice vectors.
Definition: colvarproxy_system.h:236
cvm::real cached_alch_lambda
Next value of lambda to be sent to back-end.
Definition: colvarproxy_system.h:185
virtual int get_d2E_dlambda2(cvm::real *d2E_dlambda2)
Get energy second derivative with respect to lambda (if available)
Definition: colvarproxy_system.cpp:180
virtual int request_alch_energy_freq(int const)
Request energy computation every freq steps (necessary for NAMD3, not all back-ends)
Definition: colvarproxy_system.h:155
bool cached_alch_lambda_changed
Whether lambda has been set and needs to be updated in backend.
Definition: colvarproxy_system.h:188
virtual int get_alch_lambda(cvm::real *lambda)
Get value of alchemical lambda parameter from back-end (if available)
Definition: colvarproxy_system.cpp:145
std::string units
Name of the unit system used internally by Colvars (by default, that of the back-end)....
Definition: colvarproxy_system.h:32
virtual int send_alch_lambda()
Send cached value of alchemical lambda parameter to back-end (if available)
Definition: colvarproxy_system.cpp:159
void set_alch_lambda(cvm::real lambda)
Set value of alchemical lambda parameter to be sent to back-end at end of timestep.
Definition: colvarproxy_system.cpp:152
cvm::real kcal_mol_value_
Value of 1 kcal/mol in the internal Colvars unit for energy.
Definition: colvarproxy_system.h:209
virtual int set_integration_timestep(cvm::real dt)
Set the current integration timestep of the simulation (fs units)
Definition: colvarproxy_system.cpp:51
cvm::real angstrom_value_
Value of 1 Angstrom in the internal (front-end) Colvars unit for atomic coordinates.
Definition: colvarproxy_system.h:206
cvm::rvector position_distance_internal(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
Inline version of position_distance()
Definition: colvarproxy_system.h:240
virtual int set_time_step_factor(int fact)
Set the current integration timestep of the simulation (fs units)
Definition: colvarproxy_system.cpp:57
cvm::rvector unit_cell_x
Bravais lattice vectors.
Definition: colvarproxy_system.h:233
cvm::real target_temperature() const
Current target temperature of the simulation (K units)
Definition: colvarproxy_system.h:56
double timestep_
Current integration timestep (engine units); default to 1.0 if undefined.
Definition: colvarproxy_system.h:197
virtual int get_molid(int &molid)
Definition: colvarproxy_system.cpp:137
virtual cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
Get the PBC-aware distance vector between two positions (using the MD engine's convention)
Definition: colvarproxy_system.cpp:130
cvm::real internal_to_angstrom(cvm::real l) const
Convert a length from internal to Angstrom.
Definition: colvarproxy_system.h:44
virtual bool total_forces_same_step() const
Definition: colvarproxy_system.cpp:87
virtual cvm::real rand_gaussian(void)
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_system.cpp:63
Boundaries_type boundaries_type
Type of boundary conditions.
Definition: colvarproxy_system.h:230
virtual int get_dE_dlambda(cvm::real *dE_dlambda)
Get energy derivative with respect to lambda (if available)
Definition: colvarproxy_system.cpp:166
cvm::real indirect_lambda_biasing_force
Force to be applied onto alch. lambda, propagated from biasing forces on dE_dlambda.
Definition: colvarproxy_system.h:169
int time_step_factor_
Current timestep multiplier, if Colvars is only called once every n MD timesteps.
Definition: colvarproxy_system.h:200
virtual void request_total_force(bool yesno)
Tell the proxy whether total forces are needed (they may not always be available)
Definition: colvarproxy_system.cpp:73