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