LCOV - code coverage report
Current view: top level - multicolvar - MultiColvarProduct.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 28 28 100.0 %
Date: 2020-11-18 11:20:57 Functions: 11 12 91.7 %

          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_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           2 : 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 ;
      48             : /// Is the variable periodic
      49           1 :   bool isPeriodic() { return false; }
      50             : };
      51             : 
      52        6453 : PLUMED_REGISTER_ACTION(MultiColvarProduct,"MCOLV_PRODUCT")
      53             : 
      54           2 : void MultiColvarProduct::registerKeywords( Keywords& keys ) {
      55           2 :   MultiColvarBase::registerKeywords( keys );
      56           8 :   keys.add("compulsory","DATA","the multicolvars you are calculating the product of");
      57          12 :   keys.use("MEAN"); keys.use("MORE_THAN"); keys.use("SUM"); keys.use("LESS_THAN"); keys.use("HISTOGRAM");
      58          16 :   keys.use("MIN"); keys.use("MAX"); keys.use("LOWEST"); keys.use("HIGHEST"); keys.use("ALT_MIN"); keys.use("BETWEEN"); keys.use("MOMENTS");
      59           2 : }
      60             : 
      61           1 : MultiColvarProduct::MultiColvarProduct(const ActionOptions& ao):
      62             :   Action(ao),
      63           1 :   MultiColvarBase(ao)
      64             : {
      65           1 :   buildSets();
      66           5 :   for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      67           6 :     if( mybasemulticolvars[i]->weightWithDerivatives() ) error("cannot take product of multicolvars with weights");
      68             :   }
      69           1 : }
      70             : 
      71          15 : double MultiColvarProduct::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
      72          15 :   double dot=1; std::vector<double> tval(2);
      73          90 :   for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      74          30 :     getInputData( i, false, myatoms, tval );
      75          30 :     dot *= tval[1];
      76             :   }
      77          15 :   if( !doNotCalculateDerivatives() ) {
      78          15 :     MultiValue& myvals = myatoms.getUnderlyingMultiValue(); std::vector<double> cc(2);
      79          90 :     for(unsigned i=0; i<getNumberOfBaseMultiColvars(); ++i) {
      80          60 :       getInputData( i, false, myatoms, cc ); cc[1] = dot / cc[1];
      81          30 :       MultiValue& myder=getInputDerivatives( i, false, myatoms );
      82          30 :       splitInputDerivatives( 1, 1, 2, i, cc, myder, myatoms );
      83             :     }
      84             :   }
      85          15 :   return dot;
      86             : }
      87             : 
      88             : }
      89        4839 : }

Generated by: LCOV version 1.13