22 #include "core/ActionPilot.h"
23 #include "core/ActionWithValue.h"
24 #include "core/ActionRegister.h"
25 #include "core/PlumedMain.h"
26 #include "core/ActionSet.h"
27 #include "core/Atoms.h"
28 #include "tools/IFile.h"
86 PLUMED_REGISTER_ACTION(Read,
"READ")
92 keys.add(
"compulsory",
"STRIDE",
"1",
"the frequency with which the file should be read.");
93 keys.add(
"compulsory",
"EVERY",
"1",
"only read every ith line of the colvar file. This should be used if the colvar was written more frequently than the trajectory.");
94 keys.add(
"compulsory",
"VALUES",
"the values to read from the file");
95 keys.add(
"compulsory",
"FILE",
"the name of the file from which to read these quantities");
96 keys.remove(
"NUMERICAL_DERIVATIVES");
110 std::vector<Read*> other_reads=
plumed.getActionSet().select<
Read*>();
111 for(
unsigned i=0;i<other_reads.size();++i){
113 ifile=other_reads[i]->getFile();
128 std::vector<std::string> valread;
parseVector(
"VALUES",valread);
130 std::size_t dot=valread[0].find_first_of(
'.');
131 if( valread[0].find(
".")!=std::string::npos ){
132 std::string
label=valread[0].substr(0,dot);
133 std::string
name=valread[0].substr(dot+1);
135 if( valread.size()>1 )
error(
"all values must be from the same Action when using READ");
136 std::vector<std::string> fieldnames;
138 for(
unsigned i=0;i<fieldnames.size();++i){
139 if( fieldnames[i].substr(0,dot)==
label ){
149 for(
unsigned i=1;i<valread.size();++i) {
150 if( valread[i].substr(0,dot)!=
label )
error(
"all values must be from the same Action when using READ");;
157 if( valread.size()!=1 )
error(
"all values must be from the same Action when using READ");
161 log.
printf(
" reading value %s and storing as %s\n",valread[0].c_str() ,
getLabel().c_str() );
183 error(
"Reached end of file " +
filename +
" before end of trajectory");
184 }
else if( fabs( du_time-
getTime() )>
plumed.getAtoms().getTimeStep() ){
186 error(
"mismatched times in colvar files : colvar time=" + str_dutime +
" plumed time=" + str_ptime );
192 std::string smin, smax;
193 for(
unsigned i=0;i<
readvals.size();++i){
197 readvals[i]->getDomain( smin, smax );
bool FieldExist(const std::string &s)
Check if a field exist.
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
void setNotPeriodic()
Set your default value to have no periodicity.
Log & log
Reference to the log stream.
static void registerKeywords(Keywords &keys)
This is used to create PLMD::Action objects that are run with some set frequency. ...
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
std::vector< Value * > readvals
A class for holding the value of a function together with its derivatives.
Read(const ActionOptions &)
void error(const std::string &msg) const
Crash calculation and print documentation.
const std::string & getLabel() const
Returns the label.
void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
FileBase & link(FILE *)
Link to an already open filed.
void checkRead()
Check if Action was properly read.
void addComponent(const std::string &name)
Add a value with a name like label.name.
Provides the keyword READ
void calculate()
Calculate an Action.
void set(double)
Set the value of the function.
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.
This class holds the keywords and their documentation.
const std::string name
Name of the directive in the plumed.dat file.
IFile & open(const std::string &name)
Opens the file.
This class is used to bring the relevant information to the Action constructor.
void setPeriodic(const std::string &min, const std::string &max)
Set the value to be periodic with a particular domain.
double getTime() const
Return the present time.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
static void useCustomisableComponents(Keywords &keys)
The components in the action will depend on the user.
void close()
Closes the file Should be used only for explicitely opened files.
Base class for all the input Actions.
std::string label
Label of the Action, as set with LABEL= in the plumed.dat file.
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
static void registerKeywords(Keywords &keys)
Create the keywords for actionPilot.
void componentIsPeriodic(const std::string &name, const std::string &min, const std::string &max)
Set the value to be periodic with a particular domain.
std::string getFilename() const
void apply()
Apply an Action.
IFile & scanField(const std::string &, double &)
Read a double field.
bool FileExist(const std::string &path)
Check if the file exists.
void addValue()
Add a value with the name label.
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
IFile & scanFieldList(std::vector< std::string > &)
Gets the list of all fields.
void setDomain(const std::string &, const std::string &)
Set the domain of the function.
void allowIgnoredFields()
Allow some of the fields in the input to be ignored.