Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2023 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.org for more information.
6 :
7 : This file is part of plumed, version 2.
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 "core/ActionRegister.h"
24 :
25 : namespace PLMD {
26 : namespace bias {
27 :
28 : //+PLUMEDOC BIAS LOWER_WALLS
29 : /*
30 : Defines a wall for the value of one or more collective variables,
31 : which limits the region of the phase space accessible during the simulation.
32 :
33 : The restraining potential starts acting on the system when the value of the CV is greater
34 : (in the case of UPPER_WALLS) or lower (in the case of LOWER_WALLS) than a certain limit \f$a_i\f$ (AT)
35 : minus an offset \f$o_i\f$ (OFFSET).
36 : The expression for the bias due to the wall is given by:
37 :
38 : for UPPER_WALLS:
39 : \f$
40 : \sum_i {k_i}((x_i-a_i+o_i)/s_i)^e_i
41 : \f$
42 :
43 : for LOWER_WALLS:
44 : \f$
45 : \sum_i {k_i}|(x_i-a_i-o_i)/s_i|^e_i
46 : \f$
47 :
48 : \f$k_i\f$ (KAPPA) is an energy constant in internal unit of the code, \f$s_i\f$ (EPS) a rescaling factor and
49 : \f$e_i\f$ (EXP) the exponent determining the power law. By default: EXP = 2, EPS = 1.0, OFFSET = 0.
50 :
51 :
52 : \par Examples
53 :
54 : The following input tells plumed to add both a lower and an upper walls on the distance
55 : between atoms 3 and 5 and the distance between atoms 2 and 4. The lower and upper limits
56 : are defined at different values. The strength of the walls is the same for the four cases.
57 : It also tells plumed to print the energy of the walls.
58 : \plumedfile
59 : DISTANCE ATOMS=3,5 LABEL=d1
60 : DISTANCE ATOMS=2,4 LABEL=d2
61 : 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
62 : 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
63 : PRINT ARG=uwall.bias,lwall.bias
64 : \endplumedfile
65 : (See also \ref DISTANCE and \ref PRINT).
66 :
67 : */
68 : //+ENDPLUMEDOC
69 :
70 : //+PLUMEDOC BIAS LOWER_WALLS_SCALAR
71 : /*
72 : Defines a wall for the value of one or more collective variables,
73 : which limits the region of the phase space accessible during the simulation.
74 :
75 : \par Examples
76 :
77 : */
78 : //+ENDPLUMEDOC
79 :
80 : class LWalls : public Bias {
81 : std::vector<double> at;
82 : std::vector<double> kappa;
83 : std::vector<double> exp;
84 : std::vector<double> eps;
85 : std::vector<double> offset;
86 : public:
87 : explicit LWalls(const ActionOptions&);
88 : void calculate() override;
89 : static void registerKeywords(Keywords& keys);
90 : };
91 :
92 : PLUMED_REGISTER_ACTION(LWalls,"LOWER_WALLS_SCALAR")
93 :
94 12 : void LWalls::registerKeywords(Keywords& keys) {
95 12 : Bias::registerKeywords(keys);
96 24 : keys.setDisplayName("LOWER_WALLS");
97 12 : keys.add("hidden","NO_ACTION_LOG","suppresses printing from action on the log");
98 12 : keys.add("compulsory","AT","the positions of the wall. The a_i in the expression for a wall.");
99 12 : keys.add("compulsory","KAPPA","the force constant for the wall. The k_i in the expression for a wall.");
100 12 : keys.add("compulsory","OFFSET","0.0","the offset for the start of the wall. The o_i in the expression for a wall.");
101 12 : keys.add("compulsory","EXP","2.0","the powers for the walls. The e_i in the expression for a wall.");
102 12 : keys.add("compulsory","EPS","1.0","the values for s_i in the expression for a wall");
103 24 : keys.addOutputComponent("force2","default","scalar","the instantaneous value of the squared force due to this bias potential");
104 12 : }
105 :
106 5 : LWalls::LWalls(const ActionOptions&ao):
107 : PLUMED_BIAS_INIT(ao),
108 10 : at(getNumberOfArguments(),0),
109 5 : kappa(getNumberOfArguments(),0.0),
110 5 : exp(getNumberOfArguments(),2.0),
111 5 : eps(getNumberOfArguments(),1.0),
112 10 : offset(getNumberOfArguments(),0.0) {
113 : // Note sizes of these vectors are automatically checked by parseVector :-)
114 5 : parseVector("OFFSET",offset);
115 5 : parseVector("EPS",eps);
116 5 : parseVector("EXP",exp);
117 5 : parseVector("KAPPA",kappa);
118 5 : parseVector("AT",at);
119 5 : checkRead();
120 :
121 5 : log.printf(" at");
122 10 : for(unsigned i=0; i<at.size(); i++) {
123 5 : log.printf(" %f",at[i]);
124 : }
125 5 : log.printf("\n");
126 5 : log.printf(" with an offset");
127 10 : for(unsigned i=0; i<offset.size(); i++) {
128 5 : log.printf(" %f",offset[i]);
129 : }
130 5 : log.printf("\n");
131 5 : log.printf(" with force constant");
132 10 : for(unsigned i=0; i<kappa.size(); i++) {
133 5 : log.printf(" %f",kappa[i]);
134 : }
135 5 : log.printf("\n");
136 5 : log.printf(" and exponent");
137 10 : for(unsigned i=0; i<exp.size(); i++) {
138 5 : log.printf(" %f",exp[i]);
139 : }
140 5 : log.printf("\n");
141 5 : log.printf(" rescaled");
142 10 : for(unsigned i=0; i<eps.size(); i++) {
143 5 : log.printf(" %f",eps[i]);
144 : }
145 5 : log.printf("\n");
146 :
147 10 : addComponent("force2");
148 5 : componentIsNotPeriodic("force2");
149 5 : }
150 :
151 49 : void LWalls::calculate() {
152 : double ene = 0.0;
153 : double totf2 = 0.0;
154 98 : for(unsigned i=0; i<getNumberOfArguments(); ++i) {
155 : double f = 0.0;
156 49 : const double cv=difference(i,at[i],getArgument(i));
157 49 : const double off=offset[i];
158 49 : const double epsilon=eps[i];
159 49 : const double lscale = (cv-off)/epsilon;
160 49 : if( lscale < 0.) {
161 25 : const double k=kappa[i];
162 25 : const double exponent=exp[i];
163 25 : double power = std::pow( -lscale, exponent );
164 25 : f = -( k / epsilon ) * exponent * power / lscale;
165 25 : ene += k * power;
166 25 : totf2 += f * f;
167 : }
168 49 : setOutputForce(i,f);
169 : }
170 49 : setBias(ene);
171 49 : getPntrToComponent("force2")->set(totf2);
172 49 : }
173 :
174 : }
175 : }
|