Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-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_contour_DistanceFromContourBase_h 23 : #define __PLUMED_contour_DistanceFromContourBase_h 24 : 25 : #include "core/ActionAtomistic.h" 26 : #include "core/ActionWithValue.h" 27 : #include "core/ActionWithArguments.h" 28 : #include "tools/SwitchingFunction.h" 29 : #include "tools/RootFindingBase.h" 30 : 31 : namespace PLMD { 32 : namespace contour { 33 : 34 : class DistanceFromContourBase : 35 : public ActionWithValue, 36 : public ActionAtomistic, 37 : public ActionWithArguments { 38 : private: 39 : double contour, gvol; 40 : RootFindingBase<DistanceFromContourBase> mymin; 41 : protected: 42 : std::string kerneltype; 43 : std::vector<double> bw; 44 : double rcut2; 45 : unsigned nactive; 46 : Vector pval; 47 : std::vector<double> forcesToApply; 48 : std::vector<unsigned> active_list; 49 : SwitchingFunction switchingFunction; 50 : /// 51 : double evaluateKernel( const Vector& cpos, const Vector& apos, std::vector<double>& der ) const ; 52 : /// Find a contour along line specified by direction 53 : void findContour( const std::vector<double>& direction, std::vector<double>& point ) const ; 54 : public: 55 : static void registerKeywords( Keywords& keys ); 56 : explicit DistanceFromContourBase( const ActionOptions& ); 57 : unsigned getNumberOfDerivatives() override ; 58 : void lockRequests(); 59 : void unlockRequests(); 60 0 : void calculateNumericalDerivatives( ActionWithValue* a ) { 61 0 : plumed_merror("numerical derivatives are not implemented for this action"); 62 : } 63 : double getDifferenceFromContour( const std::vector<double>& x, std::vector<double>& der ); 64 : void apply(); 65 : }; 66 : 67 : inline 68 166 : unsigned DistanceFromContourBase::getNumberOfDerivatives() { 69 166 : if( getNumberOfArguments()==1 ) { 70 17 : return 4*getNumberOfAtoms() + 8; // One derivative for each weight hence four times the number of atoms - 1 71 : } 72 149 : return 3*getNumberOfAtoms() + 9; 73 : } 74 : 75 : inline 76 : void DistanceFromContourBase::findContour( const std::vector<double>& direction, std::vector<double>& point ) const { 77 291 : mymin.lsearch( direction, point, &DistanceFromContourBase::getDifferenceFromContour ); 78 291 : } 79 : 80 : } 81 : } 82 : #endif