Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-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/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : #include "MultiColvarShortcuts.h" 25 : 26 : //+PLUMEDOC MCOLVAR COORD_ANGLES 27 : /* 28 : Calculate all the angles between bonds in the first coordination spheres of a set of atoms 29 : 30 : \par Examples 31 : 32 : 33 : */ 34 : //+ENDPLUMEDOC 35 : 36 : namespace PLMD { 37 : namespace multicolvar { 38 : 39 : class CoordAngles : public ActionShortcut { 40 : public: 41 : static void registerKeywords(Keywords& keys); 42 : static void pruneShortcuts(Keywords& keys); 43 : explicit CoordAngles(const ActionOptions&); 44 : }; 45 : 46 : PLUMED_REGISTER_ACTION(CoordAngles,"COORD_ANGLES") 47 : 48 6 : void CoordAngles::registerKeywords(Keywords& keys) { 49 6 : ActionShortcut::registerKeywords( keys ); 50 12 : keys.add("atoms","CATOMS","all the angles between the bonds that radiate out from these central atom are computed"); 51 12 : keys.add("atoms","GROUP","a list of angls between pairs of bonds connecting one of the atoms specified using the CATOM command and two of the atoms specified here are computed"); 52 12 : keys.add("compulsory","SWITCH","the switching function specifies that only those bonds that have a length that is less than a certain threshold are considered"); 53 6 : MultiColvarShortcuts::shortcutKeywords( keys ); pruneShortcuts( keys ); 54 18 : keys.needsAction("DISTANCE"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM"); 55 12 : keys.needsAction("VSTACK"); keys.needsAction("TRANSPOSE"); 56 12 : keys.needsAction("OUTER_PRODUCT"); keys.needsAction("MATRIX_PRODUCT"); 57 6 : } 58 : 59 8 : void CoordAngles::pruneShortcuts(Keywords& keys) { 60 40 : keys.remove("ALT_MIN"); keys.remove("MIN"); keys.remove("MAX"); keys.remove("HIGHEST"); keys.remove("LOWEST"); 61 8 : } 62 : 63 2 : CoordAngles::CoordAngles(const ActionOptions& ao): 64 : Action(ao), 65 2 : ActionShortcut(ao) 66 : { 67 : // Parse the central atoms 68 4 : std::vector<std::string> catoms; parseVector("CATOMS",catoms); Tools::interpretRanges(catoms); 69 : // Parse the coordination sphere 70 4 : std::vector<std::string> group; parseVector("GROUP",group); Tools::interpretRanges(group); 71 : // Create the list of atoms 72 2 : std::string atlist; unsigned k=1; 73 4 : for(unsigned i=0; i<catoms.size(); ++i) { 74 200 : for(unsigned j=0; j<group.size(); ++j) { std::string num; Tools::convert( k, num ); atlist += " ATOMS" + num + "=" + catoms[i] + "," + group[j]; k++; } 75 : } 76 : // Calculate the distances 77 4 : readInputLine( getShortcutLabel() + "_dd: DISTANCE" + atlist ); 78 : // Transform with the switching function 79 2 : std::string switch_input; parse("SWITCH",switch_input); 80 4 : readInputLine( getShortcutLabel() + "_sw: LESS_THAN ARG=" + getShortcutLabel() + "_dd SWITCH={" + switch_input +"}"); 81 : // Now get the normalised vectors 82 4 : readInputLine( getShortcutLabel() + "_comp: DISTANCE" + atlist + " COMPONENTS"); 83 4 : readInputLine( getShortcutLabel() + "_norm2: COMBINE ARG=" + getShortcutLabel() + "_comp.x" + "," + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_comp.z POWERS=2,2,2 PERIODIC=NO"); 84 4 : readInputLine( getShortcutLabel() + "_norm: CUSTOM ARG=" + getShortcutLabel() + "_norm2 FUNC=sqrt(x) PERIODIC=NO"); 85 4 : readInputLine( getShortcutLabel() + "_norm_x: CUSTOM ARG=" + getShortcutLabel() + "_comp.x," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 86 4 : readInputLine( getShortcutLabel() + "_norm_y: CUSTOM ARG=" + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 87 4 : readInputLine( getShortcutLabel() + "_norm_z: CUSTOM ARG=" + getShortcutLabel() + "_comp.z," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 88 4 : readInputLine( getShortcutLabel() + "_stack: VSTACK ARG=" + getShortcutLabel() + "_norm_x" + "," + getShortcutLabel() + "_norm_y," + getShortcutLabel() + "_norm_z"); 89 4 : readInputLine( getShortcutLabel() + "_stackT: TRANSPOSE ARG=" + getShortcutLabel() + "_stack"); 90 : // Create the matrix of weights 91 4 : readInputLine( getShortcutLabel() + "_swd: OUTER_PRODUCT ELEMENTS_ON_DIAGONAL_ARE_ZERO ARG=" + getShortcutLabel() + "_sw," + getShortcutLabel() + "_sw"); 92 : // Avoid double counting 93 4 : readInputLine( getShortcutLabel() + "_wmat: CUSTOM ARG=" + getShortcutLabel() + "_swd FUNC=0.5*x PERIODIC=NO"); 94 : // And the matrix of dot products and the angles 95 4 : readInputLine( getShortcutLabel() + "_dpmat: MATRIX_PRODUCT ARG=" + getShortcutLabel() + "_stack," + getShortcutLabel() + "_stackT"); 96 4 : readInputLine( getShortcutLabel() + "_angles: CUSTOM ARG=" + getShortcutLabel() + "_dpmat FUNC=acos(x) PERIODIC=NO"); 97 : // Read the input 98 4 : Keywords keys; MultiColvarShortcuts::shortcutKeywords( keys ); pruneShortcuts( keys ); bool do_mean; parseFlag("MEAN",do_mean); 99 4 : std::map<std::string,std::string> keymap; readShortcutKeywords( keys, keymap ); if( do_mean ) keymap.insert(std::pair<std::string,std::string>("SUM","")); 100 4 : MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_angles", getShortcutLabel() + "_wmat", keymap, this ); 101 2 : if( do_mean ) { 102 4 : readInputLine( getShortcutLabel() + "_denom: SUM ARG=" + getShortcutLabel() + "_wmat PERIODIC=NO"); 103 4 : readInputLine( getShortcutLabel() + "_mean: CUSTOM ARG=" + getShortcutLabel() + "_sum," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO"); 104 : } 105 4 : } 106 : 107 : } 108 : }