Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
colvardeps.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARDEPS_H
4 #define COLVARDEPS_H
5 
6 #include "colvarmodule.h"
7 #include "colvarparse.h"
8 
19 class colvardeps {
20 public:
21 
22  colvardeps() {}
23  virtual ~colvardeps();
24 
25  // Subclasses should initialize the following members:
26 
27  std::string description; // reference to object name (cv, cvc etc.)
28 
30  struct feature_state {
31  feature_state(bool a, bool e)
32  : available(a), enabled(e) {}
33 
35  bool available;
39  bool enabled; // see if this should be private depending on implementation
40  // bool enabledOnce; // this should trigger an update when object is evaluated
41  };
42 
43 
44 private:
46  std::vector<feature_state> feature_states;
47 
49  enum feature_type {
50  f_type_not_set,
51  f_type_dynamic,
52  f_type_user,
53  f_type_static
54  };
55 
56 public:
58  void init_feature(int feature_id, const char *description, feature_type type = f_type_not_set);
59 
62  class feature {
63 
64  public:
65  feature() {}
66  ~feature() {}
67 
68  std::string description; // Set by derived object initializer
69 
70  // features that this feature requires in the same object
71  // 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)
72  std::vector<int> requires_self;
73 
74  // Features that are incompatible, ie. required disabled
75  // if enabled, they will cause a dependency failure (they will not be disabled)
76  // To enforce these dependencies regardless of the order in which they
77  // are enabled, they are always set in a symmetric way, so whichever is enabled
78  // second will cause the dependency to fail
79  std::vector<int> requires_exclude;
80 
81  // sets of features that are required in an alternate way
82  // when parent feature is enabled, if none are enabled, the first one listed that is available will be enabled
83  std::vector<std::vector<int> > requires_alt;
84 
85  // features that this feature requires in children
86  std::vector<int> requires_children;
87 
88  inline bool is_dynamic() { return type == f_type_dynamic; }
89  inline bool is_static() { return type == f_type_static; }
90  inline bool is_user() { return type == f_type_user; }
92  feature_type type;
93  };
94 
95  inline bool is_dynamic(int id) { return features()[id]->type == f_type_dynamic; }
96  inline bool is_static(int id) { return features()[id]->type == f_type_static; }
97  inline bool is_user(int id) { return features()[id]->type == f_type_user; }
98 
99  // Accessor to array of all features with deps, static in most derived classes
100  // Subclasses with dynamic dependency trees may override this
101  // with a non-static array
102  // Intermediate classes (colvarbias and colvarcomp, which are also base classes)
103  // implement this as virtual to allow overriding
104  virtual std::vector<feature *>&features() = 0;
105 
106  void add_child(colvardeps *child);
107 
108  void remove_child(colvardeps *child);
109 
112  void remove_all_children();
113 
114 private:
115 
116  // pointers to objects this object depends on
117  // list should be maintained by any code that modifies the object
118  // this could be secured by making lists of colvars / cvcs / atom groups private and modified through accessor functions
119  std::vector<colvardeps *> children;
120 
121  // pointers to objects that depend on this object
122  // the size of this array is in effect a reference counter
123  std::vector<colvardeps *> parents;
124 
125 public:
126  // disabling a feature f:
127  // if parents depend on f, tell them to refresh / check that they are ok?
128  // if children provide features to satisfy f ONLY, disable that
129 
130  // When the state of this object has changed, recursively tell parents
131  // to enforce their dependencies
132 // void refresh_parents() {
133 //
134 // }
135 
136  // std::vector<colvardeps *> parents; // Needed to trigger a refresh if capabilities of this object change
137 
138  // End of members to be initialized by subclasses
139 
140  // Checks whether given feature is enabled
141  // Defaults to querying f_*_active
142  inline bool is_enabled(int f = f_cv_active) const {
143  return feature_states[f].enabled;
144  }
145 
146  // Checks whether given feature is available
147  // Defaults to querying f_*_active
148  inline bool is_available(int f = f_cv_active) const {
149  return feature_states[f].available;
150  }
151 
155  void provide(int feature_id, bool truefalse = true);
156 
160  void set_enabled(int feature_id, bool truefalse = true);
161 
162 protected:
163 
164 
165 
168  std::string const &conf, char const *key,
169  int feature_id, bool const &def_value,
171 
172 public:
173 
174  int enable(int f, bool dry_run = false, bool toplevel = true); // enable a feature and recursively solve its dependencies
175  // dry_run is set to true to recursively test if a feature is available, without enabling it
176 // int disable(int f);
177 
178 
182  virtual int refresh_deps() { return COLVARS_OK; }
183 
184  // NOTE that all feature enums should start with f_*_active
188  f_cvb_apply_force, // will apply forces
189  f_cvb_get_total_force, // requires total forces
190  f_cvb_history_dependent, // depends on simulation history
191  f_cvb_scalar_variables, // requires scalar colvars
192  f_cvb_calc_pmf, // whether this bias will compute a PMF
193  f_cvb_ntot
194  };
195 
254  f_cv_linear,
255  f_cv_homogeneous,
258  };
259 
261  f_cvc_active,
262  f_cvc_scalar,
263  f_cvc_gradient,
264  f_cvc_inv_gradient,
267  f_cvc_Jacobian,
268  f_cvc_one_site_total_force,
269  f_cvc_com_based,
270  f_cvc_scalable,
271  f_cvc_scalable_com,
272  f_cvc_ntot
273  };
274 
276  f_ag_active,
277  f_ag_center,
278  f_ag_rotate,
279  f_ag_fitting_group,
282 // f_ag_min_msd_fit,
283  f_ag_fit_gradient_group,// TODO check that these are sometimes needed separately
284  // maybe for minimum RMSD?
285  f_ag_fit_gradient_ref,
286  f_ag_atom_forces,
287  f_ag_scalable,
288  f_ag_scalable_com,
289  f_ag_ntot
290  };
291 
292  void init_cvb_requires();
293  void init_cv_requires();
294  void init_cvc_requires();
295  void init_ag_requires();
296 
298  void print_state();
299 };
300 
301 #endif
302 
303 
Gradients are calculated and temporarily stored, so that external forces can be applied.
Definition: colvardeps.h:201
features_biases
Definition: colvardeps.h:185
Definition: colvardeps.h:62
Calculate total force from atomic forces.
Definition: colvardeps.h:211
features_atomgroup
Definition: colvardeps.h:275
bool enabled
Definition: colvardeps.h:39
Colvar is periodic.
Definition: colvardeps.h:251
Calculate the velocity with finite differences.
Definition: colvardeps.h:206
void provide(int feature_id, bool truefalse=true)
Definition: colvardeps.cpp:27
bool available
Feature may be enabled, subject to possible dependencies.
Definition: colvardeps.h:35
Provide a discretization of the values of the colvar to be used by the biases or in analysis (needs l...
Definition: colvardeps.h:243
Output the potential and kinetic energies (for extended Lagrangian colvars only)
Definition: colvardeps.h:227
The total force is calculated, projecting the atomic forces on the inverse gradient.
Definition: colvardeps.h:209
An upper boundary is defined.
Definition: colvardeps.h:239
A lower boundary is defined.
Definition: colvardeps.h:237
is scalar
Definition: colvardeps.h:253
Collective variables main module.
Output the total force to the trajectory file.
Definition: colvardeps.h:235
The extended system coordinate undergoes Langevin dynamics.
Definition: colvardeps.h:224
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:213
The variable has a harmonic restraint around a moving center with fictitious mass; bias forces will b...
Definition: colvardeps.h:222
Compute time correlation function.
Definition: colvardeps.h:247
Subtract the applied force from the total force.
Definition: colvardeps.h:213
Calculate colvar.
Definition: colvardeps.h:198
Do not report the Jacobian force as part of the total force instead, apply a correction internally to...
Definition: colvardeps.h:218
Collect atomic gradient data from all cvcs into vector atomic_gradient.
Definition: colvardeps.h:204
Bias is active.
Definition: colvardeps.h:187
Output the value to the trajectory file (on by default)
Definition: colvardeps.h:229
(default) Read the first instance of a keyword (if any), report its value, and print a warning when t...
Definition: colvarparse.h:96
features_colvar
Definition: colvardeps.h:196
virtual int refresh_deps()
Definition: colvardeps.h:182
If enabled, calc_gradients() will call debug_gradients() for every group needed.
Definition: colvardeps.h:266
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:19
void remove_all_children()
Definition: colvardeps.cpp:543
features_cvc
Definition: colvardeps.h:260
Estimate Jacobian derivative.
Definition: colvardeps.h:215
Output the applied force to the trajectory file.
Definition: colvardeps.h:233
void set_enabled(int feature_id, bool truefalse=true)
Definition: colvardeps.cpp:32
This contains the current state of each feature for each object.
Definition: colvardeps.h:30
Parse_Mode
How a keyword is parsed in a string.
Definition: colvarparse.h:92
Compute running average.
Definition: colvardeps.h:245
Parsing functions for collective variables.
Base class containing parsing functions; all objects which need to parse input inherit from this...
Definition: colvarparse.h:18
void print_state()
print all enabled features and those of children, for debugging
Definition: colvardeps.cpp:492
Definition: colvardeps.h:283
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:46
Output the velocity to the trajectory file.
Definition: colvardeps.h:231
Number of colvar features.
Definition: colvardeps.h:257
feature_type type
Type of this feature, from the enum feature_type.
Definition: colvardeps.h:92
Value and gradient computed by user script.
Definition: colvardeps.h:249