LCOV - code coverage report
Current view: top level - maze - Loss.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 24 24 100.0 %
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 Loss.cpp
      25             :  * @author J. Rydzewski (jr@fizyka.umk.pl)
      26             :  */
      27             : 
      28             : #include "Loss.h"
      29             : #include "core/PlumedMain.h"
      30             : 
      31             : namespace PLMD {
      32             : namespace maze {
      33             : 
      34             : //+PLUMEDOC MAZE_LOSS MAZE_LOSS
      35             : /*
      36             : 
      37             : Define a coarse-grained loss function describing interactions in a
      38             : ligand-protein complex, which is minimized during the simulation to
      39             : obtain ligand unbinding pathways.
      40             : 
      41             : The loss function is the following:
      42             : \f[
      43             : \mathcal{L}=
      44             : \sum_{i=1}^{N_p}
      45             : r_i^{-\alpha}\text{e}^{-\beta r_i^{-\gamma}},
      46             : \f]
      47             : where \f$N_p\f$ is the number of ligand-protein atom pairs, \f$r\f$
      48             : is a re-scaled distance between the \f$i\f$th pair, and \f$\alpha,
      49             : \beta, \gamma\f$ are the positive parameters defined in that order by
      50             : the PARAMS keyword.
      51             : 
      52             : \par Examples
      53             : 
      54             : The loss function can be defined in the following way:
      55             : \plumedfile
      56             : l: MAZE_LOSS PARAMS=1,1,1
      57             : \endplumedfile
      58             : 
      59             : */
      60             : //+ENDPLUMEDOC
      61             : 
      62             : // Registers the LOSS action.
      63             : PLUMED_REGISTER_ACTION(Loss, "MAZE_LOSS")
      64             : 
      65          10 : void Loss::registerKeywords(Keywords& keys) {
      66          10 :   Colvar::registerKeywords(keys);
      67             : 
      68          20 :   keys.add(
      69             :     "compulsory",
      70             :     "PARAMS",
      71             :     "Parameters for the loss function."
      72             :   );
      73          10 :   keys.setValueDescription("the value of the loss function");
      74          10 : }
      75             : 
      76           8 : Loss::Loss(const ActionOptions& ao)
      77           8 :   : PLUMED_COLVAR_INIT(ao)
      78             : {
      79          16 :   if (keywords.exists("PARAMS")) {
      80          16 :     parseVector("PARAMS", params_);
      81             : 
      82           8 :     plumed_massert(
      83             :       params_.size() == 3,
      84             :       "maze> PARAMS should be of size 3: alpha, beta, gamma\n"
      85             :     );
      86             : 
      87           8 :     plumed_massert(
      88             :       params_[0] > 0 && params_[1] > 0 && params_[2] > 0,
      89             :       "maze> Each parameter should be positive\n"
      90             :     );
      91             : 
      92           8 :     log.printf("maze> \t Loss parsed with parameters: ");
      93          32 :     for (size_t i = 0; i < params_.size(); ++i) {
      94          24 :       log.printf("%f ", params_[i]);
      95             :     }
      96           8 :     log.printf("\n");
      97             :   }
      98             : 
      99           8 :   checkRead();
     100           8 : }
     101             : 
     102    16239210 : double Loss::pairing(double distance) {
     103    16239210 :   double alpha = params_[0];
     104    16239210 :   double beta = params_[1];
     105    16239210 :   double gamma = params_[2];
     106             : 
     107    32478420 :   if (getUnits().getLengthString() == "nm") {
     108    16120080 :     distance *= 10.0;
     109             :   }
     110             : 
     111    16239210 :   return pow(distance, -alpha) * exp(-beta * pow(distance, gamma));
     112             : }
     113             : 
     114             : } // namespace maze
     115             : } // namespace PLMD

Generated by: LCOV version 1.16