Collective Variables Module - Developer Documentation
1 // -*- c++ -*-
3 #ifndef COLVARDEPS_H
4 #define COLVARDEPS_H
6 #include "colvarmodule.h"
7 #include "colvarparse.h"
23 class colvardeps {
24 public:
26  colvardeps();
27  virtual ~colvardeps();
29  // Subclasses should initialize the following members:
31  std::string description; // reference to object name (cv, cvc etc.)
34  // since the feature class only contains static properties
35  struct feature_state {
36  feature_state(bool a, bool e)
37  : available(a), enabled(e), ref_count(0) {}
40  bool available;
44  bool enabled; // see if this should be private depending on implementation
46  // bool enabledOnce; // this should trigger an update when object is evaluated
52  int ref_count;
57  std::vector<int> alternate_refs;
58  };
60 protected:
68 private:
70  std::vector<feature_state> feature_states;
73  enum feature_type {
74  f_type_not_set,
75  f_type_dynamic,
76  f_type_user,
77  f_type_static
78  };
80 public:
82  inline int get_time_step_factor() const {return time_step_factor;}
85  void init_feature(int feature_id, const char *description, feature_type type = f_type_not_set);
89  class feature {
91  public:
92  feature() {}
93  ~feature() {}
95  std::string description; // Set by derived object initializer
97  // features that this feature requires in the same object
98  // NOTE: we have no safety mechanism against circular dependencies, however, they would have to be internal to an object (ie. requires_self or requires_alt)
99  std::vector<int> requires_self;
101  // Features that are incompatible, ie. required disabled
102  // if enabled, they will cause a dependency failure (they will not be disabled)
103  // To enforce these dependencies regardless of the order in which they
104  // are enabled, they are always set in a symmetric way, so whichever is enabled
105  // second will cause the dependency to fail
106  std::vector<int> requires_exclude;
108  // sets of features that are required in an alternate way
109  // when parent feature is enabled, if none are enabled, the first one listed that is available will be enabled
110  std::vector<std::vector<int> > requires_alt;
112  // features that this feature requires in children
113  std::vector<int> requires_children;
115  inline bool is_dynamic() { return type == f_type_dynamic; }
116  inline bool is_static() { return type == f_type_static; }
117  inline bool is_user() { return type == f_type_user; }
119  feature_type type;
120  };
122  inline bool is_dynamic(int id) { return features()[id]->type == f_type_dynamic; }
123  inline bool is_static(int id) { return features()[id]->type == f_type_static; }
124  inline bool is_user(int id) { return features()[id]->type == f_type_user; }
126  // Accessor to array of all features with deps, static in most derived classes
127  // Subclasses with dynamic dependency trees may override this
128  // with a non-static array
129  // Intermediate classes (colvarbias and colvarcomp, which are also base classes)
130  // implement this as virtual to allow overriding
131  virtual const std::vector<feature *>&features() = 0;
132  virtual std::vector<feature *>&modify_features() = 0;
134  void add_child(colvardeps *child);
136  void remove_child(colvardeps *child);
140  void remove_all_children();
142 private:
147  std::vector<colvardeps *> children;
151  std::vector<colvardeps *> parents;
153 public:
154  // Checks whether given feature is enabled
155  // Defaults to querying f_*_active
156  inline bool is_enabled(int f = f_cv_active) const {
157  return feature_states[f].enabled;
158  }
160  // Checks whether given feature is available
161  // Defaults to querying f_*_active
162  inline bool is_available(int f = f_cv_active) const {
163  return feature_states[f].available;
164  }
169  void provide(int feature_id, bool truefalse = true);
172  void set_enabled(int feature_id, bool truefalse = true);
174 protected:
178  std::string const &conf, char const *key,
179  int feature_id, bool const &def_value,
182 public:
188  int enable(int f, bool dry_run = false, bool toplevel = true);
192  int disable(int f);
197  void free_children_deps();
200  void restore_children_deps();
204  int decr_ref_count(int f);
209  virtual void do_feature_side_effects(int id) {}
211  // NOTE that all feature enums should start with f_*_active
235  f_cvb_ntot
236  };
300  f_cv_linear,
301  f_cv_homogeneous,
306  };
309  f_cvc_active,
310  f_cvc_scalar,
311  f_cvc_gradient,
314  f_cvc_inv_gradient,
317  f_cvc_Jacobian,
318  f_cvc_pbc_minimum_image,
319  f_cvc_one_site_total_force,
320  f_cvc_com_based,
321  f_cvc_scalable,
322  f_cvc_scalable_com,
323  f_cvc_ntot
324  };
327  f_ag_active,
328  f_ag_center,
329  f_ag_rotate,
330  f_ag_fitting_group,
333 // f_ag_min_msd_fit,
336  f_ag_fit_gradients,
337  f_ag_atom_forces,
338  f_ag_scalable,
339  f_ag_scalable_com,
340  f_ag_ntot
341  };
343  void init_cvb_requires();
344  void init_cv_requires();
345  void init_cvc_requires();
346  void init_ag_requires();
349  void print_state();
350 };
352 #endif
Does not have explicit atom gradients from parent CVC.
Definition: colvardeps.h:335
int disable(int f)
Definition: colvardeps.cpp:288
CVC doesn&#39;t calculate and store explicit atom gradients.
Definition: colvardeps.h:313
Colvar is awake (active on its own accord) this timestep.
Definition: colvardeps.h:242
Gradients are calculated and temporarily stored, so that external forces can be applied.
Definition: colvardeps.h:245
Definition: colvardeps.h:212
Definition: colvardeps.h:89
Calculate total force from atomic forces.
Definition: colvardeps.h:255
std::vector< int > alternate_refs
Definition: colvardeps.h:57
Definition: colvardeps.h:326
whether this bias will compute a PMF
Definition: colvardeps.h:228
int time_step_factor
Definition: colvardeps.h:66
bool enabled
Definition: colvardeps.h:44
Colvar is periodic.
Definition: colvardeps.h:297
Calculate the velocity with finite differences.
Definition: colvardeps.h:250
void provide(int feature_id, bool truefalse=true)
Definition: colvardeps.cpp:86
bool available
Feature may be enabled, subject to possible dependencies.
Definition: colvardeps.h:40
Provide a discretization of the values of the colvar to be used by the biases or in analysis (needs l...
Definition: colvardeps.h:287
depends on simulation history
Definition: colvardeps.h:222
requires scalar colvars
Definition: colvardeps.h:226
Output the potential and kinetic energies (for extended Lagrangian colvars only)
Definition: colvardeps.h:271
The total force is calculated, projecting the atomic forces on the inverse gradient.
Definition: colvardeps.h:253
An upper boundary is defined.
Definition: colvardeps.h:283
A lower boundary is defined.
Definition: colvardeps.h:281
is scalar
Definition: colvardeps.h:299
virtual void do_feature_side_effects(int id)
Definition: colvardeps.h:209
Collective variables main module.
void free_children_deps()
Definition: colvardeps.cpp:36
void restore_children_deps()
re-enable children features (to be used when object becomes active)
Definition: colvardeps.cpp:66
Output the total force to the trajectory file.
Definition: colvardeps.h:279
The extended system coordinate undergoes Langevin dynamics.
Definition: colvardeps.h:268
requires total forces
Definition: colvardeps.h:220
void init_feature(int feature_id, const char *description, feature_type type=f_type_not_set)
Pair a numerical feature ID with a description and type.
Definition: colvardeps.cpp:375
The variable has a harmonic restraint around a moving center with fictitious mass; bias forces will b...
Definition: colvardeps.h:266
int ref_count
Definition: colvardeps.h:52
Compute time correlation function.
Definition: colvardeps.h:291
depends on time
Definition: colvardeps.h:224
Subtract the applied force from the total force.
Definition: colvardeps.h:257
Calculate colvar.
Definition: colvardeps.h:240
multiple timestep through time_step_factor
Definition: colvardeps.h:303
Bias is awake (active on its own accord) this timestep.
Definition: colvardeps.h:216
Do not report the Jacobian force as part of the total force instead, apply a correction internally to...
Definition: colvardeps.h:262
Collect atomic gradient data from all cvcs into vector atomic_gradient.
Definition: colvardeps.h:248
Bias is active.
Definition: colvardeps.h:214
Output the value to the trajectory file (on by default)
Definition: colvardeps.h:273
(default) Read the first instance of a keyword (if any), report its value, and print a warning when t...
Definition: colvarparse.h:86
whether this bias will write TI samples
Definition: colvardeps.h:232
Definition: colvardeps.h:238
Value and gradient computed by user function through Lepton.
Definition: colvardeps.h:295
If enabled, calc_gradients() will call debug_gradients() for every group needed.
Definition: colvardeps.h:316
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:23
void remove_all_children()
Definition: colvardeps.cpp:759
Definition: colvardeps.h:308
whether this bias should write the TI PMF
Definition: colvardeps.h:234
whether this bias will compute TI samples
Definition: colvardeps.h:230
Estimate Jacobian derivative.
Definition: colvardeps.h:259
Output the applied force to the trajectory file.
Definition: colvardeps.h:277
void set_enabled(int feature_id, bool truefalse=true)
Enable or disable, depending on flag value.
Definition: colvardeps.cpp:91
This contains the current state of each feature for each object.
Definition: colvardeps.h:35
int decr_ref_count(int f)
Definition: colvardeps.cpp:350
How a keyword is parsed in a string.
Definition: colvarparse.h:82
Compute running average.
Definition: colvardeps.h:289
Parsing functions for collective variables.
int enable(int f, bool dry_run=false, bool toplevel=true)
Definition: colvardeps.cpp:116
Base class containing parsing functions; all objects which need to parse input inherit from this...
Definition: colvarparse.h:18
will apply forces
Definition: colvardeps.h:218
int get_time_step_factor() const
returns time_step_factor
Definition: colvardeps.h:82
void print_state()
print all enabled features and those of children, for debugging
Definition: colvardeps.cpp:690
bool get_keyval_feature(colvarparse *cvp, std::string const &conf, char const *key, int feature_id, bool const &def_value, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
Parse a keyword and enable a feature accordingly.
Definition: colvardeps.cpp:100
Output the velocity to the trajectory file.
Definition: colvardeps.h:275
Number of colvar features.
Definition: colvardeps.h:305
feature_type type
Type of this feature, from the enum feature_type.
Definition: colvardeps.h:119
Value and gradient computed by user script.
Definition: colvardeps.h:293