2015-02-20 02:20:52 +08:00
|
|
|
// -*- c++ -*-
|
2012-05-24 00:20:04 +08:00
|
|
|
|
2016-12-28 02:17:34 +08:00
|
|
|
// This file is part of the Collective Variables module (Colvars).
|
|
|
|
// The original version of Colvars and its updates are located at:
|
|
|
|
// https://github.com/colvars/colvars
|
|
|
|
// Please update all Colvars source files before making any changes.
|
|
|
|
// If you wish to distribute your changes, please submit them to the
|
|
|
|
// Colvars repository at GitHub.
|
|
|
|
|
2012-05-24 00:20:04 +08:00
|
|
|
#ifndef COLVARBIAS_ABF_H
|
|
|
|
#define COLVARBIAS_ABF_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include "colvarbias.h"
|
|
|
|
#include "colvargrid.h"
|
2017-10-14 01:25:02 +08:00
|
|
|
#include "colvar_UIestimator.h"
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
typedef cvm::real* gradient_t;
|
|
|
|
|
|
|
|
|
|
|
|
/// ABF bias
|
|
|
|
class colvarbias_abf : public colvarbias {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Constructor for ABF bias
|
2016-07-16 06:25:17 +08:00
|
|
|
colvarbias_abf(char const *key);
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Initializer for ABF bias
|
2016-07-16 06:25:17 +08:00
|
|
|
virtual int init(std::string const &conf);
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Default destructor for ABF bias
|
2016-07-16 06:25:17 +08:00
|
|
|
virtual ~colvarbias_abf();
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Per-timestep update of ABF bias
|
2016-07-16 06:25:17 +08:00
|
|
|
virtual int update();
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// Filename prefix for human-readable gradient/sample count output
|
2016-09-09 04:20:32 +08:00
|
|
|
std::string output_prefix;
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
/// Base filename(s) for reading previous gradient data (replaces data from restart file)
|
|
|
|
std::vector<std::string> input_prefix;
|
|
|
|
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Adapt the bias at each time step (as opposed to keeping it constant)?
|
2018-02-23 21:34:53 +08:00
|
|
|
bool update_bias;
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Use normalized definition of PMF for distance functions? (flat at long distances)
|
|
|
|
/// by including the Jacobian term separately of the recorded PMF
|
2018-02-23 21:34:53 +08:00
|
|
|
bool hide_Jacobian;
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Integrate gradients into a PMF on output
|
2018-02-23 21:34:53 +08:00
|
|
|
bool b_integrate;
|
|
|
|
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Number of samples per bin before applying the full biasing force
|
2018-02-23 21:34:53 +08:00
|
|
|
size_t full_samples;
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Number of samples per bin before applying a scaled-down biasing force
|
2018-02-23 21:34:53 +08:00
|
|
|
size_t min_samples;
|
2015-04-30 22:09:42 +08:00
|
|
|
/// frequency for updating output files
|
2018-02-23 21:34:53 +08:00
|
|
|
int output_freq;
|
2012-05-24 00:20:04 +08:00
|
|
|
/// Write combined files with a history of all output data?
|
2018-02-23 21:34:53 +08:00
|
|
|
bool b_history_files;
|
2016-10-25 05:05:47 +08:00
|
|
|
/// Write CZAR output file for stratified eABF (.zgrad)
|
2018-02-23 21:34:53 +08:00
|
|
|
bool b_czar_window_file;
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Number of timesteps between recording data in history files (if non-zero)
|
2018-02-23 21:34:53 +08:00
|
|
|
size_t history_freq;
|
2017-10-14 01:25:02 +08:00
|
|
|
/// Umbrella Integration estimator of free energy from eABF
|
|
|
|
UIestimator::UIestimator eabf_UI;
|
2018-02-23 21:34:53 +08:00
|
|
|
/// Run UI estimator?
|
|
|
|
bool b_UI_estimator;
|
|
|
|
/// Run CZAR estimator?
|
|
|
|
bool b_CZAR_estimator;
|
|
|
|
|
|
|
|
/// Frequency for updating pABF PMF (if zero, pABF is not used)
|
|
|
|
int pabf_freq;
|
|
|
|
/// Max number of CG iterations for integrating PMF at startup and for file output
|
2019-04-30 21:50:12 +08:00
|
|
|
int integrate_initial_iterations;
|
2018-02-23 21:34:53 +08:00
|
|
|
/// Tolerance for integrating PMF at startup and for file output
|
|
|
|
cvm::real integrate_initial_tol;
|
|
|
|
/// Max number of CG iterations for integrating PMF at on-the-fly pABF updates
|
2019-04-30 21:50:12 +08:00
|
|
|
int integrate_iterations;
|
2018-02-23 21:34:53 +08:00
|
|
|
/// Tolerance for integrating PMF at on-the-fly pABF updates
|
|
|
|
cvm::real integrate_tol;
|
|
|
|
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Cap the biasing force to be applied? (option maxForce)
|
2013-06-28 06:48:27 +08:00
|
|
|
bool cap_force;
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Maximum force to be applied
|
2013-06-28 06:48:27 +08:00
|
|
|
std::vector<cvm::real> max_force;
|
|
|
|
|
2012-05-24 00:20:04 +08:00
|
|
|
// Internal data and methods
|
|
|
|
|
2019-04-30 21:50:12 +08:00
|
|
|
/// Current bin in sample grid
|
|
|
|
std::vector<int> bin;
|
|
|
|
/// Current bin in force grid
|
|
|
|
std::vector<int> force_bin;
|
|
|
|
/// Cuurent bin in "actual" coordinate, when running extended Lagrangian dynamics
|
|
|
|
std::vector<int> z_bin;
|
|
|
|
|
|
|
|
/// Measured instantaneous system force
|
|
|
|
gradient_t system_force;
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
/// n-dim grid of free energy gradients
|
|
|
|
colvar_grid_gradient *gradients;
|
|
|
|
/// n-dim grid of number of samples
|
|
|
|
colvar_grid_count *samples;
|
2018-02-23 21:34:53 +08:00
|
|
|
/// n-dim grid of pmf (dimension 1 to 3)
|
|
|
|
integrate_potential *pmf;
|
2016-08-04 03:32:03 +08:00
|
|
|
/// n-dim grid: average force on "real" coordinate for eABF z-based estimator
|
|
|
|
colvar_grid_gradient *z_gradients;
|
|
|
|
/// n-dim grid of number of samples on "real" coordinate for eABF z-based estimator
|
|
|
|
colvar_grid_count *z_samples;
|
2016-09-09 04:20:32 +08:00
|
|
|
/// n-dim grid contining CZAR estimator of "real" free energy gradients
|
|
|
|
colvar_grid_gradient *czar_gradients;
|
2018-02-23 21:34:53 +08:00
|
|
|
/// n-dim grid of CZAR pmf (dimension 1 to 3)
|
|
|
|
integrate_potential *czar_pmf;
|
2012-05-24 00:20:04 +08:00
|
|
|
|
2016-10-06 06:25:40 +08:00
|
|
|
inline int update_system_force(size_t i)
|
|
|
|
{
|
|
|
|
if (colvars[i]->is_enabled(f_cv_subtract_applied_force)) {
|
|
|
|
// this colvar is already subtracting the ABF force
|
|
|
|
system_force[i] = colvars[i]->total_force().real_value;
|
|
|
|
} else {
|
|
|
|
system_force[i] = colvars[i]->total_force().real_value
|
|
|
|
- colvar_forces[i].real_value;
|
|
|
|
}
|
|
|
|
if (cvm::debug())
|
|
|
|
cvm::log("ABF System force calc: cv " + cvm::to_str(i) +
|
|
|
|
" fs " + cvm::to_str(system_force[i]) +
|
|
|
|
" = ft " + cvm::to_str(colvars[i]->total_force().real_value) +
|
|
|
|
" - fa " + cvm::to_str(colvar_forces[i].real_value));
|
|
|
|
return COLVARS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-29 03:53:17 +08:00
|
|
|
// shared ABF
|
2018-02-23 21:34:53 +08:00
|
|
|
bool shared_on;
|
|
|
|
size_t shared_freq;
|
2019-04-30 21:50:12 +08:00
|
|
|
cvm::step_number shared_last_step;
|
2014-10-29 03:53:17 +08:00
|
|
|
// Share between replicas -- may be called independently of update
|
2014-12-02 10:09:53 +08:00
|
|
|
virtual int replica_share();
|
2014-10-29 03:53:17 +08:00
|
|
|
|
|
|
|
// Store the last set for shared ABF
|
|
|
|
colvar_grid_gradient *last_gradients;
|
|
|
|
colvar_grid_count *last_samples;
|
|
|
|
|
|
|
|
// For Tcl implementation of selection rules.
|
|
|
|
/// Give the total number of bins for a given bias.
|
|
|
|
virtual int bin_num();
|
|
|
|
/// Calculate the bin index for a given bias.
|
|
|
|
virtual int current_bin();
|
|
|
|
//// Give the count at a given bin index.
|
|
|
|
virtual int bin_count(int bin_index);
|
|
|
|
|
2018-02-23 21:34:53 +08:00
|
|
|
/// Write human-readable FE gradients and sample count, and DX file in dim > 2
|
|
|
|
void write_gradients_samples(const std::string &prefix, bool append = false);
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
/// Read human-readable FE gradients and sample count (if not using restart)
|
2018-02-23 21:34:53 +08:00
|
|
|
void read_gradients_samples();
|
2012-05-24 00:20:04 +08:00
|
|
|
|
2018-11-03 05:45:20 +08:00
|
|
|
virtual std::istream& read_state_data(std::istream&);
|
|
|
|
virtual std::ostream& write_state_data(std::ostream&);
|
|
|
|
virtual int write_output_files();
|
2012-05-24 00:20:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2015-04-30 22:09:42 +08:00
|
|
|
|