LCOV - code coverage report
Current view: top level - bias - Walls.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 53 59 89.8 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2020 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 "core/ActionShortcut.h"
      23             : #include "core/ActionWithArguments.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/ActionSet.h"
      26             : #include "core/ActionRegister.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace bias {
      30             : 
      31             : class Walls : public ActionShortcut {
      32             : public:
      33             :   explicit Walls(const ActionOptions&);
      34             :   static void registerKeywords(Keywords& keys);
      35             : };
      36             : 
      37             : PLUMED_REGISTER_ACTION(Walls,"UPPER_WALLS")
      38             : PLUMED_REGISTER_ACTION(Walls,"LOWER_WALLS")
      39             : 
      40          58 : void Walls::registerKeywords(Keywords& keys) {
      41          58 :   ActionShortcut::registerKeywords(keys);
      42         116 :   keys.add("numbered","ARG","the arguments on which the bias is acting");
      43         116 :   keys.add("compulsory","AT","the positions of the wall. The a_i in the expression for a wall.");
      44         116 :   keys.add("compulsory","KAPPA","the force constant for the wall.  The k_i in the expression for a wall.");
      45         116 :   keys.add("compulsory","OFFSET","0.0","the offset for the start of the wall.  The o_i in the expression for a wall.");
      46         116 :   keys.add("compulsory","EXP","2.0","the powers for the walls.  The e_i in the expression for a wall.");
      47         116 :   keys.add("compulsory","EPS","1.0","the values for s_i in the expression for a wall");
      48         116 :   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");
      49         116 :   keys.addOutputComponent("bias","default","the instantaneous value of the bias potential");
      50         116 :   keys.addOutputComponent("force2","default","the instantaneous value of the squared force due to this bias potential");
      51         174 :   keys.addActionNameSuffix("_SCALAR"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM");
      52         174 :   keys.needsAction("SUM"); keys.needsAction("COMBINE"); keys.needsAction("BIASVALUE");
      53          58 : }
      54             : 
      55          21 : Walls::Walls(const ActionOptions&ao):
      56             :   Action(ao),
      57          21 :   ActionShortcut(ao)
      58             : {
      59             :   // Read the arguments
      60          42 :   std::vector<std::string> args; parseVector("ARG",args);
      61          21 :   if( args.size()==0 ) error("found no input arguments");
      62          21 :   std::string allargs=args[0]; for(unsigned i=1; i<args.size(); ++i) allargs += "," + args[i];
      63          21 :   std::vector<Value*> vals; ActionWithArguments::interpretArgumentList( args, plumed.getActionSet(), this, vals );
      64          21 :   if( vals.size()==0 ) error("found no input arguments");
      65             : 
      66             :   // Find the rank
      67          21 :   unsigned rank=vals[0]->getRank();
      68          42 :   for(unsigned i=0; i<vals.size(); ++i) {
      69          21 :     if( vals[i]->getRank()>0 && vals[i]->hasDerivatives() ) error("argument should not be function on grid");
      70          21 :     if( vals[i]->getRank()!=rank ) error("all arguments should have same rank");
      71             :   }
      72          21 :   if( rank==0 ) {
      73          33 :     if( getName()=="UPPER_WALLS") readInputLine( getShortcutLabel() + ": UPPER_WALLS_SCALAR ARG=" + allargs + " " + convertInputLineToString() );
      74          10 :     else if( getName()=="LOWER_WALLS") readInputLine( getShortcutLabel() + ": LOWER_WALLS_SCALAR ARG=" + allargs + " " + convertInputLineToString() );
      75           0 :     else plumed_merror( getName() + " is not valid");
      76             :     return;
      77             :   }
      78             : 
      79             :   // Note : the sizes of these vectors are checked automatically by parseVector
      80           4 :   std::vector<std::string> kappa(args.size()); parseVector("KAPPA",kappa);
      81           4 :   std::vector<std::string> offset(kappa.size()); parseVector("OFFSET",offset);
      82           4 :   std::vector<std::string> eps(kappa.size()); parseVector("EPS",eps);
      83           4 :   std::vector<std::string> exp(kappa.size()); parseVector("EXP",exp);
      84           4 :   std::vector<std::string> at(kappa.size()); parseVector("AT",at);
      85             : 
      86             :   std::string biasinp, forceinp;
      87           4 :   for(unsigned i=0; i<args.size(); ++i) {
      88           2 :     std::string argn; std::size_t dot=args[i].find_first_of(".");
      89           2 :     if(dot!=std::string::npos) argn = args[i].substr(0,dot) + "_" + args[i].substr(dot+1);
      90             :     else argn = args[i];
      91           4 :     readInputLine( getShortcutLabel() + "_cv_" + argn + ": COMBINE PERIODIC=NO ARG=" + args[i] + " PARAMETERS=" + at[i] );
      92           2 :     if( getName()=="UPPER_WALLS" ) {
      93           4 :       readInputLine( getShortcutLabel() + "_scale_" + argn + ": CUSTOM PERIODIC=NO FUNC=(x+" + offset[i] +")/" + eps[i] + " ARG=" + getShortcutLabel() + "_cv_" + argn );
      94           4 :       readInputLine( getShortcutLabel() + "_pow_" + argn + ": CUSTOM PERIODIC=NO FUNC=step(x)*x^" + exp[i] + " ARG=" + getShortcutLabel() + "_scale_" + argn );
      95           0 :     } else if( getName()=="LOWER_WALLS" ) {
      96           0 :       readInputLine( getShortcutLabel() + "_scale_" + argn + ": CUSTOM PERIODIC=NO FUNC=(x-" + offset[i] +")/" + eps[i] + " ARG=" + getShortcutLabel() + "_cv_" + argn );
      97           0 :       readInputLine( getShortcutLabel() + "_pow_" + argn + ": CUSTOM PERIODIC=NO FUNC=step(-x)*(-x)^" + exp[i] + " ARG=" + getShortcutLabel() + "_scale_" + argn );
      98             :     }
      99           4 :     readInputLine( getShortcutLabel() + "_v_wall_" + argn + ": CUSTOM PERIODIC=NO FUNC=" + kappa[i] +"*x" + " ARG=" + getShortcutLabel() + "_pow_" + argn );
     100           4 :     readInputLine( getShortcutLabel() + "_wall_" + argn + ": SUM ARG=" + getShortcutLabel() + "_v_wall_" + argn + " PERIODIC=NO");
     101           6 :     readInputLine( getShortcutLabel() + "_force_" + argn + ": CUSTOM PERIODIC=NO FUNC=" + kappa[i] + "*" + exp[i] + "*x/(y*" + eps[i] + ") " +
     102           6 :                    "ARG=" + getShortcutLabel() + "_pow_" + argn + "," + getShortcutLabel() + "_scale_" + argn );
     103           4 :     readInputLine( getShortcutLabel() + "_v_force2_" + argn + ": CUSTOM PERIODIC=NO FUNC=x*x ARG=" + getShortcutLabel() + "_force_" + argn );
     104           4 :     readInputLine( getShortcutLabel() + "_force2_" + argn + ": SUM ARG=" + getShortcutLabel() + "_v_force2_" + argn + " PERIODIC=NO");
     105           2 :     if(i==0) {
     106           4 :       biasinp = " ARG=" + getShortcutLabel() + "_wall_" + argn;
     107           4 :       forceinp = " ARG=" + getShortcutLabel() + "_force2_" + argn;
     108             :     } else {
     109           0 :       biasinp += "," + getShortcutLabel() + "_wall_" + argn;
     110           0 :       forceinp += "," + getShortcutLabel() + "_force2_" + argn;
     111             :     }
     112             :   }
     113           4 :   readInputLine( getShortcutLabel() + "_bias: COMBINE PERIODIC=NO " + biasinp );
     114           4 :   readInputLine( "BIASVALUE ARG=" + getShortcutLabel() + "_bias" );
     115           4 :   readInputLine( getShortcutLabel() + "_force2: COMBINE PERIODIC=NO " + forceinp  );
     116          23 : }
     117             : 
     118             : }
     119             : }

Generated by: LCOV version 1.16