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: 2026-11-05 10:19:04 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             : ## 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 [MAZE_LOSS](MAZE_LOSS.md) keyword.
      50             : 
      51             : ```plumed
      52             : l: MAZE_LOSS PARAMS=1,1,1
      53             : 
      54             : MAZE_RANDOM_WALK ...
      55             :   LABEL=rw
      56             : 
      57             :   LOSS=l
      58             :   OPTIMIZER_STRIDE=200
      59             : 
      60             :   LIGAND=2635-2646
      61             :   PROTEIN=1-2634
      62             : ... MAZE_RANDOM_WALK
      63             : ```
      64             : 
      65             : As shown above, each optimizer should be provided with the LIGAND and
      66             : the PROTEIN keywords.
      67             : 
      68             : */
      69             : //+ENDPLUMEDOC
      70             : 
      71             : /**
      72             :  * @class Random_Walk Random_Walk.cpp "maze/Random_Walk.cpp"
      73             :  *
      74             :  * @brief Perform a random walk within the protein matrix.
      75             :  */
      76             : class Random_Walk: public Optimizer {
      77             : public:
      78             :   /**
      79             :    * PLMD constructor.
      80             :    *
      81             :    * @param[in] ao PLMD::ActionOptions&
      82             :    */
      83             :   explicit Random_Walk(const ActionOptions& ao);
      84             : 
      85             :   /**
      86             :    * Registers PLMD keywords.
      87             :    *
      88             :    * @param[in] keys PLMD keywords
      89             :    */
      90             :   static void registerKeywords(Keywords&);
      91             : 
      92             :   /**
      93             :    * Each class deriving from Optimizer needs to override this function.
      94             :    */
      95             :   void optimize() override;
      96             : };
      97             : 
      98             : // Register MAZE_RANDOM_WALK.
      99             : PLUMED_REGISTER_ACTION(Random_Walk, "MAZE_RANDOM_WALK")
     100             : 
     101           6 : void Random_Walk::registerKeywords(Keywords& keys) {
     102           6 :   Optimizer::registerKeywords(keys);
     103             : 
     104           6 :   keys.remove("N_ITER");
     105           6 : }
     106             : 
     107           2 : Random_Walk::Random_Walk(const ActionOptions& ao)
     108           2 :   : PLUMED_OPT_INIT(ao) {
     109           2 :   log.printf("maze> Fake optimizer that returns a next step as random,\
     110             :     can be used to monitor loss, and for debugging and regtests purposes.\n");
     111             : 
     112           4 :   set_label("RANDOM_WALK");
     113             : 
     114             :   start_step_0();
     115             : 
     116           2 :   checkRead();
     117           2 : }
     118             : 
     119           6 : void Random_Walk::optimize() {
     120           6 :   set_opt(rnd::next_plmd_vector());
     121           6 :   set_opt_value(score());
     122           6 : }
     123             : 
     124             : } // namespace maze
     125             : } // namespace PLMD

Generated by: LCOV version 1.16