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/ActionWithValue.h" 25 : #include "CoordinationNumbers.h" 26 : #include "multicolvar/MultiColvarShortcuts.h" 27 : #include "core/PlumedMain.h" 28 : #include "core/ActionSet.h" 29 : 30 : //+PLUMEDOC MCOLVAR TETRA_RADIAL 31 : /* 32 : Calculate the radial tetra CV 33 : 34 : \par Examples 35 : 36 : */ 37 : //+ENDPLUMEDOC 38 : 39 : namespace PLMD { 40 : namespace symfunc { 41 : 42 : class RadialTetra : public ActionShortcut { 43 : public: 44 : static void registerKeywords( Keywords& keys ); 45 : explicit RadialTetra(const ActionOptions&ao); 46 : }; 47 : 48 : PLUMED_REGISTER_ACTION(RadialTetra,"TETRA_RADIAL") 49 : 50 3 : void RadialTetra::registerKeywords( Keywords& keys ) { 51 3 : CoordinationNumbers::shortcutKeywords( keys ); 52 6 : keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances"); 53 6 : keys.add("compulsory","CUTOFF","-1","ignore distances that have a value larger than this cutoff"); 54 15 : keys.remove("NN"); keys.remove("MM"); keys.remove("D_0"); keys.remove("R_0"); keys.remove("SWITCH"); 55 6 : keys.needsAction("DISTANCE_MATRIX"); keys.needsAction("NEIGHBORS"); 56 6 : keys.needsAction("CUSTOM"); keys.needsAction("ONES"); 57 3 : keys.needsAction("MATRIX_VECTOR_PRODUCT"); 58 3 : } 59 : 60 1 : RadialTetra::RadialTetra( const ActionOptions& ao): 61 : Action(ao), 62 1 : ActionShortcut(ao) 63 : { 64 : // Read species input and create the matrix 65 1 : bool nopbc; parseFlag("NOPBC",nopbc); 66 1 : std::string pbcstr=""; if( nopbc ) pbcstr = " NOPBC"; 67 3 : std::string sp_str, rcut; parse("SPECIES",sp_str); parse("CUTOFF",rcut); 68 1 : if( sp_str.length()>0 ) { 69 2 : readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUP=" + sp_str + " CUTOFF=" + rcut + pbcstr ); 70 : } else { 71 0 : std::string specA, specB; parse("SPECIESA",specA); parse("SPECIESB",specB); 72 0 : if( specA.length()==0 ) error("missing input atoms"); 73 0 : if( specB.length()==0 ) error("missing SPECIESB keyword"); 74 0 : readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUPA=" + specA + " GROUPB=" + specB + " CUTOFF=" + rcut + pbcstr); 75 : } 76 : // Get the neighbors matrix 77 2 : readInputLine( getShortcutLabel() + "_neigh: NEIGHBORS ARG=" + getShortcutLabel() + "_mat NLOWEST=4"); 78 : // Now get distance matrix that just contains four nearest distances 79 2 : readInputLine( getShortcutLabel() + "_near4: CUSTOM ARG=" + getShortcutLabel() + "_mat," + getShortcutLabel() + "_neigh FUNC=x*y PERIODIC=NO"); 80 : //Now compute sum of four nearest distances 81 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat"); 82 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 83 1 : std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 84 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 85 2 : readInputLine( getShortcutLabel() + "_sum4: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4," + getShortcutLabel() + "_ones"); 86 : // Now compute squares of four nearest distance 87 2 : readInputLine( getShortcutLabel() + "_near4_2: CUSTOM ARG=" + getShortcutLabel() + "_near4 FUNC=x*x PERIODIC=NO"); 88 : // Now compute sum of the squares of the four nearest distances 89 2 : readInputLine( getShortcutLabel() + "_sum4_2: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4_2," + getShortcutLabel() + "_ones"); 90 : // Evaluate the average distance to the four nearest neighbors 91 2 : readInputLine( getShortcutLabel() + "_meanr: CUSTOM ARG=" + getShortcutLabel() + "_sum4 FUNC=0.25*x PERIODIC=NO"); 92 : // Now evaluate the actual per atom CV 93 2 : readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_sum4," + getShortcutLabel() + "_sum4_2," + getShortcutLabel() + "_meanr " + 94 : "FUNC=(1-(y-x*z)/(12*z*z)) PERIODIC=NO"); 95 : // And get the things to do with the quantities we have computed 96 1 : std::map<std::string,std::string> keymap; multicolvar::MultiColvarShortcuts::readShortcutKeywords( keymap, this ); 97 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", keymap, this ); 98 1 : } 99 : 100 : } 101 : }