24 #include "tools/Exception.h"
25 #include "tools/Communicator.h"
26 #include "tools/BiasRepresentation.h"
27 #include "tools/File.h"
28 #include "tools/Tools.h"
62 void getMinMaxBin(vector<Value*> vals,
Communicator &cc, vector<double> &vmin, vector<double> &vmax, vector<unsigned> &vbin);
63 void getMinMaxBin(vector<Value*> vals,
Communicator &cc, vector<double> &vmin, vector<double> &vmax, vector<unsigned> &vbin, vector<double> &histosigma);
66 FilesHandler::FilesHandler(
const vector<string> &filenames,
const bool ¶llelread ,
Action &action ,
Log &
mylog ):filenames(filenames),log(&mylog),parallelread(parallelread),beingread(0),isopen(false){
68 for(
unsigned i=0;i<filenames.size();i++){
72 plumed_massert((ifile->
FileExist(filenames[i])),
"the file "+filenames[i]+
" does not exist " );
84 bool morefiles; morefiles=
true;
86 (*log)<<
" doing parallelread \n";
87 plumed_merror(
"parallelread is not yet implemented !!!");
89 (*log)<<
" doing serialread \n";
100 bool fileisover=
true;
104 if(stride>0 && n%stride==0 && n!=0 ){
105 (*log)<<
" done with this chunk: now with "<<n<<
" kernels \n";
118 (*log)<<
" opening file "<<filenames[
beingread]<<
"\n";
120 }
else{morefiles=
false;
121 (*log)<<
" final chunk: now with "<<n<<
" kernels \n";
126 if(fileisover && !morefiles){
break;}
129 if(!fileisover ){
break;}
204 keys.add(
"optional",
"HILLSFILES",
" source file for hills creation(may be the same as HILLS)");
205 keys.add(
"optional",
"HISTOFILES",
" source file for histogram creation(may be the same as HILLS)");
206 keys.add(
"optional",
"HISTOSIGMA",
" sigmas for binning when the histogram correction is needed ");
207 keys.add(
"optional",
"PROJ",
" only with sumhills: the projection on the cvs");
208 keys.add(
"optional",
"KT",
" only with sumhills: the kt factor when projection on cvs");
209 keys.add(
"optional",
"GRID_MIN",
"the lower bounds for the grid");
210 keys.add(
"optional",
"GRID_MAX",
"the upper bounds for the grid");
211 keys.add(
"optional",
"GRID_BIN",
"the number of bins for the grid");
212 keys.add(
"optional",
"OUTHILLS",
" output file for hills ");
213 keys.add(
"optional",
"OUTHISTO",
" output file for histogram ");
214 keys.add(
"optional",
"INITSTRIDE",
" stride if you want an initial dump ");
215 keys.add(
"optional",
"STRIDE",
" stride when you do it on the fly ");
216 keys.addFlag(
"ISCLTOOL",
true,
"use via plumed commandline: calculate at read phase and then go");
217 keys.addFlag(
"PARALLELREAD",
false,
"read parallel HILLS file");
218 keys.addFlag(
"NEGBIAS",
false,
"dump negative bias ( -bias ) instead of the free energy: needed in welltempered with flexible hills ");
219 keys.addFlag(
"NOHISTORY",
false,
"to be used with INITSTRIDE: it splits the bias/histogram in pieces without previous history ");
220 keys.add(
"optional",
"FMT",
"the format that should be used to output real numbers");
228 integratehills(false),
229 integratehisto(false),
241 log<<
" Output format is "<<
fmt<<
"\n";
244 vector<std::string> gmin;
247 plumed_massert(gmin.size()==
getNumberOfArguments() || gmin.size()==0,
"need GRID_MIN argument for this") ;
248 vector<std::string> gmax;
251 plumed_massert(gmax.size()==
getNumberOfArguments() || gmax.size()==0,
"need GRID_MAX argument for this") ;
252 vector<unsigned> gbin;
254 plumed_massert(gbin.size()==
getNumberOfArguments() || gbin.size()==0,
"need GRID_BIN argument for this");
274 vector<double> histoSigma;
277 plumed_massert(histoSigma.size()==
getNumberOfArguments(),
" The number of sigmas must be the same of the number of arguments ");
278 for(
unsigned i=0;i<histoSigma.size();i++)
log<<
" histosigma : "<<histoSigma[i]<<
"\n";
283 if(gmin.size()==0 || gmax.size()==0){
285 log<<
" No boundaries defined: need to do a prescreening of hills \n";
286 std::vector<Value*> tmpvalues;
291 vector<double> vmin,vmax;
292 vector<unsigned> vbin;
294 log<<
" found boundaries from hillsfile: \n";
295 gmin.resize(vmin.size());
296 gmax.resize(vmax.size());
300 log<<
" found nbins in input, this overrides the automatic choice \n";
313 vector<double> vmin,vmax;
314 vector<unsigned> vbin;
316 log<<
" found boundaries from histofile: \n";
317 gmin.resize(vmin.size());
318 gmax.resize(vmax.size());
322 log<<
" found nbins in input, this overrides the automatic choice \n";
338 plumed_massert(
proj.size()<
getNumberOfArguments(),
" The number of projection must be less than the full list of arguments ");
342 for(
unsigned i=0;i<
proj.size();i++)
log<<
" projection "<<i<<
" : "<<
proj[i]<<
"\n";
343 plumed_massert(
beta>0.,
"if you make a projection or a histogram correction then you need KT flag!");
356 if(
initstride<0){
log<<
" Doing only one integration: no stride \n";
359 log<<
" Doing integration slices every "<<
initstride<<
" kernels\n";
361 if(
nohistory)
log<<
" nohistory: each stride block has no memory of the previous block\n";
372 std::vector<Value*> tmpvalues;
384 log<<
" required the -bias instead of the free energy \n";
397 log<<
" Now calculating...\n";
427 log<<
" reading hills: \n";
433 log<<
" reading histogram: \n";
442 log<<
" Bias: Projecting on subgrid... \n";
447 std::ostringstream ostr;ostr<<nfiles;
450 log<<
" Bias: Writing subgrid on file "<<myout<<
" \n";
451 gridfile.
open(myout);
460 log<<
" Histo: Projecting on subgrid... \n";
466 std::ostringstream ostr;ostr<<nfiles;
469 log<<
" Histo: Writing subgrid on file "<<myout<<
" \n";
470 gridfile.
open(myout);
487 std::ostringstream ostr;ostr<<nfiles;
490 log<<
" Writing full grid on file "<<myout<<
" \n";
491 gridfile.
open(myout);
506 std::ostringstream ostr;ostr<<nfiles;
509 log<<
" Writing full grid on file "<<myout<<
" \n";
510 gridfile.
open(myout);
519 if ( !ibias && !ihisto)
break;
523 if(hillsHandler)
delete hillsHandler;
524 if(histoHandler)
delete histoHandler;
538 plumed_merror(
"You should have never got here: this stuff is not yet implemented!");
547 plumed_massert(hills.size()!=0,
"the number of files provided should be at least one" );
550 for(
unsigned i=0; i< hills.size();i++){
551 plumed_massert(ifile->FileExist(hills[i]),
"missing file "+hills[i]);
bool FieldExist(const std::string &s)
Check if a field exist.
double mylogder(double v1)
const std::string & getName() const
Get the name of the quantity.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
vector< string > filenames
Log & log
Reference to the log stream.
Grid project(const std::vector< std::string > &proj, WeightBase *ptr2obj)
project a high dimensional grid onto a low dimensional one: this should be changed at some time to en...
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...
Grid * getGridPtr()
get the pointer to the grid
BiasRepresentation * biasrep
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
vector< string > hillsFiles
void error(const std::string &msg) const
Crash calculation and print documentation.
Provides the keyword FUNCSUMHILLS
FileBase & link(FILE *)
Link to an already open filed.
Class containing wrappers to MPI.
void checkRead()
Check if Action was properly read.
Value * getPntrToArgument(const unsigned n)
Return a pointer to specific argument.
bool checkFilesAreExisting(const vector< string > &hills)
BiasRepresentation * historep
Class containing the log stream.
static void registerKeywords(Keywords &keys)
int getNumberOfKernels()
get the number of kernels contained in the representation
void clear()
clear the representation (grid included)
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
FuncSumHills(const ActionOptions &)
IFile & open(const std::string &name)
Opens the file.
This class is used to bring the relevant information to the Action constructor.
vector< string > histoFiles
OFile & link(OFile &)
Allows linking this OFile to another one.
bool scanOneHill(BiasRepresentation *br, IFile *ifile)
virtual void applyFunctionAllValuesAndDerivatives(double(*func)(double val), double(*funcder)(double valder))
apply function: takes pointer to function that accepts a double and apply
void close()
Closes the file Should be used only for explicitely opened files.
Base class for all the input Actions.
bool readBunch(BiasRepresentation *br, int stride)
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
void getMinMaxBin(vector< Value * > vals, Communicator &cc, vector< double > &vmin, vector< double > &vmax, vector< unsigned > &vbin)
static void registerKeywords(Keywords &)
void setRescaledToBias(bool rescaled)
set the flag that rescales the free energy to the bias
virtual void writeToFile(OFile &)
dump grid on file
IFile & scanField(const std::string &, double &)
Read a double field.
void calculate()
Calculate an Action.
virtual void scaleAllValuesAndDerivatives(const double &scalef)
Scale all grid values and derivatives by a constant factor.
bool FileExist(const std::string &path)
Check if the file exists.
This is the abstract base class to use for implementing new CV function, within it there is informati...
void setOutputFmt(std::string ss)
set output format
unsigned getNumberOfArguments() const
Returns the number of arguments.
OFile & open(const std::string &name)
Opens the file using automatic append/backup.
this class implements a general purpose class that aims to provide a Grid/list transparently add gaus...
void allowIgnoredFields()
Allow some of the fields in the input to be ignored.