All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BiasValue.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 "Bias.h"
23 #include "ActionRegister.h"
24 
25 
26 using namespace std;
27 
28 
29 namespace PLMD{
30 namespace bias{
31 
32 //+PLUMEDOC BIAS BIASVALUE
33 /*
34 Takes the value of one variable and use it as a bias
35 
36 This is the simplest possible bias: the bias potential is equal to a collective variable.
37 It is useful to create custom biasing potential, e.g. applying a function (see \ref Function)
38 to some collective variable then using the value of this function directly as a bias.
39 
40 \par Examples
41 
42 The following input tells plumed to use the value of the distance between atoms 3 and 5
43 and the value of the distance between atoms 2 and 4 as biases.
44 It then tells plumed to print the energy of the restraint
45 \verbatim
46 DISTANCE ATOMS=3,5 LABEL=d1
47 DISTANCE ATOMS=3,6 LABEL=d2
48 BIASVALUE ARG=d1,d2 LABEL=b
49 PRINT ARG=d1,d2,b.d1,b.d2
50 \endverbatim
51 (See also \ref DISTANCE and \ref PRINT).
52 
53 Another thing one can do is asking one system to follow
54 a circle in sin/cos according a time dependence
55 
56 \verbatim
57 t: TIME
58 # this just print cos and sin of time
59 cos: MATHEVAL ARG=t VAR=t FUNC=cos(t) PERIODIC=NO
60 sin: MATHEVAL ARG=t VAR=t FUNC=sin(t) PERIODIC=NO
61 c1: COM ATOMS=1,2
62 c2: COM ATOMS=3,4
63 d: DISTANCE COMPONENTS ATOMS=c1,c2
64 PRINT ARG=t,cos,sin,d.x,d.y,d.z STRIDE=1 FILE=colvar FMT=%8.4f
65 # this calculates sine and cosine of a projected component of distance
66 mycos: MATHEVAL ARG=d.x,d.y VAR=x,y FUNC=x/sqrt(x*x+y*y) PERIODIC=NO
67 mysin: MATHEVAL ARG=d.x,d.y VAR=x,y FUNC=y/sqrt(x*x+y*y) PERIODIC=NO
68 # this creates a moving spring so that the system follows a circle-like dynamics
69 # but it is not a bias, it is a simple value now
70 vv1: MATHEVAL ARG=mycos,mysin,cos,sin VAR=mc,ms,c,s FUNC=100*((mc-c)^2+(ms-s)^2) PERIODIC=NO
71 # this takes the value calculated with matheval and uses as a bias
72 cc: BIASVALUE ARG=vv1
73 # some printout
74 PRINT ARG=t,cos,sin,d.x,d.y,d.z,mycos,mysin,cc.bias.vv1 STRIDE=1 FILE=colvar FMT=%8.4f
75 \endverbatim
76 (see also \ref TIME, \ref MATHEVAL, \ref COM, \ref DISTANCE, and \ref PRINT).
77 
78 
79 */
80 //+ENDPLUMEDOC
81 
82 class BiasValue : public Bias{
83 public:
84  BiasValue(const ActionOptions&);
85  void calculate();
86  static void registerKeywords(Keywords& keys);
87 };
88 
89 PLUMED_REGISTER_ACTION(BiasValue,"BIASVALUE")
90 
91 void BiasValue::registerKeywords(Keywords& keys){
92  Bias::registerKeywords(keys);
93  keys.use("ARG");
94  componentsAreNotOptional(keys);
95  // Should be _bias below
96  keys.addOutputComponent("bias.","default","one or multiple instances of this quantity will be refereceable elsewhere in the input file. "
97  "these quantities will named with the arguments of the bias followed by "
98  "the character string _bias. These quantities tell the user how much the bias is "
99  "due to each of the colvars.");
100  keys.addOutputComponent("bias","default","total bias");
101 }
102 
103 BiasValue::BiasValue(const ActionOptions&ao):
105 {
106  checkRead();
107  // add one bias for each argument
108  // addComponent("bias");
109  for(unsigned i=0;i<getNumberOfArguments();++i){
110  //log<<getPntrToArgument(i)->getName()<<"\n";
111  string ss;
112  ss="bias."+getPntrToArgument(i)->getName();
113 // ss=getPntrToArgument(i)->getName()+"_bias";
115  }
116  addComponent("bias"); componentIsNotPeriodic("bias");
117 }
118 
120  double bias=0.0;
121 for(unsigned i=0;i< getNumberOfArguments() ;++i){
122  double val; val=getArgument(i);
123 // log<<"BIAS "<<val<<"\n";
124  getPntrToComponent(i)->set(val);
125  setOutputForce(i,-1.);
126  bias+=val;
127 }
129 }
130 
131 }
132 }
const std::string & getName() const
Get the name of the quantity.
Definition: Value.h:196
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
Value * getPntrToArgument(const unsigned n)
Return a pointer to specific argument.
void addComponent(const std::string &name)
Add a value with a name like label.name.
void calculate()
Calculate an Action.
Definition: BiasValue.cpp:119
void set(double)
Set the value of the function.
Definition: Value.h:174
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
void setOutputForce(int i, double g)
Definition: Bias.h:56
double getArgument(const unsigned n) const
Returns the value of an argument.
Provides the keyword BIASVALUE
Definition: BiasValue.cpp:82
This is the abstract base class to use for implementing new simulation biases, within it there is inf...
Definition: Bias.h:40
#define PLUMED_BIAS_INIT(ao)
Definition: Bias.h:29
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
unsigned getNumberOfArguments() const
Returns the number of arguments.