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 2 : log.printf("maze> Fake optimizer that returns a next step as random,\ 108 : can be used to monitor loss, and for debugging and regtests purposes.\n"); 109 : 110 4 : set_label("RANDOM_WALK"); 111 : 112 : start_step_0(); 113 : 114 2 : checkRead(); 115 2 : } 116 : 117 6 : void Random_Walk::optimize() { 118 6 : set_opt(rnd::next_plmd_vector()); 119 6 : set_opt_value(score()); 120 6 : } 121 : 122 : } // namespace maze 123 : } // namespace PLMD