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