24 #include "core/ActionSet.h"
25 #include "core/ActionWithValue.h"
26 #include "core/PlumedMain.h"
27 #include "core/Atoms.h"
28 #include "tools/IFile.h"
60 keys.
add(
"compulsory",
"STRIDE",
"1",
"the frequency with which data should be stored for analysis");
61 keys.
addFlag(
"USE_ALL_DATA",
false,
"use the data from the entire trajectory to perform the analysis");
62 keys.
add(
"compulsory",
"RUN",
"the frequency with which to run the analysis algorithm. This is not required if you specify USE_ALL_DATA");
63 keys.
add(
"optional",
"FMT",
"the format that should be used in analysis output files");
64 keys.
addFlag(
"REWEIGHT_BIAS",
false,
"reweight the data using all the biases acting on the dynamics. For more information see \\ref reweighting.");
65 keys.
add(
"optional",
"TEMP",
"the system temperature. This is required if you are reweighting.");
66 keys.
add(
"optional",
"REWEIGHT_TEMP",
"reweight data from a trajectory at one temperature and output the probability "
67 "distribution at a second temperature. For more information see \\ref reweighting. "
68 "This is not possible during postprocessing.");
69 keys.
addFlag(
"WRITE_CHECKPOINT",
false,
"write out a checkpoint so that the analysis can be restarted in a later run");
70 keys.
add(
"hidden",
"REUSE_DATA_FROM",
"eventually this will allow you to analyse the same set of data multiple times");
71 keys.
add(
"hidden",
"IGNORE_REWEIGHTING",
"this allows you to ignore any reweighting factors");
72 keys.
reserveFlag(
"NOMEMORY",
false,
"analyse each block of data separately");
83 ignore_reweight(false),
86 firstAnalysisDone(false),
91 std::string prev_analysis;
parse(
"REUSE_DATA_FROM",prev_analysis);
92 if( prev_analysis.length()>0 ){
95 if( !
mydatastash )
error(
"could not find analysis action named " + prev_analysis );
97 if(
ignore_reweight )
log.
printf(
" reusing data stored by %s but ignoring all reweighting\n",prev_analysis.c_str() );
98 else log.
printf(
" reusing data stored by %s\n",prev_analysis.c_str() );
101 bool dobias;
parseFlag(
"REWEIGHT_BIAS",dobias);
104 if( all.empty() )
error(
"your input file is not telling plumed to calculate anything");
106 log.
printf(
" reweigting using the following biases ");
107 for(
unsigned j=0;j<all.size();j++){
108 std::string flab; flab=all[j]->getLabel() +
".bias";
109 if( all[j]->exists(flab) ){
110 biases.push_back( all[j]->copyOutput(flab) );
111 arg.push_back( all[j]->copyOutput(flab) );
116 if(
biases.empty() )
error(
"you are asking to reweight bias but there does not appear to be a bias acting on your system");
122 if(
simtemp==0 && !
biases.empty() )
error(
"to reweight you must specify a temperature use TEMP");
126 if(
simtemp==0 )
error(
"to reweight you must specify a temperature use TEMP");
135 if(
freq%
getStride()!= 0 )
error(
"Frequncy of running is not a multiple of the stride");
142 log.
printf(
" analyzing all data in trajectory\n");
150 warning(
"ignoring WRITE_CHECKPOINT flag because we are analyzing all data");
156 if(
plumed.getRestart() ){
157 if(
single_run )
error(
"cannot restart histogram when using the USE_ALL_DATA option");
158 if( !
write_chq )
warning(
"restarting without writing a checkpoint file is somewhat strange");
164 log.
printf(
" restarting analysis with %u points read from restart file\n",
idata);
177 double tstep, oldtstep;
IFile ifile;
178 if( !ifile.
FileExist(filename) )
error(
"failed to find required restart file " + filename );
179 ifile.
open(filename);
183 if( !first && ((tstep-oldtstep) -
getStride()*
plumed.getAtoms().getTimeStep())>
plumed.getAtoms().getTimeStep() ){
184 error(
"frequency of data storage in " + filename +
" is not equal to frequency of data storage plumed.dat file");
192 idata++; first=
false; oldtstep=tstep;
200 if( !
plumed.getRestart() ){
222 double bias=0.0;
for(
unsigned i=0;i<
biases.size();++i) bias+=
biases[i]->
get();
226 double energy=
plumed.getAtoms().getEnergy()+bias;
228 ww=-( (1.0/
rtemp) - (1.0/
simtemp) )*(energy+bias) /
plumed.getAtoms().getKBoltzmann();
263 if( ignore_weights ){
333 else if(
idata==
logweights.size() )
error(
"something has gone wrong. Probably a wrong initial time on restart");
bool reusing_data
Are we reusing data stored by another analysis action.
void runFinalJobs()
RunFinalJobs This method is called once at the very end of the calculation.
std::vector< Value * > biases
The biases we are using in reweighting and the args we store them separately.
bool nomemory
Are we treating each block of data separately.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
bool getPeriodicityInformation(const unsigned &i, std::string &dmin, std::string &dmax)
Returns true if argument i is periodic together with the domain.
Log & log
Reference to the log stream.
unsigned idata
The piece of data we are inserting.
unsigned ndata
Number of data point we need to run analysis.
void backupAllFiles(const std::string &str)
This backs up all the files that would have been created with the name str.
bool ignore_reweight
If we are reusing data are we ignoring the reweighting in that data.
This is used to create PLMD::Action objects that are run with some set frequency. ...
OFile rfile
The checkpoint file.
void warning(const std::string &msg)
Issue a warning.
void parseOutputFile(const std::string &key, std::string &filename)
This is used to read in output file names for analysis methods.
void finalizeWeights(const bool &ignore_weights)
Convert the stored log weights to proper weights.
void readDataFromFile(const std::string &filename)
Read in data from a file.
double retrieveNorm() const
This retrieves the value of norm from the analysis action.
void requestArguments(const std::vector< Value * > &arg)
Setup the dependencies.
static void registerKeywords(Keywords &keys)
Registers the list of keywords.
bool firstAnalysisDone
Have we analyzed the data for the first time.
void error(const std::string &msg) const
Crash calculation and print documentation.
const std::string & getLabel() const
Returns the label.
std::vector< std::vector< double > > data
The data we are going to analyze.
Value * getPntrToArgument(const unsigned n)
Return a pointer to specific argument.
void add(const std::string &t, const std::string &k, const std::string &d)
Add a new keyword of type t with name k and description d.
This is used to create PLMD::Action objects that take the output from some other Action as input...
std::vector< double > args
Tempory vector to store values of arguments.
std::vector< double > weights
OFile & addConstantField(const std::string &)
double getNormalization() const
Return the normalization constant.
Analysis * mydatastash
The Analysis action that we are reusing data from.
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
double simtemp
The temperature at which we are running the calculation.
void getDomain(std::string &, std::string &) const
Get the domain of the quantity.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
IFile & open(const std::string &name)
Opens the file.
This class is used to bring the relevant information to the Action constructor.
unsigned freq
The frequency with which we are performing analysis.
bool write_chq
Are we writing a checkpoint file.
OFile & link(OFile &)
Allows linking this OFile to another one.
double getTime() const
Return the present time.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
void close()
Closes the file Should be used only for explicitely opened files.
const std::string & getName() const
Returns the name.
Base class for all the input Actions.
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
static void registerKeywords(Keywords &keys)
Create the keywords for actionPilot.
void use(const std::string &k)
Use one of the reserved keywords.
std::vector< Value * > getArguments()
Overwrite ActionWithArguments getArguments() so that we don't return the bias.
unsigned getNumberOfDataPoints() const
Return the number of data points.
double getArgument(const unsigned n) const
Returns the value of an argument.
void reserveFlag(const std::string &k, const bool def, const std::string &d, const bool isvessel=false)
Reserve a flag.
This is the abstract base class to use for implementing new methods for analyzing the trajectory...
void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
unsigned getNumberOfArguments() const
Return the number of arguments (this overwrites the one in ActionWithArguments)
IFile & scanField(const std::string &, double &)
Read a double field.
virtual void performAnalysis()=0
long int getStep() const
Return the present timestep.
bool exists(const std::string &k) const
Check if there is a keyword with name k.
bool FileExist(const std::string &path)
Check if the file exists.
OFile & printField(const std::string &, double)
Set the value of a double precision field.
bool isPeriodic() const
Check if the value is periodic.
void calculate()
Calculate an Action.
bool single_run
Are we running only once for the whole trajectory.
Analysis(const ActionOptions &)
void setBackupString(const std::string &)
Set the string name to be used for automatic backup.
double rtemp
The temperature at which we want the histogram.
bool needeng
Do we need the energy (are we reweighting at a different temperature)
static void registerKeywords(Keywords &keys)
OFile & open(const std::string &name)
Opens the file using automatic append/backup.
const Keywords & keywords
std::string ofmt
The format to use in output files.
double norm
The value of the old normalization constant.
OFile & setupPrintValue(Value *val)
Used to setup printing of values.
void addFlag(const std::string &k, const bool def, const std::string &d)
Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag.
std::vector< double > logweights
The weights of all the data points.