Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvaratoms.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 COLVARATOMS_H
11#define COLVARATOMS_H
12
13#include "colvarmodule.h"
14#include "colvarproxy.h"
15#include "colvarparse.h"
16#include "colvardeps.h"
17
18template <typename T1, typename T2>
20
21
30
32
33protected:
34
36 int index;
37
38public:
39
41 int id;
42
45
48
52
56
60
72
74 atom();
75
79 atom(int atom_number);
80
86 atom(cvm::residue_id const &residue,
87 std::string const &atom_name,
88 std::string const &segment_id);
89
91 atom(atom const &a);
92
94 ~atom();
95
97 atom & operator = (atom const &a);
98
100 inline void reset_data()
101 {
102 pos = cvm::atom_pos(0.0);
103 vel = grad = total_force = cvm::rvector(0.0);
104 }
105
107 inline void update_mass()
108 {
111 }
112
114 inline void update_charge()
115 {
118 }
119
121 inline void read_position()
122 {
123 pos = (cvm::proxy)->get_atom_position(index);
124 }
125
127 inline void read_velocity()
128 {
129 vel = (cvm::proxy)->get_atom_velocity(index);
130 }
131
133 inline void read_total_force()
134 {
135 total_force = (cvm::proxy)->get_atom_total_force(index);
136 }
137
147 inline void apply_force(cvm::rvector const &new_force) const
148 {
149 (cvm::proxy)->apply_atom_force(index, new_force);
150 }
151};
152
153
154
158 : public colvarparse, public colvardeps
159{
160public:
161
162
164 atom_group();
165
167 atom_group(char const *key);
168
170 atom_group(std::vector<cvm::atom> const &atoms_in);
171
173 ~atom_group() override;
174
176 std::string name;
177
179 // TODO Make this field part of the data structures that link a group to a CVC
180 std::string key;
181
183 int init();
184
186 int init_dependencies() override;
187
189 int setup();
190
193 int parse(std::string const &conf);
194
195 int add_atom_numbers(std::string const &numbers_conf);
196 int add_atoms_of_group(atom_group const * ag);
197 int add_index_group(std::string const &index_group_name);
198 int add_atom_numbers_range(std::string const &range_conf);
199 int add_atom_name_residue_range(std::string const &psf_segid,
200 std::string const &range_conf);
201 int parse_fitting_options(std::string const &group_conf);
202
204 int add_atom(cvm::atom const &a);
205
207 int add_atom_id(int aid);
208
210 int remove_atom(cvm::atom_iter ai);
211
213 int set_dummy();
214
216 int set_dummy_pos(cvm::atom_pos const &pos);
217
221 void print_properties(std::string const &colvar_name, int i, int j);
222
224 static std::vector<feature *> ag_features;
225
227 const std::vector<feature *> &features() const override { return ag_features; }
228
229 std::vector<feature *> &modify_features() override { return ag_features; }
230
231 static void delete_features()
232 {
233 for (size_t i = 0; i < ag_features.size(); i++) {
234 delete ag_features[i];
235 }
236 ag_features.clear();
237 }
238
239protected:
240
242 std::vector<cvm::atom> atoms;
243
245 std::vector<int> atoms_ids;
246
249 std::vector<int> sorted_atoms_ids;
250
252 std::vector<int> sorted_atoms_ids_map;
253
256
258 int index;
259
260public:
261
262 inline cvm::atom & operator [] (size_t const i)
263 {
264 return atoms[i];
265 }
266
267 inline cvm::atom const & operator [] (size_t const i) const
268 {
269 return atoms[i];
270 }
271
272 inline cvm::atom_iter begin()
273 {
274 return atoms.begin();
275 }
276
277 inline cvm::atom_const_iter begin() const
278 {
279 return atoms.begin();
280 }
281
282 inline cvm::atom_iter end()
283 {
284 return atoms.end();
285 }
286
287 inline cvm::atom_const_iter end() const
288 {
289 return atoms.end();
290 }
291
292 inline size_t size() const
293 {
294 return atoms.size();
295 }
296
301
303 inline std::vector<int> const &ids() const
304 {
305 return atoms_ids;
306 }
307
308 std::string const print_atom_ids() const;
309
311 int create_sorted_ids();
312
315 inline std::vector<int> const &sorted_ids() const
316 {
317 return sorted_atoms_ids;
318 }
319
321 inline std::vector<int> const &sorted_ids_map() const
322 {
324 }
325
328 static int overlap(const atom_group &g1, const atom_group &g2);
329
332
335
340
342 std::vector<cvm::atom_pos> ref_pos;
343
348
352
355
357 void update_total_mass();
358
361
363 void update_total_charge();
364
368
370 void read_positions();
371
374
375 void setup_rotation_derivative();
376
384 void center_ref_pos();
385
387 void apply_translation(cvm::rvector const &t);
388
392 void read_velocities();
393
397 void read_total_forces();
398
400 inline void reset_atoms_data()
401 {
402 for (cvm::atom_iter ai = atoms.begin(); ai != atoms.end(); ai++)
403 ai->reset_data();
404 if (fitting_group)
406 }
407
410
412 std::vector<cvm::atom_pos> positions() const;
413
417
418private:
419
422
425
426public:
427
430 {
431 return cog;
432 }
433
437
438private:
439
442
444 // TODO for scalable calculations of more complex variables (e.g. rotation),
445 // use a colvarvalue of vectors to hold the entire derivative
447
448public:
449
452 {
453 return com;
454 }
455
459 {
460 return scalar_com_gradient;
461 }
462
464 std::vector<cvm::atom_pos> positions_shifted(cvm::rvector const &shift) const;
465
467 std::vector<cvm::rvector> velocities() const;
468
470 int calc_dipole(cvm::atom_pos const &dipole_center);
471
472private:
473
476
477public:
478
480 inline cvm::rvector dipole() const
481 {
482 return dip;
483 }
484
486 std::vector<cvm::rvector> total_forces() const;
487
490
491
495 void set_weighted_gradient(cvm::rvector const &grad);
496
498 void calc_fit_gradients();
499
508 template <bool B_ag_center, bool B_ag_rotate> void calc_fit_gradients_impl();
509
511 std::vector<cvm::atom_pos> fit_gradients;
512
525 void apply_colvar_force(cvm::real const &force);
526
538 void apply_force(cvm::rvector const &force);
539
543 void do_feature_side_effects(int id) override;
544};
545
546
547#endif
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
Group of atom objects, mostly used by a colvar::cvc object to gather all atomic data.
Definition: colvaratoms.h:159
std::vector< int > sorted_atoms_ids_map
Map entries of sorted_atoms_ids onto the original positions in the group.
Definition: colvaratoms.h:252
std::vector< int > sorted_atoms_ids
Definition: colvaratoms.h:249
void read_positions()
Get the current positions.
Definition: colvaratoms.cpp:998
int remove_atom(cvm::atom_iter ai)
Remove an atom object from this group.
Definition: colvaratoms.cpp:177
cvm::atom_pos cog_orig
Center of geometry before any fitting.
Definition: colvaratoms.h:424
int init()
Set default values for common flags.
Definition: colvaratoms.cpp:223
void calc_fit_gradients()
Calculate the derivatives of the fitting transformation.
Definition: colvaratoms.cpp:1213
void update_total_charge()
Update the total mass of the group.
Definition: colvaratoms.cpp:357
cvm::rvector scalar_com_gradient
The derivative of a scalar variable with respect to the COM.
Definition: colvaratoms.h:446
std::vector< cvm::atom_pos > positions_shifted(cvm::rvector const &shift) const
Return a copy of the current atom positions, shifted by a constant vector.
Definition: colvaratoms.cpp:1306
cvm::rvector center_of_mass_scalar_gradient() const
Return previously gradient of scalar variable with respect to the COM.
Definition: colvaratoms.h:458
void read_total_forces()
Get the current total_forces; this must be called always after read_positions(); if f_ag_rotate is de...
Definition: colvaratoms.cpp:1129
cvm::atom_pos com
Center of mass.
Definition: colvaratoms.h:441
int index
Index in the colvarproxy arrays (if the group is scalable)
Definition: colvaratoms.h:258
void reset_atoms_data()
Call reset_data() for each atom.
Definition: colvaratoms.h:400
int init_dependencies() override
Initialize dependency tree.
Definition: colvaratoms.cpp:250
void print_properties(std::string const &colvar_name, int i, int j)
Print the updated the total mass and charge of a group. This is needed in case the hosting MD code ha...
Definition: colvaratoms.cpp:375
std::string key
Keyword used to define the group.
Definition: colvaratoms.h:180
std::string name
Optional name to reuse properties of this in other groups.
Definition: colvaratoms.h:176
bool noforce
Don't apply any force on this group (use its coordinates only to calculate a colvar)
Definition: colvaratoms.h:367
int calc_required_properties()
Recompute all mutable quantities that are required to compute CVCs.
Definition: colvaratoms.cpp:1011
static std::vector< feature * > ag_features
Implementation of the feature list for atom group.
Definition: colvaratoms.h:224
atom_group()
Default constructor.
Definition: colvaratoms.cpp:90
std::vector< cvm::atom_pos > ref_pos
use reference coordinates for f_ag_center or f_ag_rotate
Definition: colvaratoms.h:342
void update_total_mass()
Update the total mass of the atom group.
Definition: colvaratoms.cpp:336
cvm::real total_charge
Total charge of the atom group.
Definition: colvaratoms.h:360
std::vector< int > const & sorted_ids_map() const
Map entries of sorted_atoms_ids onto the original positions in the group.
Definition: colvaratoms.h:321
std::vector< int > const & sorted_ids() const
Definition: colvaratoms.h:315
int add_atom(cvm::atom const &a)
Add an atom object to this group.
Definition: colvaratoms.cpp:132
void apply_force(cvm::rvector const &force)
Apply a force "to the center of mass", i.e. the force is distributed on each atom according to its ma...
Definition: colvaratoms.cpp:1436
void calc_apply_roto_translation()
(Re)calculate the optimal roto-translation
Definition: colvaratoms.cpp:1040
int add_atom_id(int aid)
Add an atom ID to this group (the actual atomicdata will be not be handled by the group)
Definition: colvaratoms.cpp:157
std::vector< int > const & ids() const
Internal atom IDs (populated during initialization)
Definition: colvaratoms.h:303
std::vector< cvm::rvector > total_forces() const
Return a copy of the total forces.
Definition: colvaratoms.cpp:1348
cvm::rvector dipole() const
Return the (previously calculated) dipole of the atom group.
Definition: colvaratoms.h:480
cvm::real total_mass
Total mass of the atom group.
Definition: colvaratoms.h:354
std::vector< cvm::atom_pos > positions() const
Return a copy of the current atom positions.
Definition: colvaratoms.cpp:1285
int calc_dipole(cvm::atom_pos const &dipole_center)
Calculate the dipole of the atom group around the specified center.
Definition: colvaratoms.cpp:1185
void apply_translation(cvm::rvector const &t)
Move all positions.
Definition: colvaratoms.cpp:1089
bool b_user_defined_fit
Indicates that the user has explicitly set centerToReference or rotateReference, and the correspondin...
Definition: colvaratoms.h:339
rotation_derivative< cvm::atom, cvm::atom_pos > * rot_deriv
Rotation derivative;.
Definition: colvaratoms.h:334
int set_dummy_pos(cvm::atom_pos const &pos)
If this group is dummy, set the corresponding position.
Definition: colvaratoms.cpp:210
int calc_center_of_mass()
Calculate the center of mass of the atomic positions, assuming that they are already pbc-wrapped.
Definition: colvaratoms.cpp:1165
cvm::atom_pos ref_pos_cog
Center of geometry of the reference coordinates; regardless of whether f_ag_center is true,...
Definition: colvaratoms.h:347
~atom_group() override
Destructor.
Definition: colvaratoms.cpp:111
cvm::atom_pos center_of_geometry() const
Return the center of geometry of the atomic positions.
Definition: colvaratoms.h:429
std::vector< cvm::atom_pos > fit_gradients
Derivatives of the fitting transformation.
Definition: colvaratoms.h:511
void center_ref_pos()
Save aside the center of geometry of the reference positions, then subtract it from them.
Definition: colvaratoms.cpp:984
std::vector< cvm::atom > atoms
Array of atom objects.
Definition: colvaratoms.h:242
cvm::atom_pos center_of_mass() const
Return the center of mass (COM) of the atomic positions.
Definition: colvaratoms.h:451
bool b_dummy
If this option is on, this group merely acts as a wrapper for a fixed position; any calls to atoms wi...
Definition: colvaratoms.h:300
cvm::rvector dip
Dipole moment of the atom group.
Definition: colvaratoms.h:475
void apply_colvar_force(cvm::real const &force)
Used by a (scalar) colvar to apply its force on its atom_group members.
Definition: colvaratoms.cpp:1390
cvm::rotation rot
The rotation calculated automatically if f_ag_rotate is defined.
Definition: colvaratoms.h:331
cvm::atom_pos dummy_atom_pos
Dummy atom position.
Definition: colvaratoms.h:255
cvm::rvector total_force() const
Return a copy of the aggregated total force on the group.
Definition: colvaratoms.cpp:1371
int calc_center_of_geometry()
Calculate the center of geometry of the atomic positions, assuming that they are already pbc-wrapped.
Definition: colvaratoms.cpp:1150
int create_sorted_ids()
Allocates and populates sorted_ids and sorted_ids_map.
Definition: colvaratoms.cpp:936
cvm::atom_pos cog
Center of geometry.
Definition: colvaratoms.h:421
std::vector< int > atoms_ids
Internal atom IDs for host code.
Definition: colvaratoms.h:245
atom_group * fitting_group
If f_ag_center or f_ag_rotate is true, use this group to define the transformation (default: this gro...
Definition: colvaratoms.h:351
int set_dummy()
Set this group as a dummy group (no actual atoms)
Definition: colvaratoms.cpp:198
void set_weighted_gradient(cvm::rvector const &grad)
Shorthand: save the specified gradient on each atom, weighting with the atom mass (mostly used in com...
Definition: colvaratoms.cpp:1199
int setup()
Update data required to calculate cvc's.
Definition: colvaratoms.cpp:311
std::vector< cvm::rvector > velocities() const
Return a copy of the current atom velocities.
Definition: colvaratoms.cpp:1327
static int overlap(const atom_group &g1, const atom_group &g2)
Definition: colvaratoms.cpp:972
const std::vector< feature * > & features() const override
Implementation of the feature list accessor for atom group.
Definition: colvaratoms.h:227
void calc_fit_gradients_impl()
Actual implementation of calc_fit_gradients. The template is used to avoid branching inside the loops...
Definition: colvaratoms.cpp:1235
void do_feature_side_effects(int id) override
Definition: colvaratoms.cpp:922
void read_velocities()
Get the current velocities; this must be called always after read_positions(); if f_ag_rotate is defi...
Definition: colvaratoms.cpp:1107
Stores numeric id, mass and all mutable data for an atom, mostly used by a colvar::cvc.
Definition: colvaratoms.h:31
int id
Identifier for the MD program (0-based)
Definition: colvaratoms.h:41
void apply_force(cvm::rvector const &new_force) const
Apply a force to the atom.
Definition: colvaratoms.h:147
cvm::rvector grad
Gradient of a scalar collective variable with respect to this atom.
Definition: colvaratoms.h:71
void read_velocity()
Get the current velocity.
Definition: colvaratoms.h:127
void update_charge()
Get the latest value of the charge.
Definition: colvaratoms.h:114
int index
Index in the colvarproxy arrays (NOT in the global topology!)
Definition: colvaratoms.h:36
void reset_data()
Set mutable data (everything except id and mass) to zero.
Definition: colvaratoms.h:100
~atom()
Destructor.
Definition: colvaratoms.cpp:70
cvm::real charge
Charge.
Definition: colvaratoms.h:47
atom & operator=(atom const &a)
Assignment operator (added to appease LGTM)
Definition: colvaratoms.cpp:78
cvm::rvector total_force
System force at the previous step (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:59
void read_position()
Get the current position.
Definition: colvaratoms.h:121
void read_total_force()
Get the total force.
Definition: colvaratoms.h:133
cvm::real mass
Mass.
Definition: colvaratoms.h:44
cvm::rvector vel
Current velocity (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:55
cvm::atom_pos pos
Current position (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:51
atom()
Default constructor (sets index and id both to -1)
Definition: colvaratoms.cpp:24
void update_mass()
Get the latest value of the mass.
Definition: colvaratoms.h:107
A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion)
Definition: colvartypes.h:1314
vector of real numbers with three components
Definition: colvartypes.h:727
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:197
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
int residue_id
Residue identifier.
Definition: colvarmodule.h:193
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:794
static colvarproxy * proxy
Pointer to the proxy object, used to retrieve atomic data from the hosting program; it is static in o...
Definition: colvarmodule.h:860
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
cvm::real get_atom_mass(int index) const
Definition: colvarproxy.h:89
cvm::real get_atom_charge(int index) const
Definition: colvarproxy.h:103
Definition: colvarproxy.h:573
Collective variables main module.
Parsing functions for collective variables.
Colvars proxy classes.
Helper class for calculating the derivative of rotation.
Definition: colvar_rotation_derivative.h:49