Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
colvarbias_abf.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 COLVARBIAS_ABF_H
11#define COLVARBIAS_ABF_H
12
13#include <vector>
14#include <list>
15#include <sstream>
16#include <iomanip>
17#include <memory>
18
19#include "colvarproxy.h"
20#include "colvarbias.h"
21#include "colvargrid.h"
22#include "colvar_UIestimator.h"
23
24typedef cvm::real *gradient_t;
25
26
28class colvarbias_abf : public colvarbias {
29
30public:
31
33 colvarbias_abf(char const *key);
35 int init(std::string const &conf) override;
37 ~colvarbias_abf() override;
39 int update() override;
40
41private:
42
44 std::vector<std::string> input_prefix;
45
53
70
81
85 std::vector<cvm::real> max_force;
86
87 // Internal data and methods
88
90 std::vector<int> bin;
92 std::vector<int> force_bin;
94 std::vector<int> z_bin;
95
97 gradient_t system_force;
98
100 std::shared_ptr<colvar_grid_gradient> gradients;
102 std::shared_ptr<colvar_grid_count> samples;
104 std::shared_ptr<integrate_potential> pmf;
106 std::shared_ptr<colvar_grid_gradient> z_gradients;
108 std::shared_ptr<colvar_grid_count> z_samples;
110 std::shared_ptr<colvar_grid_gradient> czar_gradients;
112 std::shared_ptr<integrate_potential> czar_pmf;
113
116
118 int calc_biasing_force(std::vector<cvm::real> &force);
119
122
123 // shared ABF
124 bool shared_on;
125 size_t shared_freq;
126 cvm::step_number shared_last_step;
127
128 // Share between replicas -- may be called independently of update
129 int replica_share() override;
130
131 // Share data needed for CZAR between replicas - called before output only
132 int replica_share_CZAR();
133
135 size_t replica_share_freq() const override;
136
137 // Data just after the last share (start of cycle) in shared ABF
138 std::unique_ptr<colvar_grid_gradient> last_gradients;
139 std::shared_ptr<colvar_grid_count> last_samples;
140 // eABF/CZAR local data last shared
141 std::unique_ptr<colvar_grid_gradient> z_gradients_in;
142 std::shared_ptr<colvar_grid_count> z_samples_in;
143 // ABF data from local replica only in shared ABF
144 std::shared_ptr<colvar_grid_gradient> local_gradients;
145 std::shared_ptr<colvar_grid_count> local_samples;
146 std::unique_ptr<integrate_potential> local_pmf;
147 // eABF/CZAR data collected from all replicas in shared eABF on replica 0
148 // if non-shared, aliases of regular CZAR grids, for output purposes
149 std::shared_ptr<colvar_grid_gradient> global_z_gradients;
150 std::shared_ptr<colvar_grid_count> global_z_samples;
151 std::shared_ptr<colvar_grid_gradient> global_czar_gradients;
152 std::shared_ptr<integrate_potential> global_czar_pmf;
153
154
155 // For Tcl implementation of selection rules.
157 int bin_num() override;
159 int current_bin() override;
161 int bin_count(int bin_index) override;
163 int local_sample_count(int radius) override;
164
167 void write_gradients_samples(const std::string &prefix, bool close = true, bool local = false);
168
171
173 template <class T> int write_grid_to_file(T const *grid,
174 std::string const &name,
175 bool close);
176
177private:
178
180 template <typename OST> OST &write_state_data_template_(OST &os);
181
183 template <typename IST> IST &read_state_data_template_(IST &is);
184
185public:
186
187 std::ostream &write_state_data(std::ostream &os) override;
188
190
191 std::istream &read_state_data(std::istream &is) override;
192
194
195 int write_output_files() override;
196
198 int calc_energy(std::vector<colvarvalue> const *values) override;
199};
200#endif
Definition: colvar_UIestimator.h:215
ABF bias.
Definition: colvarbias_abf.h:28
std::shared_ptr< colvar_grid_count > samples
n-dim grid of number of samples
Definition: colvarbias_abf.h:102
int calc_biasing_force(std::vector< cvm::real > &force)
Calulate the biasing force for the current bin.
Definition: colvarbias_abf.cpp:487
int local_sample_count(int radius) override
Return the average number of samples in a given "radius" around current bin.
int current_bin() override
Calculate the bin index for a given bias.
Definition: colvarbias_abf.cpp:853
int pabf_integrate_iterations
Max number of CG iterations for integrating PMF at on-the-fly pABF updates.
Definition: colvarbias_abf.h:78
int init(std::string const &conf) override
Initializer for ABF bias.
Definition: colvarbias_abf.cpp:27
bool b_CZAR_estimator
Run CZAR estimator?
Definition: colvarbias_abf.h:69
std::vector< cvm::real > max_force
Maximum force to be applied.
Definition: colvarbias_abf.h:85
bool cap_force
Cap the biasing force to be applied? (option maxForce)
Definition: colvarbias_abf.h:83
int write_grid_to_file(T const *grid, std::string const &name, bool close)
Shorthand template used in write_gradient_samples()
Definition: colvarbias_abf.cpp:730
size_t replica_share_freq() const override
Report the frequency at which this bias needs to communicate with replicas.
Definition: colvarbias_abf.cpp:724
std::vector< int > z_bin
Cuurent bin in "actual" coordinate, when running extended Lagrangian dynamics.
Definition: colvarbias_abf.h:94
bool b_czar_window_file
Write CZAR output file for stratified eABF (.zgrad)
Definition: colvarbias_abf.h:61
std::vector< std::string > input_prefix
Base filename(s) for reading previous gradient data (replaces data from restart file)
Definition: colvarbias_abf.h:44
int bin_num() override
Give the total number of bins for a given bias.
Definition: colvarbias_abf.cpp:848
int update_system_force()
Calculate system force for all colvars.
Definition: colvarbias_abf.cpp:455
OST & write_state_data_template_(OST &os)
Generic stream writing function (formatted and not)
Definition: colvarbias_abf.cpp:917
std::shared_ptr< colvar_grid_gradient > z_gradients
n-dim grid: average force on "real" coordinate for eABF z-based estimator
Definition: colvarbias_abf.h:106
int read_gradients_samples()
Read human-readable FE gradients and sample count (if not using restart)
Definition: colvarbias_abf.cpp:871
bool b_integrate
Integrate gradients into a PMF on output.
Definition: colvarbias_abf.h:52
std::shared_ptr< integrate_potential > pmf
n-dim grid of pmf (dimension 1 to 3)
Definition: colvarbias_abf.h:104
cvm::real integrate_tol
Tolerance for integrating PMF at startup and for file output.
Definition: colvarbias_abf.h:76
std::shared_ptr< colvar_grid_gradient > gradients
n-dim grid of free energy gradients
Definition: colvarbias_abf.h:100
size_t full_samples
Number of samples per bin before applying the full biasing force.
Definition: colvarbias_abf.h:55
std::ostream & write_state_data(std::ostream &os) override
Write all mutable data not already written by get_state_params() to a formatted stream.
Definition: colvarbias_abf.cpp:949
cvm::step_number history_last_step
Latest absolute time step at which history files were written.
Definition: colvarbias_abf.h:59
std::vector< int > force_bin
Current bin in force grid.
Definition: colvarbias_abf.h:92
gradient_t system_force
Measured instantaneous system force.
Definition: colvarbias_abf.h:97
int update() override
Per-timestep update of ABF bias.
Definition: colvarbias_abf.cpp:317
cvm::real smoothing_factor(cvm::real weight)
Calulate the smoothing factor to apply to biasing forces for given local count.
Definition: colvarbias_abf.cpp:473
bool update_bias
Adapt the bias at each time step (as opposed to keeping it constant)?
Definition: colvarbias_abf.h:47
int bin_count(int bin_index) override
Give the count at a given bin index.
Definition: colvarbias_abf.cpp:858
cvm::real pabf_integrate_tol
Tolerance for integrating PMF at on-the-fly pABF updates.
Definition: colvarbias_abf.h:80
bool b_UI_estimator
Run UI estimator?
Definition: colvarbias_abf.h:67
std::vector< int > bin
Current bin in sample grid.
Definition: colvarbias_abf.h:90
size_t history_freq
Number of timesteps between recording data in history files (if non-zero)
Definition: colvarbias_abf.h:63
std::shared_ptr< colvar_grid_count > z_samples
n-dim grid of number of samples on "real" coordinate for eABF z-based estimator
Definition: colvarbias_abf.h:108
std::istream & read_state_data(std::istream &is) override
Read all mutable data not already set by set_state_params() from a formatted stream.
Definition: colvarbias_abf.cpp:1029
std::shared_ptr< integrate_potential > czar_pmf
n-dim grid of CZAR pmf (dimension 1 to 3)
Definition: colvarbias_abf.h:112
IST & read_state_data_template_(IST &is)
Generic stream readingx function (formatted and not)
Definition: colvarbias_abf.cpp:961
int integrate_iterations
Max number of CG iterations for integrating PMF at startup and for file output.
Definition: colvarbias_abf.h:74
int write_output_files() override
Write any output files that this bias may have (e.g. PMF files)
Definition: colvarbias_abf.cpp:1041
UIestimator::UIestimator eabf_UI
Umbrella Integration estimator of free energy from eABF.
Definition: colvarbias_abf.h:65
void write_gradients_samples(const std::string &prefix, bool close=true, bool local=false)
Definition: colvarbias_abf.cpp:769
std::shared_ptr< colvar_grid_gradient > czar_gradients
n-dim grid containing CZAR estimatr of "real" free energy gradients
Definition: colvarbias_abf.h:110
int pabf_freq
Frequency for updating pABF PMF (if zero, pABF is not used)
Definition: colvarbias_abf.h:72
size_t min_samples
Number of samples per bin before applying a scaled-down biasing force.
Definition: colvarbias_abf.h:57
~colvarbias_abf() override
Default destructor for ABF bias.
Definition: colvarbias_abf.cpp:309
bool hide_Jacobian
Definition: colvarbias_abf.h:50
int calc_energy(std::vector< colvarvalue > const *values) override
Calculate the bias energy for 1D ABF.
Definition: colvarbias_abf.cpp:1085
Collective variable bias, base class.
Definition: colvarbias.h:23
std::string name
Name of this bias.
Definition: colvarbias.h:27
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:92
Definition: colvars_memstream.h:30
Colvars proxy classes.