LCOV - code coverage report
Current view: top level - maze - Steered_MD.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 31 32 96.9 %
Date: 2024-10-18 14:00:25 Functions: 3 4 75.0 %

          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           3 :   keys.remove("N_ITER");
     111             : 
     112           6 :   keys.add(
     113             :     "compulsory",
     114             :     "PULLING",
     115             :     "Constant biasing direction."
     116             :   );
     117             : 
     118           6 :   keys.addOutputComponent(
     119             :     "tdist",
     120             :     "default",
     121             :     "Total distance traveled by biased atoms."
     122             :   );
     123           3 : }
     124             : 
     125           1 : Steered_MD::Steered_MD(const ActionOptions& ao)
     126             :   : PLUMED_OPT_INIT(ao),
     127           1 :     total_dist_(0.0)
     128             : {
     129           1 :   log.printf("maze> Steered MD.\n");
     130             : 
     131           2 :   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             :   }
     161             :   else {
     162           0 :     d = delta(c, com_);
     163             :   }
     164             : 
     165           2 :   double dist = d.modulo();
     166           2 :   total_dist_ += dist;
     167             : 
     168             :   set_opt(pulling_);
     169           2 :   set_opt_value(score());
     170           2 :   com_ = c;
     171             : 
     172           2 :   value_total_dist_->set(total_dist_);
     173           2 : }
     174             : 
     175             : } // namespace maze
     176             : } // namespace PLMD

Generated by: LCOV version 1.16