Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2018 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 "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 10 : class BiasValue : public Bias {
83 : public:
84 : explicit BiasValue(const ActionOptions&);
85 : void calculate();
86 : static void registerKeywords(Keywords& keys);
87 : };
88 :
89 2528 : PLUMED_REGISTER_ACTION(BiasValue,"BIASVALUE")
90 :
91 6 : void BiasValue::registerKeywords(Keywords& keys) {
92 6 : Bias::registerKeywords(keys);
93 6 : keys.use("ARG");
94 : // Should be _bias below
95 : keys.addOutputComponent("_bias","default","one or multiple instances of this quantity will be refereceable elsewhere in the input file. "
96 : "these quantities will named with the arguments of the bias followed by "
97 : "the character string _bias. These quantities tell the user how much the bias is "
98 6 : "due to each of the colvars.");
99 6 : }
100 :
101 5 : BiasValue::BiasValue(const ActionOptions&ao):
102 5 : PLUMED_BIAS_INIT(ao)
103 : {
104 5 : checkRead();
105 : // add one bias for each argument
106 11 : for(unsigned i=0; i<getNumberOfArguments(); ++i) {
107 6 : string ss=getPntrToArgument(i)->getName()+"_bias";
108 6 : addComponent(ss); componentIsNotPeriodic(ss);
109 6 : }
110 5 : }
111 :
112 26 : void BiasValue::calculate() {
113 26 : double bias=0.0;
114 58 : for(unsigned i=0; i<getNumberOfArguments(); ++i) {
115 32 : double val; val=getArgument(i);
116 32 : getPntrToComponent(i+1)->set(val);
117 32 : setOutputForce(i,-1.);
118 32 : bias+=val;
119 : }
120 26 : setBias(bias);
121 26 : }
122 :
123 : }
124 2523 : }
|