LCOV - code coverage report
Current view: top level - refdist - Displacement.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 33 100.0 %
Date: 2024-10-18 14:00:25 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2018 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/ActionRegister.h"
      23             : #include "core/PlumedMain.h"
      24             : #include "core/ActionSet.h"
      25             : #include "core/ActionShortcut.h"
      26             : #include "core/ActionWithValue.h"
      27             : 
      28             : //+PLUMEDOC MCOLVAR DISPLACEMENT
      29             : /*
      30             : Calculate the displacement vector between the pair of input vectors
      31             : 
      32             : \par Examples
      33             : 
      34             : 
      35             : */
      36             : //+ENDPLUMEDOC
      37             : 
      38             : namespace PLMD {
      39             : namespace refdist {
      40             : 
      41             : class Displacement : public ActionShortcut {
      42             : public:
      43             :   static std::string fixArgumentDot( const std::string& argin );
      44             :   static void registerKeywords( Keywords& keys );
      45             :   Value* getValueWithLabel( const std::string& name ) const ;
      46             :   explicit Displacement(const ActionOptions&ao);
      47             : };
      48             : 
      49             : PLUMED_REGISTER_ACTION(Displacement,"DISPLACEMENT")
      50             : 
      51         104 : void Displacement::registerKeywords( Keywords& keys ) {
      52         104 :   ActionShortcut::registerKeywords(keys);
      53         208 :   keys.add("compulsory","ARG1","The point that we are calculating the distance from");
      54         208 :   keys.add("compulsory","ARG2","The point that we are calculating the distance to");
      55         104 :   keys.setValueDescription("the differences between the input arguments");
      56         312 :   keys.needsAction("DIFFERENCE"); keys.needsAction("TRANSPOSE"); keys.needsAction("VSTACK");
      57         104 : }
      58             : 
      59         354 : std::string Displacement::fixArgumentDot( const std::string& argin ) {
      60         354 :   std::string argout = argin; std::size_t dot=argin.find(".");
      61         362 :   if( dot!=std::string::npos ) argout = argin.substr(0,dot) + "_" + argin.substr(dot+1);
      62         354 :   return argout;
      63             : }
      64             : 
      65          52 : Displacement::Displacement( const ActionOptions& ao):
      66             :   Action(ao),
      67          52 :   ActionShortcut(ao)
      68             : {
      69             :   // Read in argument names
      70         156 :   std::vector<std::string> arg1f, arg2f; parseVector("ARG1",arg1f); parseVector("ARG2",arg2f);
      71             :   // Check if one of the input arguments is a reference cluster
      72          52 :   if( arg1f.size()!=arg2f.size() ) error("number of arguments specified to ARG1 should be same as number for ARG2");
      73             : 
      74          52 :   Value* val1=getValueWithLabel( arg1f[0] );
      75          52 :   if( arg1f.size()==1 && val1->getRank()!=0 ) {
      76           7 :     Value* val2=getValueWithLabel( arg2f[0] );
      77           7 :     if( val1->getNumberOfValues()==val2->getNumberOfValues() ) {
      78          10 :       readInputLine( getShortcutLabel() + "_" + fixArgumentDot(arg1f[0]) + "_diff: DIFFERENCE ARG=" + arg1f[0] + "," + arg2f[0] );
      79          10 :       readInputLine( getShortcutLabel() + ": TRANSPOSE ARG=" + getShortcutLabel() + "_" + fixArgumentDot(arg1f[0]) + "_diff");
      80           4 :     } else readInputLine( getShortcutLabel() + ": DIFFERENCE ARG=" + arg1f[0] + "," + arg2f[0] );
      81             :   } else {
      82         217 :     for(unsigned i=0; i<arg1f.size(); ++i) readInputLine( getShortcutLabel() + "_" + fixArgumentDot(arg1f[i]) + "_diff: DIFFERENCE ARG=" + arg1f[i] + "," + arg2f[i] );
      83         217 :     std::string argdat = "ARG=" + getShortcutLabel() + "_" + fixArgumentDot(arg1f[0]) + "_diff"; for(unsigned i=1; i<arg1f.size(); ++i) argdat += "," +  getShortcutLabel() + "_" + fixArgumentDot(arg1f[i]) + "_diff";
      84          90 :     readInputLine( getShortcutLabel() + ": VSTACK " + argdat );
      85             :   }
      86          52 : }
      87             : 
      88          59 : Value* Displacement::getValueWithLabel( const std::string& name ) const {
      89          59 :   std::size_t dot=name.find("."); std::string sname = name.substr(0,dot);
      90          59 :   ActionWithValue* vv=plumed.getActionSet().selectWithLabel<ActionWithValue*>( sname );
      91          59 :   if( !vv ) error("cannot find value with name " + name );
      92          59 :   if( dot==std::string::npos ) return vv->copyOutput(0);
      93           2 :   if( !vv->exists(name) ) error("cannot find value with name " + name );
      94           2 :   return vv->copyOutput( name );
      95             : }
      96             : 
      97             : }
      98             : }

Generated by: LCOV version 1.16