Collective Variables Module - Developer Documentation
colvar.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 COLVAR_H
11 #define COLVAR_H
12 
13 #include <functional>
14 #include <list>
15 #include <iosfwd>
16 #include <map>
17 #include <memory>
18 
19 #include "colvarmodule.h"
20 #include "colvarvalue.h"
21 #include "colvarparse.h"
22 #include "colvardeps.h"
23 
24 #ifdef LEPTON
25 #include "Lepton.h" // for runtime custom expressions
26 #endif
27 
52 
53 class colvar : public colvardeps {
54 
55 public:
56 
58  std::string name;
59 
61  colvarvalue const & value() const;
62 
64  colvarvalue const & actual_value() const;
65 
67  colvarvalue const & run_ave() const;
68 
70  cvm::real const & force_constant() const;
71 
73  colvarvalue const & velocity() const;
74 
83  colvarvalue const & total_force() const;
84 
94 
96  static std::vector<feature *> cv_features;
97 
99  virtual const std::vector<feature *> &features() const override
100  {
101  return cv_features;
102  }
103  virtual std::vector<feature *> &modify_features() override
104  {
105  return cv_features;
106  }
107  static void delete_features() {
108  for (size_t i=0; i < cv_features.size(); i++) {
109  delete cv_features[i];
110  }
111  cv_features.clear();
112  }
113 
117  void do_feature_side_effects(int id) override;
118 
120  std::vector<colvarbias *> biases;
121 
122 protected:
123 
124 
125  /*
126  extended:
127  H = H_{0} + \sum_{i} 1/2*\lambda*(S_i(x(t))-s_i(t))^2 \\
128  + \sum_{i} 1/2*m_i*(ds_i(t)/dt)^2 \\
129  + \sum_{t'<t} W * exp(-1/2*\sum_{i} (s_i(t')-s_i(t))^2/(\delta{}s_i)^2) \\
130  + \sum_{w} (\sum_{i}c_{w,i}s_i(t) - D_w)^M/(\Sigma_w)^M
131 
132  normal:
133  H = H_{0} + \sum_{t'<t} W * exp(-1/2*\sum_{i} (S_i(x(t'))-S_i(x(t)))^2/(\delta{}S_i)^2) \\
134  + \sum_{w} (\sum_{i}c_{w,i}S_i(t) - D_w)^M/(\Sigma_w)^M
135 
136  output:
137  H = H_{0} (only output S(x), no forces)
138 
139  Here:
140  S(x(t)) = x
141  s(t) = x_ext
142  DS = Ds = delta
143  */
144 
145 
148 
149  // TODO: implement functionality to treat these
150  // /// Vector of individual values from CVCs
151  // colvarvalue x_cvc;
152 
153  // /// Jacobian matrix of individual values from CVCs
154  // colvarvalue dx_cvc;
155 
158 
161 
162  inline colvarvalue fdiff_velocity(colvarvalue const &xold,
163  colvarvalue const &xnew)
164  {
165  // using the gradient of the square distance to calculate the
166  // velocity (non-scalar variables automatically taken into
167  // account)
168  cvm::real dt = cvmodule->dt();
169  return ( ( (dt > 0.0) ? (1.0/dt) : 1.0 ) *
170  0.5 * dist2_lgrad(xnew, xold) );
171  }
172 
175 
176  // Options for extended_lagrangian
193 
196 
199 
202 
203 public:
204 
205 
209 
212 
217 
220 
224 
227 
230 
233  bool expand_boundaries = false;
234 
237 
240 
242  bool periodic_boundaries() const;
243 
245  bool periodic_boundaries(colvarvalue const &lb, colvarvalue const &ub) const;
246 
247 
249  colvar(colvarmodule *cvmodule_in);
250 
252  int init(std::string const &conf);
253 
255  void define_component_types();
256 
258  int init_components(std::string const &conf);
259 
261  int init_custom_function(std::string const &conf);
262 
264  int init_grid_parameters(std::string const &conf);
265 
267  int check_grid_parameters();
268 
270  int parse_legacy_wall_params(std::string const &conf);
271 
273  int init_extended_Lagrangian(std::string const &conf);
274 
276  int init_output_flags(std::string const &conf);
277 
279  int init_dependencies() override;
280 
281 private:
282 
284  template <typename def_class_name>
285  void add_component_type(char const *description, char const *config_key);
286 
288  int init_components_type(const std::string &conf, const char *config_key);
289 
290 public:
291 
293  void setup();
294 
296  ~colvar();
297 
298 
300  int calc();
301 
303  int end_of_step();
304 
308  int calc_cvcs(int first = 0, size_t num_cvcs = 0);
309 
311  int check_cvc_range(int first_cvc, size_t num_cvcs);
312 
314  int calc_cvc_values(int first, size_t num_cvcs);
316  int calc_cvc_gradients(int first, size_t num_cvcs);
318  int calc_cvc_total_force(int first, size_t num_cvcs);
320  int calc_cvc_Jacobians(int first, size_t num_cvcs);
321 
323  int collect_cvc_data();
324 
326  int collect_cvc_values();
328  int collect_cvc_gradients();
332  int collect_cvc_Jacobians();
335 
337  inline colvarvalue const applied_force() const
338  {
339  if (is_enabled(f_cv_extended_Lagrangian)) {
340  return fr;
341  }
342  return f;
343  }
344 
346  void reset_bias_force();
347 
349  void add_bias_force(colvarvalue const &force);
350 
352  void add_bias_force_actual_value(colvarvalue const &force);
353 
359 
362 
365  void communicate_forces();
366 
368  int set_cvc_flags(std::vector<bool> const &flags);
369 
371  int update_cvc_flags();
372 
374  int update_cvc_config(std::vector<std::string> const &confs);
375 
377  int cvc_param_exists(std::string const &param_name);
378 
380  cvm::real get_cvc_param(std::string const &param_name);
381 
383  void const *get_cvc_param_ptr(std::string const &param_name);
384 
386  colvarvalue const *get_cvc_param_grad(std::string const &param_name);
387 
389  int set_cvc_param(std::string const &param_name, void const *new_value);
390 
391 protected:
392 
394  size_t n_active_cvcs = 0;
395 
398 
401 
404 
405 public:
406 
408  inline size_t num_dimensions() const
409  {
410  return value().size();
411  }
412 
414  inline size_t num_cvcs() const
415  {
416  return cvcs.size();
417  }
418 
421  inline size_t num_active_cvcs() const
422  {
423  return n_active_cvcs;
424  }
425 
430  cvm::real dist2(colvarvalue const &x1,
431  colvarvalue const &x2) const;
432 
438  colvarvalue const &x2) const;
439 
445  colvarvalue const &x2) const;
446 
451  void wrap(colvarvalue &x_unwrapped) const;
452 
454  int parse_analysis(std::string const &conf);
455 
457  int analyze();
458 
460  std::istream & read_traj(std::istream &is);
461 
463  std::ostream & write_traj(std::ostream &os);
465  std::ostream & write_traj_label(std::ostream &os);
466 
468  std::istream & read_state(std::istream &is);
469 
472 
474  int check_matching_state(std::string const &state_conf);
475 
477  int set_state_params(std::string const &state_conf);
478 
480  std::string const get_state_params() const;
481 
483  std::ostream & write_state(std::ostream &os) const;
484 
487 
489  int write_output_files();
490 
491 protected:
492 
495 
498 
501 
504 
507  std::list< std::list<colvarvalue> > acf_x_history, acf_v_history;
510  std::list< std::list<colvarvalue> >::iterator acf_x_history_p, acf_v_history_p;
511 
513  std::list< std::list<colvarvalue> > x_history;
516  std::list< std::list<colvarvalue> >::iterator x_history_p;
517 
520  std::string acf_colvar_name;
522  size_t acf_length;
524  size_t acf_offset;
526  size_t acf_stride;
528  size_t acf_nframes;
532  std::vector<cvm::real> acf;
534  std::string acf_outfile;
535 
537  enum acf_type_e {
546  acf_p2coor
547  };
548 
551 
553  void calc_vel_acf(std::list<colvarvalue> &v_history,
554  colvarvalue const &v);
555 
558  void calc_coor_acf(std::list<colvarvalue> &x_history,
559  colvarvalue const &x);
560 
563  void calc_p2coor_acf(std::list<colvarvalue> &x_history,
564  colvarvalue const &x);
565 
567  int calc_acf();
569  int write_acf(std::ostream &os);
570 
576  std::string runave_outfile;
581 
583  int calc_runave();
584 
589 
590 public:
591 
592  // collective variable component base class
593  class cvc;
594 
595  // list of available collective variable components
596 
597  // scalar colvar components
598  class distance;
599  class distance_z;
600  class distance_xy;
601  class polar_theta;
602  class polar_phi;
603  class distance_inv;
604  class distance_pairs;
605  class dipole_magnitude;
606  class angle;
607  class dipole_angle;
608  class dihedral;
609  class coordnum;
610  class selfcoordnum;
611  class groupcoordnum;
612  class h_bond;
613  class rmsd;
614  class orientation_angle;
615  class orientation_proj;
616  class tilt;
617  class spin_angle;
618  class gyration;
619  class inertia;
620  class inertia_z;
621  class eigenvector;
622  class alpha_dihedrals;
623  class alpha_angles;
624  class dihedPC;
625  class alch_lambda;
626  class alch_Flambda;
627  class CartesianBasedPath;
628  class aspath;
629  class azpath;
630  class gspath;
631  class gzpath;
632  class linearCombination;
633  class CVBasedPath;
634  class gspathCV;
635  class gzpathCV;
636  class aspathCV;
637  class azpathCV;
638  class euler_phi;
639  class euler_psi;
640  class euler_theta;
641  class neuralNetwork;
642  class torchANN;
643  class customColvar;
644 
645  // non-scalar components
646  class distance_vec;
647  class distance_dir;
648  class cartesian;
649  class orientation;
650 
651  // components that do not handle any atoms directly
652  class map_total;
653 
655  static const std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>> &get_global_cvc_map()
656  {
657  return global_cvc_map;
658  }
659 
661  static bool compare_cvc(const colvar::cvc* const i, const colvar::cvc* const j);
662 
664  const std::vector<std::shared_ptr<colvar::cvc>>& get_cvcs() const {
665  return cvcs;
666  }
667 
669  std::vector<std::shared_ptr<colvar::cvc>>& get_cvcs() {
670  return cvcs;
671  }
672 
673 protected:
674 
676  std::vector<std::shared_ptr<colvar::cvc>> cvcs;
677 
679  std::vector<bool> cvc_flags;
680 
683  void build_atom_list(void);
684 
686  std::string scripted_function;
687 
690  std::vector<const colvarvalue *> sorted_cvc_values;
691 
692 #ifdef LEPTON
694  std::vector<Lepton::CompiledExpression *> value_evaluators;
695 
697  std::vector<Lepton::CompiledExpression *> gradient_evaluators;
698 
700  std::vector<double *> value_eval_var_refs;
701  std::vector<double *> grad_eval_var_refs;
702 
704  double dev_null;
705 #endif
706 
708  static std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>> global_cvc_map;
709 
711  static std::map<std::string, std::string> global_cvc_desc_map;
712 
714  std::vector<int> volmap_ids_;
715 
716 public:
717 
719  std::vector<int> atom_ids;
720 
724  std::vector<cvm::rvector> atomic_gradients;
725 
727  virtual std::vector<std::vector<int> > get_atom_lists();
728 
730  std::vector<int> const &get_volmap_ids();
731 
732 };
733 
734 
735 inline cvm::real const & colvar::force_constant() const
736 {
737  return ext_force_k;
738 }
739 
740 
741 inline colvarvalue const & colvar::value() const
742 {
743  return x_reported;
744 }
745 
746 
747 inline colvarvalue const & colvar::actual_value() const
748 {
749  return x;
750 }
751 
752 
753 inline colvarvalue const & colvar::run_ave() const
754 {
755  return runave;
756 }
757 
758 
759 inline colvarvalue const & colvar::velocity() const
760 {
761  return v_reported;
762 }
763 
764 
765 inline colvarvalue const & colvar::total_force() const
766 {
767  return ft_reported;
768 }
769 
770 
771 inline void colvar::add_bias_force(colvarvalue const &force)
772 {
773  if (! is_enabled(f_cv_apply_force)) {
774  cvmodule->error("Error: applying a force to the variable \""+name+" requires that the feature \""+
775  features()[f_cv_apply_force]->description+"\" is active.\n", COLVARS_BUG_ERROR);
776  }
777 
778  if (cvm::debug()) {
779  cvmodule->log("Adding biasing force "+cvm::to_str(force)+" to colvar \""+name+"\".\n");
780  }
781  fb += force;
782 }
783 
784 
786 {
787  if (cvm::debug()) {
788  cvmodule->log("Adding biasing force "+cvm::to_str(force)+" to colvar \""+name+"\".\n");
789  }
790  fb_actual += force;
791 }
792 
793 
795  fb.type(value());
796  fb.reset();
797  fb_actual.type(value());
798  fb_actual.reset();
799 }
800 
801 
802 namespace {
803  // Tolerance parameter to decide when two boundaries coincide
804  constexpr cvm::real colvar_boundaries_tol = 1.0e-10;
805 }
806 
807 #endif
Definition: colvarcomp.h:1282
Definition: colvarcomp.h:1153
Definition: colvarcomp.h:1139
Definition: colvarcomp.h:1121
Colvar component: alpha helix content of a contiguous segment of 5 or more residues,...
Definition: colvarcomp.h:805
Colvar component: angle between the centers of mass of three groups (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:687
Definition: colvarcomp.h:1385
Definition: colvarcomp.h:1355
Definition: colvarcomp.h:1401
Definition: colvarcomp.h:1370
Definition: colvarcomp.h:1090
Colvar component: coordination number between two groups (colvarvalue::type_scalar type,...
Definition: colvarcomp_coordnums.h:23
custom expression of colvars
Definition: colvarcomp.h:1256
Colvar component (base class for collective variables)
Definition: colvarcomp.h:71
Colvar component: dihedPC Projection of the config onto a dihedral principal component See e....
Definition: colvarcomp.h:852
Colvar component: dihedral between the centers of mass of four groups (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:763
Colvar component: angle between the dipole of a molecule and an axis formed by two groups of atoms(co...
Definition: colvarcomp.h:728
Colvar component: dipole magnitude of a molecule.
Definition: colvarcomp.h:584
Colvar component: distance unit vector (direction) between centers of mass of two groups (colvarvalue...
Definition: colvarcomp.h:424
Colvar component: average distance between two groups of atoms, weighted as the sixth power,...
Definition: colvarcomp.h:535
Colvar component: N1xN2 vector of pairwise distances (colvarvalue::type_vector type,...
Definition: colvarcomp.h:557
Definition: colvarcomp.h:401
Colvar component: projection of the distance vector on a plane (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:479
Colvar component: projection of the distance vector along an axis(colvarvalue::type_scalar type,...
Definition: colvarcomp.h:447
Colvar component: distance between the centers of mass of two groups (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:378
Colvar component: projection of 3N coordinates onto an eigenvector(colvarvalue::type_scalar type,...
Definition: colvarcomp.h:655
Definition: colvarcomp.h:1000
Definition: colvarcomp.h:1011
Definition: colvarcomp.h:1022
Colvar component: coordination number between centers of two groups (colvarvalue::type_scalar type,...
Definition: colvarcomp_coordnums.h:152
Colvar component: alternative path collective variable using geometry, variable s Allow any combinati...
Definition: colvarcomp.h:1321
Colvar component: alternative path collective variable using geometry, variable s For more informatio...
Definition: colvarcomp.h:1182
Colvar component: Radius of gyration of an atom group (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:603
Definition: colvarcomp.h:1338
Colvar component: alternative path collective variable using geometry, variable z This should be merg...
Definition: colvarcomp.h:1204
Colvar component: hydrogen bond, defined as the product of a colvar::coordnum and 1/2*(1-cos((180-ang...
Definition: colvarcomp_coordnums.h:164
Colvar component: moment of inertia of an atom group around a user-defined axis (colvarvalue::type_sc...
Definition: colvarcomp.h:637
Colvar component: moment of inertia of an atom group (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:623
Current only linear combination of sub-CVCs is available.
Definition: colvarcomp.h:1224
Definition: colvarcomp.h:1453
Definition: colvarcomp.h:1422
Definition: colvarcomp.h:928
Colvar component: cosine of the angle of rotation with respect to a set of reference coordinates (col...
Definition: colvarcomp.h:953
Colvar component: orientation in space of an atom group, with respect to a set of reference coordinat...
Definition: colvarcomp.h:878
Colvar component: polar coordinate phi of a group (colvarvalue::type_scalar type, range [-180:180])
Definition: colvarcomp.h:499
Colvar component: polar coordinate theta of a group (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:517
Colvar component: root mean square deviation (RMSD) of a group with respect to a set of reference coo...
Definition: colvarcomp.h:1037
Colvar component: self-coordination number within a group (colvarvalue::type_scalar type,...
Definition: colvarcomp_coordnums.h:135
Colvar component: angle of rotation around a predefined axis (colvarvalue::type_scalar type,...
Definition: colvarcomp.h:988
Colvar component: projection of the orientation vector onto a predefined axis (colvarvalue::type_scal...
Definition: colvarcomp.h:968
Definition: colvarcomp_torchann.h:54
A collective variable (main class); to be defined, it needs at least one object of a derived class of...
Definition: colvar.h:53
bool periodic_boundaries() const
Is the interval defined by the two boundaries periodic?
Definition: colvar.cpp:2404
void update_active_cvc_square_norm()
Update the sum of square coefficients for active cvcs.
Definition: colvar.cpp:2267
void communicate_forces()
Communicate forces (previously calculated in colvar::update()) to the external degrees of freedom.
Definition: colvar.cpp:2168
std::vector< std::shared_ptr< colvar::cvc > > & get_cvcs()
Get all colvarcomp objects.
Definition: colvar.h:669
size_t num_cvcs() const
Number of CVC objects defined.
Definition: colvar.h:414
int end_of_step()
Carry out operations needed before next step is run.
Definition: colvar.cpp:2150
colvarvalue const * get_cvc_param_grad(std::string const &param_name)
Pointer to the derivative of the variable with respect to param_name.
Definition: colvar.cpp:2369
colvarvalue const & actual_value() const
Current actual value (not extended DOF)
Definition: colvar.h:747
colvarvalue const & run_ave() const
Current running average (if calculated as set by analysis flag)
Definition: colvar.h:753
colvarvalue const & velocity() const
Current velocity (previously set by calc() or by read_traj())
Definition: colvar.h:759
cvm::real active_cvc_square_norm
Sum of square coefficients for active cvcs.
Definition: colvar.h:397
colvarvalue x_restart
Value read from the most recent state file (if any)
Definition: colvar.h:500
size_t num_dimensions() const
Number of dimensions of the value of this colvar.
Definition: colvar.h:408
cvm::real runave_variance
Current value of the square deviation from the running average.
Definition: colvar.h:580
int calc_cvc_total_force(int first, size_t num_cvcs)
Same as colvar::calc_cvc_values but for total forces.
Definition: colvar.cpp:1728
colvarvalue f
Total applied force; fr (if extended_lagrangian is defined), fb (if biases are applied) and the walls...
Definition: colvar.h:216
std::vector< colvarbias * > biases
List of biases that depend on this colvar.
Definition: colvar.h:120
std::vector< const colvarvalue * > sorted_cvc_values
Definition: colvar.h:690
int check_grid_parameters()
Consistency check for the grid paramaters.
Definition: colvar.cpp:678
static std::map< std::string, std::function< colvar::cvc *(colvarmodule *cvmodule_in)> > global_cvc_map
A global mapping of cvc names to the cvc constructors.
Definition: colvar.h:708
colvarvalue const & value() const
Current value (previously set by calc() or by read_traj())
Definition: colvar.h:741
int write_output_files()
Write output files (if defined, e.g. in analysis mode)
Definition: colvar.cpp:2839
std::ostream & write_state(std::ostream &os) const
Write the colvar's state to a formatted output stream.
Definition: colvar.cpp:2686
int parse_analysis(std::string const &conf)
Read the analysis tasks.
Definition: colvar.cpp:1077
static const std::map< std::string, std::function< colvar::cvc *(colvarmodule *cvmodule_in)> > & get_global_cvc_map()
A global mapping of cvc names to the cvc constructors.
Definition: colvar.h:655
int init_custom_function(std::string const &conf)
Parse parameters for custom function with Lepton.
Definition: colvar.cpp:515
cvm::real ext_gamma
Friction coefficient for Langevin extended dynamics.
Definition: colvar.h:190
std::string acf_outfile
Name of the file to write the ACF.
Definition: colvar.h:534
cvm::real ext_mass
Mass of the restraint center.
Definition: colvar.h:186
int init_components_type(const std::string &conf, const char *config_key)
Initialize any CVC objects matching the given key.
Definition: colvar.cpp:841
std::ostream & write_traj(std::ostream &os)
Output formatted values to the trajectory file.
Definition: colvar.cpp:2799
cvm::real dist2(colvarvalue const &x1, colvarvalue const &x2) const
Use the internal metrics (as from colvar::cvc objects) to calculate square distances and gradients.
Definition: colvar.cpp:2415
void do_feature_side_effects(int id) override
Definition: colvar.cpp:1020
bool after_restart
True if a state file was just read.
Definition: colvar.h:503
std::string name
Name.
Definition: colvar.h:58
colvarvalue v_ext
Velocity of the restraint center.
Definition: colvar.h:182
virtual std::vector< std::vector< int > > get_atom_lists()
Get vector of vectors of atom IDs for all atom groups.
Definition: colvar.cpp:1323
std::list< std::list< colvarvalue > >::iterator acf_x_history_p
Definition: colvar.h:510
size_t acf_nframes
Number of frames for each ACF point.
Definition: colvar.h:528
int set_state_params(std::string const &state_conf)
Read the values of colvar mutable data from a string (used by both versions of read_state())
Definition: colvar.cpp:2546
bool matching_state
Flag used to tell if the state string being read is for this colvar.
Definition: colvar.h:494
colvar(colvarmodule *cvmodule_in)
Constructor.
Definition: colvar.cpp:35
int calc()
Calculate the colvar's value and related quantities.
Definition: colvar.cpp:1409
cvm::real period
Period, if this variable is periodic.
Definition: colvar.h:226
cvm::real kinetic_energy
If extended Lagrangian active: colvar kinetic energy.
Definition: colvar.h:586
void calc_vel_acf(std::list< colvarvalue > &v_history, colvarvalue const &v)
Velocity ACF, scalar product between v(0) and v(t)
Definition: colvar.cpp:2998
colvarvalue lower_boundary
Location of the lower boundary.
Definition: colvar.h:236
int update_cvc_config(std::vector< std::string > const &confs)
Modify the configuration of CVCs (currently, only base class data)
Definition: colvar.cpp:2302
int init_output_flags(std::string const &conf)
Init output flags.
Definition: colvar.cpp:794
int collect_cvc_values()
Collect the values of the CVCs.
Definition: colvar.cpp:1550
std::istream & read_traj(std::istream &is)
Read the value from a collective variable trajectory file.
Definition: colvar.cpp:2636
int check_cvc_range(int first_cvc, size_t num_cvcs)
Ensure that the selected range of CVCs is consistent.
Definition: colvar.cpp:1486
colvarvalue fb
Bias force; reset_bias_force() should be called before the biases are updated.
Definition: colvar.h:208
size_t n_active_cvcs
Number of CVC objects with an active flag.
Definition: colvar.h:394
std::vector< cvm::real > acf
ACF values.
Definition: colvar.h:532
int cvc_param_exists(std::string const &param_name)
Whether this named parameter exists (in the first and only component)
Definition: colvar.cpp:2337
colvarvalue dist2_rgrad(colvarvalue const &x1, colvarvalue const &x2) const
Use the internal metrics (as from colvar::cvc objects) to calculate square distances and gradients.
Definition: colvar.cpp:2453
size_t runave_length
Length of running average series.
Definition: colvar.h:572
acf_type_e
Type of autocorrelation function (ACF)
Definition: colvar.h:537
@ acf_coor
Coordinate ACF, scalar product between x(0) and x(t)
Definition: colvar.h:543
@ acf_notset
Unset type.
Definition: colvar.h:539
@ acf_vel
Velocity ACF, scalar product between v(0) and v(t)
Definition: colvar.h:541
@ acf_p2coor
Coordinate ACF, second order Legendre polynomial between x(0) and x(t) (does not work with scalar num...
Definition: colvar.h:546
colvarvalue fj
Jacobian force, when Jacobian_force is enabled.
Definition: colvar.h:198
colvarvalue const applied_force() const
Get the current applied force.
Definition: colvar.h:337
void calc_p2coor_acf(std::list< colvarvalue > &x_history, colvarvalue const &x)
Coordinate ACF, second order Legendre polynomial between x(0) and x(t) (does not work with scalar num...
Definition: colvar.cpp:3043
int init_grid_parameters(std::string const &conf)
Init defaults for grid options.
Definition: colvar.cpp:531
int collect_cvc_Jacobians()
Same as colvar::collect_cvc_values but for Jacobian derivatives/forces.
Definition: colvar.cpp:1861
virtual const std::vector< feature * > & features() const override
Implementation of the feature list accessor for colvar.
Definition: colvar.h:99
void wrap(colvarvalue &x_unwrapped) const
Use the internal metrics (as from colvar::cvc objects) to wrap a value into a standard interval.
Definition: colvar.cpp:2473
int calc_runave()
Calculate the running average and its standard deviation.
Definition: colvar.cpp:3123
cvm::step_number prev_timestep
Absolute timestep number when this colvar was last updated.
Definition: colvar.h:403
colvarvalue prev_x_ext
Previous value of the restraint center;.
Definition: colvar.h:180
int check_matching_state(std::string const &state_conf)
Check the name of the bias vs. the given string, set the matching_state flag accordingly.
Definition: colvar.cpp:2522
std::string scripted_function
Name of scripted function to be used.
Definition: colvar.h:686
void add_bias_force(colvarvalue const &force)
Add to the total force from biases.
Definition: colvar.h:771
int init_dependencies() override
Initialize dependency tree.
Definition: colvar.cpp:1150
std::ostream & write_traj_label(std::ostream &os)
Write a label to the trajectory file (comment line)
Definition: colvar.cpp:2748
int calc_colvar_properties()
Calculate the quantities associated to the colvar (but not to the CVCs)
Definition: colvar.cpp:1884
int calc_cvc_Jacobians(int first, size_t num_cvcs)
Same as colvar::calc_cvc_values but for Jacobian derivatives/forces.
Definition: colvar.cpp:1820
int collect_cvc_total_forces()
Same as colvar::collect_cvc_values but for total forces.
Definition: colvar.cpp:1784
bool expand_boundaries
Expand the boundaries of multiples of width, to keep the value always within range.
Definition: colvar.h:233
void calc_coor_acf(std::list< colvarvalue > &x_history, colvarvalue const &x)
Coordinate ACF, scalar product between x(0) and x(t) (does not work with scalar numbers)
Definition: colvar.cpp:3023
static bool compare_cvc(const colvar::cvc *const i, const colvar::cvc *const j)
function for sorting cvcs by their names
Definition: colvar.cpp:61
std::list< std::list< colvarvalue > > x_history
Time series of values and velocities used in running averages.
Definition: colvar.h:513
colvarvalue v_reported
Cached reported velocity.
Definition: colvar.h:174
std::list< std::list< colvarvalue > >::iterator x_history_p
Definition: colvar.h:516
colvarvalue fr
Applied force on extended DOF, for output (unscaled if using MTS)
Definition: colvar.h:195
colvarvalue upper_boundary
Location of the upper boundary.
Definition: colvar.h:239
std::list< std::list< colvarvalue > > acf_x_history
Definition: colvar.h:507
std::string const get_state_params() const
Write the state information of this colvar in a block of text, suitable for later parsing.
Definition: colvar.cpp:2698
bool acf_normalize
Normalize the ACF to a maximum value of 1?
Definition: colvar.h:530
colvarvalue v_fdiff
Finite-difference velocity.
Definition: colvar.h:160
colvarvalue prev_v_ext
Previous velocity of the restraint center.
Definition: colvar.h:184
int init_extended_Lagrangian(std::string const &conf)
Init extended Lagrangian parameters.
Definition: colvar.cpp:710
static std::vector< feature * > cv_features
Implementation of the feature list for colvar.
Definition: colvar.h:96
cvm::real ext_sigma
Amplitude of Gaussian white noise for Langevin extended dynamics.
Definition: colvar.h:192
std::vector< cvm::rvector > atomic_gradients
Array of atomic gradients collected from all cvcs with appropriate components, rotations etc....
Definition: colvar.h:724
cvm::real width
Typical fluctuation amplitude for this collective variable (e.g. local width of a free energy basin)
Definition: colvar.h:93
colvarvalue runave
Current value of the running average.
Definition: colvar.h:578
void const * get_cvc_param_ptr(std::string const &param_name)
Get a pointer to the named parameter (from the first and only component)
Definition: colvar.cpp:2358
size_t acf_offset
After how many steps the ACF starts.
Definition: colvar.h:524
colvarvalue ft_reported
Cached reported total force.
Definition: colvar.h:201
std::vector< std::shared_ptr< colvar::cvc > > cvcs
Array of components objects.
Definition: colvar.h:676
static std::map< std::string, std::string > global_cvc_desc_map
A global mapping of cvc names to the corresponding descriptions.
Definition: colvar.h:711
acf_type_e acf_type
Type of autocorrelation function (ACF)
Definition: colvar.h:550
void build_atom_list(void)
Initialize the sorted list of atom IDs for atoms involved in all cvcs (called when enabling f_cv_coll...
Definition: colvar.cpp:1037
std::istream & read_state(std::istream &is)
Read the colvar's state from a formatted input stream.
Definition: colvar.cpp:2492
cvm::real get_cvc_param(std::string const &param_name)
Get the value of the named parameter (from the first and only component)
Definition: colvar.cpp:2347
cvm::real wrap_center
Center of wrapping, if this variable is periodic.
Definition: colvar.h:229
void add_bias_force_actual_value(colvarvalue const &force)
Apply a force to the actual value (only meaningful with extended Lagrangian)
Definition: colvar.h:785
const std::vector< std::shared_ptr< colvar::cvc > > & get_cvcs() const
Get all colvarcomp objects.
Definition: colvar.h:664
colvarvalue f_old
Applied force at the previous step (to be subtracted from total force if needed)
Definition: colvar.h:219
int update_cvc_flags()
Updates the flags in the CVC objects, and their number.
Definition: colvar.cpp:2278
cvm::real const & force_constant() const
Force constant of the spring.
Definition: colvar.h:735
cvm::real ext_force_k
Restraint force constant.
Definition: colvar.h:188
colvarvalue dist2_lgrad(colvarvalue const &x1, colvarvalue const &x2) const
Use the internal metrics (as from colvar::cvc objects) to calculate square distances and gradients.
Definition: colvar.cpp:2434
void define_component_types()
Populate the map of available CVC types.
Definition: colvar.cpp:901
~colvar()
Destructor.
Definition: colvar.cpp:1349
int calc_acf()
Calculate the auto-correlation function (ACF)
Definition: colvar.cpp:2903
void reset_bias_force()
Set the total biasing force to zero.
Definition: colvar.h:794
colvarvalue ft
Total force, as derived from the atomic trajectory; should equal the system force plus f.
Definition: colvar.h:223
std::string acf_colvar_name
Collective variable with which the correlation is calculated (default: itself)
Definition: colvar.h:520
colvarvalue const & total_force() const
Current total force (previously obtained from calc() or read_traj()). Note: this is calculated using ...
Definition: colvar.h:765
int init_components(std::string const &conf)
Parse the CVC configuration and allocate their data.
Definition: colvar.cpp:964
int collect_cvc_gradients()
Same as colvar::collect_cvc_values but for gradients.
Definition: colvar.cpp:1709
colvarvalue fb_actual
Bias force to the actual value (only useful with extended Lagrangian)
Definition: colvar.h:211
int collect_cvc_data()
Collect quantities from CVCs and update aggregated data for the colvar.
Definition: colvar.cpp:1458
size_t runave_stride
Timesteps to skip between two values in the running average series.
Definition: colvar.h:574
int calc_cvcs(int first=0, size_t num_cvcs=0)
Calculate a subset of the colvar components (CVCs) currently active (default: all active CVCs) Note: ...
Definition: colvar.cpp:1424
colvarvalue x_reported
Cached reported value (x may be manipulated)
Definition: colvar.h:157
colvarvalue x_old
Previous value (to calculate velocities during analysis)
Definition: colvar.h:497
int init(std::string const &conf)
Main init function.
Definition: colvar.cpp:67
cvm::real update_forces_energy()
Collect all forces on this colvar, integrate internal equations of motion of internal degrees of free...
Definition: colvar.cpp:1964
std::vector< int > const & get_volmap_ids()
Volmap numeric IDs, one for each CVC (-1 if not available)
Definition: colvar.cpp:1334
cvm::real potential_energy
If extended Lagrangian active: colvar harmonic potential.
Definition: colvar.h:588
colvarvalue x
Value of the colvar.
Definition: colvar.h:147
size_t acf_stride
How many timesteps separate two ACF values.
Definition: colvar.h:526
size_t num_active_cvcs() const
number of CVC objects with an active flag (as set by update_cvc_flags)
Definition: colvar.h:421
void update_extended_Lagrangian()
Integrate equations of motion of extended Lagrangian coordinate if needed.
Definition: colvar.cpp:2010
int parse_legacy_wall_params(std::string const &conf)
Read legacy wall keyword (these are biases now)
Definition: colvar.cpp:615
int calc_cvc_values(int first, size_t num_cvcs)
Calculate the values of the given subset of CVCs.
Definition: colvar.cpp:1497
void add_component_type(char const *description, char const *config_key)
Declare an available CVC type and its description, register them in the global map.
Definition: colvar.cpp:830
std::vector< bool > cvc_flags
Flags to enable or disable cvcs at next colvar evaluation.
Definition: colvar.h:679
std::vector< int > volmap_ids_
Volmap numeric IDs, one for each CVC (-1 if not available)
Definition: colvar.h:714
size_t acf_length
Length of autocorrelation function (ACF)
Definition: colvar.h:522
std::string runave_outfile
Name of the file to write the running average.
Definition: colvar.h:576
int set_cvc_param(std::string const &param_name, void const *new_value)
Set the named parameter in the first and only component to the given value.
Definition: colvar.cpp:2380
int write_acf(std::ostream &os)
Save the ACF to a file.
Definition: colvar.cpp:3065
int calc_cvc_gradients(int first, size_t num_cvcs)
Same as colvar::calc_cvc_values but for gradients.
Definition: colvar.cpp:1624
colvarvalue x_ext
Restraint center.
Definition: colvar.h:178
int set_cvc_flags(std::vector< bool > const &flags)
Enables and disables individual CVCs based on the given array.
Definition: colvar.cpp:2254
int analyze()
Perform analysis tasks.
Definition: colvar.cpp:2869
std::vector< int > atom_ids
Sorted array of (zero-based) IDs for all atoms involved.
Definition: colvar.h:719
void setup()
Get ready for a run and re-initialize internal data if needed.
Definition: colvar.cpp:1309
Parent class for a member object of a bias, cv or cvc etc. containing features and their dependencies...
Definition: colvardeps.h:34
@ f_cv_extended_Lagrangian
The variable has a harmonic restraint around a moving center with fictitious mass; bias forces will b...
Definition: colvardeps.h:332
@ f_cv_apply_force
External force can be applied, either to atoms or to an extended DOF.
Definition: colvardeps.h:303
Collective variables module (main class)
Definition: colvarmodule.h:87
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:114
real dt()
Time step of MD integrator (fs)
Definition: colvarmodule.cpp:2542
void log(std::string const &message, int min_log_level=10)
Definition: colvarmodule.cpp:2164
int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2248
static constexpr bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:403
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2603
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:111
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
Type type() const
Get the current type.
Definition: colvarvalue.h:154
void reset()
Set to the null value for the data type currently defined.
Definition: colvarvalue.cpp:180
size_t size() const
Number of dimensions of this variable.
Definition: colvarvalue.h:379
Definition: colvars_memstream.h:30
Collective variables main module.
Parsing functions for collective variables.