LCOV - code coverage report
Current view: top level - analysis - SelectRandomFrames.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 5 20 25.0 %
Date: 2024-10-11 08:09:47 Functions: 3 7 42.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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 "LandmarkSelectionBase.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "tools/Random.h"
      25             : 
      26             : //+PLUMEDOC LANDMARKS LANDMARK_SELECT_RANDOM
      27             : /*
      28             : Select a random set of landmarks from a large set of configurations.
      29             : 
      30             : \par Examples
      31             : 
      32             : */
      33             : //+ENDPLUMEDOC
      34             : 
      35             : namespace PLMD {
      36             : namespace analysis {
      37             : 
      38             : class SelectRandomFrames : public LandmarkSelectionBase {
      39             : private:
      40             :   unsigned seed;
      41             : public:
      42             :   static void registerKeywords( Keywords& keys );
      43             :   explicit SelectRandomFrames( const ActionOptions& ao );
      44             :   void selectLandmarks() override;
      45             : };
      46             : 
      47       10419 : PLUMED_REGISTER_ACTION(SelectRandomFrames,"LANDMARK_SELECT_RANDOM")
      48             : 
      49           1 : void SelectRandomFrames::registerKeywords( Keywords& keys ) {
      50           1 :   LandmarkSelectionBase::registerKeywords(keys);
      51           2 :   keys.add("compulsory","SEED","1234","a random number seed");
      52           1 : }
      53             : 
      54           0 : SelectRandomFrames::SelectRandomFrames( const ActionOptions& ao ):
      55             :   Action(ao),
      56           0 :   LandmarkSelectionBase(ao)
      57             : {
      58           0 :   parse("SEED",seed);
      59           0 : }
      60             : 
      61           0 : void SelectRandomFrames::selectLandmarks() {
      62           0 :   Random r; r.setSeed(-seed);
      63           0 :   unsigned nframe=my_input_data->getNumberOfDataPoints();
      64           0 :   unsigned nland=getNumberOfDataPoints();
      65             : 
      66           0 :   std::vector<bool> selected( nframe, false );
      67             : 
      68             :   unsigned fcount=0;
      69           0 :   while (fcount<nland) {
      70           0 :     unsigned iframe = std::floor( r.U01()*nframe );
      71           0 :     if (!selected[iframe]) {
      72             :       selected[iframe]=true;
      73           0 :       selectFrame( iframe );
      74           0 :       ++fcount;
      75             :     }
      76             :   }
      77           0 : }
      78             : 
      79             : }
      80             : }

Generated by: LCOV version 1.15