diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index 286f0e9ae642fb2b520932807cab4a794998d5a2..53b71fb05568516096eb301880b39fb2472b850f 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -167,10 +167,11 @@ private: vector<Gaussian> hills_; OFile hillsOfile_; Grid* BiasGrid_; + Grid* ExtGrid_; bool storeOldGrids_; - std::string gridfilename_; + std::string gridfilename_,gridreadfilename_; int wgridstride_; - bool grid_; + bool grid_,hasextgrid_; double height0_; double biasf_; double temp_; @@ -237,6 +238,7 @@ void MetaD::registerKeywords(Keywords& keys){ keys.add("optional","WALKERS_DIR", "shared directory with the hills files from all the walkers"); keys.add("optional","WALKERS_RSTRIDE","stride for reading hills files"); keys.add("optional","INTERVAL","monodimensional lower and upper limits, outside the limits the system will not fell the bias (when used together with grid SPLINES are automatically deactivated)"); + keys.add("optional","GRID_RFILE","a grid file from which the bias should be read at the initial step of the simulation"); } MetaD::~MetaD(){ @@ -254,7 +256,7 @@ MetaD::~MetaD(){ MetaD::MetaD(const ActionOptions& ao): PLUMED_BIAS_INIT(ao), // Grid stuff initialization -BiasGrid_(NULL), wgridstride_(0), grid_(false), +BiasGrid_(NULL),ExtGrid_(NULL), wgridstride_(0), grid_(false), hasextgrid_(false), // Metadynamics basic parameters height0_(0.0), biasf_(1.0), temp_(0.0), stride_(0), welltemp_(false), @@ -334,10 +336,13 @@ isFirstStep(true) if(grid_ && gridfilename_.length()>0){ if(wgridstride_==0 ) error("frequency with which to output grid not specified use GRID_WSTRIDE"); } + if(grid_ && wgridstride_>0){ if(gridfilename_.length()==0) error("grid filename not specified use GRID_WFILE"); } + parse("GRID_RFILE",gridreadfilename_); + // Multiple walkers parse("WALKERS_N",mw_n_); parse("WALKERS_ID",mw_id_); @@ -383,6 +388,11 @@ isFirstStep(true) if(sparsegrid){log.printf(" Grid uses sparse grid\n");} if(wgridstride_>0){log.printf(" Grid is written on file %s with stride %d\n",gridfilename_.c_str(),wgridstride_);} } + if(gridreadfilename_.length()>0){ + log.printf(" Reading an additional bias from grid in file %s \n",gridreadfilename_.c_str()); + } + + if(mw_n_>1){ log.printf(" %d multiple walkers active\n",mw_n_); log.printf(" walker id %d\n",mw_id_); @@ -402,6 +412,20 @@ isFirstStep(true) else{BiasGrid_=new SparseGrid(funcl,getArguments(),gmin,gmax,gbin,spline,true);} } +// initializing external grid + if(gridreadfilename_.length()>0){ + hasextgrid_=true; + // read the grid in input, find the keys + IFile gridfile; gridfile.open(gridreadfilename_); + std::string funcl=getLabel() + ".bias"; + ExtGrid_=Grid::create(funcl,getArguments(),gridfile,false,false,true); + gridfile.close(); + if(ExtGrid_->getDimension()!=getNumberOfArguments()) error("mismatch between dimensionality of input grid and number of arguments"); + for(unsigned i=0;i<getNumberOfArguments();++i){ + if( getPntrToArgument(i)->isPeriodic()!=ExtGrid_->getIsPeriodic()[i] ) error("periodicity mismatch between arguments and input bias"); + } + } + // creating vector of ifile* for hills reading // open all files at the beginning and read Gaussians if restarting for(int i=0;i<mw_n_;++i){ @@ -645,6 +669,17 @@ double MetaD::getBiasAndDerivatives(const vector<double>& cv, double* der) bias=BiasGrid_->getValue(cv); } } + if(hasextgrid_){ + if(der){ + vector<double> vder(getNumberOfArguments()); + bias+=ExtGrid_->getValueAndDerivatives(cv,vder); + if( ( doInt_ && cv[0] > lowI_ && cv[0] < uppI_) || (!doInt_) ) { // because interval can be used only with monodimensional metaD + for(unsigned i=0;i<getNumberOfArguments();++i) {der[i]+=vder[i];} + } + }else{ + bias+=ExtGrid_->getValue(cv); + } + } return bias; }