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

Generated by: LCOV version 1.15