LCOV - code coverage report
Current view: top level - colvar - ExtraCV.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 25 25 100.0 %
Date: 2024-10-11 08:09:47 Functions: 8 9 88.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-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 "ActionRegister.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/Atoms.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace colvar {
      29             : 
      30             : //+PLUMEDOC COLVAR EXTRACV
      31             : /*
      32             : Allow PLUMED to use collective variables computed in the MD engine.
      33             : 
      34             : This feature requires the MD engine to use special instructions to pass to PLUMED the value of
      35             : some pre-computed collective variable. Check the documentation of the MD code to find out which
      36             : collective variables can be computed and passed to PLUMED. These variables can then be accessed by
      37             : name using the EXTRACV action.
      38             : 
      39             : \par Examples
      40             : 
      41             : This example takes the lambda variable pre-computed in GROMACS and apply to it a restraint to keep
      42             : it close to the value 3.
      43             : \plumedfile
      44             : l: EXTRACV NAME=lambda
      45             : RESTRAINT ARG=l KAPPA=10 AT=3
      46             : \endplumedfile
      47             : 
      48             : 
      49             : */
      50             : //+ENDPLUMEDOC
      51             : 
      52             : 
      53             : class ExtraCV : public Colvar {
      54             :   std::string name;
      55             : public:
      56             :   explicit ExtraCV(const ActionOptions&);
      57             : // active methods:
      58             :   void prepare() override;
      59             :   void calculate() override;
      60             :   unsigned getNumberOfDerivatives() override;
      61             :   static void registerKeywords( Keywords& keys );
      62             : };
      63             : 
      64       10423 : PLUMED_REGISTER_ACTION(ExtraCV,"EXTRACV")
      65             : 
      66           2 : ExtraCV::ExtraCV(const ActionOptions&ao):
      67           2 :   PLUMED_COLVAR_INIT(ao)
      68             : {
      69           2 :   addValueWithDerivatives(); setNotPeriodic();
      70           2 :   getPntrToValue()->resizeDerivatives(1);
      71           2 :   parse("NAME",name);
      72           2 :   log<<"  name: "<<name<<"\n";
      73           2 :   isExtraCV=true;
      74             :   setExtraCV(name);
      75           2 : }
      76             : 
      77           3 : void ExtraCV::registerKeywords( Keywords& keys ) {
      78           3 :   Action::registerKeywords( keys );
      79           3 :   ActionAtomistic::registerKeywords( keys );
      80           3 :   ActionWithValue::registerKeywords( keys );
      81           3 :   keys.remove("NUMERICAL_DERIVATIVES");
      82           6 :   keys.add("compulsory","NAME","name of the CV as computed by the MD engine");
      83           3 : }
      84             : 
      85           4 : unsigned ExtraCV::getNumberOfDerivatives() {
      86           4 :   return 1;
      87             : }
      88             : 
      89          60 : void ExtraCV::prepare() {
      90             : /// \todo: notify Atoms that this is requested
      91          60 : }
      92             : 
      93             : // calculator
      94          60 : void ExtraCV::calculate() {
      95          60 :   double value=plumed.getAtoms().getExtraCV(name);
      96          60 :   setValue( value );
      97          60 :   getPntrToComponent(0)->addDerivative(0,1.0);
      98          60 : }
      99             : 
     100             : }
     101             : }
     102             : 
     103             : 
     104             : 

Generated by: LCOV version 1.15