LCOV - code coverage report
Current view: top level - bias - Bias.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 36 100.0 %
Date: 2024-10-18 14:00:25 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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             : 
      24             : 
      25             : namespace PLMD {
      26             : namespace bias {
      27             : 
      28         966 : Bias::Bias(const ActionOptions&ao):
      29             :   Action(ao),
      30             :   ActionPilot(ao),
      31             :   ActionWithValue(ao),
      32             :   ActionWithArguments(ao),
      33         966 :   outputForces(getNumberOfArguments(),0.0)
      34             : {
      35        1932 :   addComponentWithDerivatives("bias");
      36         966 :   componentIsNotPeriodic("bias");
      37         966 :   valueBias=getPntrToComponent("bias");
      38             : 
      39         966 :   if(getStride()>1) {
      40           3 :     log<<"  multiple time step "<<getStride()<<" ";
      41           6 :     log<<cite("Ferrarotti, Bottaro, Perez-Villa, and Bussi, J. Chem. Theory Comput. 11, 139 (2015)")<<"\n";
      42             :   }
      43        5132 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
      44        4166 :     (getPntrToArgument(i)->getPntrToAction())->turnOnDerivatives();
      45             :   }
      46             : 
      47         966 :   ActionWithValue::turnOnDerivatives();
      48         966 : }
      49             : 
      50        1326 : void Bias::registerKeywords( Keywords& keys ) {
      51        1326 :   Action::registerKeywords(keys);
      52        1326 :   ActionPilot::registerKeywords(keys);
      53        1326 :   ActionWithValue::registerKeywords(keys);
      54        1326 :   ActionWithArguments::registerKeywords(keys);
      55        2652 :   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        2652 :   keys.addOutputComponent("bias","default","the instantaneous value of the bias potential");
      57        1326 : }
      58             : 
      59       99464 : void Bias::apply() {
      60       99464 :   const unsigned noa=getNumberOfArguments();
      61       99464 :   const unsigned ncp=getNumberOfComponents();
      62             : 
      63       99464 :   if(onStep()) {
      64       99464 :     double gstr = static_cast<double>(getStride());
      65      275283 :     for(unsigned i=0; i<noa; ++i) {
      66      175819 :       getPntrToArgument(i)->addForce(gstr*outputForces[i]);
      67             :     }
      68             :   }
      69             : 
      70       99464 :   f.assign(noa,0.0);
      71       99464 :   forces.resize(noa);
      72             : 
      73             :   bool at_least_one_forced=false;
      74      473081 :   for(unsigned i=0; i<ncp; ++i) {
      75      373617 :     if(getPntrToComponent(i)->applyForce(forces)) {
      76             :       at_least_one_forced=true;
      77         913 :       for(unsigned j=0; j<noa; j++) f[j]+=forces[j];
      78             :     }
      79             :   }
      80             : 
      81       99464 :   if(at_least_one_forced && !onStep()) error("you are biasing a bias with an inconsistent STRIDE");
      82             : 
      83      100305 :   if(at_least_one_forced) for(unsigned i=0; i<noa; ++i) {
      84         559 :       getPntrToArgument(i)->addForce(f[i]);
      85             :     }
      86             : 
      87       99464 : }
      88             : 
      89             : }
      90             : }
      91             : 
      92             : 

Generated by: LCOV version 1.16