LCOV - code coverage report
Current view: top level - maze - Steered_MD.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 35 36 97.2 %
Date: 2024-10-11 08:09:47 Functions: 8 10 80.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             :    * Destructor.
      80             :    */
      81             :   ~Steered_MD();
      82             : 
      83             :   /**
      84             :    * Registers PLMD keywords.
      85             :    *
      86             :    * @param[in] keys PLMD keywords
      87             :    */
      88             :   static void registerKeywords(Keywords&);
      89             : 
      90             :   /**
      91             :    * Each class deriving from Optimizer needs to override this function.
      92             :    */
      93             :   void optimize() override;
      94             : 
      95             : private:
      96             :   //! Total distance traveled by the ligand.
      97             :   double total_dist_;
      98             : 
      99             :   //! Ligand center of mass.
     100             :   Vector com_;
     101             : 
     102             :   //! Constant direction of biasing.
     103             :   Vector pulling_;
     104             : 
     105             :   //! PLMD::Value of total distance.
     106             :   Value* value_total_dist_;
     107             : };
     108             : 
     109             : // Register MAZE_STEERED_MD.
     110       10421 : PLUMED_REGISTER_ACTION(Steered_MD, "MAZE_STEERED_MD")
     111             : 
     112           2 : void Steered_MD::registerKeywords(Keywords& keys) {
     113           2 :   Optimizer::registerKeywords(keys);
     114             : 
     115           2 :   keys.remove("N_ITER");
     116             : 
     117           4 :   keys.add(
     118             :     "compulsory",
     119             :     "PULLING",
     120             :     "Constant biasing direction."
     121             :   );
     122             : 
     123           4 :   keys.addOutputComponent(
     124             :     "tdist",
     125             :     "default",
     126             :     "Total distance traveled by biased atoms."
     127             :   );
     128           2 : }
     129             : 
     130           1 : Steered_MD::Steered_MD(const ActionOptions& ao)
     131             :   : PLUMED_OPT_INIT(ao),
     132           1 :     total_dist_(0.0)
     133             : {
     134           1 :   log.printf("maze> Steered MD.\n");
     135             : 
     136           2 :   if (keywords.exists("PULLING")) {
     137             :     std::vector<double> v;
     138           1 :     parseVector("PULLING", v);
     139           1 :     pulling_ = tls::vector2Vector(v);
     140             : 
     141           1 :     log.printf("maze> PULLING read.\n");
     142             :   }
     143             : 
     144           2 :   set_label("STEERED_MD");
     145             :   set_opt(pulling_);
     146             :   set_opt_value(0.0);
     147             : 
     148             :   start_step_stride();
     149             : 
     150           1 :   checkRead();
     151             : 
     152           1 :   com_ = center_of_mass();
     153             : 
     154           1 :   addComponent("tdist");
     155           1 :   componentIsNotPeriodic("tdist");
     156           1 :   value_total_dist_ = getPntrToComponent("tdist");
     157           1 : }
     158             : 
     159           2 : Steered_MD::~Steered_MD() {
     160           1 :   delete neighbor_list_;
     161           2 : }
     162             : 
     163           2 : void Steered_MD::optimize() {
     164           2 :   Vector c = center_of_mass();
     165           2 :   Vector d;
     166             : 
     167           2 :   if (pbc_) {
     168           2 :     d = pbcDistance(c, com_);
     169             :   }
     170             :   else {
     171           0 :     d = delta(c, com_);
     172             :   }
     173             : 
     174           2 :   double dist = d.modulo();
     175           2 :   total_dist_ += dist;
     176             : 
     177             :   set_opt(pulling_);
     178           2 :   set_opt_value(score());
     179           2 :   com_ = c;
     180             : 
     181           2 :   value_total_dist_->set(total_dist_);
     182           2 : }
     183             : 
     184             : } // namespace maze
     185             : } // namespace PLMD

Generated by: LCOV version 1.15