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_Acceleration_MD.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_ACCELERATION_MD 36 : /* 37 : 38 : Performs random acceleration MD within the protein matrix. 39 : 40 : ## Examples 41 : 42 : Every optimizer implemented in the maze module needs a loss function as 43 : an argument, and it should be passed using the [MAZE_LOSS](MAZE_LOSS.md) keyword. 44 : 45 : ```plumed 46 : l: MAZE_LOSS PARAMS=1,1,1 47 : 48 : MAZE_RANDOM_ACCELERATION_MD ... 49 : LABEL=rw 50 : 51 : OPTIMIZER_STRIDE=200 52 : LOSS=l 53 : R_MIN=0.5 54 : 55 : LIGAND=2635-2646 56 : PROTEIN=1-2634 57 : ... MAZE_RANDOM_ACCELERATION_MD 58 : ``` 59 : 60 : As shown above, each optimizer should be provided with the LIGAND and 61 : the PROTEIN keywords. 62 : 63 : */ 64 : //+ENDPLUMEDOC 65 : 66 : /** 67 : * @class Random_Acceleration_MD Random_Acceleration_MD.cpp 68 : * "maze/Random_Acceleration_MD.cpp" 69 : * 70 : * @brief Perform RAMD simulation. 71 : */ 72 : class Random_Acceleration_MD: public Optimizer { 73 : public: 74 : /** 75 : * PLMD constructor. 76 : * 77 : * @param[in] ao PLMD::ActionOptions& 78 : */ 79 : explicit Random_Acceleration_MD(const ActionOptions&); 80 : 81 : /** 82 : * Registers PLMD keywords. 83 : * 84 : * @param[in] keys PLMD keywords 85 : */ 86 : static void registerKeywords(Keywords&); 87 : 88 : /** 89 : * Each class deriving from Optimizer needs to override this function. 90 : */ 91 : void optimize() override; 92 : 93 : private: 94 : //! Threshold distance that the ligand needs to pass. 95 : double r_min_; 96 : 97 : //! Total distance. 98 : double total_dist_; 99 : 100 : //! Distance. 101 : double dist_; 102 : 103 : //! Ligand center of mass. 104 : Vector com_; 105 : 106 : //! PLMD value for distance. 107 : Value* value_dist_; 108 : 109 : //! PLMD value for total distance. 110 : Value* value_total_dist_; 111 : }; 112 : 113 : // Register MAZE_RANDOM_ACCELERATION_MD. 114 : PLUMED_REGISTER_ACTION(Random_Acceleration_MD, "MAZE_RANDOM_ACCELERATION_MD") 115 : 116 5 : void Random_Acceleration_MD::registerKeywords(Keywords& keys) { 117 5 : Optimizer::registerKeywords(keys); 118 : 119 10 : keys.remove("N_ITER"); 120 : 121 5 : keys.add( 122 : "compulsory", 123 : "R_MIN", 124 : "Minimal distance traveled before sampling a new direction of biasing." 125 : ); 126 : 127 10 : keys.addOutputComponent( 128 : "dist", 129 : "default", 130 : "scalar", 131 : "Distance traveled in one sampling interval." 132 : ); 133 : 134 10 : keys.addOutputComponent( 135 : "tdist", 136 : "default", 137 : "scalar", 138 : "Total distance traveled by biased atoms." 139 : ); 140 5 : } 141 : 142 1 : Random_Acceleration_MD::Random_Acceleration_MD(const ActionOptions& ao) 143 : : PLUMED_OPT_INIT(ao), 144 1 : total_dist_(0.0), 145 1 : dist_(0.0) { 146 1 : log.printf("maze> Random accelerated molecular dynamics.\n"); 147 : 148 1 : if(keywords.exists("R_MIN")) { 149 1 : parse("R_MIN", r_min_); 150 : 151 1 : plumed_massert( 152 : r_min_ > 0, 153 : "maze> R_MIN should be explicitly specified and positive.\n" 154 : ); 155 : 156 1 : log.printf( 157 : "maze> R_MIN read: %f [A].\n", 158 : r_min_ 159 : ); 160 : } 161 : 162 1 : set_label("RANDOM_ACCELERATION_MD"); 163 1 : set_opt(rnd::next_plmd_vector()); 164 : set_opt_value(0.0); 165 : 166 : start_step_stride(); 167 : 168 1 : checkRead(); 169 : 170 1 : com_ = center_of_mass(); 171 : 172 2 : addComponent("dist"); 173 1 : componentIsNotPeriodic("dist"); 174 1 : value_dist_ = getPntrToComponent("dist"); 175 : 176 2 : addComponent("tdist"); 177 1 : componentIsNotPeriodic("tdist"); 178 1 : value_total_dist_ = getPntrToComponent("tdist"); 179 1 : } 180 : 181 2 : void Random_Acceleration_MD::optimize() { 182 2 : Vector c = center_of_mass(); 183 2 : Vector d; 184 : 185 2 : if (pbc_) { 186 2 : d = pbcDistance(c, com_); 187 : } else { 188 0 : d = delta(c, com_); 189 : } 190 : 191 2 : dist_ = d.modulo(); 192 2 : total_dist_ += dist_; 193 : 194 2 : if(dist_ < r_min_) { 195 0 : set_opt(rnd::next_plmd_vector()); 196 : } 197 : 198 2 : set_opt_value(score()); 199 2 : com_ = c; 200 : 201 2 : value_dist_->set(dist_); 202 2 : value_total_dist_->set(total_dist_); 203 2 : } 204 : 205 : } // namespace maze 206 : } // namespace PLMD