2016-06-18 07:07:51 +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
|
|
|
#include "colvarmodule.h"
|
|
|
|
#include "colvarvalue.h"
|
|
|
|
#include "colvarparse.h"
|
|
|
|
#include "colvar.h"
|
|
|
|
#include "colvarcomp.h"
|
|
|
|
#include "colvargrid.h"
|
|
|
|
|
|
|
|
|
|
|
|
colvar_grid_count::colvar_grid_count()
|
|
|
|
: colvar_grid<size_t>()
|
2015-02-20 02:20:52 +08:00
|
|
|
{
|
|
|
|
mult = 1;
|
|
|
|
}
|
2012-05-24 00:20:04 +08:00
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_count::colvar_grid_count(std::vector<int> const &nx_i,
|
|
|
|
size_t const &def_count)
|
2015-02-20 02:20:52 +08:00
|
|
|
: colvar_grid<size_t>(nx_i, def_count, 1)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_count::colvar_grid_count(std::vector<colvar *> &colvars,
|
|
|
|
size_t const &def_count)
|
2015-02-20 02:20:52 +08:00
|
|
|
: colvar_grid<size_t>(colvars, def_count, 1)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
colvar_grid_scalar::colvar_grid_scalar()
|
2014-12-02 10:09:53 +08:00
|
|
|
: colvar_grid<cvm::real>(), samples(NULL), grad(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_scalar::colvar_grid_scalar(colvar_grid_scalar const &g)
|
|
|
|
: colvar_grid<cvm::real>(g), samples(NULL), grad(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{
|
|
|
|
grad = new cvm::real[nd];
|
|
|
|
}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_scalar::colvar_grid_scalar(std::vector<int> const &nx_i)
|
2016-09-09 04:20:32 +08:00
|
|
|
: colvar_grid<cvm::real>(nx_i, 0.0, 1), samples(NULL), grad(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{
|
|
|
|
grad = new cvm::real[nd];
|
|
|
|
}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_scalar::colvar_grid_scalar(std::vector<colvar *> &colvars, bool margin)
|
2016-09-09 04:20:32 +08:00
|
|
|
: colvar_grid<cvm::real>(colvars, 0.0, 1, margin), samples(NULL), grad(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{
|
|
|
|
grad = new cvm::real[nd];
|
|
|
|
}
|
|
|
|
|
|
|
|
colvar_grid_scalar::~colvar_grid_scalar()
|
|
|
|
{
|
|
|
|
if (grad) {
|
|
|
|
delete [] grad;
|
|
|
|
grad = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:36:59 +08:00
|
|
|
cvm::real colvar_grid_scalar::maximum_value() const
|
|
|
|
{
|
|
|
|
cvm::real max = data[0];
|
|
|
|
for (size_t i = 0; i < nt; i++) {
|
|
|
|
if (data[i] > max) max = data[i];
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cvm::real colvar_grid_scalar::minimum_value() const
|
|
|
|
{
|
|
|
|
cvm::real min = data[0];
|
|
|
|
for (size_t i = 0; i < nt; i++) {
|
|
|
|
if (data[i] < min) min = data[i];
|
|
|
|
}
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
2016-12-28 02:17:34 +08:00
|
|
|
cvm::real colvar_grid_scalar::minimum_pos_value() const
|
|
|
|
{
|
|
|
|
cvm::real minpos = data[0];
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < nt; i++) {
|
|
|
|
if(data[i] > 0) {
|
|
|
|
minpos = data[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < nt; i++) {
|
|
|
|
if (data[i] > 0 && data[i] < minpos) minpos = data[i];
|
|
|
|
}
|
|
|
|
return minpos;
|
|
|
|
}
|
2015-07-22 22:36:59 +08:00
|
|
|
|
|
|
|
cvm::real colvar_grid_scalar::integral() const
|
|
|
|
{
|
|
|
|
cvm::real sum = 0.0;
|
|
|
|
for (size_t i = 0; i < nt; i++) {
|
|
|
|
sum += data[i];
|
|
|
|
}
|
|
|
|
cvm::real bin_volume = 1.0;
|
|
|
|
for (size_t id = 0; id < widths.size(); id++) {
|
|
|
|
bin_volume *= widths[id];
|
|
|
|
}
|
|
|
|
return bin_volume * sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cvm::real colvar_grid_scalar::entropy() const
|
|
|
|
{
|
|
|
|
cvm::real sum = 0.0;
|
|
|
|
for (size_t i = 0; i < nt; i++) {
|
|
|
|
sum += -1.0 * data[i] * std::log(data[i]);
|
|
|
|
}
|
|
|
|
cvm::real bin_volume = 1.0;
|
|
|
|
for (size_t id = 0; id < widths.size(); id++) {
|
|
|
|
bin_volume *= widths[id];
|
|
|
|
}
|
|
|
|
return bin_volume * sum;
|
|
|
|
}
|
|
|
|
|
2012-05-24 00:20:04 +08:00
|
|
|
|
|
|
|
colvar_grid_gradient::colvar_grid_gradient()
|
2014-12-02 10:09:53 +08:00
|
|
|
: colvar_grid<cvm::real>(), samples(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_gradient::colvar_grid_gradient(std::vector<int> const &nx_i)
|
|
|
|
: colvar_grid<cvm::real>(nx_i, 0.0, nx_i.size()), samples(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
colvar_grid_gradient::colvar_grid_gradient(std::vector<colvar *> &colvars)
|
|
|
|
: colvar_grid<cvm::real>(colvars, 0.0, colvars.size()), samples(NULL)
|
2012-05-24 00:20:04 +08:00
|
|
|
{}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
void colvar_grid_gradient::write_1D_integral(std::ostream &os)
|
2012-05-24 00:20:04 +08:00
|
|
|
{
|
|
|
|
cvm::real bin, min, integral;
|
|
|
|
std::vector<cvm::real> int_vals;
|
2013-06-28 06:48:27 +08:00
|
|
|
|
2012-05-24 00:20:04 +08:00
|
|
|
os << "# xi A(xi)\n";
|
|
|
|
|
|
|
|
if ( cv.size() != 1 ) {
|
2014-12-02 10:09:53 +08:00
|
|
|
cvm::fatal_error("Cannot write integral for multi-dimensional gradient grids.");
|
2012-05-24 00:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
integral = 0.0;
|
2014-12-02 10:09:53 +08:00
|
|
|
int_vals.push_back( 0.0 );
|
2012-05-24 00:20:04 +08:00
|
|
|
min = 0.0;
|
|
|
|
|
|
|
|
// correction for periodic colvars, so that the PMF is periodic
|
|
|
|
cvm::real corr;
|
|
|
|
if ( periodic[0] ) {
|
|
|
|
corr = average();
|
|
|
|
} else {
|
|
|
|
corr = 0.0;
|
|
|
|
}
|
|
|
|
|
2016-03-02 04:40:25 +08:00
|
|
|
for (std::vector<int> ix = new_index(); index_ok(ix); incr(ix)) {
|
2013-06-28 06:48:27 +08:00
|
|
|
|
2012-05-24 00:20:04 +08:00
|
|
|
if (samples) {
|
2014-12-02 10:09:53 +08:00
|
|
|
size_t const samples_here = samples->value(ix);
|
2012-05-24 00:20:04 +08:00
|
|
|
if (samples_here)
|
2014-12-02 10:09:53 +08:00
|
|
|
integral += (value(ix) / cvm::real(samples_here) - corr) * cv[0]->width;
|
2012-05-24 00:20:04 +08:00
|
|
|
} else {
|
2014-12-02 10:09:53 +08:00
|
|
|
integral += (value(ix) - corr) * cv[0]->width;
|
2012-05-24 00:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( integral < min ) min = integral;
|
2014-12-02 10:09:53 +08:00
|
|
|
int_vals.push_back( integral );
|
2012-05-24 00:20:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bin = 0.0;
|
|
|
|
for ( int i = 0; i < nx[0]; i++, bin += 1.0 ) {
|
2014-12-02 10:09:53 +08:00
|
|
|
os << std::setw(10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
|
|
|
|
<< std::setw(cvm::cv_width)
|
|
|
|
<< std::setprecision(cvm::cv_prec)
|
2012-05-24 00:20:04 +08:00
|
|
|
<< int_vals[i] - min << "\n";
|
|
|
|
}
|
|
|
|
|
2014-12-02 10:09:53 +08:00
|
|
|
os << std::setw(10) << cv[0]->lower_boundary.real_value + cv[0]->width * bin << " "
|
|
|
|
<< std::setw(cvm::cv_width)
|
|
|
|
<< std::setprecision(cvm::cv_prec)
|
2012-05-24 00:20:04 +08:00
|
|
|
<< int_vals[nx[0]] - min << "\n";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|