LCOV - code coverage report
Current view: top level - core - Colvar.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 29 100.0 %
Date: 2026-03-30 13:16:06 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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             : #ifndef __PLUMED_core_Colvar_h
      23             : #define __PLUMED_core_Colvar_h
      24             : 
      25             : #include "ActionAtomistic.h"
      26             : #include "ActionWithValue.h"
      27             : #include <vector>
      28             : 
      29             : #define PLUMED_COLVAR_INIT(ao) Action(ao),Colvar(ao)
      30             : 
      31             : namespace PLMD {
      32             : 
      33             : /**
      34             : \ingroup INHERIT
      35             : This is the abstract base class to use for implementing new collective variables, within it there is
      36             : \ref AddingAColvar "information" as to how to go about implementing a new CV.
      37             : */
      38             : 
      39             : class Colvar :
      40             :   public ActionAtomistic,
      41             :   public ActionWithValue {
      42             : private:
      43             : protected:
      44             :   bool isEnergy;
      45             :   bool isExtraCV;
      46             :   void requestAtoms(const std::vector<AtomNumber> & a);
      47             : // Set the derivatives for a particular atom equal to the input Vector
      48             : // This routine is called setAtomsDerivatives because not because you
      49             : // are setting the derivative of many atoms but because you are setting
      50             : // the derivatives of a particular atom.  The s is an apostrophe s
      51             : // but you can't put apostrophes in function names
      52             :   void           setAtomsDerivatives(int,const Vector&);
      53             :   void           setAtomsDerivatives(Value*,int,const Vector&);
      54             :   void           setBoxDerivatives(const Tensor&);
      55             :   void           setBoxDerivatives(Value*,const Tensor&);
      56             :   const Tensor & getBoxDerivatives()const;
      57             :   const double & getForce()const;
      58             :   void apply() override;
      59             : /// Set box derivatives automatically.
      60             : /// It should be called after the setAtomsDerivatives has been used for all
      61             : /// single atoms.
      62             : /// \warning It only works for collective variable NOT using PBCs!
      63             :   void           setBoxDerivativesNoPbc();
      64             :   void           setBoxDerivativesNoPbc(Value*);
      65             : public:
      66             :   bool checkIsEnergy() {
      67      119450 :     return isEnergy;
      68             :   }
      69             :   explicit Colvar(const ActionOptions&);
      70        1927 :   ~Colvar() {}
      71             :   static void registerKeywords( Keywords& keys );
      72             :   unsigned getNumberOfDerivatives() override;
      73             : };
      74             : 
      75             : inline
      76    18513544 : void Colvar::setAtomsDerivatives(Value*v,int i,const Vector&d) {
      77    18513544 :   v->addDerivative(3*i+0,d[0]);
      78    18513544 :   v->addDerivative(3*i+1,d[1]);
      79    18513544 :   v->addDerivative(3*i+2,d[2]);
      80    18513544 : }
      81             : 
      82             : 
      83             : inline
      84      232541 : void Colvar::setBoxDerivatives(Value* v,const Tensor&d) {
      85             :   unsigned nat=getNumberOfAtoms();
      86      232541 :   v->addDerivative(3*nat+0,d(0,0));
      87      232541 :   v->addDerivative(3*nat+1,d(0,1));
      88      232541 :   v->addDerivative(3*nat+2,d(0,2));
      89      232541 :   v->addDerivative(3*nat+3,d(1,0));
      90      232541 :   v->addDerivative(3*nat+4,d(1,1));
      91      232541 :   v->addDerivative(3*nat+5,d(1,2));
      92      232541 :   v->addDerivative(3*nat+6,d(2,0));
      93      232541 :   v->addDerivative(3*nat+7,d(2,1));
      94      232541 :   v->addDerivative(3*nat+8,d(2,2));
      95      232541 : }
      96             : 
      97             : inline
      98    16702116 : void Colvar::setAtomsDerivatives(int i,const Vector&d) {
      99    16702116 :   setAtomsDerivatives(getPntrToValue(),i,d);
     100    16702116 : }
     101             : 
     102             : inline
     103       15261 : void Colvar::setBoxDerivatives(const Tensor&d) {
     104       15261 :   setBoxDerivatives(getPntrToValue(),d);
     105       15261 : }
     106             : 
     107             : inline
     108      120447 : void Colvar::setBoxDerivativesNoPbc() {
     109      120447 :   setBoxDerivativesNoPbc(getPntrToValue());
     110      120447 : }
     111             : 
     112             : inline
     113        5027 : unsigned Colvar::getNumberOfDerivatives() {
     114        5027 :   return 3*getNumberOfAtoms() + 9;
     115             : }
     116             : 
     117             : 
     118             : }
     119             : 
     120             : #endif

Generated by: LCOV version 1.16