Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2017 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 "AdjacencyMatrixBase.h" 23 : #include "core/ActionRegister.h" 24 : #include "tools/SwitchingFunction.h" 25 : #include "tools/Matrix.h" 26 : 27 : //+PLUMEDOC MATRIX DISTANCE_MATRIX 28 : /* 29 : Calculate a matrix of distances 30 : 31 : \par Examples 32 : 33 : */ 34 : //+ENDPLUMEDOC 35 : 36 : 37 : namespace PLMD { 38 : namespace adjmat { 39 : 40 : class DistanceMatrix : public AdjacencyMatrixBase { 41 : private: 42 : double cutoff; 43 : public: 44 : /// Create manual 45 : static void registerKeywords( Keywords& keys ); 46 : /// Constructor 47 : explicit DistanceMatrix(const ActionOptions&); 48 : /// This does nothing 49 : double calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const ; 50 : }; 51 : 52 : PLUMED_REGISTER_ACTION(DistanceMatrix,"DISTANCE_MATRIX") 53 : 54 178 : void DistanceMatrix::registerKeywords( Keywords& keys ) { 55 178 : AdjacencyMatrixBase::registerKeywords( keys ); 56 356 : keys.add("compulsory","CUTOFF","-1","ignore distances that have a value larger than this cutoff"); 57 178 : } 58 : 59 92 : DistanceMatrix::DistanceMatrix( const ActionOptions& ao ): 60 : Action(ao), 61 92 : AdjacencyMatrixBase(ao) 62 : { 63 : // And set the link cell cutoff 64 92 : log.printf(" weight is distance between atoms \n"); 65 92 : parse("CUTOFF",cutoff); 66 92 : if( cutoff<0 ) { 67 5 : setLinkCellCutoff( true, std::numeric_limits<double>::max() ); 68 : } else { 69 87 : log.printf(" ignoring distances that are larger than %f \n", cutoff); 70 87 : setLinkCellCutoff( true, cutoff ); 71 : } 72 92 : } 73 : 74 5857010 : double DistanceMatrix::calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const { 75 5857010 : Vector distance = pos2; double mod = distance.modulo(); 76 5857010 : if( cutoff<0 || mod<cutoff ) { 77 5157580 : double invd = 1.0/mod; 78 5157580 : addAtomDerivatives( 0, (-invd)*distance, myvals ); 79 5157580 : addAtomDerivatives( 1, (+invd)*distance, myvals ); 80 5157580 : addBoxDerivatives( (-invd)*Tensor(distance,distance), myvals ); 81 : } 82 5857010 : return mod; 83 : } 84 : 85 : } 86 : } 87 :