LCOV - code coverage report
Current view: top level - multicolvar - MultiColvarCombine.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 44 45 97.8 %
Date: 2026-03-30 13:16:06 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-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 "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             : 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 override;
      49             : /// Is the variable periodic
      50           1 :   bool isPeriodic() override {
      51           1 :     return false;
      52             :   }
      53             : };
      54             : 
      55       13787 : PLUMED_REGISTER_ACTION(MultiColvarCombine,"MCOLV_COMBINE")
      56             : 
      57           5 : void MultiColvarCombine::registerKeywords( Keywords& keys ) {
      58           5 :   MultiColvarBase::registerKeywords( keys );
      59          10 :   keys.add("compulsory","DATA","the multicolvars you are calculating linear combinations for");
      60          10 :   keys.add("compulsory","COEFFICIENTS","1.0","the coefficients to use for the various multicolvars");
      61           5 :   keys.use("MEAN");
      62           5 :   keys.use("MORE_THAN");
      63           5 :   keys.use("SUM");
      64           5 :   keys.use("LESS_THAN");
      65           5 :   keys.use("HISTOGRAM");
      66           5 :   keys.use("MIN");
      67           5 :   keys.use("MAX");
      68           5 :   keys.use("LOWEST");
      69           5 :   keys.use("HIGHEST");
      70           5 :   keys.use("ALT_MIN");
      71           5 :   keys.use("BETWEEN");
      72           5 :   keys.use("MOMENTS");
      73           5 : }
      74             : 
      75           1 : MultiColvarCombine::MultiColvarCombine(const ActionOptions& ao):
      76             :   Action(ao),
      77           1 :   MultiColvarBase(ao) {
      78           1 :   buildSets();
      79           3 :   for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      80           2 :     if( mybasemulticolvars[i]->weightWithDerivatives() ) {
      81           0 :       error("cannot combine multicolvars with weights");
      82             :     }
      83             :   }
      84           1 :   coeff.resize( getNumberOfBaseMultiColvars() );
      85           1 :   parseVector("COEFFICIENTS",coeff);
      86           1 :   log.printf("  coefficients of multicolvars %f", coeff[0] );
      87           2 :   for(unsigned i=1; i<coeff.size(); ++i) {
      88           1 :     log.printf(", %f", coeff[i] );
      89             :   }
      90           1 :   log.printf("\n");
      91           1 : }
      92             : 
      93          15 : double MultiColvarCombine::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
      94             :   double dot=0;
      95          15 :   std::vector<double> tval(2);
      96          45 :   for(unsigned i=0; i<coeff.size(); ++i) {
      97          30 :     getInputData( i, false, myatoms, tval );
      98          30 :     dot += coeff[i]*tval[1];
      99             :   }
     100          15 :   if( !doNotCalculateDerivatives() ) {
     101          15 :     std::vector<double> cc(2);
     102          45 :     for(unsigned i=0; i<coeff.size(); ++i) {
     103          30 :       cc[1]=coeff[i];
     104          30 :       MultiValue& myder=getInputDerivatives( i, false, myatoms );
     105          30 :       splitInputDerivatives( 1, 1, 2, i, cc, myder, myatoms );
     106             :     }
     107             :   }
     108          15 :   return dot;
     109             : }
     110             : 
     111             : }
     112             : }

Generated by: LCOV version 1.16