LCOV - code coverage report
Current view: top level - core - Colvar.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 24 24 100.0 %
Date: 2024-10-18 13:59:31 Functions: 4 4 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             : {
      43             : private:
      44             : protected:
      45             :   void requestAtoms(const std::vector<AtomNumber> & a);
      46             : // Set the derivatives for a particular atom equal to the input Vector
      47             : // This routine is called setAtomsDerivatives because not because you
      48             : // are setting the derivative of many atoms but because you are setting
      49             : // the derivatives of a particular atom.  The s is an apostrophe s
      50             : // but you can't put apostrophes in function names
      51             :   void           setAtomsDerivatives(int,const Vector&);
      52             :   void           setAtomsDerivatives(Value*,int,const Vector&);
      53             :   void           setBoxDerivatives(const Tensor&);
      54             :   void           setBoxDerivatives(Value*,const Tensor&);
      55             :   const Tensor & getBoxDerivatives()const;
      56             :   const double & getForce()const;
      57             :   void apply() override;
      58             : /// Set box derivatives automatically.
      59             : /// It should be called after the setAtomsDerivatives has been used for all
      60             : /// single atoms.
      61             : /// \warning It only works for collective variable NOT using PBCs!
      62             :   void           setBoxDerivativesNoPbc();
      63             :   void           setBoxDerivativesNoPbc(Value*);
      64             : public:
      65             :   explicit Colvar(const ActionOptions&);
      66        2143 :   ~Colvar() {}
      67             :   static void registerKeywords( Keywords& keys );
      68             :   unsigned getNumberOfDerivatives() override;
      69             :   static void setBoxDerivativesNoPbc( const std::vector<Vector>& pos, std::vector<std::vector<Vector> >& derivs, std::vector<Tensor>& virial );
      70             : };
      71             : 
      72             : inline
      73    18284933 : void Colvar::setAtomsDerivatives(Value*v,int i,const Vector&d) {
      74    18284933 :   v->addDerivative(3*i+0,d[0]);
      75    18284933 :   v->addDerivative(3*i+1,d[1]);
      76    18284933 :   v->addDerivative(3*i+2,d[2]);
      77    18284933 : }
      78             : 
      79             : 
      80             : inline
      81      263933 : void Colvar::setBoxDerivatives(Value* v,const Tensor&d) {
      82             :   unsigned nat=getNumberOfAtoms();
      83      263933 :   v->addDerivative(3*nat+0,d(0,0));
      84      263933 :   v->addDerivative(3*nat+1,d(0,1));
      85      263933 :   v->addDerivative(3*nat+2,d(0,2));
      86      263933 :   v->addDerivative(3*nat+3,d(1,0));
      87      263933 :   v->addDerivative(3*nat+4,d(1,1));
      88      263933 :   v->addDerivative(3*nat+5,d(1,2));
      89      263933 :   v->addDerivative(3*nat+6,d(2,0));
      90      263933 :   v->addDerivative(3*nat+7,d(2,1));
      91      263933 :   v->addDerivative(3*nat+8,d(2,2));
      92      263933 : }
      93             : 
      94             : inline
      95             : void Colvar::setAtomsDerivatives(int i,const Vector&d) {
      96    16472515 :   setAtomsDerivatives(getPntrToValue(),i,d);
      97             : }
      98             : 
      99             : inline
     100             : void Colvar::setBoxDerivatives(const Tensor&d) {
     101      124547 :   setBoxDerivatives(getPntrToValue(),d);
     102        2010 : }
     103             : 
     104             : inline
     105             : void Colvar::setBoxDerivativesNoPbc() {
     106       42244 :   setBoxDerivativesNoPbc(getPntrToValue());
     107         222 : }
     108             : 
     109             : inline
     110      150618 : unsigned Colvar::getNumberOfDerivatives() {
     111      150618 :   return 3*getNumberOfAtoms() + 9;
     112             : }
     113             : 
     114             : 
     115             : }
     116             : 
     117             : #endif

Generated by: LCOV version 1.16