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