LCOV - code coverage report
Current view: top level - bias - Bias.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 35 37 94.6 %
Date: 2020-11-18 11:20:57 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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             : 
      24             : 
      25             : namespace PLMD {
      26             : namespace bias {
      27             : 
      28         510 : Bias::Bias(const ActionOptions&ao):
      29             :   Action(ao),
      30             :   ActionPilot(ao),
      31             :   ActionWithValue(ao),
      32             :   ActionWithArguments(ao),
      33        1020 :   outputForces(getNumberOfArguments(),0.0)
      34             : {
      35        1016 :   addComponentWithDerivatives("bias");
      36        1016 :   componentIsNotPeriodic("bias");
      37        1016 :   valueBias=getPntrToComponent("bias");
      38             : 
      39         508 :   if(getStride()>1) {
      40           0 :     log<<"  multiple time step "<<getStride()<<" ";
      41           0 :     log<<cite("Ferrarotti, Bottaro, Perez-Villa, and Bussi, J. Chem. Theory Comput. 11, 139 (2015)")<<"\n";
      42             :   }
      43        7626 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
      44        3559 :     (getPntrToArgument(i)->getPntrToAction())->turnOnDerivatives();
      45             :   }
      46             : 
      47         508 :   turnOnDerivatives();
      48         508 : }
      49             : 
      50         527 : void Bias::registerKeywords( Keywords& keys ) {
      51         527 :   Action::registerKeywords(keys);
      52         527 :   ActionPilot::registerKeywords(keys);
      53         527 :   ActionWithValue::registerKeywords(keys);
      54         527 :   ActionWithArguments::registerKeywords(keys);
      55        2108 :   keys.add("hidden","STRIDE","the frequency with which the forces due to the bias should be calculated.  This can be used to correctly set up multistep algorithms");
      56         527 :   componentsAreNotOptional(keys);
      57        2108 :   keys.addOutputComponent("bias","default","the instantaneous value of the bias potential");
      58         527 : }
      59             : 
      60       30046 : void Bias::apply() {
      61       30046 :   const unsigned noa=getNumberOfArguments();
      62       30046 :   const unsigned ncp=getNumberOfComponents();
      63             : 
      64       30046 :   if(onStep()) {
      65       30046 :     double gstr = static_cast<double>(getStride());
      66      193748 :     for(unsigned i=0; i<noa; ++i) {
      67       81851 :       getPntrToArgument(i)->addForce(gstr*outputForces[i]);
      68             :     }
      69             :   }
      70             : 
      71             :   // additional forces on the bias component
      72       30046 :   std::vector<double> f(noa,0.0);
      73       30046 :   std::vector<double> forces(noa);
      74             : 
      75             :   bool at_least_one_forced=false;
      76      470656 :   for(unsigned i=0; i<ncp; ++i) {
      77      220305 :     if(getPntrToComponent(i)->applyForce(forces)) {
      78             :       at_least_one_forced=true;
      79        2127 :       for(unsigned j=0; j<noa; j++) f[j]+=forces[j];
      80             :     }
      81             :   }
      82             : 
      83       30046 :   if(at_least_one_forced && !onStep()) error("you are biasing a bias with an inconsistent STRIDE");
      84             : 
      85       30605 :   if(at_least_one_forced) for(unsigned i=0; i<noa; ++i) {
      86         559 :       getPntrToArgument(i)->addForce(f[i]);
      87             :     }
      88             : 
      89       30046 : }
      90             : 
      91             : }
      92             : }
      93             : 
      94             : 

Generated by: LCOV version 1.13