Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : 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 plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "ActionVolume.h" 23 : 24 : namespace PLMD { 25 : namespace multicolvar { 26 : 27 52 : void ActionVolume::registerKeywords( Keywords& keys ) { 28 52 : VolumeGradientBase::registerKeywords( keys ); 29 104 : if( keys.reserved("VMEAN") ) { 30 104 : keys.use("VMEAN"); 31 : } 32 52 : keys.use("MEAN"); 33 52 : keys.use("LESS_THAN"); 34 52 : keys.use("MORE_THAN"); 35 52 : keys.use("BETWEEN"); 36 52 : keys.use("HISTOGRAM"); 37 52 : keys.use("SUM"); 38 104 : keys.add("compulsory","SIGMA","the width of the function to be used for kernel density estimation"); 39 104 : keys.add("compulsory","KERNEL","gaussian","the type of kernel function to be used"); 40 104 : keys.addFlag("OUTSIDE",false,"calculate quantities for colvars that are on atoms outside the region of interest"); 41 52 : } 42 : 43 28 : ActionVolume::ActionVolume(const ActionOptions&ao): 44 : Action(ao), 45 28 : VolumeGradientBase(ao) { 46 : // Find number of quantities 47 28 : if( getPntrToMultiColvar()->isDensity() ) { 48 11 : nquantities=2; // Value + weight 49 17 : } else if( getPntrToMultiColvar()->getNumberOfQuantities()==2 ) { 50 15 : nquantities=2; // Value + weight 51 : } else { 52 2 : nquantities = 1 + getPntrToMultiColvar()->getNumberOfQuantities()-2 + 1; // Norm + vector + weight 53 : } 54 : 55 : // Output some nice information 56 28 : std::string functype=getPntrToMultiColvar()->getName(); 57 28 : std::transform( functype.begin(), functype.end(), functype.begin(), [](unsigned char c) { 58 251 : return std::tolower(c); 59 : } ); 60 28 : log.printf(" calculating %s inside region of insterest\n",functype.c_str() ); 61 : 62 28 : parseFlag("OUTSIDE",not_in); 63 28 : sigma=0.0; 64 56 : if( keywords.exists("SIGMA") ) { 65 50 : parse("SIGMA",sigma); 66 : } 67 56 : if( keywords.exists("KERNEL") ) { 68 56 : parse("KERNEL",kerneltype); 69 : } 70 : 71 28 : if( getPntrToMultiColvar()->isDensity() ) { 72 : std::string input; 73 22 : addVessel( "SUM", input, -1 ); // -1 here means that this value will be named getLabel() 74 : } 75 28 : readVesselKeywords(); 76 28 : } 77 : 78 69358 : void ActionVolume::calculateAllVolumes( const unsigned& curr, MultiValue& outvals ) const { 79 69358 : Vector catom_pos=getPntrToMultiColvar()->getCentralAtomPos( curr ); 80 : 81 : double weight; 82 69358 : Vector wdf; 83 69358 : Tensor vir; 84 69358 : std::vector<Vector> refders( getNumberOfAtoms() ); 85 69358 : weight=calculateNumberInside( catom_pos, wdf, vir, refders ); 86 69358 : if( not_in ) { 87 4000 : weight = 1.0 - weight; 88 4000 : wdf *= -1.; 89 4000 : vir *=-1; 90 8000 : for(unsigned i=0; i<refders.size(); ++i) { 91 4000 : refders[i]*=-1; 92 : } 93 : } 94 69358 : setNumberInVolume( 0, curr, weight, wdf, vir, refders, outvals ); 95 69358 : } 96 : 97 148129 : bool ActionVolume::inVolumeOfInterest( const unsigned& curr ) const { 98 148129 : Vector catom_pos=getPntrToMultiColvar()->getCentralAtomPos( curr ); 99 148129 : Vector wdf; 100 148129 : Tensor vir; 101 148129 : std::vector<Vector> refders( getNumberOfAtoms() ); 102 148129 : double weight=calculateNumberInside( catom_pos, wdf, vir, refders ); 103 148129 : if( not_in ) { 104 0 : weight = 1.0 - weight; 105 : } 106 148129 : if( weight<getTolerance() ) { 107 144691 : return false; 108 : } 109 : return true; 110 : } 111 : 112 : } 113 : }