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, bool silent = false);
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
263 std::vector<cvm::rvector> group_forces;
264
265public:
266
274 public:
307 void add_atom_force(size_t i, const cvm::rvector& force);
308 private:
309 cvm::atom_group* m_ag;
310 cvm::atom_group* m_group_for_fit;
311 bool m_has_fitting_force;
312 void apply_force_with_fitting_group();
313 };
314
315 group_force_object get_group_force_object();
316
317 inline cvm::atom & operator [] (size_t const i)
318 {
319 return atoms[i];
320 }
321
322 inline cvm::atom const & operator [] (size_t const i) const
323 {
324 return atoms[i];
325 }
326
327 inline cvm::atom_iter begin()
328 {
329 return atoms.begin();
330 }
331
332 inline cvm::atom_const_iter begin() const
333 {
334 return atoms.begin();
335 }
336
337 inline cvm::atom_iter end()
338 {
339 return atoms.end();
340 }
341
342 inline cvm::atom_const_iter end() const
343 {
344 return atoms.end();
345 }
346
347 inline size_t size() const
348 {
349 return atoms.size();
350 }
351
356
358 inline std::vector<int> const &ids() const
359 {
360 return atoms_ids;
361 }
362
363 std::string const print_atom_ids() const;
364
366 int create_sorted_ids();
367
370 inline std::vector<int> const &sorted_ids() const
371 {
372 return sorted_atoms_ids;
373 }
374
376 inline std::vector<int> const &sorted_ids_map() const
377 {
379 }
380
383 static int overlap(const atom_group &g1, const atom_group &g2);
384
387
390
395
397 std::vector<cvm::atom_pos> ref_pos;
398
403
407
410
412 void update_total_mass();
413
416
418 void update_total_charge();
419
423
425 void read_positions();
426
429
430 void setup_rotation_derivative();
431
439 void center_ref_pos();
440
442 void apply_translation(cvm::rvector const &t);
443
447 void read_velocities();
448
452 void read_total_forces();
453
455 inline void reset_atoms_data()
456 {
457 for (cvm::atom_iter ai = atoms.begin(); ai != atoms.end(); ai++)
458 ai->reset_data();
459 if (fitting_group)
461 }
462
465
467 std::vector<cvm::atom_pos> positions() const;
468
472
473private:
474
477
480
482 std::vector<cvm::atom_pos> pos_unrotated;
483
484public:
485
488 {
489 return cog;
490 }
491
495
496private:
497
500
502 // TODO for scalable calculations of more complex variables (e.g. rotation),
503 // use a colvarvalue of vectors to hold the entire derivative
505
506public:
507
510 {
511 return com;
512 }
513
517 {
518 return scalar_com_gradient;
519 }
520
522 std::vector<cvm::atom_pos> positions_shifted(cvm::rvector const &shift) const;
523
525 std::vector<cvm::rvector> velocities() const;
526
528 int calc_dipole(cvm::atom_pos const &dipole_center);
529
530private:
531
534
535public:
536
538 inline cvm::rvector dipole() const
539 {
540 return dip;
541 }
542
544 std::vector<cvm::rvector> total_forces() const;
545
548
549
553 void set_weighted_gradient(cvm::rvector const &grad);
554
556 void calc_fit_gradients();
557
587 template <bool B_ag_center, bool B_ag_rotate,
588 typename main_force_accessor_T, typename fitting_force_accessor_T>
590 main_force_accessor_T accessor_main,
591 fitting_force_accessor_T accessor_fitting) const;
592
608 template <typename main_force_accessor_T, typename fitting_force_accessor_T>
609 void calc_fit_forces(
610 main_force_accessor_T accessor_main,
611 fitting_force_accessor_T accessor_fitting) const;
612
614 std::vector<cvm::atom_pos> fit_gradients;
615
628 void apply_colvar_force(cvm::real const &force);
629
641 void apply_force(cvm::rvector const &force);
642
646 void do_feature_side_effects(int id) override;
647};
648
649
650#endif
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
A helper class for applying forces on an atom group in a way that is aware of the fitting group....
Definition: colvaratoms.h:273
void add_atom_force(size_t i, const cvm::rvector &force)
Apply force to atom i.
Definition: colvaratoms.cpp:1517
~group_force_object()
Destructor of group_force_object.
Definition: colvaratoms.cpp:1511
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:1001
int remove_atom(cvm::atom_iter ai)
Remove an atom object from this group.
Definition: colvaratoms.cpp:177
std::vector< cvm::rvector > group_forces
The temporary forces acting on the main group atoms. Currently this is only used for calculating the ...
Definition: colvaratoms.h:263
cvm::atom_pos cog_orig
Center of geometry before any fitting.
Definition: colvaratoms.h:479
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:1224
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:504
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:1339
cvm::rvector center_of_mass_scalar_gradient() const
Return previously gradient of scalar variable with respect to the COM.
Definition: colvaratoms.h:516
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:1140
cvm::atom_pos com
Center of mass.
Definition: colvaratoms.h:499
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:455
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
void calc_fit_forces_impl(main_force_accessor_T accessor_main, fitting_force_accessor_T accessor_fitting) const
Actual implementation of calc_fit_gradients and calc_fit_forces. The template is used to avoid branch...
Definition: colvaratoms.cpp:1251
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:422
int calc_required_properties()
Recompute all mutable quantities that are required to compute CVCs.
Definition: colvaratoms.cpp:1014
void calc_fit_forces(main_force_accessor_T accessor_main, fitting_force_accessor_T accessor_fitting) const
Calculate or apply the fitting group forces from the main group forces.
Definition: colvaratoms.cpp:1304
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:397
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:415
std::vector< int > const & sorted_ids_map() const
Map entries of sorted_atoms_ids onto the original positions in the group.
Definition: colvaratoms.h:376
std::vector< int > const & sorted_ids() const
Definition: colvaratoms.h:370
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:1469
void calc_apply_roto_translation()
(Re)calculate the optimal roto-translation
Definition: colvaratoms.cpp:1043
std::vector< cvm::atom_pos > pos_unrotated
Unrotated atom positions for fit gradients.
Definition: colvaratoms.h:482
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:358
std::vector< cvm::rvector > total_forces() const
Return a copy of the total forces.
Definition: colvaratoms.cpp:1381
cvm::rvector dipole() const
Return the (previously calculated) dipole of the atom group.
Definition: colvaratoms.h:538
cvm::real total_mass
Total mass of the atom group.
Definition: colvaratoms.h:409
std::vector< cvm::atom_pos > positions() const
Return a copy of the current atom positions.
Definition: colvaratoms.cpp:1318
int calc_dipole(cvm::atom_pos const &dipole_center)
Calculate the dipole of the atom group around the specified center.
Definition: colvaratoms.cpp:1196
void apply_translation(cvm::rvector const &t)
Move all positions.
Definition: colvaratoms.cpp:1100
bool b_user_defined_fit
Indicates that the user has explicitly set centerToReference or rotateReference, and the correspondin...
Definition: colvaratoms.h:394
rotation_derivative< cvm::atom, cvm::atom_pos > * rot_deriv
Rotation derivative;.
Definition: colvaratoms.h:389
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:1176
cvm::atom_pos ref_pos_cog
Center of geometry of the reference coordinates; regardless of whether f_ag_center is true,...
Definition: colvaratoms.h:402
~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:487
std::vector< cvm::atom_pos > fit_gradients
Derivatives of the fitting transformation.
Definition: colvaratoms.h:614
void center_ref_pos()
Save aside the center of geometry of the reference positions, then subtract it from them.
Definition: colvaratoms.cpp:987
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:509
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:355
cvm::rvector dip
Dipole moment of the atom group.
Definition: colvaratoms.h:533
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:1423
cvm::rotation rot
The rotation calculated automatically if f_ag_rotate is defined.
Definition: colvaratoms.h:386
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:1404
int calc_center_of_geometry()
Calculate the center of geometry of the atomic positions, assuming that they are already pbc-wrapped.
Definition: colvaratoms.cpp:1161
int create_sorted_ids()
Allocates and populates sorted_ids and sorted_ids_map.
Definition: colvaratoms.cpp:939
cvm::atom_pos cog
Center of geometry.
Definition: colvaratoms.h:476
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:406
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:1210
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:1360
static int overlap(const atom_group &g1, const atom_group &g2)
Definition: colvaratoms.cpp:975
const std::vector< feature * > & features() const override
Implementation of the feature list accessor for atom group.
Definition: colvaratoms.h:227
void do_feature_side_effects(int id) override
Definition: colvaratoms.cpp:925
void read_velocities()
Get the current velocities; this must be called always after read_positions(); if f_ag_rotate is defi...
Definition: colvaratoms.cpp:1118
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:1363
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:90
cvm::real get_atom_charge(int index) const
Definition: colvarproxy.h:104
Definition: colvarproxy.h:542
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:59