23 #include "tools/Exception.h"
28 void ActionWithValue::registerKeywords(
Keywords& keys){
30 "input file by using the label of the action. Alternatively this Action can be used "
31 "to be used to calculate the following quantities by employing the keywords listed "
32 "below. These quanties can be referenced elsewhere in the input by using this Action's "
33 "label followed by a dot and the name of the quantity required from the list below.");
34 keys.
addFlag(
"NUMERICAL_DERIVATIVES",
false,
"calculate the derivatives for these quantities numerically");
37 void ActionWithValue::noAnalyticalDerivatives(
Keywords& keys){
38 keys.
remove(
"NUMERICAL_DERIVATIVES");
39 keys.
addFlag(
"NUMERICAL_DERIVATIVES",
true,
"analytical derivatives are not implemented for this keyword so numerical derivatives are always used");
42 void ActionWithValue::componentsAreNotOptional(
Keywords& keys){
44 "be referenced elsewhere in the input by using this Action's label followed by a "
45 "dot and the name of the quantity required from the list below.");
48 void ActionWithValue::useCustomisableComponents(
Keywords& keys){
50 "actions input file. However, in addition to these customizable components the "
51 "following quantities will always be output");
56 numericalDerivatives(false)
67 for(
unsigned i=0;i<
values.size();i++)
values[i]->clearInputForce();
76 for(
unsigned i=0;i<
values.size();++i){
77 if (
values[i]->name==name)
return true;
83 for(
unsigned i=0;i<
values.size();++i){
86 plumed_merror(
"there is no pointer with name " + name);
91 plumed_massert(n<
values.size(),
"you have requested a pointer that is out of bounds");
98 plumed_massert(
values.empty(),
"You have already added the default value for this action");
103 plumed_massert(
values.empty(),
"You have already added the default value for this action");
108 plumed_massert(
values.size()==1,
"The number of components is not equal to one");
109 plumed_massert(
values[0]->
name==
getLabel(),
"The value you are trying to set is not the default");
111 values[0]->setupPeriodicity();
115 plumed_massert(
values.size()==1,
"The number of components is not equal to one");
116 plumed_massert(
values[0]->
name==
getLabel(),
"The value you are trying to set is not the default");
117 values[0]->setDomain( min, max );
121 plumed_dbg_massert(
values.size()==1,
"The number of components is not equal to one");
122 plumed_dbg_massert(
values[0]->
name==
getLabel(),
"The value you are trying to retrieve is not the default");
131 warning(
"a description of component " + name +
" has not been added to the manual. Components should be registered like keywords in "
132 "registerKeywords as described in the developer docs. In version 2.2 this warning will turn into an error i.e. component registration will be compulsory");
135 for(
unsigned i=0;i<
values.size();++i){
136 plumed_massert(
values[i]->name!=
getLabel(),
"Cannot mix single values with components");
137 plumed_massert(
values[i]->name!=thename,
"there is already a value with this name");
139 values.push_back(
new Value(
this,thename,
false ) );
140 std::string msg=
" added component to this action: "+thename+
" \n";
147 warning(
"a description of component " + name +
" has not been added to the manual. Components should be registered like keywords in "
148 "registerKeywords as described in the developer doc. In version 2.2 this warning will turn into an error i.e. component registration will be compulsory");
151 for(
unsigned i=0;i<
values.size();++i){
152 plumed_massert(
values[i]->name!=
getLabel(),
"Cannot mix single values with components");
153 plumed_massert(
values[i]->name!=thename,
"there is already a value with this name");
156 std::string msg=
" added component to this action: "+thename+
" \n";
161 plumed_massert( !
exists(
getLabel() ),
"You should not be calling this routine if you are using a value");
163 for(
unsigned i=0;i<
values.size();++i){
164 if (
values[i]->name==thename)
return i;
166 plumed_merror(
"there is no component with name " + name);
171 std::string complist;
173 for(
unsigned i=0;i<
values.size();++i){
174 complist+=
values[i]->name+
" ";
180 std::vector<std::string> complist;
182 for(
unsigned i=0;i<
values.size();++i){
191 values[kk]->setupPeriodicity();
196 for(
unsigned i=0;i<
values.size();i++)
values[i]->setGradients();
202 values[kk]->setDomain(min,max);
211 plumed_dbg_massert(n<
values.size(),
"you have requested a pointer that is out of bounds");
217 for(
unsigned i=0;i<derivatives.size();++i){
void setComponentsIntroduction(const std::string &instr)
Set the text that introduces how the components for this action are introduced.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
void setNotPeriodic()
Set your default value to have no periodicity.
Log & log
Reference to the log stream.
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
void warning(const std::string &msg)
Issue a warning.
int getComponent(const std::string &name) const
Return the index for the component named name.
A class for holding the value of a function together with its derivatives.
std::vector< Value * > values
An array containing the values for this action.
unsigned getNumberOfDerivatives() const
Get the number of derivatives that this particular value has.
Value * getPntrToValue()
Get a pointer to the default value.
const std::string & getLabel() const
Returns the label.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void addComponent(const std::string &name)
Add a value with a name like label.name.
void setGradientsIfNeeded()
Calculate the gradients and store them for all the values (need for projections)
This class holds the keywords and their documentation.
const std::string name
Name of the directive in the plumed.dat file.
std::string getComponentsList() const
get a string that contains all the available components
bool exists(const std::string &name) const
Check if a value with a particular name is present.
This class is used to bring the relevant information to the Action constructor.
void clearInputForces()
Clear the forces on the values.
void setPeriodic(const std::string &min, const std::string &max)
Set the value to be periodic with a particular domain.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Base class for all the input Actions.
Value * copyOutput(const std::string &name) const
Return a pointer to the value with name (this is used to retrieve values in other PLMD::Actions) You ...
bool isOptionOn(const std::string &s) const
Check if an option is on.
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::vector< std::string > getComponentsVector() const
get a vector that contains the label for all the components
void remove(const std::string &k)
Remove the keyword with name k.
virtual void mergeFieldDerivatives(const std::vector< double > &derivatives, Value *val_out)
bool exists(const std::string &k) const
Check if there is a keyword with name k.
void addComponentWithDerivatives(const std::string &name)
Add a value with a name like label.name that has derivatives.
virtual void clearDerivatives()
Clear the derivatives of values wrt parameters.
int getNumberOfComponents() const
Returns the number of values defined.
void addValue()
Add a value with the name label.
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
bool outputComponentExists(const std::string &name, const bool &custom) const
Has a component with this name been added?
bool numericalDerivatives
Are we using numerical derivatives to differentiate.
const Keywords & keywords
void addDerivative(unsigned i, double d)
Add some derivative to the ith component of the derivatives array.
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.