Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2018 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 "core/ActionRegister.h" 23 : #include "core/ActionShortcut.h" 24 : #include "core/PlumedMain.h" 25 : #include "core/ActionSet.h" 26 : #include "core/ActionWithValue.h" 27 : 28 : //+PLUMEDOC MCOLVAR EUCLIDEAN_DISTANCE 29 : /* 30 : Calculate the euclidean distance between two vectors of arguments 31 : 32 : \par Examples 33 : 34 : */ 35 : //+ENDPLUMEDOC 36 : 37 : namespace PLMD { 38 : namespace refdist { 39 : 40 : class EuclideanDistance : public ActionShortcut { 41 : public: 42 : static void registerKeywords( Keywords& keys ); 43 : explicit EuclideanDistance(const ActionOptions&ao); 44 : }; 45 : 46 : PLUMED_REGISTER_ACTION(EuclideanDistance,"EUCLIDEAN_DISTANCE") 47 : 48 35 : void EuclideanDistance::registerKeywords( Keywords& keys ) { 49 35 : ActionShortcut::registerKeywords(keys); 50 70 : keys.add("compulsory","ARG1","The poin that we are calculating the distance from"); 51 70 : keys.add("compulsory","ARG2","The point that we are calculating the distance to"); 52 70 : keys.addFlag("SQUARED",false,"The squared distance should be calculated"); 53 35 : keys.setValueDescription("the euclidean distances between the input vectors"); 54 35 : keys.needsAction("DISPLACEMENT"); 55 35 : keys.needsAction("CUSTOM"); 56 35 : keys.needsAction("TRANSPOSE"); 57 35 : keys.needsAction("MATRIX_PRODUCT_DIAGONAL"); 58 35 : } 59 : 60 28 : EuclideanDistance::EuclideanDistance( const ActionOptions& ao): 61 : Action(ao), 62 28 : ActionShortcut(ao) { 63 : std::string arg1, arg2; 64 28 : parse("ARG1",arg1); 65 28 : parse("ARG2",arg2); 66 : // Vectors are in rows here 67 56 : readInputLine( getShortcutLabel() + "_diff: DISPLACEMENT ARG1=" + arg1 + " ARG2=" + arg2 ); 68 : // Get the action that computes the differences 69 28 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_diff"); 70 28 : plumed_assert( av ); 71 : // Check if squared 72 : bool squared; 73 28 : parseFlag("SQUARED",squared); 74 28 : std::string olab = getShortcutLabel(); 75 28 : if( !squared ) { 76 : olab += "_2"; 77 : } 78 : // Deal with an annoying corner case when displacement has a single argument 79 28 : if( av->copyOutput(0)->getRank()==0 ) { 80 0 : readInputLine( olab + ": CUSTOM ARG=" + getShortcutLabel() + "_diff FUNC=x*x PERIODIC=NO"); 81 : } else { 82 : // Notice that the vectors are in the columns here 83 56 : readInputLine( getShortcutLabel() + "_diffT: TRANSPOSE ARG=" + getShortcutLabel() + "_diff"); 84 56 : readInputLine( olab + ": MATRIX_PRODUCT_DIAGONAL ARG=" + getShortcutLabel() + "_diff," + getShortcutLabel() + "_diffT"); 85 : } 86 28 : if( !squared ) { 87 46 : readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_2 FUNC=sqrt(x) PERIODIC=NO"); 88 : } 89 28 : } 90 : 91 : } 92 : }