Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2014-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 "MultiColvarFilter.h" 23 : 24 : namespace PLMD { 25 : namespace multicolvar { 26 : 27 38 : void MultiColvarFilter::registerKeywords( Keywords& keys ) { 28 38 : BridgedMultiColvarFunction::registerKeywords( keys ); 29 76 : if( keys.reserved("VMEAN") ) { 30 76 : keys.use("VMEAN"); 31 : } 32 38 : keys.use("MEAN"); 33 38 : keys.use("MOMENTS"); 34 38 : keys.use("MIN"); 35 38 : keys.use("MAX"); 36 38 : keys.use("ALT_MIN"); 37 38 : keys.use("LOWEST"); 38 38 : keys.use("HIGHEST"); 39 38 : } 40 : 41 14 : MultiColvarFilter::MultiColvarFilter(const ActionOptions&ao): 42 : Action(ao), 43 14 : BridgedMultiColvarFunction(ao) { 44 14 : if( getPntrToMultiColvar()->isDensity() ) { 45 0 : error("filtering/transforming density makes no sense"); 46 : } 47 : 48 14 : if( getName().find("MFILTER")!=std::string::npos ) { 49 13 : filter=true; 50 : } else { 51 1 : plumed_assert( getName().find("MTRANSFORM")!=std::string::npos ); 52 1 : filter=false; 53 : } 54 : 55 14 : readVesselKeywords(); 56 14 : } 57 : 58 46 : void MultiColvarFilter::doJobsRequiredBeforeTaskList() { 59 46 : ActionWithValue::clearDerivatives(); 60 46 : ActionWithVessel::doJobsRequiredBeforeTaskList(); 61 46 : } 62 : 63 20027 : void MultiColvarFilter::completeTask( const unsigned& curr, MultiValue& invals, MultiValue& outvals ) const { 64 20027 : invals.copyValues( outvals ); 65 20027 : if( derivativesAreRequired() ) { 66 16151 : invals.copyDerivatives( outvals ); 67 : } 68 : 69 : // Retrieve the value of the multicolvar and apply filter 70 20027 : double val=invals.get(1), df, weight=applyFilter( val, df ); 71 : 72 : // Now propegate derivatives 73 20027 : if( filter && !getPntrToMultiColvar()->weightHasDerivatives ) { 74 : outvals.setValue( 0, weight ); 75 18447 : if( derivativesAreRequired() ) { 76 2268072 : for(unsigned i=0; i<invals.getNumberActive(); ++i) { 77 2253501 : unsigned jder=invals.getActiveIndex(i); 78 2253501 : outvals.addDerivative( 0, jder, df*invals.getDerivative(1, jder ) ); 79 : } 80 : } 81 1580 : } else if( filter ) { 82 : double ww=outvals.get(0); 83 0 : outvals.setValue( 0, ww*weight ); 84 0 : if( derivativesAreRequired() ) { 85 0 : for(unsigned i=0; i<outvals.getNumberActive(); ++i) { 86 0 : unsigned ider=outvals.getActiveIndex(i); 87 0 : outvals.setDerivative( 0, ider, weight*outvals.getDerivative(1,ider) + ww*df*outvals.getDerivative(0,ider) ); 88 : } 89 : } 90 : } else { 91 : outvals.setValue( 1, weight ); 92 1580 : if( derivativesAreRequired() ) { 93 80912 : for(unsigned i=0; i<invals.getNumberActive(); ++i) { 94 79332 : unsigned jder=invals.getActiveIndex(i); 95 79332 : outvals.setDerivative( 1, jder, df*invals.getDerivative(1, jder ) ); 96 : } 97 : } 98 : } 99 20027 : } 100 : 101 0 : void MultiColvarFilter::addBridgeForces( const std::vector<double>& bb ) { 102 : plumed_dbg_assert( bb.size()==0 ); 103 0 : } 104 : 105 : } 106 : }