22 #include "core/Value.h"
38 ndim=tmpvalues.size();
39 for(
int i=0;i<
ndim;i++){
40 values.push_back(tmpvalues[i]);
46 ndim=tmpvalues.size();
47 for(
int i=0;i<
ndim;i++){
48 values.push_back(tmpvalues[i]);
54 ndim=tmpvalues.size();
55 for(
int i=0;i<
ndim;i++){
56 values.push_back(tmpvalues[i]);
64 ndim=tmpvalues.size();
65 for(
int i=0;i<
ndim;i++){
66 values.push_back(tmpvalues[i]);
75 for(
unsigned i=0;i<
hills.size();i++)
delete hills[i];
79 plumed_massert(
hills.size()==0,
"you can set the grid before loading the hills");
80 plumed_massert(
hasgrid==
false,
"to build the grid you should not having the grid in this bias representation");
81 string ss; ss=
"file.free";
82 vector<Value*> vv;
for(
unsigned i=0;i<
values.size();i++)vv.push_back(
values[i]);
88 if(
histosigma.size()==0){
return false;}
else{
return true;}
91 plumed_massert(
hills.size()==0,
"you can set the rescaling function only before loading hills");
116 vector<double> cc(
names.size() );
117 for(
unsigned i=0;i<
names.size();++i){
137 string dummy;
double dummyd;
142 biasf.push_back(dummyd);
144 string mins,maxs,minv,maxv,mini,maxi;mins=
"min_";maxs=
"max_";
145 for(
unsigned i=0 ; i<
ndim; i++){
146 if(
values[i]->isPeriodic()){
150 values[i]->getDomain(mini,maxi);
151 plumed_massert(mini==minv,
"the input periodicity in hills and in value definition does not match" );
152 plumed_massert(maxi==maxv,
"the input periodicity in hills and in value definition does not match" );
160 vector<double> der(ndim);
161 vector<double> xx(ndim);
163 for(
int i=0;i<neighbors.size();++i){
164 unsigned ineigh=neighbors[i];
165 for(
int j=0;j<
ndim;++j){der[j]=0.0;}
168 for(
int j=0;j<
ndim;++j){
values[j]->set(xx[j]);}
173 for(
int j=0;j<
ndim;++j){der[j]*=f;}
180 vector<double> allder(ndim*neighbors.size(),0.0);
181 vector<double> allbias(neighbors.size(),0.0);
182 vector<double> tmpder(ndim);
183 for(
unsigned i=rank;i<neighbors.size();i+=stride){
184 unsigned ineigh=neighbors[i];
186 for(
int j=0;j<
ndim;++j){
values[j]->set(xx[j]);}
191 for(
int j=0;j<
ndim;++j){tmpder[j]*=f;}
195 for(
int j=0;j<
ndim;++j){ allder[ndim*i+j]=tmpder[j];tmpder[j]=0.;}
199 for(
unsigned i=0;i<neighbors.size();++i){
200 unsigned ineigh=neighbors[i];
201 for(
unsigned j=0;j<
ndim;++j){der[j]=allder[ndim*i+j];}
211 plumed_massert(
hasgrid,
"if you want the grid pointer then you should have defined a grid before");
215 vector<double> ss,cc,binsize;
216 vmin.clear();vmin.resize(
ndim,10.e20);
217 vmax.clear();vmax.resize(
ndim,-10.e20);
218 vbin.clear();vbin.resize(
ndim);
219 binsize.clear();binsize.resize(
ndim,10.e20);
221 for(
unsigned i=0;i<
hills.size();i++){
225 ss=
hills[i]->getContinuousSupport();
227 cc=
hills[i]->getCenter();
228 for(
unsigned j=0;j<
ndim;j++){
229 double dmin=cc[j]-ss[j];
230 double dmax=cc[j]+ss[j];
231 double ddiv=ss[j]/double(ndiv);
232 if(dmin<vmin[j])vmin[j]=dmin;
233 if(dmax>vmax[j])vmax[j]=dmax;
234 if(ddiv<binsize[j])binsize[j]=ddiv;
237 for(
unsigned j=0;j<
ndim;j++){
239 if(
values[j]->isPeriodic()){
241 values[j]->getDomain(minv,maxv);
242 if(minv>vmin[j])vmin[j]=minv;
243 if(maxv<vmax[j])vmax[j]=maxv;
245 vbin[j]=
static_cast<unsigned>(ceil((vmax[j]-vmin[j])/binsize[j]) );
250 for(vector<KernelFunctions*>::const_iterator it =
hills.begin(); it !=
hills.end(); ++it)
bool FieldExist(const std::string &s)
Check if a field exist.
std::vector< unsigned > getSupport(const std::vector< double > &dx) const
Get the support.
std::vector< double > getCenter() const
Get the position of the center.
static KernelFunctions * read(IFile *ifile, const std::vector< std::string > &valnames)
Read a kernel function from a file.
double evaluate(const std::vector< Value * > &pos, std::vector< double > &derivatives, bool usederiv=true) const
Evaluate the kernel function.
void pushKernel(IFile *ff)
push a kernel on the representation (includes widths and height)
bool hasSigmaInInput()
check if the sigma values are already provided (in case of a histogram representation with input sigm...
Value * getPtrToValue(unsigned i)
get a pointer to a specific value
Grid * getGridPtr()
get the pointer to the grid
void getMinMaxBin(vector< double > &vmin, vector< double > &vmax, vector< unsigned > &vbin)
get an automatic min/max from the set so to know how to configure the grid
A class for holding the value of a function together with its derivatives.
virtual void clear()
clear grid
unsigned getNumberOfDimensions()
retrieve the number of dimension of the representation
Class containing wrappers to MPI.
int getNumberOfKernels()
get the number of kernels contained in the representation
void clear()
clear the representation (grid included)
int Get_rank() const
Obtain the rank of the present process.
std::vector< double > getDx() const
get bin size
KernelFunctions * readFromPoint(IFile *ifile)
get a new histogram point from a file
virtual void addValueAndDerivatives(unsigned index, double value, std::vector< double > &der)
add to grid value and derivatives
void addGrid(vector< string > gmin, vector< string > gmax, vector< unsigned > nbin)
add the grid to the representation
BiasRepresentation(vector< Value * > tmpvalues, Communicator &cc)
create a bias representation from a list of pointer to values
vector< KernelFunctions * > hills
void setRescaledToBias(bool rescaled)
set the flag that rescales the free energy to the bias
vector< double > histosigma
IFile & scanField(const std::string &, double &)
Read a double field.
const vector< Value * > & getPtrToValues()
get the pointer to the values
vector< string > getNames()
get the names of the variables
std::vector< double > getPoint(unsigned index) const
int Get_size() const
Obtain the number of processes.
std::vector< unsigned > getNeighbors(unsigned index, const std::vector< unsigned > &neigh) const
get neighbors
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.
const string & getName(unsigned i)
get the name of the i-th value
~BiasRepresentation()
destructor
void allowIgnoredFields()
Allow some of the fields in the input to be ignored.
const bool & isRescaledToBias()
check if the representation is rescaled to the bias