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