Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-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 "DistanceFromContourBase.h" 23 : #include "core/ActionRegister.h" 24 : 25 : //+PLUMEDOC COLVAR DISTANCE_FROM_SPHERICAL_CONTOUR 26 : /* 27 : Calculate the perpendicular distance from a Willard-Chandler dividing surface. 28 : 29 : \par Examples 30 : 31 : */ 32 : //+ENDPLUMEDOC 33 : 34 : namespace PLMD { 35 : namespace contour { 36 : 37 : class DistanceFromSphericalContour : public DistanceFromContourBase { 38 : public: 39 : static void registerKeywords( Keywords& keys ); 40 : explicit DistanceFromSphericalContour( const ActionOptions& ); 41 : void calculate(); 42 : void evaluateDerivatives( const Vector& root1, const double& root2 ); 43 : }; 44 : 45 : PLUMED_REGISTER_ACTION(DistanceFromSphericalContour,"DISTANCE_FROM_SPHERICAL_CONTOUR") 46 : 47 3 : void DistanceFromSphericalContour::registerKeywords( Keywords& keys ) { 48 3 : DistanceFromContourBase::registerKeywords( keys ); 49 6 : keys.addOutputComponent("dist","default","scalar","the distance between the reference atom and the nearest contour"); 50 6 : keys.addOutputComponent("radius","default","scalar","the radial distance from the center of the contour to the edge"); 51 6 : keys.add("atoms","ORIGIN","The position of the center of the region that the contour encloses"); 52 3 : } 53 : 54 1 : DistanceFromSphericalContour::DistanceFromSphericalContour( const ActionOptions& ao ): 55 : Action(ao), 56 1 : DistanceFromContourBase(ao) 57 : { 58 : // Create the values 59 : std::vector<unsigned> shape; 60 2 : addComponentWithDerivatives("dist", shape ); componentIsNotPeriodic("dist"); 61 3 : addComponent("radius", shape ); componentIsNotPeriodic("radius"); 62 1 : } 63 : 64 17 : void DistanceFromSphericalContour::calculate() { 65 : // Check box is orthorhombic 66 17 : if( !getPbc().isOrthorombic() ) error("cell box must be orthorhombic"); 67 : 68 : // Calculate the director of the vector connecting the center of the sphere to the molecule of interest 69 17 : Vector dirv = pbcDistance( getPosition(getNumberOfAtoms()-1), getPosition(getNumberOfAtoms()-2) ); 70 17 : double len=dirv.modulo(); dirv /= len; 71 : // Now work out which atoms need to be considered explicitly 72 17 : Vector myvec = pbcDistance( getPosition(getNumberOfAtoms()-1), getPosition(0) ); 73 17 : nactive=1; active_list[0]=0; 74 8704 : for(unsigned j=1; j<getNumberOfAtoms()-2; ++j) { 75 8687 : if( getNumberOfArguments()==1 ) { 76 8687 : if( getPntrToArgument(0)->get(j)<epsilon ) continue; 77 : } 78 6698 : active_list[nactive]=j; nactive++; 79 6698 : Vector distance=pbcDistance( getPosition(getNumberOfAtoms()-1), getPosition(j) ); 80 6698 : double dp = dotProduct( distance, dirv ); double cp = distance.modulo2() - dp*dp; 81 6698 : if( cp<rcut2 ) { active_list[nactive]=j; nactive++; } 82 : } 83 : // Get maximum length to fit in box 84 17 : double hbox = 0.5*getBox()(0,0); 85 17 : if( 0.5*getBox()(1,1)<hbox ) hbox = 0.5*getBox()(1,1); 86 17 : if( 0.5*getBox()(2,2)<hbox ) hbox = 0.5*getBox()(2,2); 87 : // Set initial guess for position of contour to position of closest molecule in region 88 17 : std::vector<double> pos1(3), dirv2(3); 89 68 : for(unsigned k=0; k<3; ++k) { dirv2[k]=hbox*dirv[k]; pos1[k]=0; } 90 : // Now do a search for the contours 91 : findContour( dirv2, pos1 ); 92 : // Now find the distance between the center of the sphere and the contour 93 17 : double rad = sqrt( pos1[0]*pos1[0] + pos1[1]*pos1[1] + pos1[2]*pos1[2] ); 94 : // Set the radius 95 17 : getPntrToComponent("radius")->set( rad ); 96 : // Set the distance between the contour and the molecule 97 17 : getPntrToComponent("dist")->set( len - rad ); 98 : 99 : // Now calculate the derivatives 100 17 : if( !doNotCalculateDerivatives() ) plumed_merror("derivatives not implemented"); 101 17 : } 102 : 103 0 : void DistanceFromSphericalContour::evaluateDerivatives( const Vector& root1, const double& root2 ) { 104 0 : plumed_error(); 105 : } 106 : 107 : } 108 : }