Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2017-2019 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 "MultiColvarBase.h"
23 : #include "AtomValuePack.h"
24 : #include "core/ActionRegister.h"
25 :
26 : #include <string>
27 : #include <cmath>
28 :
29 : //+PLUMEDOC MCOLVARF MCOLV_COMBINE
30 : /*
31 : Calculate linear combinations of multiple multicolvars
32 :
33 : \par Examples
34 :
35 : */
36 : //+ENDPLUMEDOC
37 :
38 : namespace PLMD {
39 : namespace multicolvar {
40 :
41 3 : class MultiColvarCombine : public MultiColvarBase {
42 : private:
43 : std::vector<double> coeff;
44 : public:
45 : static void registerKeywords( Keywords& keys );
46 : explicit MultiColvarCombine(const ActionOptions&);
47 : /// Actually do the calculation
48 : double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
49 : /// Is the variable periodic
50 1 : bool isPeriodic() { return false; }
51 : };
52 :
53 6453 : PLUMED_REGISTER_ACTION(MultiColvarCombine,"MCOLV_COMBINE")
54 :
55 2 : void MultiColvarCombine::registerKeywords( Keywords& keys ) {
56 2 : MultiColvarBase::registerKeywords( keys );
57 8 : keys.add("compulsory","DATA","the multicolvars you are calculating linear combinations for");
58 10 : keys.add("compulsory","COEFFICIENTS","1.0","the coeficients to use for the various multicolvars");
59 12 : keys.use("MEAN"); keys.use("MORE_THAN"); keys.use("SUM"); keys.use("LESS_THAN"); keys.use("HISTOGRAM");
60 16 : keys.use("MIN"); keys.use("MAX"); keys.use("LOWEST"); keys.use("HIGHEST"); keys.use("ALT_MIN"); keys.use("BETWEEN"); keys.use("MOMENTS");
61 2 : }
62 :
63 1 : MultiColvarCombine::MultiColvarCombine(const ActionOptions& ao):
64 : Action(ao),
65 1 : MultiColvarBase(ao)
66 : {
67 1 : buildSets();
68 5 : for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
69 6 : if( mybasemulticolvars[i]->weightWithDerivatives() ) error("cannot combine multicolvars with weights");
70 : }
71 1 : coeff.resize( getNumberOfBaseMultiColvars() );
72 2 : parseVector("COEFFICIENTS",coeff);
73 2 : log.printf(" coefficients of multicolvars %f", coeff[0] );
74 5 : for(unsigned i=1; i<coeff.size(); ++i) log.printf(", %f", coeff[i] );
75 1 : log.printf("\n");
76 1 : }
77 :
78 15 : double MultiColvarCombine::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
79 15 : double dot=0; std::vector<double> tval(2);
80 90 : for(unsigned i=0; i<coeff.size(); ++i) {
81 30 : getInputData( i, false, myatoms, tval );
82 90 : dot += coeff[i]*tval[1];
83 : }
84 15 : if( !doNotCalculateDerivatives() ) {
85 15 : MultiValue& myvals = myatoms.getUnderlyingMultiValue(); std::vector<double> cc(2);
86 90 : for(unsigned i=0; i<coeff.size(); ++i) {
87 30 : cc[1]=coeff[i]; MultiValue& myder=getInputDerivatives( i, false, myatoms );
88 30 : splitInputDerivatives( 1, 1, 2, i, cc, myder, myatoms );
89 : }
90 : }
91 15 : return dot;
92 : }
93 :
94 : }
95 4839 : }
|