LCOV - code coverage report
Current view: top level - colvar - Fake.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 41 80.5 %
Date: 2020-11-18 11:20:57 Functions: 9 11 81.8 %

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

Generated by: LCOV version 1.13