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