All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Constant.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "Colvar.h"
23 #include "ActionRegister.h"
24 #include "core/PlumedMain.h"
25 #include "core/Atoms.h"
26 
27 #include <string>
28 #include <cmath>
29 
30 namespace PLMD{
31 namespace colvar{
32 
33 //+PLUMEDOC COLVAR CONSTANT
34 /*
35 Return a constant quantity.
36 
37 Useful in combination with functions.
38 
39 \par Examples
40 
41 The following input instructs plumed to compute the distance
42 between atoms 1 and 2. If this distance is between 1.0 and 2.0, it is
43 printed. If it is lower than 1.0 (larger than 2.0), 1.0 (2.0) is printed
44 
45 \verbatim
46 one: CONSTANT VALUE=1.0
47 two: CONSTANT VALUE=2.0
48 dis: DISTANCE ATOMS=1,2
49 sss: SORT ARG=one,dis,two
50 PRINT ARG=sss.2
51 \endverbatim
52 (See also \ref DISTANCE, \ref SORT, and \ref PRINT).
53 
54 */
55 //+ENDPLUMEDOC
56 
57 
58 class Constant : public Colvar {
59  double value;
60 public:
61  Constant(const ActionOptions&);
62 // active methods:
63  virtual void calculate();
64  static void registerKeywords( Keywords& keys );
65 };
66 
67 
68 using namespace std;
69 
70 
71 PLUMED_REGISTER_ACTION(Constant,"CONSTANT")
72 
75 value(0.0)
76 {
77  parse("VALUE",value);
78  addValueWithDerivatives();
79  setNotPeriodic();
80 // fake request to avoid errors:
81  std::vector<AtomNumber> atoms;
82  requestAtoms(atoms);
83 }
84 
89  keys.remove("NUMERICAL_DERIVATIVES");
90  keys.add("compulsory","VALUE","The value of the constant");
91 }
92 
93 // calculator
95  setValue(value);
96 }
97 
98 }
99 }
100 
101 
102 
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
static void registerKeywords(Keywords &keys)
STL namespace.
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.
Definition: Keywords.cpp:167
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
This is the abstract base class to use for implementing new collective variables, within it there is ...
Definition: Colvar.h:39
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
Definition: Action.cpp:49
Provides the keyword CONSTANT
Definition: Constant.cpp:58
virtual void calculate()
Calculate an Action.
Definition: Constant.cpp:94
void remove(const std::string &k)
Remove the keyword with name k.
Definition: Keywords.cpp:204
Constant(const ActionOptions &)
Definition: Constant.cpp:73
static void registerKeywords(Keywords &keys)
Definition: Constant.cpp:85