Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
colvaratoms.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARATOMS_H
4 #define COLVARATOMS_H
5 
6 #include "colvarmodule.h"
7 #include "colvarparse.h"
8 #include "colvardeps.h"
9 
10 
19 
21 
22 protected:
23 
25  int index;
26 
27 public:
28 
30  int id;
31 
34 
37 
41 
45 
49 
61 
63  atom();
64 
68  atom(int atom_number);
69 
75  atom(cvm::residue_id const &residue,
76  std::string const &atom_name,
77  std::string const &segment_id);
78 
80  atom(atom const &a);
81 
83  ~atom();
84 
86  inline void reset_data()
87  {
88  pos = cvm::atom_pos(0.0);
89  vel = grad = total_force = cvm::rvector(0.0);
90  }
91 
93  inline void update_mass()
94  {
95  mass = (cvm::proxy)->get_atom_mass(index);
96  }
97 
99  inline void update_charge()
100  {
101  charge = (cvm::proxy)->get_atom_charge(index);
102  }
103 
105  inline void read_position()
106  {
107  pos = (cvm::proxy)->get_atom_position(index);
108  }
109 
111  inline void read_velocity()
112  {
113  vel = (cvm::proxy)->get_atom_velocity(index);
114  }
115 
117  inline void read_total_force()
118  {
119  total_force = (cvm::proxy)->get_atom_total_force(index);
120  }
121 
131  inline void apply_force(cvm::rvector const &new_force) const
132  {
133  (cvm::proxy)->apply_atom_force(index, new_force);
134  }
135 };
136 
137 
138 
142  : public colvarparse, public colvardeps
143 {
144 public:
145 
150  atom_group(std::string const &conf,
151  char const *key);
152 
154  // TODO Make this field part of the data structures that link a group to a CVC
155  std::string key;
156 
158  int init();
159 
161  int setup();
162 
165  int parse(std::string const &conf);
166 
167  int add_atom_numbers(std::string const &numbers_conf);
168  int add_index_group(std::string const &index_group_name);
169  int add_atom_numbers_range(std::string const &range_conf);
170  int add_atom_name_residue_range(std::string const &psf_segid,
171  std::string const &range_conf);
172  int parse_fitting_options(std::string const &group_conf);
173 
175  atom_group(std::vector<cvm::atom> const &atoms_in);
176 
178  int add_atom(cvm::atom const &a);
179 
181  int add_atom_id(int aid);
182 
184  int remove_atom(cvm::atom_iter ai);
185 
189  void reset_mass(std::string &name, int i, int j);
190 
192  static std::vector<feature *> ag_features;
193 
195  virtual std::vector<feature *> &features() {
196  return ag_features;
197  }
198 
200  atom_group();
201 
203  ~atom_group();
204 
205 protected:
206 
208  std::vector<cvm::atom> atoms;
209 
211  std::vector<int> atoms_ids;
212 
215 
217  int index;
218 
219 public:
220 
221  inline cvm::atom & operator [] (size_t const i)
222  {
223  return atoms[i];
224  }
225 
226  inline cvm::atom const & operator [] (size_t const i) const
227  {
228  return atoms[i];
229  }
230 
231  inline cvm::atom_iter begin()
232  {
233  return atoms.begin();
234  }
235 
236  inline cvm::atom_const_iter begin() const
237  {
238  return atoms.begin();
239  }
240 
241  inline cvm::atom_iter end()
242  {
243  return atoms.end();
244  }
245 
246  inline cvm::atom_const_iter end() const
247  {
248  return atoms.end();
249  }
250 
251  inline size_t size() const
252  {
253  return atoms.size();
254  }
255 
256  std::string const print_atom_ids() const;
257 
261  bool b_dummy;
262 
265  std::vector<int> sorted_ids;
266 
268  int create_sorted_ids(void);
269 
272  bool b_center;
273 
281  bool b_rotate;
284 
289 
293 
295  std::vector<cvm::atom_pos> ref_pos;
296 
301 
305 
308  void update_total_mass();
309 
312  void update_total_charge();
313 
316  bool noforce;
317 
319  void read_positions();
320 
323 
331  void center_ref_pos();
332 
334  void apply_translation(cvm::rvector const &t);
335 
339  void read_velocities();
340 
344  void read_total_forces();
345 
347  inline void reset_atoms_data()
348  {
349  for (cvm::atom_iter ai = atoms.begin(); ai != atoms.end(); ai++)
350  ai->reset_data();
351  if (fitting_group)
353  }
354 
357 
359  std::vector<cvm::atom_pos> positions() const;
360 
364 
365 private:
366 
368  cvm::atom_pos cog;
369 
371  cvm::atom_pos cog_orig;
372 
373 public:
374 
377  {
378  return cog;
379  }
380 
383  int calc_center_of_mass();
384 private:
386  cvm::atom_pos com;
388  // TODO for scalable calculations of more complex variables (e.g. rotation),
389  // use a colvarvalue of vectors to hold the entire derivative
390  cvm::rvector scalar_com_gradient;
391 public:
394  {
395  return com;
396  }
397 
399  std::vector<cvm::atom_pos> positions_shifted(cvm::rvector const &shift) const;
400 
402  std::vector<cvm::rvector> velocities() const;
403 
405  int calc_dipole(cvm::atom_pos const &com);
406 private:
407  cvm::rvector dip;
408 public:
410  inline cvm::rvector dipole() const
411  {
412  return dip;
413  }
414 
416  std::vector<cvm::rvector> total_forces() const;
417 
419  cvm::rvector total_force() const;
420 
421 
425  void set_weighted_gradient(cvm::rvector const &grad);
426 
428  void calc_fit_gradients();
429 
431  std::vector<cvm::atom_pos> fit_gradients;
432 
445  void apply_colvar_force(cvm::real const &force);
446 
458  void apply_force(cvm::rvector const &force);
459 
460 };
461 
462 
463 #endif
std::vector< int > atoms_ids
Array of atom identifiers for the MD program (0-based)
Definition: colvaratoms.h:211
cvm::rvector dipole() const
Return the (previously calculated) dipole of the atom group.
Definition: colvaratoms.h:410
atom_group()
Default constructor.
Definition: colvaratoms.cpp:86
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:979
atom()
Default constructor (sets index and id both to -1)
Definition: colvaratoms.cpp:7
cvm::real total_mass
Total mass of the atom group.
Definition: colvaratoms.h:307
void reset_mass(std::string &name, int i, int j)
Re-initialize the total mass of a group. This is needed in case the hosting MD code has an option to ...
Definition: colvaratoms.cpp:234
int parse(std::string const &conf)
Initialize the group by looking up its configuration string in conf and parsing it.
Definition: colvaratoms.cpp:261
void read_velocity()
Get the current velocity.
Definition: colvaratoms.h:111
bool b_center
When updating atomic coordinates, translate them to align with the center of mass of the reference co...
Definition: colvaratoms.h:272
int remove_atom(cvm::atom_iter ai)
Remove an atom object from this group.
Definition: colvaratoms.cpp:151
std::string key
Keyword used to define the group.
Definition: colvaratoms.h:155
Stores numeric id, mass and all mutable data for an atom, mostly used by a cvc.
Definition: colvaratoms.h:20
bool noforce
Don't apply any force on this group (use its coordinates only to calculate a colvar) ...
Definition: colvaratoms.h:316
void read_velocities()
Get the current velocities; this must be called always after read_positions(); if b_rotate is defined...
Definition: colvaratoms.cpp:889
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:596
int calc_center_of_mass()
Calculate the center of mass of the atomic positions, assuming that they are already pbc-wrapped...
Definition: colvaratoms.cpp:945
std::vector< cvm::atom_pos > fit_gradients
Derivatives of the fitting transformation.
Definition: colvaratoms.h:431
cvm::real mass
Mass.
Definition: colvaratoms.h:33
void reset_data()
Set mutable data (everything except id and mass) to zero; update mass.
Definition: colvaratoms.h:86
int calc_dipole(cvm::atom_pos const &com)
Calculate the dipole of the atom group around the specified center.
Definition: colvaratoms.cpp:965
cvm::atom_pos center_of_geometry() const
Return the center of geometry of the atomic positions.
Definition: colvaratoms.h:376
vector of real numbers with three components
Definition: colvartypes.h:709
void apply_translation(cvm::rvector const &t)
Move all positions.
Definition: colvaratoms.cpp:871
void read_total_forces()
Get the current total_forces; this must be called always after read_positions(); if b_rotate is defin...
Definition: colvaratoms.cpp:910
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:1198
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:1152
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:1068
cvm::rotation rot
The rotation calculated automatically if b_rotate is defined.
Definition: colvaratoms.h:283
virtual std::vector< feature * > & features()
Implementation of the feature list accessor for atom group.
Definition: colvaratoms.h:195
static std::vector< feature * > ag_features
Implementation of the feature list for atom group.
Definition: colvaratoms.h:192
int index
Index in the colvarproxy arrays (if the group is scalable)
Definition: colvaratoms.h:217
Collective variables main module.
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:85
int index
Index in the colvarproxy arrays (NOT in the global topology!)
Definition: colvaratoms.h:25
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:93
cvm::real total_charge
Total charge of the atom group.
Definition: colvaratoms.h:311
~atom_group()
Destructor.
Definition: colvaratoms.cpp:92
cvm::rvector grad
Gradient of a scalar collective variable with respect to this atom.
Definition: colvaratoms.h:60
cvm::atom_pos ref_pos_cog
Center of geometry of the reference coordinates; regardless of whether b_center is true...
Definition: colvaratoms.h:300
bool b_user_defined_fit
Indicates that the user has explicitly set centerReference or rotateReference, and the corresponding ...
Definition: colvaratoms.h:288
atom_group * fitting_group
If b_center or b_rotate is true, use this group to define the transformation (default: this group its...
Definition: colvaratoms.h:304
cvm::rvector vel
Current velocity (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:44
int calc_center_of_geometry()
Calculate the center of geometry of the atomic positions, assuming that they are already pbc-wrapped...
Definition: colvaratoms.cpp:930
int id
Identifier for the MD program (0-based)
Definition: colvaratoms.h:30
~atom()
Destructor.
Definition: colvaratoms.cpp:54
std::vector< cvm::atom_pos > positions() const
Return a copy of the current atom positions.
Definition: colvaratoms.cpp:1047
cvm::real charge
Charge.
Definition: colvaratoms.h:36
void calc_apply_roto_translation()
(Re)calculate the optimal roto-translation
Definition: colvaratoms.cpp:823
void reset_atoms_data()
Call reset_data() for each atom.
Definition: colvaratoms.h:347
cvm::atom_pos center_of_mass() const
Return the center of mass of the atomic positions.
Definition: colvaratoms.h:393
void read_total_force()
Get the total force.
Definition: colvaratoms.h:117
int create_sorted_ids(void)
Allocates and populates the sorted list of atom ids.
Definition: colvaratoms.cpp:737
int residue_id
Residue identifier.
Definition: colvarmodule.h:87
std::vector< int > sorted_ids
Definition: colvaratoms.h:265
void calc_fit_gradients()
Calculate the derivatives of the fitting transformation.
Definition: colvaratoms.cpp:994
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:19
void update_charge()
Get the latest value of the charge.
Definition: colvaratoms.h:99
void read_positions()
Get the current positions.
Definition: colvaratoms.cpp:781
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:261
cvm::atom_pos pos
Current position (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:40
int add_atom(cvm::atom const &a)
Add an atom object to this group.
Definition: colvaratoms.cpp:106
cvm::rvector total_force() const
Return a copy of the aggregated total force on the group.
Definition: colvaratoms.cpp:1133
bool b_fit_gradients
Whether or not the derivatives of the roto-translation should be included when calculating the colvar...
Definition: colvaratoms.h:292
cvm::atom_pos dummy_atom_pos
Dummy atom position.
Definition: colvaratoms.h:214
bool b_rotate
When updating atom coordinates (and after centering them if b_center is set), rotate the group to ali...
Definition: colvaratoms.h:281
std::vector< cvm::rvector > velocities() const
Return a copy of the current atom velocities.
Definition: colvaratoms.cpp:1089
Parsing functions for collective variables.
int setup()
Update data required to calculate cvc's.
Definition: colvaratoms.cpp:204
Base class containing parsing functions; all objects which need to parse input inherit from this...
Definition: colvarparse.h:18
std::vector< cvm::atom_pos > ref_pos
use reference coordinates for b_center or b_rotate
Definition: colvaratoms.h:295
A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion) ...
Definition: colvartypes.h:1374
void read_position()
Get the current position.
Definition: colvaratoms.h:105
int init()
Set default values for common flags.
Definition: colvaratoms.cpp:172
std::vector< cvm::rvector > total_forces() const
Return a copy of the total forces.
Definition: colvaratoms.cpp:1110
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:131
void center_ref_pos()
Save aside the center of geometry of the reference positions, then subtract it from them...
Definition: colvaratoms.cpp:767
int calc_required_properties()
Recompute all mutable quantities that are required to compute CVCs.
Definition: colvaratoms.cpp:794
std::vector< cvm::atom > atoms
Array of atom objects.
Definition: colvaratoms.h:208
void update_mass()
Get the latest value of the mass.
Definition: colvaratoms.h:93
void apply_force(cvm::rvector const &new_force) const
Apply a force to the atom.
Definition: colvaratoms.h:131
cvm::rvector total_force
System force at the previous step (copied from the program, can be modified if necessary) ...
Definition: colvaratoms.h:48
Group of atom objects, mostly used by a cvc object to gather all atomic data.
Definition: colvaratoms.h:141