LCOV - code coverage report
Current view: top level - bias - BiasValue.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 21 21 100.0 %
Date: 2020-11-18 11:20:57 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2019 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             : \plumedfile
      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             : \endplumedfile
      51             : 
      52             : Another thing one can do is asking one system to follow
      53             : a circle in sin/cos according a  time dependence
      54             : 
      55             : \plumedfile
      56             : t: TIME
      57             : # this just print cos and sin of time
      58             : cos: MATHEVAL ARG=t VAR=t FUNC=cos(t) PERIODIC=NO
      59             : sin: MATHEVAL ARG=t VAR=t FUNC=sin(t) PERIODIC=NO
      60             : c1: COM ATOMS=1,2
      61             : c2: COM ATOMS=3,4
      62             : d: DISTANCE COMPONENTS ATOMS=c1,c2
      63             : PRINT ARG=t,cos,sin,d.x,d.y,d.z STRIDE=1 FILE=colvar FMT=%8.4f
      64             : # this calculates sine and cosine of a projected component of distance
      65             : mycos:  MATHEVAL ARG=d.x,d.y  VAR=x,y   FUNC=x/sqrt(x*x+y*y) PERIODIC=NO
      66             : mysin:  MATHEVAL ARG=d.x,d.y  VAR=x,y   FUNC=y/sqrt(x*x+y*y) PERIODIC=NO
      67             : # this creates a moving spring so that the system follows a circle-like dynamics
      68             : # but it is not a bias, it is a simple value now
      69             : vv1:  MATHEVAL ARG=mycos,mysin,cos,sin VAR=mc,ms,c,s  FUNC=100*((mc-c)^2+(ms-s)^2) PERIODIC=NO
      70             : # this takes the value calculated with matheval and uses as a bias
      71             : cc: BIASVALUE ARG=vv1
      72             : # some printout
      73             : PRINT ARG=t,cos,sin,d.x,d.y,d.z,mycos,mysin,cc.bias.vv1 STRIDE=1 FILE=colvar FMT=%8.4f
      74             : \endplumedfile
      75             : 
      76             : */
      77             : //+ENDPLUMEDOC
      78             : 
      79          38 : class BiasValue : public Bias {
      80             : public:
      81             :   explicit BiasValue(const ActionOptions&);
      82             :   void calculate();
      83             :   static void registerKeywords(Keywords& keys);
      84             : };
      85             : 
      86        6471 : PLUMED_REGISTER_ACTION(BiasValue,"BIASVALUE")
      87             : 
      88          20 : void BiasValue::registerKeywords(Keywords& keys) {
      89          20 :   Bias::registerKeywords(keys);
      90          40 :   keys.use("ARG");
      91             :   // Should be _bias below
      92          80 :   keys.addOutputComponent("_bias","default","one or multiple instances of this quantity will be refereceable elsewhere in the input file. "
      93             :                           "these quantities will named with  the arguments of the bias followed by "
      94             :                           "the character string _bias. These quantities tell the user how much the bias is "
      95             :                           "due to each of the colvars.");
      96          20 : }
      97             : 
      98          19 : BiasValue::BiasValue(const ActionOptions&ao):
      99          19 :   PLUMED_BIAS_INIT(ao)
     100             : {
     101          19 :   checkRead();
     102             :   // add one bias for each argument
     103          59 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
     104          20 :     string ss=getPntrToArgument(i)->getName()+"_bias";
     105          20 :     addComponent(ss); componentIsNotPeriodic(ss);
     106             :   }
     107          19 : }
     108             : 
     109         138 : void BiasValue::calculate() {
     110             :   double bias=0.0;
     111         426 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
     112             :     double val; val=getArgument(i);
     113         144 :     getPntrToComponent(i+1)->set(val);
     114         144 :     setOutputForce(i,-1.);
     115         144 :     bias+=val;
     116             :   }
     117             :   setBias(bias);
     118         138 : }
     119             : 
     120             : }
     121        4839 : }

Generated by: LCOV version 1.13