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