LCOV - code coverage report
Current view: top level - maze - Random_Walk.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 14 14 100.0 %
Date: 2024-10-18 14:00:25 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             : Copyright (c) 2019 Jakub Rydzewski (jr@fizyka.umk.pl). All rights reserved.
       3             : 
       4             : See http://www.maze-code.github.io for more information.
       5             : 
       6             : This file is part of maze.
       7             : 
       8             : maze is free software: you can redistribute it and/or modify it under the
       9             : terms of the GNU Lesser General Public License as published by the Free
      10             : Software Foundation, either version 3 of the License, or (at your option)
      11             : any later version.
      12             : 
      13             : maze is distributed in the hope that it will be useful, but WITHOUT ANY
      14             : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      15             : FOR A PARTICULAR PURPOSE.
      16             : 
      17             : See the 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 maze. If not, see <https://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : 
      23             : /**
      24             :  * @file Random_Walk.cpp
      25             :  *
      26             :  * @author J. Rydzewski (jr@fizyka.umk.pl)
      27             :  */
      28             : 
      29             : #include "core/ActionRegister.h"
      30             : #include "Optimizer.h"
      31             : 
      32             : namespace PLMD {
      33             : namespace maze {
      34             : 
      35             : //+PLUMEDOC MAZE_OPTIMIZER MAZE_RANDOM_WALK
      36             : /*
      37             : 
      38             : Fake optimizer that can be used for debugging.
      39             : 
      40             : This is dummy optimizer that can be used for debugging and monitoring
      41             : purposes. It returns a random direction of biasing, changed every
      42             : OPTIMIZER_STRIDE.
      43             : 
      44             : Performs a random walk within the protein matrix.
      45             : 
      46             : \par Examples
      47             : 
      48             : Every optimizer implemented in the maze module needs a loss function as
      49             : an argument, and it should be passed using the \ref MAZE_LOSS keyword.
      50             : 
      51             : \plumedfile
      52             : MAZE_RANDOM_WALK ...
      53             :   LABEL=rw
      54             : 
      55             :   LOSS=l
      56             :   OPTIMIZER_STRIDE=200
      57             : 
      58             :   LIGAND=2635-2646
      59             :   PROTEIN=1-2634
      60             : ... MAZE_RANDOM_WALK
      61             : \endplumedfile
      62             : 
      63             : As shown above, each optimizer should be provided with the LIGAND and
      64             : the PROTEIN keywords.
      65             : 
      66             : */
      67             : //+ENDPLUMEDOC
      68             : 
      69             : /**
      70             :  * @class Random_Walk Random_Walk.cpp "maze/Random_Walk.cpp"
      71             :  *
      72             :  * @brief Perform a random walk within the protein matrix.
      73             :  */
      74             : class Random_Walk: public Optimizer {
      75             : public:
      76             :   /**
      77             :    * PLMD constructor.
      78             :    *
      79             :    * @param[in] ao PLMD::ActionOptions&
      80             :    */
      81             :   explicit Random_Walk(const ActionOptions& ao);
      82             : 
      83             :   /**
      84             :    * Registers PLMD keywords.
      85             :    *
      86             :    * @param[in] keys PLMD keywords
      87             :    */
      88             :   static void registerKeywords(Keywords&);
      89             : 
      90             :   /**
      91             :    * Each class deriving from Optimizer needs to override this function.
      92             :    */
      93             :   void optimize() override;
      94             : };
      95             : 
      96             : // Register MAZE_RANDOM_WALK.
      97             : PLUMED_REGISTER_ACTION(Random_Walk, "MAZE_RANDOM_WALK")
      98             : 
      99           4 : void Random_Walk::registerKeywords(Keywords& keys) {
     100           4 :   Optimizer::registerKeywords(keys);
     101             : 
     102           4 :   keys.remove("N_ITER");
     103           4 : }
     104             : 
     105           2 : Random_Walk::Random_Walk(const ActionOptions& ao)
     106           2 :   : PLUMED_OPT_INIT(ao)
     107             : {
     108           2 :   log.printf("maze> Fake optimizer that returns a next step as random,\
     109             :     can be used to monitor loss, and for debugging and regtests purposes.\n");
     110             : 
     111           4 :   set_label("RANDOM_WALK");
     112             : 
     113             :   start_step_0();
     114             : 
     115           2 :   checkRead();
     116           2 : }
     117             : 
     118           6 : void Random_Walk::optimize() {
     119           6 :   set_opt(rnd::next_plmd_vector());
     120           6 :   set_opt_value(score());
     121           6 : }
     122             : 
     123             : } // namespace maze
     124             : } // namespace PLMD

Generated by: LCOV version 1.16