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 10 : keys.add( 69 : "compulsory", 70 : "PARAMS", 71 : "Parameters for the loss function." 72 : ); 73 20 : keys.setValueDescription("scalar","the value of the loss function"); 74 10 : } 75 : 76 8 : Loss::Loss(const ActionOptions& ao) 77 8 : : PLUMED_COLVAR_INIT(ao) { 78 8 : if (keywords.exists("PARAMS")) { 79 16 : parseVector("PARAMS", params_); 80 : 81 8 : plumed_massert( 82 : params_.size() == 3, 83 : "maze> PARAMS should be of size 3: alpha, beta, gamma\n" 84 : ); 85 : 86 8 : plumed_massert( 87 : params_[0] > 0 && params_[1] > 0 && params_[2] > 0, 88 : "maze> Each parameter should be positive\n" 89 : ); 90 : 91 8 : log.printf("maze> \t Loss parsed with parameters: "); 92 32 : for (size_t i = 0; i < params_.size(); ++i) { 93 24 : log.printf("%f ", params_[i]); 94 : } 95 8 : log.printf("\n"); 96 : } 97 : 98 8 : checkRead(); 99 8 : } 100 : 101 16239210 : double Loss::pairing(double distance) { 102 16239210 : double alpha = params_[0]; 103 16239210 : double beta = params_[1]; 104 16239210 : double gamma = params_[2]; 105 : 106 32478420 : if (getUnits().getLengthString() == "nm") { 107 16120080 : distance *= 10.0; 108 : } 109 : 110 16239210 : return pow(distance, -alpha) * exp(-beta * pow(distance, gamma)); 111 : } 112 : 113 : } // namespace maze 114 : } // namespace PLMD