LCOV - code coverage report
Current view: top level - colvar - ExtraCV.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 27 27 100.0 %
Date: 2019-08-13 10:15:31 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-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             : #include "core/PlumedMain.h"
      25             : #include "core/Atoms.h"
      26             : 
      27             : #include <string>
      28             : #include <cmath>
      29             : 
      30             : namespace PLMD {
      31             : namespace colvar {
      32             : 
      33             : //+PLUMEDOC COLVAR EXTRACV
      34             : /*
      35             : XX
      36             : 
      37             : \par Examples
      38             : 
      39             : XX
      40             : 
      41             : */
      42             : //+ENDPLUMEDOC
      43             : 
      44             : 
      45           6 : class ExtraCV : public Colvar {
      46             :   std::string name;
      47             : public:
      48             :   explicit ExtraCV(const ActionOptions&);
      49             : // active methods:
      50             :   void prepare() override;
      51             :   void calculate() override;
      52             :   unsigned getNumberOfDerivatives() override;
      53             :   static void registerKeywords( Keywords& keys );
      54             : };
      55             : 
      56             : 
      57             : using namespace std;
      58             : 
      59             : 
      60        7836 : PLUMED_REGISTER_ACTION(ExtraCV,"EXTRACV")
      61             : 
      62           2 : ExtraCV::ExtraCV(const ActionOptions&ao):
      63           2 :   PLUMED_COLVAR_INIT(ao)
      64             : {
      65           2 :   addValueWithDerivatives(); setNotPeriodic();
      66           2 :   getPntrToValue()->resizeDerivatives(1);
      67           4 :   parse("NAME",name);
      68           2 :   log<<"  name: "<<name<<"\n";
      69           2 :   isExtraCV=true;
      70             :   setExtraCV(name);
      71           2 : }
      72             : 
      73           3 : void ExtraCV::registerKeywords( Keywords& keys ) {
      74           3 :   Action::registerKeywords( keys );
      75           3 :   ActionAtomistic::registerKeywords( keys );
      76           3 :   ActionWithValue::registerKeywords( keys );
      77           6 :   keys.remove("NUMERICAL_DERIVATIVES");
      78          12 :   keys.add("compulsory","NAME","name of the CV as computed by the MD engine");
      79           3 : }
      80             : 
      81           4 : unsigned ExtraCV::getNumberOfDerivatives() {
      82           4 :   return 1;
      83             : }
      84             : 
      85          40 : void ExtraCV::prepare() {
      86             : /// \todo: notify Atoms that this is requested
      87          40 : }
      88             : 
      89             : // calculator
      90          40 : void ExtraCV::calculate() {
      91          80 :   double value=plumed.getAtoms().getExtraCV(name);
      92          40 :   setValue( value );
      93          40 :   getPntrToComponent(0)->addDerivative(0,1.0);
      94          40 : }
      95             : 
      96             : }
      97        5874 : }
      98             : 
      99             : 
     100             : 

Generated by: LCOV version 1.14