All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
UWalls.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 UPPER_WALLS
33 /*
34 The LOWER_WALLS and UPPER_WALLS keywords define a wall for the value of one or more collective variables,
35  which limits the region of the phase space accessible during the simulation.
36 
37 The restraining potential starts acting on the system when the value of the CV is greater
38 (in the case of UPPER_WALLS) or lower (in the case of LOWER_WALLS) than a certain limit \f$a_i\f$ (AT)
39 minus an offset \f$o_i\f$ (OFFSET).
40 The expression for the bias due to the wall is given by:
41 
42 \f$
43  \sum_i {k_i}((x_i-a_i+o_i)/s_i)^e_i
44 \f$
45 
46 \f$k_i\f$ (KAPPA) is an energy constant in internal unit of the code, \f$s_i\f$ (EPS) a rescaling factor and
47 \f$e_i\f$ (EXP) the exponent determining the power law. By default: EXP = 2, EPS = 1.0, OFF = 0.
48 
49 
50 \par Examples
51 The following input tells plumed to add both a lower and an upper walls on the distance
52 between atoms 3 and 5 and the distance between atoms 2 and 4. The lower and upper limits
53 are defined at different values. The strength of the walls is the same for the four cases.
54 It also tells plumed to print the energy of the walls.
55 \verbatim
56 DISTANCE ATOMS=3,5 LABEL=d1
57 DISTANCE ATOMS=2,4 LABEL=d2
58 UPPER_WALLS ARG=d1,d2 AT=1.0,1.5 KAPPA=150.0,150.0 EXP=2,2 EPS=1,1 OFFSET 0,0 LABEL=uwall
59 LOWER_WALLS ARG=d1,d2 AT=0.0,1.0 KAPPA=150.0,150.0 EXP=2,2 EPS=1,1 OFFSET 0,0 LABEL=lwall
60 PRINT ARG=uwall.bias,lwall.bias
61 \endverbatim
62 (See also \ref DISTANCE and \ref PRINT).
63 
64 */
65 //+ENDPLUMEDOC
66 
67 class UWalls : public Bias{
68  std::vector<double> at;
69  std::vector<double> kappa;
70  std::vector<double> exp;
71  std::vector<double> eps;
72  std::vector<double> offset;
73 public:
74  UWalls(const ActionOptions&);
75  void calculate();
76  static void registerKeywords(Keywords& keys);
77 };
78 
79 PLUMED_REGISTER_ACTION(UWalls,"UPPER_WALLS")
80 
81 void UWalls::registerKeywords(Keywords& keys){
82  Bias::registerKeywords(keys);
83  keys.use("ARG");
84  keys.add("compulsory","AT","the positions of the wall. The a_i in the expression for a wall.");
85  keys.add("compulsory","KAPPA","the force constant for the wall. The k_i in the expression for a wall.");
86  keys.add("compulsory","OFFSET","0.0","the offset for the start of the wall. The o_i in the expression for a wall.");
87  keys.add("compulsory","EXP","2.0","the powers for the walls. The e_i in the expression for a wall.");
88  keys.add("compulsory","EPS","1.0","the values for s_i in the expression for a wall");
89  componentsAreNotOptional(keys);
90  keys.addOutputComponent("bias","default","the instantaneous value of the bias potential");
91  keys.addOutputComponent("force2","default","the instantaneous value of the squared force due to this bias potential");
92 }
93 
94 UWalls::UWalls(const ActionOptions&ao):
96 at(getNumberOfArguments(),0),
97 kappa(getNumberOfArguments(),0.0),
98 exp(getNumberOfArguments(),2.0),
99 eps(getNumberOfArguments(),1.0),
100 offset(getNumberOfArguments(),0.0)
101 {
102  // Note : the sizes of these vectors are checked automatically by parseVector
103  parseVector("OFFSET",offset);
104  parseVector("EPS",eps);
105  parseVector("EXP",exp);
106  parseVector("KAPPA",kappa);
107  parseVector("AT",at);
108  checkRead();
109 
110  log.printf(" at");
111  for(unsigned i=0;i<at.size();i++) log.printf(" %f",at[i]);
112  log.printf("\n");
113  log.printf(" with an offset");
114  for(unsigned i=0;i<offset.size();i++) log.printf(" %f",offset[i]);
115  log.printf("\n");
116  log.printf(" with force constant");
117  for(unsigned i=0;i<kappa.size();i++) log.printf(" %f",kappa[i]);
118  log.printf("\n");
119  log.printf(" and exponent");
120  for(unsigned i=0;i<exp.size();i++) log.printf(" %f",exp[i]);
121  log.printf("\n");
122  log.printf(" rescaled");
123  for(unsigned i=0;i<eps.size();i++) log.printf(" %f",eps[i]);
124  log.printf("\n");
125 
126  addComponent("bias"); componentIsNotPeriodic("bias");
127  addComponent("force2"); componentIsNotPeriodic("force2");
128 }
129 
131  double ene=0.0;
132  double totf2=0.0;
133  for(unsigned i=0;i<getNumberOfArguments();++i){
134  const double cv=difference(i,at[i],getArgument(i));
135  const double k=kappa[i];
136  const double exponent=exp[i];
137  const double epsilon=eps[i];
138  const double off=offset[i];
139  const double uscale = (cv+off)/epsilon;
140  double f = 0.0;
141  if( uscale > 0.) {
142  double power = pow( uscale, exponent );
143  f = -( k / epsilon ) * exponent * power / uscale;
144  ene += k * power;
145  totf2 += f * f;
146  }
147  setOutputForce(i,f);
148  }
149  getPntrToComponent("bias")->set(ene);
150  getPntrToComponent("force2")->set(totf2);
151 }
152 
153 }
154 }
std::vector< double > at
Definition: UWalls.cpp:68
Log & log
Reference to the log stream.
Definition: Action.h:93
const double epsilon
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
std::vector< double > kappa
Definition: UWalls.cpp:69
void calculate()
Calculate an Action.
Definition: UWalls.cpp:130
double difference(int, double, double) const
Takes the difference taking into account pbc for arg i.
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void addComponent(const std::string &name)
Add a value with a name like label.name.
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
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
Definition: Action.h:311
void setOutputForce(int i, double g)
Definition: Bias.h:56
double getArgument(const unsigned n) const
Returns the value of an argument.
std::vector< double > eps
Definition: UWalls.cpp:71
This is the abstract base class to use for implementing new simulation biases, within it there is inf...
Definition: Bias.h:40
std::vector< double > exp
Definition: UWalls.cpp:70
#define PLUMED_BIAS_INIT(ao)
Definition: Bias.h:29
std::vector< double > offset
Definition: UWalls.cpp:72
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
unsigned getNumberOfArguments() const
Returns the number of arguments.
Provides the keyword UPPER_WALLS
Definition: UWalls.cpp:67