Collective Variables Module - Developer Documentation
colvarbias_abf.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARBIAS_ABF_H
4 #define COLVARBIAS_ABF_H
5 
6 #include <vector>
7 #include <list>
8 #include <sstream>
9 #include <iomanip>
10 
11 #include "colvarbias.h"
12 #include "colvargrid.h"
13 #include "colvar_UIestimator.h"
14 
15 typedef cvm::real* gradient_t;
16 
17 
19 class colvarbias_abf : public colvarbias {
20 
21 public:
22 
23  colvarbias_abf(char const *key);
24  virtual int init(std::string const &conf);
25  virtual ~colvarbias_abf();
26  virtual int update();
27 
28 private:
29 
31  std::string output_prefix;
32 
34  std::vector<std::string> input_prefix;
35 
36  bool update_bias;
37  bool hide_Jacobian;
38  size_t full_samples;
39  size_t min_samples;
41  int output_freq;
43  bool b_history_files;
45  bool b_czar_window_file;
46  size_t history_freq;
49  // Run UI estimator?
50  bool b_UI_estimator;
51  // Run CZAR estimator?
52  bool b_CZAR_estimator;
53 
55  bool cap_force;
56  std::vector<cvm::real> max_force;
57 
58  // Internal data and methods
59 
60  std::vector<int> bin, force_bin, z_bin;
61  gradient_t system_force, applied_force;
62 
64  colvar_grid_gradient *gradients;
66  colvar_grid_count *samples;
68  colvar_grid_gradient *z_gradients;
70  colvar_grid_count *z_samples;
72  colvar_grid_gradient *czar_gradients;
73 
74  inline int update_system_force(size_t i)
75  {
76  if (colvars[i]->is_enabled(f_cv_subtract_applied_force)) {
77  // this colvar is already subtracting the ABF force
78  system_force[i] = colvars[i]->total_force().real_value;
79  } else {
80  system_force[i] = colvars[i]->total_force().real_value
81  - colvar_forces[i].real_value;
82  }
83  if (cvm::debug())
84  cvm::log("ABF System force calc: cv " + cvm::to_str(i) +
85  " fs " + cvm::to_str(system_force[i]) +
86  " = ft " + cvm::to_str(colvars[i]->total_force().real_value) +
87  " - fa " + cvm::to_str(colvar_forces[i].real_value));
88  return COLVARS_OK;
89  }
90 
91  // shared ABF
92  bool shared_on;
93  size_t shared_freq;
94  int shared_last_step;
95  // Share between replicas -- may be called independently of update
96  virtual int replica_share();
97 
98  // Store the last set for shared ABF
99  colvar_grid_gradient *last_gradients;
100  colvar_grid_count *last_samples;
101 
102  // For Tcl implementation of selection rules.
104  virtual int bin_num();
106  virtual int current_bin();
108  virtual int bin_count(int bin_index);
109 
111  void write_gradients_samples(const std::string &prefix, bool append = false);
112  void write_last_gradients_samples(const std::string &prefix, bool append = false);
113 
115  void read_gradients_samples();
116 
117  std::istream& read_state_data(std::istream&);
118  std::ostream& write_state_data(std::ostream&);
119 };
120 
121 #endif
122 
virtual ~colvarbias_abf()
Destructor.
Definition: colvarbias_abf.cpp:223
std::vector< colvar * > colvars
Pointers to collective variables to which the bias is applied; current values and metric functions wi...
Definition: colvarbias.h:194
std::vector< colvarvalue > colvar_forces
Current forces from this bias to the variables.
Definition: colvarbias.h:197
Definition: colvar_UIestimator.h:205
ABF bias.
Definition: colvarbias_abf.h:19
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:76
Collective variable bias, base class.
Definition: colvarbias.h:12
Subtract the applied force from the total force.
Definition: colvardeps.h:257
static std::string to_str(T const &x, size_t const &width=0, size_t const &prec=0)
Quick conversion of an object to a string.
Definition: colvarmodule.h:607
virtual int update()
Definition: colvarbias_abf.cpp:273
Colvar_grid derived class to hold counters in discrete n-dim colvar space.
Definition: colvargrid.h:1146
void init()
Set the object ready to parse a new configuration string.
Definition: colvarparse.h:61
static void log(std::string const &message)
Print a message to the main log.
Definition: colvarmodule.cpp:1518
Class for accumulating the gradient of a scalar function on a grid.
Definition: colvargrid.h:1378
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:237