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 : * Destructor. 85 : */ 86 : ~Random_Walk(); 87 : 88 : /** 89 : * Registers PLMD keywords. 90 : * 91 : * @param[in] keys PLMD keywords 92 : */ 93 : static void registerKeywords(Keywords&); 94 : 95 : /** 96 : * Each class deriving from Optimizer needs to override this function. 97 : */ 98 : void optimize() override; 99 : }; 100 : 101 : // Register MAZE_RANDOM_WALK. 102 10423 : PLUMED_REGISTER_ACTION(Random_Walk, "MAZE_RANDOM_WALK") 103 : 104 3 : void Random_Walk::registerKeywords(Keywords& keys) { 105 3 : Optimizer::registerKeywords(keys); 106 : 107 3 : keys.remove("N_ITER"); 108 3 : } 109 : 110 2 : Random_Walk::Random_Walk(const ActionOptions& ao) 111 2 : : PLUMED_OPT_INIT(ao) 112 : { 113 2 : log.printf("maze> Fake optimizer that returns a next step as random,\ 114 : can be used to monitor loss, and for debugging and regtests purposes.\n"); 115 : 116 4 : set_label("RANDOM_WALK"); 117 : 118 : start_step_0(); 119 : 120 2 : checkRead(); 121 2 : } 122 : 123 4 : Random_Walk::~Random_Walk() { 124 2 : delete neighbor_list_; 125 4 : } 126 : 127 6 : void Random_Walk::optimize() { 128 6 : set_opt(rnd::next_plmd_vector()); 129 6 : set_opt_value(score()); 130 6 : } 131 : 132 : } // namespace maze 133 : } // namespace PLMD