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 3 : keys.remove("NN"); 55 3 : keys.remove("MM"); 56 3 : keys.remove("D_0"); 57 3 : keys.remove("R_0"); 58 3 : keys.remove("SWITCH"); 59 3 : keys.needsAction("DISTANCE_MATRIX"); 60 3 : keys.needsAction("NEIGHBORS"); 61 3 : keys.needsAction("CUSTOM"); 62 3 : keys.needsAction("ONES"); 63 3 : keys.needsAction("MATRIX_VECTOR_PRODUCT"); 64 3 : } 65 : 66 1 : RadialTetra::RadialTetra( const ActionOptions& ao): 67 : Action(ao), 68 1 : ActionShortcut(ao) { 69 : // Read species input and create the matrix 70 : bool nopbc; 71 1 : parseFlag("NOPBC",nopbc); 72 1 : std::string pbcstr=""; 73 1 : if( nopbc ) { 74 : pbcstr = " NOPBC"; 75 : } 76 : std::string sp_str, rcut; 77 1 : parse("SPECIES",sp_str); 78 2 : parse("CUTOFF",rcut); 79 1 : if( sp_str.length()>0 ) { 80 2 : readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUP=" + sp_str + " CUTOFF=" + rcut + pbcstr ); 81 : } else { 82 : std::string specA, specB; 83 0 : parse("SPECIESA",specA); 84 0 : parse("SPECIESB",specB); 85 0 : if( specA.length()==0 ) { 86 0 : error("missing input atoms"); 87 : } 88 0 : if( specB.length()==0 ) { 89 0 : error("missing SPECIESB keyword"); 90 : } 91 0 : readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUPA=" + specA + " GROUPB=" + specB + " CUTOFF=" + rcut + pbcstr); 92 : } 93 : // Get the neighbors matrix 94 2 : readInputLine( getShortcutLabel() + "_neigh: NEIGHBORS ARG=" + getShortcutLabel() + "_mat NLOWEST=4"); 95 : // Now get distance matrix that just contains four nearest distances 96 2 : readInputLine( getShortcutLabel() + "_near4: CUSTOM ARG=" + getShortcutLabel() + "_mat," + getShortcutLabel() + "_neigh FUNC=x*y PERIODIC=NO"); 97 : //Now compute sum of four nearest distances 98 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat"); 99 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 100 : std::string size; 101 1 : Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 102 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 103 2 : readInputLine( getShortcutLabel() + "_sum4: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4," + getShortcutLabel() + "_ones"); 104 : // Now compute squares of four nearest distance 105 2 : readInputLine( getShortcutLabel() + "_near4_2: CUSTOM ARG=" + getShortcutLabel() + "_near4 FUNC=x*x PERIODIC=NO"); 106 : // Now compute sum of the squares of the four nearest distances 107 2 : readInputLine( getShortcutLabel() + "_sum4_2: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4_2," + getShortcutLabel() + "_ones"); 108 : // Evaluate the average distance to the four nearest neighbors 109 2 : readInputLine( getShortcutLabel() + "_meanr: CUSTOM ARG=" + getShortcutLabel() + "_sum4 FUNC=0.25*x PERIODIC=NO"); 110 : // Now evaluate the actual per atom CV 111 2 : readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_sum4," + getShortcutLabel() + "_sum4_2," + getShortcutLabel() + "_meanr " + 112 : "FUNC=(1-(y-x*z)/(12*z*z)) PERIODIC=NO"); 113 : // And get the things to do with the quantities we have computed 114 : std::map<std::string,std::string> keymap; 115 1 : multicolvar::MultiColvarShortcuts::readShortcutKeywords( keymap, this ); 116 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", keymap, this ); 117 1 : } 118 : 119 : } 120 : }