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 : #include "PathBase.h" 23 : #include "tools/SwitchingFunction.h" 24 : 25 : namespace PLMD { 26 : namespace mapping { 27 : 28 17 : void PathBase::registerKeywords( Keywords& keys ) { 29 17 : Mapping::registerKeywords( keys ); 30 34 : keys.add("compulsory","LAMBDA","0","the value of the lambda parameter for paths"); 31 34 : keys.addFlag("NOZPATH",false,"do not calculate the zpath position"); 32 17 : } 33 : 34 9 : PathBase::PathBase(const ActionOptions& ao): 35 : Action(ao), 36 9 : Mapping(ao) { 37 : setLowMemOption( true ); 38 9 : weightHasDerivatives=true; 39 : bool noz; 40 9 : parseFlag("NOZPATH",noz); 41 9 : parse("LAMBDA",lambda); 42 : 43 : // Create the list of tasks 44 405 : for(unsigned i=0; i<getNumberOfReferencePoints(); ++i) { 45 396 : addTaskToList( i ); 46 : } 47 : // And activate them all 48 9 : deactivateAllTasks(); 49 405 : for(unsigned i=0; i<getFullNumberOfTasks(); ++i) { 50 396 : taskFlags[i]=1; 51 : } 52 9 : lockContributors(); 53 : 54 9 : std::string empty="LABEL=zpath"; 55 9 : if(!noz) { 56 7 : if( lambda==0 ) { 57 0 : error("you must set LAMDBA value in order to calculate ZPATH coordinate. Use LAMBDA/NOZPATH keyword"); 58 : } 59 14 : addVessel("ZPATH",empty,0); 60 : } 61 9 : } 62 : 63 1103 : double PathBase::getLambda() { 64 1103 : return lambda; 65 : } 66 : 67 4914 : void PathBase::calculate() { 68 : // Loop over all frames is now performed by ActionWithVessel 69 4914 : runAllTasks(); 70 4914 : } 71 : 72 170352 : void PathBase::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const { 73 : // This builds a pack to hold the derivatives 74 170352 : ReferenceValuePack mypack( getNumberOfArguments(), getNumberOfAtoms(), myvals ); 75 170352 : finishPackSetup( current, mypack ); 76 : // Calculate the distance from the frame 77 170352 : double val=calculateDistanceFunction( current, mypack, true ); 78 : // Put the element value in element zero 79 : myvals.setValue( 0, val ); 80 : myvals.setValue( 1, 1.0 ); 81 170352 : return; 82 170352 : } 83 : 84 170352 : double PathBase::transformHD( const double& dist, double& df ) const { 85 170352 : if( lambda==0 ) { 86 55692 : df=1; 87 55692 : return dist; 88 : } 89 114660 : double val = exp( -dist*lambda ); 90 114660 : df = -lambda*val; 91 114660 : return val; 92 : } 93 : 94 : } 95 : }