Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 
14 typedef cvm::real* gradient_t;
15 
16 
18 class colvarbias_abf : public colvarbias {
19 
20 public:
21 
22  colvarbias_abf(char const *key);
23  virtual int init(std::string const &conf);
24  virtual ~colvarbias_abf();
25  virtual int update();
26 
27 private:
28 
30  std::string output_prefix;
31 
33  std::vector<std::string> input_prefix;
34 
35  bool update_bias;
36  bool hide_Jacobian;
37  size_t full_samples;
38  size_t min_samples;
40  int output_freq;
42  bool b_history_files;
44  bool b_czar_window_file;
45  size_t history_freq;
46 
48  bool cap_force;
49  std::vector<cvm::real> max_force;
50 
51  // Internal data and methods
52 
53  std::vector<int> bin, force_bin, z_bin;
54  gradient_t system_force, applied_force;
55 
57  colvar_grid_gradient *gradients;
59  colvar_grid_count *samples;
61  colvar_grid_gradient *z_gradients;
63  colvar_grid_count *z_samples;
65  colvar_grid_gradient *czar_gradients;
66 
67  inline int update_system_force(size_t i)
68  {
69  if (colvars[i]->is_enabled(f_cv_subtract_applied_force)) {
70  // this colvar is already subtracting the ABF force
71  system_force[i] = colvars[i]->total_force().real_value;
72  } else {
73  system_force[i] = colvars[i]->total_force().real_value
74  - colvar_forces[i].real_value;
75  }
76  if (cvm::debug())
77  cvm::log("ABF System force calc: cv " + cvm::to_str(i) +
78  " fs " + cvm::to_str(system_force[i]) +
79  " = ft " + cvm::to_str(colvars[i]->total_force().real_value) +
80  " - fa " + cvm::to_str(colvar_forces[i].real_value));
81  return COLVARS_OK;
82  }
83 
84  // shared ABF
85  bool shared_on;
86  size_t shared_freq;
87  int shared_last_step;
88  // Share between replicas -- may be called independently of update
89  virtual int replica_share();
90 
91  // Store the last set for shared ABF
92  colvar_grid_gradient *last_gradients;
93  colvar_grid_count *last_samples;
94 
95  // For Tcl implementation of selection rules.
97  virtual int bin_num();
99  virtual int current_bin();
101  virtual int bin_count(int bin_index);
102 
104  void write_gradients_samples(const std::string &prefix, bool append = false);
105  void write_last_gradients_samples(const std::string &prefix, bool append = false);
106 
108  void read_gradients_samples();
109 
110  std::istream& read_state_data(std::istream&);
111  std::ostream& write_state_data(std::ostream&);
112 };
113 
114 #endif
115 
virtual ~colvarbias_abf()
Destructor.
Definition: colvarbias_abf.cpp:172
std::vector< colvar * > colvars
Pointers to collective variables to which the bias is applied; current values and metric functions wi...
Definition: colvarbias.h:181
std::vector< colvarvalue > colvar_forces
Current forces from this bias to the variables.
Definition: colvarbias.h:184
ABF bias.
Definition: colvarbias_abf.h:18
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:85
Collective variable bias, base class.
Definition: colvarbias.h:12
Subtract the applied force from the total force.
Definition: colvardeps.h:213
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:615
virtual int update()
Definition: colvarbias_abf.cpp:222
Colvar_grid derived class to hold counters in discrete n-dim colvar space.
Definition: colvargrid.h:1150
void init()
Set the object ready to parse a new configuration string.
Definition: colvarparse.h:71
static void log(std::string const &message)
Print a message to the main log.
Definition: colvarmodule.cpp:1467
Class for accumulating the gradient of a scalar function on a grid.
Definition: colvargrid.h:1382
static bool debug()
Whether debug output should be enabled (compile-time option)
Definition: colvarmodule.h:225