LCOV - code coverage report
Current view: top level - refdist - EuclideanDistance.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 20 21 95.2 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

          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/ActionShortcut.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/ActionSet.h"
      26             : #include "core/ActionWithValue.h"
      27             : 
      28             : //+PLUMEDOC MCOLVAR EUCLIDEAN_DISTANCE
      29             : /*
      30             : Calculate the euclidean distance between two vectors of arguments
      31             : 
      32             : \par Examples
      33             : 
      34             : */
      35             : //+ENDPLUMEDOC
      36             : 
      37             : namespace PLMD {
      38             : namespace refdist {
      39             : 
      40             : class EuclideanDistance : public ActionShortcut {
      41             : public:
      42             :   static void registerKeywords( Keywords& keys );
      43             :   explicit EuclideanDistance(const ActionOptions&ao);
      44             : };
      45             : 
      46             : PLUMED_REGISTER_ACTION(EuclideanDistance,"EUCLIDEAN_DISTANCE")
      47             : 
      48          35 : void EuclideanDistance::registerKeywords( Keywords& keys ) {
      49          35 :   ActionShortcut::registerKeywords(keys);
      50          70 :   keys.add("compulsory","ARG1","The poin that we are calculating the distance from");
      51          70 :   keys.add("compulsory","ARG2","The point that we are calculating the distance to");
      52          70 :   keys.addFlag("SQUARED",false,"The squared distance should be calculated");
      53          35 :   keys.setValueDescription("the euclidean distances between the input vectors");
      54          70 :   keys.needsAction("DISPLACEMENT"); keys.needsAction("CUSTOM");
      55          70 :   keys.needsAction("TRANSPOSE"); keys.needsAction("MATRIX_PRODUCT_DIAGONAL");
      56          35 : }
      57             : 
      58          28 : EuclideanDistance::EuclideanDistance( const ActionOptions& ao):
      59             :   Action(ao),
      60          28 :   ActionShortcut(ao)
      61             : {
      62          56 :   std::string arg1, arg2; parse("ARG1",arg1); parse("ARG2",arg2);
      63             :   // Vectors are in rows here
      64          56 :   readInputLine( getShortcutLabel() + "_diff: DISPLACEMENT ARG1=" + arg1 + " ARG2=" + arg2 );
      65             :   // Get the action that computes the differences
      66          56 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_diff"); plumed_assert( av );
      67             :   // Check if squared
      68          56 :   bool squared; parseFlag("SQUARED",squared); std::string olab = getShortcutLabel(); if( !squared ) olab += "_2";
      69             :   // Deal with an annoying corner case when displacement has a single argument
      70          28 :   if( av->copyOutput(0)->getRank()==0 ) {
      71           0 :     readInputLine( olab + ": CUSTOM ARG=" + getShortcutLabel() + "_diff FUNC=x*x PERIODIC=NO");
      72             :   } else {
      73             :     // Notice that the vectors are in the columns here
      74          56 :     readInputLine( getShortcutLabel() + "_diffT: TRANSPOSE ARG=" + getShortcutLabel() + "_diff");
      75          56 :     readInputLine( olab + ": MATRIX_PRODUCT_DIAGONAL ARG=" + getShortcutLabel() + "_diff," + getShortcutLabel() + "_diffT");
      76             :   }
      77          51 :   if( !squared ) readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_2 FUNC=sqrt(x) PERIODIC=NO");
      78          28 : }
      79             : 
      80             : }
      81             : }

Generated by: LCOV version 1.16