Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvardeps.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 COLVARDEPS_H
11#define COLVARDEPS_H
12
13#include "colvarmodule.h"
14#include "colvarparse.h"
15
34class colvardeps : public colvarparse {
35public:
36
37 colvardeps ();
38 colvardeps(colvarmodule *cvmodule_in);
39 virtual ~colvardeps();
40
41 // Subclasses should initialize the following members:
42
43 std::string description; // reference to object name (cv, cvc etc.)
44
46 // since the feature class only contains static properties
48 feature_state(bool a, bool e)
49 : available(a), enabled(e), ref_count(0) {}
50
56 bool enabled; // see if this should be private depending on implementation
57
58 // bool enabledOnce; // this should trigger an update when object is evaluated
59
69 std::vector<int> alternate_refs;
70 };
71
72protected:
79
81 std::vector<feature_state> feature_states;
82
85 f_type_not_set,
86 f_type_dynamic,
87 f_type_user,
88 f_type_static
89 };
90
91public:
93 inline int get_time_step_factor() const {return time_step_factor;}
94
96 void init_feature(int feature_id, const char *description, feature_type type);
97
100 class feature {
101
102 public:
103 feature() : type(f_type_not_set) {}
104 ~feature() {}
105
106 std::string description; // Set by derived object initializer
107
108 // features that this feature requires in the same object
109 // 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)
110 std::vector<int> requires_self;
111
112 // Features that are incompatible, ie. required disabled
113 // if enabled, they will cause a dependency failure (they will not be disabled)
114 // To enforce these dependencies regardless of the order in which they
115 // are enabled, they are always set in a symmetric way, so whichever is enabled
116 // second will cause the dependency to fail
117 std::vector<int> requires_exclude;
118
119 // sets of features that are required in an alternate way
120 // when parent feature is enabled, if none are enabled, the first one listed that is available will be enabled
121 std::vector<std::vector<int> > requires_alt;
122
123 // features that this feature requires in children
124 std::vector<int> requires_children;
125
126 inline bool is_dynamic() { return type == f_type_dynamic; }
127 inline bool is_static() { return type == f_type_static; }
128 inline bool is_user() { return type == f_type_user; }
131 };
132
133 inline bool is_not_set(int id) { return features()[id]->type == f_type_not_set; }
134 inline bool is_dynamic(int id) { return features()[id]->type == f_type_dynamic; }
135 inline bool is_static(int id) { return features()[id]->type == f_type_static; }
136 inline bool is_user(int id) { return features()[id]->type == f_type_user; }
137
138 // Accessor to array of all features with deps, static in most derived classes
139 // Subclasses with dynamic dependency trees may override this
140 // with a non-static array
141 // Intermediate classes (colvarbias and colvarcomp, which are also base classes)
142 // implement this as virtual to allow overriding
143 virtual const std::vector<feature *> &features() const = 0;
144 virtual std::vector<feature *>&modify_features() = 0;
145
146 void add_child(colvardeps *child);
147
148 void remove_child(colvardeps *child);
149
152 void remove_all_children();
153
154private:
155
159 std::vector<colvardeps *> children;
160
163 std::vector<colvardeps *> parents;
164
165public:
166 // Checks whether given feature is enabled
167 // Defaults to querying f_*_active
168 inline bool is_enabled(int f = f_cv_active) const {
169 return feature_states[f].enabled;
170 }
171
172 // Checks whether given feature is available
173 // Defaults to querying f_*_active
174 inline bool is_available(int f = f_cv_active) const {
175 return feature_states[f].available;
176 }
177
181 void provide(int feature_id, bool truefalse = true);
182
184 void set_enabled(int feature_id, bool truefalse = true);
185
186protected:
187
190 std::string const &conf, char const *key,
191 int feature_id, bool const &def_value,
193
194public:
195
204 int enable(int f, bool dry_run = false, bool toplevel = true, bool error = false);
205
208 int disable(int f);
209
213 void free_children_deps();
214
217
220 int decr_ref_count(int f);
221
225 virtual void do_feature_side_effects(int /* id */) {}
226
227 // NOTE that all feature enums should start with f_*_active
263 f_cvb_ntot
264 };
265
352 f_cv_linear,
353 f_cv_homogeneous,
358 };
359
402 };
403
405 f_ag_active,
406 f_ag_center,
407 f_ag_center_origin,
408 f_ag_rotate,
409 f_ag_fitting_group,
412// f_ag_min_msd_fit,
415 f_ag_fit_gradients,
416 f_ag_atom_forces,
417 f_ag_scalable,
418 f_ag_scalable_com,
421 f_ag_ntot
422 };
423
425 virtual int init_dependencies() = 0;
426
428 void require_feature_self(int f, int g);
429
431 void exclude_feature_self(int f, int g);
432
434 void require_feature_children(int f, int g);
435
437 void require_feature_alt(int f, int g, int h);
438
440 void require_feature_alt(int f, int g, int h, int i);
441
443 void require_feature_alt(int f, int g, int h, int i, int j);
444
446 void print_state();
447
449 std::vector<colvardeps *> get_parents() const {return parents;}
450
452 std::vector<colvardeps *> get_children() const {return children;}
453
454};
455
456#endif
457
458
Definition: colvardeps.h:100
feature_type type
Type of this feature, from the enum feature_type.
Definition: colvardeps.h:130
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
void init_feature(int feature_id, const char *description, feature_type type)
Pair a numerical feature ID with a description and type.
Definition: colvardeps.cpp:407
virtual void do_feature_side_effects(int)
Definition: colvardeps.h:225
void require_feature_alt(int f, int g, int h)
Make feature f require either g or h within the same object.
Definition: colvardeps.cpp:431
std::vector< colvardeps * > children
Definition: colvardeps.h:159
features_cvc
Definition: colvardeps.h:360
@ f_cvc_scalar
This CVC computes a scalar value.
Definition: colvardeps.h:364
@ f_cvc_pbc_minimum_image
Definition: colvardeps.h:389
@ f_cvc_active
Computation of this CVC is enabled.
Definition: colvardeps.h:362
@ f_cvc_ntot
Number of CVC features.
Definition: colvardeps.h:401
@ f_cvc_explicit_gradient
CVC calculates and stores explicit atom gradients on rank 0.
Definition: colvardeps.h:378
@ f_cvc_gradient
CVC calculates atom gradients.
Definition: colvardeps.h:376
@ f_cvc_Jacobian
CVC calculates the Jacobian term of the total-force expression.
Definition: colvardeps.h:382
@ f_cvc_scalable
This CVC can be computed in parallel.
Definition: colvardeps.h:393
@ f_cvc_one_site_total_force
The total force for this CVC will be computed from one group only.
Definition: colvardeps.h:384
@ f_cvc_com_based
This CVC is a function of centers of mass.
Definition: colvardeps.h:391
@ f_cvc_periodic
Values of this CVC lie in a periodic interval.
Definition: colvardeps.h:366
@ f_cvc_debug_gradient
calc_gradients() will call debug_gradients() for every group needed
Definition: colvardeps.h:386
@ f_cvc_inv_gradient
CVC calculates and stores inverse atom gradients (used for total force)
Definition: colvardeps.h:380
@ f_cvc_lower_boundary
This CVC provides a default value for the colvar's lower boundary.
Definition: colvardeps.h:370
@ f_cvc_explicit_atom_groups
CVC accesses atom groups directly (as opposed to going throuh other objects)
Definition: colvardeps.h:374
@ f_cvc_require_cpu_buffers
This CVC requires CPU buffers.
Definition: colvardeps.h:399
@ f_cvc_width
This CVC provides a default value for the colvar's width.
Definition: colvardeps.h:368
@ f_cvc_upper_boundary
This CVC provides a default value for the colvar's upper boundary.
Definition: colvardeps.h:372
@ f_cvc_scalable_com
Centers-of-mass used in this CVC can be computed in parallel.
Definition: colvardeps.h:395
@ f_cvc_collect_atom_ids
Build list of atoms involved in CVC calculation.
Definition: colvardeps.h:397
int disable(int f)
Definition: colvardeps.cpp:318
feature_type
Enum of possible feature types.
Definition: colvardeps.h:84
virtual int init_dependencies()=0
Initialize dependency tree for object of a derived class.
std::vector< colvardeps * > get_parents() const
Return the parents.
Definition: colvardeps.h:449
features_atomgroup
Definition: colvardeps.h:404
@ f_ag_explicit_gradient
Does not have explicit atom gradients from parent CVC.
Definition: colvardeps.h:414
@ f_ag_collect_atom_ids
Build list of atoms involved in atom group.
Definition: colvardeps.h:420
int decr_ref_count(int f)
Definition: colvardeps.cpp:381
int get_time_step_factor() const
returns time_step_factor
Definition: colvardeps.h:93
int enable(int f, bool dry_run=false, bool toplevel=true, bool error=false)
Definition: colvardeps.cpp:132
void require_feature_self(int f, int g)
Make feature f require feature g within the same object.
Definition: colvardeps.cpp:414
std::vector< colvardeps * > get_children() const
Return the children.
Definition: colvardeps.h:452
void require_feature_children(int f, int g)
Make feature f require feature g within children.
Definition: colvardeps.cpp:426
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:114
void set_enabled(int feature_id, bool truefalse=true)
Enable or disable, depending on flag value.
Definition: colvardeps.cpp:105
void exclude_feature_self(int f, int g)
Make features f and g mutually exclusive within the same object.
Definition: colvardeps.cpp:420
features_biases
Definition: colvardeps.h:228
@ f_cvb_apply_force
will apply forces
Definition: colvardeps.h:236
@ f_cvb_scale_biasing_force
whether this bias uses an external grid to scale the biasing forces
Definition: colvardeps.h:258
@ f_cvb_calc_pmf
whether this bias will compute a PMF
Definition: colvardeps.h:250
@ f_cvb_time_dependent
depends on time
Definition: colvardeps.h:246
@ f_cvb_history_dependent
depends on simulation history
Definition: colvardeps.h:244
@ f_cvb_calc_ti_samples
whether this bias will compute TI samples
Definition: colvardeps.h:252
@ f_cvb_extended
whether this bias is applied to one or more ext-Lagrangian colvars
Definition: colvardeps.h:260
@ f_cvb_awake
Bias is awake (active on its own accord) this timestep.
Definition: colvardeps.h:232
@ f_cvb_get_total_force
requires total forces
Definition: colvardeps.h:240
@ f_cvb_write_ti_pmf
whether this bias should write the TI PMF
Definition: colvardeps.h:256
@ f_cvb_step_zero_data
Accumulates data starting from step 0 of a simulation run.
Definition: colvardeps.h:234
@ f_cvb_smp
Process this bias's data in parallel over multiple CPU threads.
Definition: colvardeps.h:262
@ f_cvb_bypass_ext_lagrangian
force this bias to act on actual value for extended-Lagrangian coordinates
Definition: colvardeps.h:238
@ f_cvb_active
Bias is active.
Definition: colvardeps.h:230
@ f_cvb_scalar_variables
requires scalar colvars
Definition: colvardeps.h:248
@ f_cvb_write_ti_samples
whether this bias will write TI samples
Definition: colvardeps.h:254
@ f_cvb_output_acc_work
whether this bias should record the accumulated work
Definition: colvardeps.h:242
std::vector< feature_state > feature_states
List of the states of all features.
Definition: colvardeps.h:81
std::vector< colvardeps * > parents
Definition: colvardeps.h:163
void restore_children_deps()
re-enable children features (to be used when object becomes active)
Definition: colvardeps.cpp:78
void provide(int feature_id, bool truefalse=true)
Definition: colvardeps.cpp:98
features_colvar
Definition: colvardeps.h:266
@ f_cv_Jacobian
Estimate Jacobian derivative.
Definition: colvardeps.h:295
@ f_cv_ntot
Number of colvar features.
Definition: colvardeps.h:357
@ f_cv_total_force
The total force is calculated, projecting the atomic forces on the inverse gradient.
Definition: colvardeps.h:286
@ f_cv_extended_Lagrangian
The variable has a harmonic restraint around a moving center with fictitious mass; bias forces will b...
Definition: colvardeps.h:302
@ f_cv_upper_boundary
An upper boundary is defined.
Definition: colvardeps.h:325
@ f_cv_subtract_applied_force
Subtract the applied force from the total force.
Definition: colvardeps.h:293
@ f_cv_collect_gradient
Collect atomic gradient data from all cvcs into vector atomic_gradient.
Definition: colvardeps.h:279
@ f_cv_hard_lower_boundary
The lower boundary is not defined from user's choice.
Definition: colvardeps.h:327
@ f_cv_runave
Compute running average.
Definition: colvardeps.h:339
@ f_cv_output_total_force
Output the total force to the trajectory file.
Definition: colvardeps.h:321
@ f_cv_hard_upper_boundary
The upper boundary is not defined from user's choice.
Definition: colvardeps.h:329
@ f_cv_gradient
Gradients are calculated and temporarily stored, so that external forces can be propagated to atoms.
Definition: colvardeps.h:276
@ f_cv_periodic
Colvar is periodic.
Definition: colvardeps.h:347
@ f_cv_corrfunc
Compute time correlation function.
Definition: colvardeps.h:341
@ f_cv_total_force_current_step
Total force is that of current time step.
Definition: colvardeps.h:291
@ f_cv_reflecting_upper_boundary
Reflecting upper boundary condition.
Definition: colvardeps.h:333
@ f_cv_total_force_calc
Calculate total force from atomic forces or get it from the back-end for an external parameter.
Definition: colvardeps.h:289
@ f_cv_reflecting_lower_boundary
Reflecting lower boundary condition.
Definition: colvardeps.h:331
@ f_cv_single_cvc
The colvar has only one component.
Definition: colvardeps.h:349
@ f_cv_awake
Colvar is awake (active on its own accord) this timestep.
Definition: colvardeps.h:270
@ f_cv_Langevin
The extended system coordinate undergoes Langevin dynamics.
Definition: colvardeps.h:310
@ f_cv_multiple_ts
multiple timestep through time_step_factor
Definition: colvardeps.h:355
@ f_cv_scripted
Value and gradient computed by user script.
Definition: colvardeps.h:343
@ f_cv_collect_atom_ids
Build list of atoms involved in CV calculation.
Definition: colvardeps.h:281
@ f_cv_grid
Provide a discretization of the values of the colvar to be used by the biases or in analysis (needs l...
Definition: colvardeps.h:337
@ f_cv_apply_force
External force can be applied, either to atoms or to an extended DOF.
Definition: colvardeps.h:273
@ f_cv_custom_function
Value and gradient computed by user function through Lepton.
Definition: colvardeps.h:345
@ f_cv_output_velocity
Output the velocity to the trajectory file.
Definition: colvardeps.h:317
@ f_cv_scalar
is scalar
Definition: colvardeps.h:351
@ f_cv_active
Calculate colvar.
Definition: colvardeps.h:268
@ f_cv_output_value
Output the value to the trajectory file (on by default)
Definition: colvardeps.h:315
@ f_cv_fdiff_velocity
Calculate the velocity with finite differences.
Definition: colvardeps.h:283
@ f_cv_external
A variable that constrains or follows an external parameter in the back-end (eg. an alchemical coupli...
Definition: colvardeps.h:308
@ f_cv_output_applied_force
Output the applied force to the trajectory file.
Definition: colvardeps.h:319
@ f_cv_lower_boundary
A lower boundary is defined.
Definition: colvardeps.h:323
@ f_cv_hide_Jacobian
Do not report the Jacobian force as part of the total force instead, apply a correction internally to...
Definition: colvardeps.h:298
@ f_cv_output_energy
Output the potential and kinetic energies (for extended Lagrangian colvars only)
Definition: colvardeps.h:313
void free_children_deps()
Definition: colvardeps.cpp:48
int time_step_factor
Definition: colvardeps.h:78
void remove_all_children()
Definition: colvardeps.cpp:526
void print_state()
print all enabled features and those of children, for debugging
Definition: colvardeps.cpp:455
Collective variables module (main class)
Definition: colvarmodule.h:72
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
Parse_Mode
How a keyword is parsed in a string.
Definition: colvarparse.h:63
@ parse_normal
Alias for old default behavior (should be phased out)
Definition: colvarparse.h:82
Collective variables main module.
Parsing functions for collective variables.
This contains the current state of each feature for each object.
Definition: colvardeps.h:47
int ref_count
Definition: colvardeps.h:64
bool enabled
Definition: colvardeps.h:56
bool available
Feature may be enabled, subject to possible dependencies.
Definition: colvardeps.h:52
std::vector< int > alternate_refs
Definition: colvardeps.h:69