22 #ifndef __PLUMED_core_Action_h
23 #define __PLUMED_core_Action_h
27 #include "tools/Keywords.h"
29 #include "tools/Tools.h"
30 #include "tools/Log.h"
47 std::vector<std::string>
line;
72 std::vector<std::string>
line;
112 void parse(
const std::string&key,T&t);
116 bool parseNumbered(
const std::string&key,
const int no, T&t);
120 void parseVector(
const std::string&key,std::vector<T>&t);
127 void parseFlag(
const std::string&key,
bool&t);
130 void error(
const std::string & msg )
const;
133 void warning(
const std::string & msg );
183 virtual void apply()=0;
201 const std::string &
getLabel()
const;
204 const std::string &
getName()
const;
210 virtual void setOption(
const std::string &s);
241 FILE *
fopen(
const char *path,
const char *mode);
256 std::string
cite(
const std::string&s);
280 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
283 bool found; std::string def;
290 log.
printf(
"ERROR in action %s with label %s : keyword %s has weird default value",
name.c_str(),
label.c_str(),key.c_str() );
294 error(
"keyword " + key +
" is compulsory for this action");
302 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
319 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
320 unsigned size=t.size();
bool skipcheck=
false;
321 if(size==0) skipcheck=
true;
324 bool found; std::string def; T val;
331 if( !skipcheck && t.size()!=size )
error(
"vector read in for keyword " + key +
" has the wrong size");
338 log.
printf(
"ERROR in action %s with label %s : keyword %s has weird default value",
name.c_str(),
label.c_str(),key.c_str() );
341 for(
unsigned i=0;i<t.size();++i) t[i]=val;
344 error(
"keyword " + key +
" is compulsory for this action");
346 }
else if ( !found ){
353 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
356 unsigned size=t.size();
bool skipcheck=
false;
357 if(size==0) skipcheck=
true;
361 if (!skipcheck && found && t.size()!=size )
error(
"vector read in for keyword " + key + num +
" has the wrong size");
362 }
else if ( !found ){
bool parseNumbered(const std::string &key, const int no, T &t)
Parse one numbered keyword as generic type.
static Keywords emptyKeys
bool isActive() const
Check if action is active.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Action(const ActionOptions &)
Standard constructor from ActionOptions.
Log & log
Reference to the log stream.
bool active
Switch to activate Action on this step.
ActionOptions(PlumedMain &p, const std::vector< std::string > &)
Constructor.
const Dependencies & getDependencies() const
Return dependencies.
void warning(const std::string &msg)
Issue a warning.
void exit(int c=0)
Exit with error code c.
virtual bool checkNumericalDerivatives() const
Check if numerical derivatives should be performed.
void calculateFromPDB(const PDB &)
Calculate the action given a pdb file as input.
void error(const std::string &msg) const
Crash calculation and print documentation.
const std::string & getLabel() const
Returns the label.
virtual void activate()
Set action to active.
Class containing wrappers to MPI.
virtual void lockRequests()
double getTimeStep() const
Return the timestep.
virtual void readAtomsFromPDB(const PDB &)
This is overwritten in ActionAtomistic so that we can read the atoms from the pdb input file rather t...
void checkRead()
Check if Action was properly read.
virtual void clearOptions()
virtual void unlockRequests()
virtual void calculate()=0
Calculate an Action.
const Keywords & keys
The documentation for this action.
Class containing the log stream.
std::vector< std::string > line
Directive line.
bool getDefaultValue(std::string key, std::string &def) const
Get the value of the default for the keyword named key.
void addDependency(Action *)
Specify that this Action depends on another one.
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
virtual void update()
Update.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Communicator & multi_sim_comm
FILE * fopen(const char *path, const char *mode)
Opens a file.
virtual bool checkNeedsGradients() const
Check if the action needs gradient.
This class holds the keywords and their documentation.
const std::string name
Name of the directive in the plumed.dat file.
This class is used to bring the relevant information to the Action constructor.
virtual void deactivate()
Set action to inactive.
bool numbered(const std::string &k) const
Check if numbered keywords are allowed for this action.
double getTime() const
Return the present time.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
const std::string & getName() const
Returns the name.
Base class for all the input Actions.
std::string label
Label of the Action, as set with LABEL= in the plumed.dat file.
virtual void calculateNumericalDerivatives(ActionWithValue *a=NULL)
Perform calculation using numerical derivatives N.B.
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
bool getExchangeStep() const
Check if we are on an exchange step.
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
virtual ~Action()
Destructor.
bool isOptionOn(const std::string &s) const
Check if an option is on.
virtual std::string getDocumentation() const
virtual void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
virtual void setOption(const std::string &s)
bool style(const std::string &k, const std::string &t) const
Check if the keyword with name k has style t.
PlumedMain & plumed
Reference to main plumed object.
virtual void apply()=0
Apply an Action.
int fclose(FILE *fp)
Closes a file opened with Action::fclose().
Action & operator=(const Action &a)
Assignment operator is disabled (private and unimplemented)
Dependencies after
Actions on which this Action depends.
void fflush()
Tell to the Action to flush open files.
std::set< Action * > Dependencies
std::vector< std::string > line
Input line which sets up the action.
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 parseNumberedVector(const std::string &key, const int no, std::vector< T > &t)
Parse a vector with a number.
virtual void runFinalJobs()
RunFinalJobs This method is called once at the very end of the calculation.
void clearDependencies()
Clear the dependence list for this Action.
Register holding all the allowed keywords.
const Keywords & keywords
std::set< FILE * >::iterator files_iterator
std::string cite(const std::string &s)
Cite a paper see PlumedMain::cite.
PlumedMain & plumed
Reference to main PlumedMain object.
std::set< std::string > options
Option that you might have enabled.