LCOV - code coverage report
Current view: top level - multicolvar - Density.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 22 30 73.3 %
Date: 2026-03-30 13:16:06 Functions: 8 12 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-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             : namespace PLMD {
      30             : namespace multicolvar {
      31             : 
      32             : //+PLUMEDOC MCOLVAR DENSITY
      33             : /*
      34             : Calculate functions of the density of atoms as a function of the box.  This allows one to calculate
      35             :  the number of atoms in half the box.
      36             : 
      37             : \par Examples
      38             : 
      39             : The following example calculates the number of atoms in one half of the simulation box.
      40             : 
      41             : \plumedfile
      42             : DENSITY SPECIES=1-100 LABEL=d
      43             : AROUND ATOM=101 DATA=d SIGMA=0.1 XLOWER=0.0 XUPPER=0.5 LABEL=d1
      44             : PRINT ARG=d1.* FILE=colvar1 FMT=%8.4f
      45             : \endplumedfile
      46             : 
      47             : */
      48             : //+ENDPLUMEDOC
      49             : 
      50             : 
      51             : class Density : public MultiColvarBase {
      52             : public:
      53             :   static void registerKeywords( Keywords& keys );
      54             :   explicit Density(const ActionOptions&);
      55             : // active methods:
      56             :   double compute( const unsigned& tindex, AtomValuePack& myatoms ) const override;
      57             :   /// Returns the number of coordinates of the field
      58           4 :   bool isPeriodic() override {
      59           4 :     return false;
      60             :   }
      61      200727 :   bool isDensity() const override {
      62      200727 :     return true;
      63             :   }
      64           0 :   bool hasDifferentiableOrientation() const override {
      65           0 :     return true;
      66             :   }
      67             : //  void addOrientationDerivativesToBase( const unsigned& iatom, const unsigned& jstore, const unsigned& base_cv_no,
      68             : //                                        const std::vector<double>& weight, MultiColvarFunction* func ){}
      69             :   void getIndexList( const unsigned& ntotal, const unsigned& jstore, const unsigned& maxder, std::vector<unsigned>& indices );
      70             : //  unsigned getNumberOfQuantities();
      71             :   void getValueForTask( const unsigned& iatom, std::vector<double>& vals );
      72             : };
      73             : 
      74       13807 : PLUMED_REGISTER_ACTION(Density,"DENSITY")
      75             : 
      76          15 : void Density::registerKeywords( Keywords& keys ) {
      77          15 :   MultiColvarBase::registerKeywords( keys );
      78          15 :   keys.use("SPECIES");
      79          15 : }
      80             : 
      81          11 : Density::Density(const ActionOptions&ao):
      82             :   Action(ao),
      83          11 :   MultiColvarBase(ao) {
      84             :   std::vector<AtomNumber> all_atoms;
      85          11 :   parseMultiColvarAtomList("SPECIES", -1, all_atoms);
      86          11 :   ablocks.resize(1);
      87          11 :   ablocks[0].resize( atom_lab.size() );
      88         489 :   for(unsigned i=0; i<atom_lab.size(); ++i) {
      89         478 :     addTaskToList(i);
      90         478 :     ablocks[0][i]=i;
      91             :   }
      92          11 :   setupMultiColvarBase( all_atoms );
      93             :   // And check everything has been read in correctly
      94          11 :   checkRead();
      95          11 : }
      96             : 
      97       15955 : double Density::compute( const unsigned& tindex, AtomValuePack& myvals ) const {
      98       15955 :   return 1.0;
      99             : }
     100             : 
     101           0 : void Density::getIndexList( const unsigned& ntotal, const unsigned& jstore, const unsigned& maxder, std::vector<unsigned>& indices ) {
     102           0 :   indices[jstore]=0;
     103           0 : }
     104             : 
     105             : // unsigned Density::getNumberOfQuantities(){
     106             : //    return 2;
     107             : // }
     108             : 
     109           0 : void Density::getValueForTask( const unsigned& iatom, std::vector<double>& vals ) {
     110             :   plumed_dbg_assert( vals.size()==2 );
     111           0 :   vals[0]=vals[1]=1.0;
     112           0 : }
     113             : 
     114             : }
     115             : }
     116             : 

Generated by: LCOV version 1.16