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 Steered_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_STEERED_MD 36 : /* 37 : 38 : Performs a linear unbinding along a predefined biasing direction that 39 : needs to be provided using the PULLING keyword. 40 : 41 : \par Examples 42 : 43 : Every optimizer implemented in the maze module needs a loss function as 44 : an argument, and it should be passed using the \ref MAZE_LOSS keyword. 45 : 46 : \plumedfile 47 : MAZE_STEERED_MD ... 48 : LABEL=smd 49 : 50 : LOSS=l 51 : PULLING=0.3,0.3,0.3 52 : OPTIMIZER_STRIDE=_ 53 : 54 : LIGAND=2635-2646 55 : PROTEIN=1-2634 56 : ... MAZE_STEERED_MD 57 : \endplumedfile 58 : 59 : As shown above, each optimizer should be provided with the LIGAND and 60 : the PROTEIN keywords. 61 : 62 : */ 63 : //+ENDPLUMEDOC 64 : 65 : /** 66 : * @class Steered_MD Steered_MD.cpp "maze/Steered_MD.cpp" 67 : * @brief Performs steered MD simulation. 68 : */ 69 : class Steered_MD: public Optimizer { 70 : public: 71 : /** 72 : * PLMD constructor. 73 : * 74 : * @param[in] ao PLMD::ActionOptions& 75 : */ 76 : explicit Steered_MD(const ActionOptions& ao); 77 : 78 : /** 79 : * Registers PLMD keywords. 80 : * 81 : * @param[in] keys PLMD keywords 82 : */ 83 : static void registerKeywords(Keywords&); 84 : 85 : /** 86 : * Each class deriving from Optimizer needs to override this function. 87 : */ 88 : void optimize() override; 89 : 90 : private: 91 : //! Total distance traveled by the ligand. 92 : double total_dist_; 93 : 94 : //! Ligand center of mass. 95 : Vector com_; 96 : 97 : //! Constant direction of biasing. 98 : Vector pulling_; 99 : 100 : //! PLMD::Value of total distance. 101 : Value* value_total_dist_; 102 : }; 103 : 104 : // Register MAZE_STEERED_MD. 105 : PLUMED_REGISTER_ACTION(Steered_MD, "MAZE_STEERED_MD") 106 : 107 3 : void Steered_MD::registerKeywords(Keywords& keys) { 108 3 : Optimizer::registerKeywords(keys); 109 : 110 6 : keys.remove("N_ITER"); 111 : 112 3 : keys.add( 113 : "compulsory", 114 : "PULLING", 115 : "Constant biasing direction." 116 : ); 117 : 118 6 : keys.addOutputComponent( 119 : "tdist", 120 : "default", 121 : "scalar", 122 : "Total distance traveled by biased atoms." 123 : ); 124 3 : } 125 : 126 1 : Steered_MD::Steered_MD(const ActionOptions& ao) 127 : : PLUMED_OPT_INIT(ao), 128 1 : total_dist_(0.0) { 129 1 : log.printf("maze> Steered MD.\n"); 130 : 131 1 : if (keywords.exists("PULLING")) { 132 : std::vector<double> v; 133 1 : parseVector("PULLING", v); 134 1 : pulling_ = tls::vector2Vector(v); 135 : 136 1 : log.printf("maze> PULLING read.\n"); 137 : } 138 : 139 2 : set_label("STEERED_MD"); 140 : set_opt(pulling_); 141 : set_opt_value(0.0); 142 : 143 : start_step_stride(); 144 : 145 1 : checkRead(); 146 : 147 1 : com_ = center_of_mass(); 148 : 149 2 : addComponent("tdist"); 150 1 : componentIsNotPeriodic("tdist"); 151 1 : value_total_dist_ = getPntrToComponent("tdist"); 152 1 : } 153 : 154 2 : void Steered_MD::optimize() { 155 2 : Vector c = center_of_mass(); 156 2 : Vector d; 157 : 158 2 : if (pbc_) { 159 2 : d = pbcDistance(c, com_); 160 : } else { 161 0 : d = delta(c, com_); 162 : } 163 : 164 2 : double dist = d.modulo(); 165 2 : total_dist_ += dist; 166 : 167 : set_opt(pulling_); 168 2 : set_opt_value(score()); 169 2 : com_ = c; 170 : 171 2 : value_total_dist_->set(total_dist_); 172 2 : } 173 : 174 : } // namespace maze 175 : } // namespace PLMD