Collective Variables Module - Developer Documentation
colvaratoms.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARATOMS_H
4 #define COLVARATOMS_H
5 
6 #include "colvarmodule.h"
7 #include "colvarproxy.h"
8 #include "colvarparse.h"
9 #include "colvardeps.h"
10 
11 
20 
22 
23 protected:
24 
26  int index;
27 
28 public:
29 
31  int id;
32 
35 
38 
42 
46 
50 
62 
64  atom();
65 
69  atom(int atom_number);
70 
76  atom(cvm::residue_id const &residue,
77  std::string const &atom_name,
78  std::string const &segment_id);
79 
81  atom(atom const &a);
82 
84  ~atom();
85 
87  inline void reset_data()
88  {
89  pos = cvm::atom_pos(0.0);
90  vel = grad = total_force = cvm::rvector(0.0);
91  }
92 
94  inline void update_mass()
95  {
96  mass = (cvm::proxy)->get_atom_mass(index);
97  }
98 
100  inline void update_charge()
101  {
102  charge = (cvm::proxy)->get_atom_charge(index);
103  }
104 
106  inline void read_position()
107  {
108  pos = (cvm::proxy)->get_atom_position(index);
109  }
110 
112  inline void read_velocity()
113  {
114  vel = (cvm::proxy)->get_atom_velocity(index);
115  }
116 
118  inline void read_total_force()
119  {
120  total_force = (cvm::proxy)->get_atom_total_force(index);
121  }
122 
132  inline void apply_force(cvm::rvector const &new_force) const
133  {
134  (cvm::proxy)->apply_atom_force(index, new_force);
135  }
136 };
137 
138 
139 
143  : public colvarparse, public colvardeps
144 {
145 public:
146 
147 
149  atom_group();
150 
152  atom_group(char const *key);
153 
155  atom_group(std::vector<cvm::atom> const &atoms_in);
156 
158  ~atom_group();
159 
161  std::string name;
162 
164  // TODO Make this field part of the data structures that link a group to a CVC
165  std::string key;
166 
168  int init();
169 
171  int setup();
172 
175  int parse(std::string const &conf);
176 
177  int add_atom_numbers(std::string const &numbers_conf);
178  int add_atoms_of_group(atom_group const * ag);
179  int add_index_group(std::string const &index_group_name);
180  int add_atom_numbers_range(std::string const &range_conf);
181  int add_atom_name_residue_range(std::string const &psf_segid,
182  std::string const &range_conf);
183  int parse_fitting_options(std::string const &group_conf);
184 
186  int add_atom(cvm::atom const &a);
187 
189  int add_atom_id(int aid);
190 
192  int remove_atom(cvm::atom_iter ai);
193 
197  void reset_mass(std::string &name, int i, int j);
198 
200  static std::vector<feature *> ag_features;
201 
203  virtual const std::vector<feature *> &features()
204  {
205  return ag_features;
206  }
207  virtual std::vector<feature *> &modify_features()
208  {
209  return ag_features;
210  }
211  static void delete_features() {
212  for (size_t i=0; i < ag_features.size(); i++) {
213  delete ag_features[i];
214  }
215  ag_features.clear();
216  }
217 
218 protected:
219 
221  std::vector<cvm::atom> atoms;
222 
224  std::vector<int> atoms_ids;
225 
228 
230  int index;
231 
232 public:
233 
234  inline cvm::atom & operator [] (size_t const i)
235  {
236  return atoms[i];
237  }
238 
239  inline cvm::atom const & operator [] (size_t const i) const
240  {
241  return atoms[i];
242  }
243 
244  inline cvm::atom_iter begin()
245  {
246  return atoms.begin();
247  }
248 
249  inline cvm::atom_const_iter begin() const
250  {
251  return atoms.begin();
252  }
253 
254  inline cvm::atom_iter end()
255  {
256  return atoms.end();
257  }
258 
259  inline cvm::atom_const_iter end() const
260  {
261  return atoms.end();
262  }
263 
264  inline size_t size() const
265  {
266  return atoms.size();
267  }
268 
269  std::string const print_atom_ids() const;
270 
274  bool b_dummy;
275 
278  std::vector<int> sorted_ids;
279 
281  int create_sorted_ids(void);
282 
285  static int overlap(const atom_group &g1, const atom_group &g2);
286 
289  bool b_center;
290 
298  bool b_rotate;
301 
306 
308  std::vector<cvm::atom_pos> ref_pos;
309 
314 
318 
321  void update_total_mass();
322 
325  void update_total_charge();
326 
329  bool noforce;
330 
332  void read_positions();
333 
335  void calc_apply_roto_translation();
336 
344  void center_ref_pos();
345 
347  void apply_translation(cvm::rvector const &t);
348 
352  void read_velocities();
353 
357  void read_total_forces();
358 
360  inline void reset_atoms_data()
361  {
362  for (cvm::atom_iter ai = atoms.begin(); ai != atoms.end(); ai++)
363  ai->reset_data();
364  if (fitting_group)
365  fitting_group->reset_atoms_data();
366  }
367 
369  int calc_required_properties();
370 
372  std::vector<cvm::atom_pos> positions() const;
373 
376  int calc_center_of_geometry();
377 
378 private:
379 
381  cvm::atom_pos cog;
382 
384  cvm::atom_pos cog_orig;
385 
386 public:
387 
390  {
391  return cog;
392  }
393 
396  int calc_center_of_mass();
397 private:
399  cvm::atom_pos com;
401  // TODO for scalable calculations of more complex variables (e.g. rotation),
402  // use a colvarvalue of vectors to hold the entire derivative
403  cvm::rvector scalar_com_gradient;
404 public:
407  {
408  return com;
409  }
410 
412  std::vector<cvm::atom_pos> positions_shifted(cvm::rvector const &shift) const;
413 
415  std::vector<cvm::rvector> velocities() const;
416 
418  int calc_dipole(cvm::atom_pos const &com);
419 private:
420  cvm::rvector dip;
421 public:
423  inline cvm::rvector dipole() const
424  {
425  return dip;
426  }
427 
429  std::vector<cvm::rvector> total_forces() const;
430 
432  cvm::rvector total_force() const;
433 
434 
438  void set_weighted_gradient(cvm::rvector const &grad);
439 
441  void calc_fit_gradients();
442 
444  std::vector<cvm::atom_pos> fit_gradients;
445 
458  void apply_colvar_force(cvm::real const &force);
459 
471  void apply_force(cvm::rvector const &force);
472 
476  void do_feature_side_effects(int id);
477 };
478 
479 
480 #endif
std::vector< int > atoms_ids
Array of atom identifiers for the MD program (0-based)
Definition: colvaratoms.h:224
atom()
Default constructor (sets index and id both to -1)
Definition: colvaratoms.cpp:9
cvm::real total_mass
Total mass of the atom group.
Definition: colvaratoms.h:320
void read_velocity()
Get the current velocity.
Definition: colvaratoms.h:112
bool b_center
When updating atomic coordinates, translate them to align with the center of mass of the reference co...
Definition: colvaratoms.h:289
std::string key
Keyword used to define the group.
Definition: colvaratoms.h:165
Stores numeric id, mass and all mutable data for an atom, mostly used by a cvc.
Definition: colvaratoms.h:21
bool noforce
Don&#39;t apply any force on this group (use its coordinates only to calculate a colvar) ...
Definition: colvaratoms.h:329
cvm::atom_pos center_of_geometry() const
Return the center of geometry of the atomic positions.
Definition: colvaratoms.h:389
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:590
std::vector< cvm::atom_pos > fit_gradients
Derivatives of the fitting transformation.
Definition: colvaratoms.h:444
cvm::real mass
Mass.
Definition: colvaratoms.h:34
void reset_data()
Set mutable data (everything except id and mass) to zero; update mass.
Definition: colvaratoms.h:87
vector of real numbers with three components
Definition: colvartypes.h:714
Colvars proxy classes.
cvm::rotation rot
The rotation calculated automatically if b_rotate is defined.
Definition: colvaratoms.h:300
static std::vector< feature * > ag_features
Implementation of the feature list for atom group.
Definition: colvaratoms.h:200
int index
Index in the colvarproxy arrays (if the group is scalable)
Definition: colvaratoms.h:230
Collective variables main module.
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:76
int index
Index in the colvarproxy arrays (NOT in the global topology!)
Definition: colvaratoms.h:26
rvector atom_pos
Atom position (different type name from rvector, to make possible future PBC-transparent implementati...
Definition: colvarmodule.h:99
cvm::real total_charge
Total charge of the atom group.
Definition: colvaratoms.h:324
cvm::rvector grad
Gradient of a scalar collective variable with respect to this atom.
Definition: colvaratoms.h:61
cvm::atom_pos ref_pos_cog
Center of geometry of the reference coordinates; regardless of whether b_center is true...
Definition: colvaratoms.h:313
bool b_user_defined_fit
Indicates that the user has explicitly set centerReference or rotateReference, and the corresponding ...
Definition: colvaratoms.h:305
cvm::atom_pos center_of_mass() const
Return the center of mass of the atomic positions.
Definition: colvaratoms.h:406
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:317
cvm::rvector vel
Current velocity (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:45
int id
Identifier for the MD program (0-based)
Definition: colvaratoms.h:31
~atom()
Destructor.
Definition: colvaratoms.cpp:56
cvm::real charge
Charge.
Definition: colvaratoms.h:37
void reset_atoms_data()
Call reset_data() for each atom.
Definition: colvaratoms.h:360
size_t size() const
How many objects are configured yet?
Definition: colvarmodule.cpp:109
void read_total_force()
Get the total force.
Definition: colvaratoms.h:118
int residue_id
Residue identifier.
Definition: colvarmodule.h:93
std::vector< int > sorted_ids
Definition: colvaratoms.h:278
cvm::rvector dipole() const
Return the (previously calculated) dipole of the atom group.
Definition: colvaratoms.h:423
int setup()
Definition: colvarmodule.cpp:1000
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:23
void update_charge()
Get the latest value of the charge.
Definition: colvaratoms.h:100
virtual const std::vector< feature * > & features()
Implementation of the feature list accessor for atom group.
Definition: colvaratoms.h:203
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:274
cvm::atom_pos pos
Current position (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:41
cvm::atom_pos dummy_atom_pos
Dummy atom position.
Definition: colvaratoms.h:227
bool b_rotate
When updating atom coordinates (and after centering them if b_center is set), rotate the group to ali...
Definition: colvaratoms.h:298
Parsing functions for collective variables.
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:308
A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion) ...
Definition: colvartypes.h:1369
void read_position()
Get the current position.
Definition: colvaratoms.h:106
colvarparse * parse
Configuration file parser object.
Definition: colvarmodule.h:543
std::vector< cvm::atom > atoms
Array of atom objects.
Definition: colvaratoms.h:221
void update_mass()
Get the latest value of the mass.
Definition: colvaratoms.h:94
void apply_force(cvm::rvector const &new_force) const
Apply a force to the atom.
Definition: colvaratoms.h:132
cvm::rvector total_force
System force at the previous step (copied from the program, can be modified if necessary) ...
Definition: colvaratoms.h:49
std::string name
Optional name to reuse properties of this in other groups.
Definition: colvaratoms.h:161
Group of atom objects, mostly used by a cvc object to gather all atomic data.
Definition: colvaratoms.h:142