LCOV - code coverage report
Current view: top level - bias - Walls.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 65 77 84.4 %
Date: 2025-03-25 09:33:27 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.addInputKeyword("numbered","ARG","scalar/vector","the arguments on which the bias is acting");
      43          58 :   keys.add("compulsory","AT","the positions of the wall. The a_i in the expression for a wall.");
      44          58 :   keys.add("compulsory","KAPPA","the force constant for the wall.  The k_i in the expression for a wall.");
      45          58 :   keys.add("compulsory","OFFSET","0.0","the offset for the start of the wall.  The o_i in the expression for a wall.");
      46          58 :   keys.add("compulsory","EXP","2.0","the powers for the walls.  The e_i in the expression for a wall.");
      47          58 :   keys.add("compulsory","EPS","1.0","the values for s_i in the expression for a wall");
      48          58 :   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","scalar","the instantaneous value of the bias potential");
      50         116 :   keys.addOutputComponent("force2","default","scalar","the instantaneous value of the squared force due to this bias potential");
      51          58 :   keys.addActionNameSuffix("_SCALAR");
      52          58 :   keys.needsAction("COMBINE");
      53          58 :   keys.needsAction("CUSTOM");
      54          58 :   keys.needsAction("SUM");
      55          58 :   keys.needsAction("COMBINE");
      56          58 :   keys.needsAction("BIASVALUE");
      57          58 : }
      58             : 
      59          21 : Walls::Walls(const ActionOptions&ao):
      60             :   Action(ao),
      61          21 :   ActionShortcut(ao) {
      62             :   // Read the arguments
      63             :   std::vector<std::string> args;
      64          42 :   parseVector("ARG",args);
      65          21 :   if( args.size()==0 ) {
      66           0 :     error("found no input arguments");
      67             :   }
      68          21 :   std::string allargs=args[0];
      69          21 :   for(unsigned i=1; i<args.size(); ++i) {
      70           0 :     allargs += "," + args[i];
      71             :   }
      72             :   std::vector<Value*> vals;
      73          21 :   ActionWithArguments::interpretArgumentList( args, plumed.getActionSet(), this, vals );
      74          21 :   if( vals.size()==0 ) {
      75           0 :     error("found no input arguments");
      76             :   }
      77             : 
      78             :   // Find the rank
      79          21 :   unsigned rank=vals[0]->getRank();
      80          42 :   for(unsigned i=0; i<vals.size(); ++i) {
      81          21 :     if( vals[i]->getRank()>0 && vals[i]->hasDerivatives() ) {
      82           0 :       error("argument should not be function on grid");
      83             :     }
      84          21 :     if( vals[i]->getRank()!=rank ) {
      85           0 :       error("all arguments should have same rank");
      86             :     }
      87             :   }
      88          21 :   if( rank==0 ) {
      89          19 :     if( getName()=="UPPER_WALLS") {
      90          28 :       readInputLine( getShortcutLabel() + ": UPPER_WALLS_SCALAR ARG=" + allargs + " " + convertInputLineToString() );
      91           5 :     } else if( getName()=="LOWER_WALLS") {
      92          10 :       readInputLine( getShortcutLabel() + ": LOWER_WALLS_SCALAR ARG=" + allargs + " " + convertInputLineToString() );
      93             :     } else {
      94           0 :       plumed_merror( getName() + " is not valid");
      95             :     }
      96             :     return;
      97             :   }
      98             : 
      99             :   // Note : the sizes of these vectors are checked automatically by parseVector
     100           2 :   std::vector<std::string> kappa(args.size());
     101           4 :   parseVector("KAPPA",kappa);
     102           2 :   std::vector<std::string> offset(kappa.size());
     103           4 :   parseVector("OFFSET",offset);
     104           2 :   std::vector<std::string> eps(kappa.size());
     105           4 :   parseVector("EPS",eps);
     106           2 :   std::vector<std::string> exp(kappa.size());
     107           4 :   parseVector("EXP",exp);
     108           2 :   std::vector<std::string> at(kappa.size());
     109           4 :   parseVector("AT",at);
     110             : 
     111             :   std::string biasinp, forceinp;
     112           4 :   for(unsigned i=0; i<args.size(); ++i) {
     113             :     std::string argn;
     114           2 :     std::size_t dot=args[i].find_first_of(".");
     115           2 :     if(dot!=std::string::npos) {
     116           0 :       argn = args[i].substr(0,dot) + "_" + args[i].substr(dot+1);
     117             :     } else {
     118             :       argn = args[i];
     119             :     }
     120           4 :     readInputLine( getShortcutLabel() + "_cv_" + argn + ": COMBINE PERIODIC=NO ARG=" + args[i] + " PARAMETERS=" + at[i] );
     121           2 :     if( getName()=="UPPER_WALLS" ) {
     122           4 :       readInputLine( getShortcutLabel() + "_scale_" + argn + ": CUSTOM PERIODIC=NO FUNC=(x+" + offset[i] +")/" + eps[i] + " ARG=" + getShortcutLabel() + "_cv_" + argn );
     123           4 :       readInputLine( getShortcutLabel() + "_pow_" + argn + ": CUSTOM PERIODIC=NO FUNC=step(x)*x^" + exp[i] + " ARG=" + getShortcutLabel() + "_scale_" + argn );
     124           0 :     } else if( getName()=="LOWER_WALLS" ) {
     125           0 :       readInputLine( getShortcutLabel() + "_scale_" + argn + ": CUSTOM PERIODIC=NO FUNC=(x-" + offset[i] +")/" + eps[i] + " ARG=" + getShortcutLabel() + "_cv_" + argn );
     126           0 :       readInputLine( getShortcutLabel() + "_pow_" + argn + ": CUSTOM PERIODIC=NO FUNC=step(-x)*(-x)^" + exp[i] + " ARG=" + getShortcutLabel() + "_scale_" + argn );
     127             :     }
     128           4 :     readInputLine( getShortcutLabel() + "_v_wall_" + argn + ": CUSTOM PERIODIC=NO FUNC=" + kappa[i] +"*x" + " ARG=" + getShortcutLabel() + "_pow_" + argn );
     129           4 :     readInputLine( getShortcutLabel() + "_wall_" + argn + ": SUM ARG=" + getShortcutLabel() + "_v_wall_" + argn + " PERIODIC=NO");
     130           6 :     readInputLine( getShortcutLabel() + "_force_" + argn + ": CUSTOM PERIODIC=NO FUNC=" + kappa[i] + "*" + exp[i] + "*x/(y*" + eps[i] + ") " +
     131           6 :                    "ARG=" + getShortcutLabel() + "_pow_" + argn + "," + getShortcutLabel() + "_scale_" + argn );
     132           4 :     readInputLine( getShortcutLabel() + "_v_force2_" + argn + ": CUSTOM PERIODIC=NO FUNC=x*x ARG=" + getShortcutLabel() + "_force_" + argn );
     133           4 :     readInputLine( getShortcutLabel() + "_force2_" + argn + ": SUM ARG=" + getShortcutLabel() + "_v_force2_" + argn + " PERIODIC=NO");
     134           2 :     if(i==0) {
     135           4 :       biasinp = " ARG=" + getShortcutLabel() + "_wall_" + argn;
     136           4 :       forceinp = " ARG=" + getShortcutLabel() + "_force2_" + argn;
     137             :     } else {
     138           0 :       biasinp += "," + getShortcutLabel() + "_wall_" + argn;
     139           0 :       forceinp += "," + getShortcutLabel() + "_force2_" + argn;
     140             :     }
     141             :   }
     142           4 :   readInputLine( getShortcutLabel() + "_bias: COMBINE PERIODIC=NO " + biasinp );
     143           4 :   readInputLine( "BIASVALUE ARG=" + getShortcutLabel() + "_bias" );
     144           4 :   readInputLine( getShortcutLabel() + "_force2: COMBINE PERIODIC=NO " + forceinp  );
     145          23 : }
     146             : 
     147             : }
     148             : }

Generated by: LCOV version 1.16