LCOV - code coverage report
Current view: top level - multicolvar - MultiColvarProduct.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 39 97.4 %
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_PRODUCT
      30             : /*
      31             : Calculate a product of multiple multicolvars
      32             : 
      33             : \par Examples
      34             : 
      35             : */
      36             : //+ENDPLUMEDOC
      37             : 
      38             : namespace PLMD {
      39             : namespace multicolvar {
      40             : 
      41             : class MultiColvarProduct : public MultiColvarBase {
      42             : private:
      43             : public:
      44             :   static void registerKeywords( Keywords& keys );
      45             :   explicit MultiColvarProduct(const ActionOptions&);
      46             : /// Actually do the calculation
      47             :   double compute( const unsigned& tindex, AtomValuePack& myatoms ) const override;
      48             : /// Is the variable periodic
      49           1 :   bool isPeriodic() override {
      50           1 :     return false;
      51             :   }
      52             : };
      53             : 
      54       13787 : PLUMED_REGISTER_ACTION(MultiColvarProduct,"MCOLV_PRODUCT")
      55             : 
      56           5 : void MultiColvarProduct::registerKeywords( Keywords& keys ) {
      57           5 :   MultiColvarBase::registerKeywords( keys );
      58          10 :   keys.add("compulsory","DATA","the multicolvars you are calculating the product of");
      59           5 :   keys.use("MEAN");
      60           5 :   keys.use("MORE_THAN");
      61           5 :   keys.use("SUM");
      62           5 :   keys.use("LESS_THAN");
      63           5 :   keys.use("HISTOGRAM");
      64           5 :   keys.use("MIN");
      65           5 :   keys.use("MAX");
      66           5 :   keys.use("LOWEST");
      67           5 :   keys.use("HIGHEST");
      68           5 :   keys.use("ALT_MIN");
      69           5 :   keys.use("BETWEEN");
      70           5 :   keys.use("MOMENTS");
      71           5 : }
      72             : 
      73           1 : MultiColvarProduct::MultiColvarProduct(const ActionOptions& ao):
      74             :   Action(ao),
      75           1 :   MultiColvarBase(ao) {
      76           1 :   buildSets();
      77           3 :   for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      78           2 :     if( mybasemulticolvars[i]->weightWithDerivatives() ) {
      79           0 :       error("cannot take product of multicolvars with weights");
      80             :     }
      81             :   }
      82           1 : }
      83             : 
      84          15 : double MultiColvarProduct::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
      85             :   double dot=1;
      86          15 :   std::vector<double> tval(2);
      87          45 :   for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      88          30 :     getInputData( i, false, myatoms, tval );
      89          30 :     dot *= tval[1];
      90             :   }
      91          15 :   if( !doNotCalculateDerivatives() ) {
      92          15 :     std::vector<double> cc(2);
      93          45 :     for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      94          30 :       getInputData( i, false, myatoms, cc );
      95          30 :       cc[1] = dot / cc[1];
      96          30 :       MultiValue& myder=getInputDerivatives( i, false, myatoms );
      97          30 :       splitInputDerivatives( 1, 1, 2, i, cc, myder, myatoms );
      98             :     }
      99             :   }
     100          15 :   return dot;
     101             : }
     102             : 
     103             : }
     104             : }

Generated by: LCOV version 1.16