LCOV - code coverage report
Current view: top level - volumes - VolumeShortcut.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 66 74 89.2 %
Date: 2026-11-05 10:19:04 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-2017 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             : #ifndef __PLUMED_volumes_VolumeShortcut_h
      23             : #define __PLUMED_volumes_VolumeShortcut_h
      24             : 
      25             : #include "core/ActionShortcut.h"
      26             : #include "core/ActionRegister.h"
      27             : #include "core/PlumedMain.h"
      28             : #include "core/ActionSet.h"
      29             : #include "core/Group.h"
      30             : 
      31             : namespace PLMD {
      32             : namespace volumes {
      33             : 
      34             : template <const char* v>
      35             : class VolumeShortcut : public ActionShortcut {
      36             : public:
      37             :   static void registerKeywords( Keywords& keys );
      38             :   VolumeShortcut(const ActionOptions&ao);
      39             : };
      40             : 
      41             : template <const char* v>
      42         108 : void VolumeShortcut<v>::registerKeywords( Keywords& keys ) {
      43         324 :   actionRegister().getKeywords( std::string(v) + "_CALC", keys );
      44         108 :   keys.add("hidden","IS_SHORTCUT","hidden keyword to tell if actions are shortcuts so that example generator can provide expansions of shortcuts");
      45         108 :   keys.addDeprecatedKeyword("DATA","");
      46         108 :   keys.addDeprecatedKeyword("LESS_THAN","");
      47         216 :   keys.addOutputComponent("lessthan","LESS_THAN","scalar","the number of cvs in the region of interest that are less than a certain threshold");
      48         108 :   keys.addDeprecatedKeyword("MORE_THAN","");
      49         216 :   keys.addOutputComponent("morethan","MORE_THAN","scalar","the number of cvs in the region of interest that are more than a certain threshold");
      50         108 :   keys.addDeprecatedKeyword("BETWEEN","");
      51         216 :   keys.addOutputComponent("between","BETWEEN","scalar","the number of cvs in the region of interest that are within a certain range");
      52         216 :   keys.addDeprecatedFlag("SUM","");
      53         216 :   keys.addOutputComponent("sum","SUM","scalar","the sum of all the colvars weighted by the function that determines if we are in the region");
      54         216 :   keys.addDeprecatedFlag("MEAN","");
      55         216 :   keys.addOutputComponent("mean","MEAN","scalar","the average values of the colvar in the region of interest");
      56         108 :   keys.addActionNameSuffix("_CALC");
      57         108 :   keys.addActionNameSuffix("_ACC");
      58         108 :   keys.needsAction("LESS_THAN");
      59         108 :   keys.needsAction("MORE_THAN");
      60         108 :   keys.needsAction("GROUP");
      61         108 :   keys.needsAction("BETWEEN");
      62         108 :   keys.needsAction("SUM");
      63         108 :   keys.needsAction("MEAN");
      64         108 :   keys.needsAction("CUSTOM");
      65         216 :   keys.setValueDescription("scalar","sum of values of input CVs in regin of interest");
      66         108 : }
      67             : 
      68             : template <const char* v>
      69          68 : VolumeShortcut<v>::VolumeShortcut(const ActionOptions&ao):
      70             :   Action(ao),
      71          68 :   ActionShortcut(ao) {
      72          68 :   std::string voltype(v), mc_lab;
      73          68 :   parse("DATA",mc_lab);
      74             :   bool dosum;
      75          68 :   parseFlag("SUM",dosum);
      76          68 :   std::string shortcutType="_CALC ";
      77             :   {
      78             :     bool usegpu;
      79          68 :     parseFlag("USEGPU",usegpu);
      80          68 :     if (usegpu) {
      81             :       shortcutType="_ACC ";
      82             :     }
      83             :   }
      84          68 :   if( mc_lab.length()>0 ) {
      85          12 :     Group* mygrp = plumed.getActionSet().template selectWithLabel<Group*>(mc_lab);
      86          12 :     Group* mygrp2 = plumed.getActionSet().template selectWithLabel<Group*>(mc_lab + "_grp");
      87          12 :     if( mygrp || mygrp2 ) {
      88          20 :       readInputLine( getShortcutLabel() + "_grp: GROUP ATOMS=" + mc_lab );
      89             :     }
      90             :     bool domean;
      91          24 :     parseFlag("MEAN",domean);
      92             :     std::string lt_input, mt_input, bt_input;
      93          12 :     parse("LESS_THAN",lt_input);
      94          12 :     parse("MORE_THAN",mt_input);
      95          24 :     parse("BETWEEN",bt_input);
      96             :     std::string atomsd;
      97          24 :     parse("ATOMS",atomsd);
      98          12 :     if( atomsd.length()==0 ) {
      99             :       atomsd=mc_lab;
     100             :     }
     101             :     // Create the apprpriate volume object
     102          36 :     readInputLine( getShortcutLabel() + ": " + voltype + shortcutType + convertInputLineToString() + " ATOMS=" + atomsd );
     103             :     // Now create input for sums
     104          12 :     if( dosum || domean ) {
     105          36 :       readInputLine( getShortcutLabel() + "_prod: CUSTOM ARG=" + mc_lab + "," + getShortcutLabel() + " FUNC=x*y PERIODIC=NO");
     106          12 :       std::string tlab = getShortcutLabel() + "_numer";
     107          12 :       if( dosum ) {
     108           0 :         tlab = getShortcutLabel() + "_sum";
     109             :       }
     110          36 :       readInputLine( tlab + ": SUM ARG=" + getShortcutLabel() + "_prod PERIODIC=NO");
     111             :     }
     112          12 :     if( domean ) {
     113             :       // Calculate denominator
     114          24 :       readInputLine( getShortcutLabel() + "_norm: SUM ARG=" + getShortcutLabel() + " PERIODIC=NO");
     115             :       // And calculate final quantity which is mean of these two actions
     116          12 :       std::string arg1_lab = getShortcutLabel() + "_numer";
     117          12 :       if( dosum ) {
     118           0 :         arg1_lab = getShortcutLabel()  + "_sum";
     119             :       }
     120          48 :       readInputLine( getShortcutLabel() + "_mean: CUSTOM ARG=" + arg1_lab + "," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     121             :     }
     122          12 :     if( lt_input.length()>0 ) {
     123             :       // Calculate number less than
     124          28 :       readInputLine( mc_lab + "_" + getShortcutLabel() + "_lt: LESS_THAN ARG=" + mc_lab + " SWITCH={" + lt_input +"}");
     125             :       // And the matheval bit
     126          28 :       readInputLine( getShortcutLabel() + "_lt: CUSTOM ARG=" + mc_lab + "_" + getShortcutLabel() + "_lt," + getShortcutLabel() + " FUNC=x*y PERIODIC=NO");
     127             :       // And the final sum
     128          21 :       readInputLine( getShortcutLabel() + "_lessthan: SUM ARG=" + getShortcutLabel() + "_lt PERIODIC=NO");
     129             :     }
     130          12 :     if( mt_input.length()>0 ) {
     131             :       // Calculate number less than
     132           0 :       readInputLine( mc_lab + "_" + getShortcutLabel() + "_mt: MORE_THAN ARG=" + mc_lab + " SWITCH={" + mt_input  + "}");
     133             :       // And the matheval bit
     134           0 :       readInputLine( getShortcutLabel() + "_mt: CUSTOM ARG=" + mc_lab + "_" + getShortcutLabel() + "_mt," + getShortcutLabel() + " FUNC=x*y PERIODIC=NO");
     135             :       // And the final sum
     136           0 :       readInputLine( getShortcutLabel() + "_morethan: SUM ARG=" + getShortcutLabel() + "_mt PERIODIC=NO");
     137             :     }
     138          12 :     if( bt_input.length()>0 ) {
     139             :       // Calculate number less than
     140           0 :       readInputLine( mc_lab + "_" + getShortcutLabel() + "_bt: BETWEEN ARG=" + mc_lab + " SWITCH={" + bt_input +"}");
     141             :       // And the matheval bit
     142           0 :       readInputLine( getShortcutLabel() + "_bt: CUSTOM ARG=" + mc_lab + "_" + getShortcutLabel() + "_bt," + getShortcutLabel() + " FUNC=x*y PERIODIC=NO");
     143             :       // And the final sum
     144           0 :       readInputLine( getShortcutLabel() + "_between: SUM ARG=" + getShortcutLabel() + "_bt PERIODIC=NO");
     145             :     }
     146          56 :   } else if( dosum ) {
     147          22 :     readInputLine( getShortcutLabel() + "_vols: " + voltype + shortcutType + convertInputLineToString() );
     148          33 :     readInputLine( getShortcutLabel() + ": SUM ARG=" + getShortcutLabel() + "_vols PERIODIC=NO");
     149             :   } else {
     150          90 :     readInputLine( getShortcutLabel() + ": " + voltype + shortcutType + convertInputLineToString() );
     151             :   }
     152          68 : }
     153             : 
     154             : }
     155             : }
     156             : #endif

Generated by: LCOV version 1.16