LCOV - code coverage report
Current view: top level - colvar - Fake.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 38 78.9 %
Date: 2024-10-18 14:00:25 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2023 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 "Colvar.h"
      23             : #include "core/ActionRegister.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace colvar {
      27             : 
      28             : //+PLUMEDOC COLVAR FAKE
      29             : /*
      30             : This is a fake colvar container used by cltools or various other actions that supports input and period definitions
      31             : 
      32             : \par Examples
      33             : 
      34             : \plumedfile
      35             : FAKE ATOMS=1 PERIODIC=-3.14,3.14   LABEL=d2
      36             : \endplumedfile
      37             : 
      38             : */
      39             : //+ENDPLUMEDOC
      40             : 
      41             : class ColvarFake : public Colvar {
      42             : 
      43             : public:
      44             :   static void registerKeywords( Keywords& keys );
      45             :   explicit ColvarFake(const ActionOptions&);
      46           0 :   std::string getOutputComponentDescription( const std::string& cname, const Keywords& keys ) const override { plumed_error(); }
      47             : // active methods:
      48             :   void calculate() override;
      49             : };
      50             : 
      51             : PLUMED_REGISTER_ACTION(ColvarFake,"FAKE")
      52             : 
      53          19 : void ColvarFake::registerKeywords( Keywords& keys ) {
      54          19 :   Colvar::registerKeywords( keys );
      55          38 :   keys.add("atoms","ATOMS","the fake atom index, a number is enough");
      56          38 :   keys.reserve("compulsory","PERIODIC","if the output of your function is periodic then you should specify the periodicity of the function.  If the output is not periodic you must state this using PERIODIC=NO,NO (one for the lower and the other for the upper boundary). For multicomponents then it is PERIODIC=mincomp1,maxcomp1,mincomp2,maxcomp2  etc ");
      57          19 :   keys.use("PERIODIC");
      58          38 :   keys.add("optional","COMPONENTS","additional components that this variable is supposed to have. Periodicity is ruled by PERIODIC keyword ");
      59          19 :   useCustomisableComponents(keys);
      60          19 : }
      61             : 
      62          17 : ColvarFake::ColvarFake(const ActionOptions&ao):
      63          17 :   PLUMED_COLVAR_INIT(ao)
      64             : {
      65             :   std::vector<AtomNumber> atoms;
      66          34 :   parseAtomList("ATOMS",atoms);
      67             : 
      68             :   std::vector<std::string> comps;
      69             :   // multiple components for this variable
      70          34 :   parseVector("COMPONENTS",comps);
      71          17 :   if(comps.size()!=0) {
      72           2 :     for(unsigned i=0; i<comps.size(); i++) {
      73           2 :       addComponentWithDerivatives(comps[i]);
      74             :     }
      75             :     // periodicity
      76             :   } else {
      77             :     // only one component for this variable
      78          32 :     addValueWithDerivatives();
      79             :   }
      80             :   std::vector<std::string> period;
      81          34 :   parseVector("PERIODIC",period);
      82          17 :   if(period.size()!=0) {
      83          17 :     plumed_massert(static_cast<unsigned>(getNumberOfComponents()*2)==period.size(),"the periodicty should coincide with the number of components");
      84          17 :     if(comps.size()!=0) {
      85           2 :       for(int i=0; i<getNumberOfComponents(); i++) {
      86           1 :         std::string pp=comps[i];
      87           1 :         if(period[i*2]!="none" && period[i*2+1]!="none" ) {
      88           1 :           componentIsPeriodic(pp,period[i*2],period[i*2+1]);
      89             :         } else {
      90           0 :           componentIsNotPeriodic(pp);
      91             :         }
      92             :       }
      93             :     } else {
      94          29 :       if(period[0]!="none" && period[1]!="none" ) {
      95          13 :         setPeriodic(period[0],period[1]);
      96             :       } else {
      97           3 :         setNotPeriodic();
      98             :       }
      99             :     }
     100             :   } else {
     101           0 :     if(comps.size()!=0) {
     102           0 :       for(int i=0; i<getNumberOfComponents(); i++) {
     103           0 :         componentIsNotPeriodic(getPntrToComponent(i)->getName());
     104             :       }
     105             :     } else {
     106           0 :       setNotPeriodic();
     107             :     }
     108             :   }
     109          17 :   checkRead();
     110          17 :   requestAtoms(atoms);
     111             : 
     112          34 : }
     113             : 
     114             : 
     115             : // calculator
     116           0 : void ColvarFake::calculate() {
     117           0 :   plumed_merror("you should never have got here");
     118             : }
     119             : 
     120             : }
     121             : }
     122             : 
     123             : 
     124             : 

Generated by: LCOV version 1.16