25 #include "tools/Log.h"
26 #include "tools/Exception.h"
50 plumed_assert( keys.
size()==0 );
51 keys.
add(
"hidden",
"LABEL",
"a label for the action so that its output can be referenced in the input to other actions. Actions with scalar output are referenced using their label only. Actions with vector output must have a separate label for every component. Individual componets are then refered to using label.component" );
61 multi_sim_comm(
plumed.multi_sim_comm),
69 if(
label.length()==0){
79 std::cerr<<
"WARNING: some files open in action "+
getLabel()+
" where not properly closed. This could lead to data loss!!\n";
85 for(
const char*p=mode;*p;p++)
if(*p==
'w' || *p==
'a' || *p==
'+') write=
true;
88 else fp=
plumed.fopen(path,mode);
106 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
109 plumed_massert(
keywords.
style(key,
"flag"),
"keyword " + key +
" is not a flag");
117 log.
printf(
"ERROR in action %s with label %s : flag %s has no default",
name.c_str(),
label.c_str(),key.c_str() );
124 after.insert(action);
137 for(Dependencies::iterator p=
after.begin();p!=
after.end();++p) (*p)->activate();
144 for(Dependencies::iterator p=
after.begin();p!=
after.end();++p) (*p)->setOption(s);
158 return std::string(
"UNDOCUMENTED ACTION");
163 std::string msg=
"cannot understand the following words from the input line : ";
164 for(
unsigned i=0;i<
line.size();i++) msg = msg +
line[i] +
", ";
178 return plumed.getAtoms().getTimeStep();
188 plumed_merror(
"if you get here it means that you are trying to use numerical derivatives for a class that does not implement them");
196 log.
printf(
"ERROR in input to action %s with label %s : %s \n \n",
name.c_str(),
label.c_str(), msg.c_str() );
198 plumed_merror(
"ERROR in input to action " +
name +
" with label " +
label +
" : " + msg );
202 log.
printf(
"WARNING for action %s with label %s : %s \n",
name.c_str(),
label.c_str(), msg.c_str() );
207 for(Dependencies::iterator p=
after.begin();p!=
after.end();++p){
210 (*p)->readAtomsFromPDB( pdb );
218 return plumed.getExchangeStep();
static Keywords emptyKeys
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.
void warning(const std::string &msg)
Issue a warning.
void exit(int c=0)
Exit with error code c.
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.
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()
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.
virtual void calculate()=0
Calculate an Action.
std::vector< std::string > line
Directive line.
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 ...
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
FILE * fopen(const char *path, const char *mode)
Opens a file.
This class holds the keywords and their documentation.
const std::string name
Name of the directive in the plumed.dat file.
int Get_rank() const
Obtain the rank of the present process.
This class is used to bring the relevant information to the Action constructor.
void clearInputForces()
Clear the forces on the values.
void print(Log &log) const
Print the documentation to the log file (used by PLMD::Action::error)
double getTime() const
Return the present time.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
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.
virtual ~Action()
Destructor.
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.
int fclose(FILE *fp)
Closes a file opened with Action::fclose().
Dependencies after
Actions on which this Action depends.
void fflush()
Tell to the Action to flush open files.
long int getStep() const
Return the present timestep.
bool exists(const std::string &k) const
Check if there is a keyword with name k.
virtual void clearDerivatives()
Clear the derivatives of values wrt parameters.
void clearDependencies()
Clear the dependence list for this Action.
bool getLogicalDefault(std::string key, bool &def) const
find out whether flag key is on or off by default.
const Keywords & keywords
std::set< FILE * >::iterator files_iterator
std::string cite(const std::string &s)
Cite a paper see PlumedMain::cite.
std::set< std::string > options
Option that you might have enabled.
unsigned size() const
Return the number of defined keywords.