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 functions of the distribution of angles between bonds in the first coordination spheres of a set of atoms 29 : 30 : This action ncan be used to calculate functions, $g$, such as: 31 : 32 : $$ 33 : f(x) = \sum_{ijk} s(r_{ij})s(r_{jk}) g(\theta_{ijk}) 34 : $$ 35 : 36 : where $\theta_{ijk}$ is the angle between the vector connecting atom $i$ and and $j$ and the vector connecting atom $j$ and atom $k$ and 37 : where $s(r)$ is a switching function. The switching functions in the expression above ensure that we can calculate all the angles in the first coordination 38 : spheres of an atom using an input like the one shown below: 39 : 40 : ```plumed 41 : c1: COORD_ANGLES ... 42 : CATOMS=1 GROUP=2-100 SWITCH={RATIONAL R_0=1.0} SUM 43 : ... 44 : PRINT ARG=c1.sum FILE=colvar 45 : ``` 46 : 47 : The input above will output the sum of all the angles in the first coordination sphere. 48 : 49 : __As you can see if you expand the shortcut in the input above, the calculation of the above sum is obtained by calculating a [Hadamard product](https://en.wikipedia.org/wiki/Hadamard_product_(matrices)) 50 : of an [OUTER_PRODUCT](OUTER_PRODUCT.md) matrix and a [MATRIX_PRODUCT](MATRIX_PRODUCT.md). We have thus deprecated this action as we believe that there is value in learning to use the more complicated syntax 51 : directly.__ 52 : 53 : */ 54 : //+ENDPLUMEDOC 55 : 56 : namespace PLMD { 57 : namespace multicolvar { 58 : 59 : class CoordAngles : public ActionShortcut { 60 : public: 61 : static void registerKeywords(Keywords& keys); 62 : static void pruneShortcuts(Keywords& keys); 63 : explicit CoordAngles(const ActionOptions&); 64 : }; 65 : 66 : PLUMED_REGISTER_ACTION(CoordAngles,"COORD_ANGLES") 67 : 68 6 : void CoordAngles::registerKeywords(Keywords& keys) { 69 6 : ActionShortcut::registerKeywords( keys ); 70 6 : keys.add("atoms","CATOMS","all the angles between the bonds that radiate out from these central atom are computed"); 71 6 : 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"); 72 6 : 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"); 73 6 : MultiColvarShortcuts::shortcutKeywords( keys ); 74 6 : pruneShortcuts( keys ); 75 6 : keys.needsAction("DISTANCE"); 76 6 : keys.needsAction("COMBINE"); 77 6 : keys.needsAction("CUSTOM"); 78 6 : keys.needsAction("VSTACK"); 79 6 : keys.needsAction("TRANSPOSE"); 80 6 : keys.needsAction("OUTER_PRODUCT"); 81 6 : keys.needsAction("MATRIX_PRODUCT"); 82 6 : keys.setDeprecated("MATRIX_PRODUCT"); 83 6 : } 84 : 85 8 : void CoordAngles::pruneShortcuts(Keywords& keys) { 86 8 : keys.remove("ALT_MIN"); 87 8 : keys.remove("MIN"); 88 8 : keys.remove("MAX"); 89 8 : keys.remove("HIGHEST"); 90 8 : keys.remove("LOWEST"); 91 8 : } 92 : 93 2 : CoordAngles::CoordAngles(const ActionOptions& ao): 94 : Action(ao), 95 2 : ActionShortcut(ao) { 96 : // Parse the central atoms 97 : std::vector<std::string> catoms; 98 2 : parseVector("CATOMS",catoms); 99 2 : Tools::interpretRanges(catoms); 100 : // Parse the coordination sphere 101 : std::vector<std::string> group; 102 2 : parseVector("GROUP",group); 103 2 : Tools::interpretRanges(group); 104 : // Create the list of atoms 105 : std::string atlist; 106 2 : unsigned k=1; 107 4 : for(unsigned i=0; i<catoms.size(); ++i) { 108 200 : for(unsigned j=0; j<group.size(); ++j) { 109 : std::string num; 110 198 : Tools::convert( k, num ); 111 396 : atlist += " ATOMS" + num + "=" + catoms[i] + "," + group[j]; 112 198 : k++; 113 : } 114 : } 115 : // Calculate the distances 116 4 : readInputLine( getShortcutLabel() + "_dd: DISTANCE" + atlist ); 117 : // Transform with the switching function 118 : std::string switch_input; 119 2 : parse("SWITCH",switch_input); 120 4 : readInputLine( getShortcutLabel() + "_sw: LESS_THAN ARG=" + getShortcutLabel() + "_dd SWITCH={" + switch_input +"}"); 121 : // Now get the normalised vectors 122 4 : readInputLine( getShortcutLabel() + "_comp: DISTANCE" + atlist + " COMPONENTS"); 123 4 : readInputLine( getShortcutLabel() + "_norm2: COMBINE ARG=" + getShortcutLabel() + "_comp.x" + "," + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_comp.z POWERS=2,2,2 PERIODIC=NO"); 124 4 : readInputLine( getShortcutLabel() + "_norm: CUSTOM ARG=" + getShortcutLabel() + "_norm2 FUNC=sqrt(x) PERIODIC=NO"); 125 4 : readInputLine( getShortcutLabel() + "_norm_x: CUSTOM ARG=" + getShortcutLabel() + "_comp.x," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 126 4 : readInputLine( getShortcutLabel() + "_norm_y: CUSTOM ARG=" + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 127 4 : readInputLine( getShortcutLabel() + "_norm_z: CUSTOM ARG=" + getShortcutLabel() + "_comp.z," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO"); 128 4 : readInputLine( getShortcutLabel() + "_stack: VSTACK ARG=" + getShortcutLabel() + "_norm_x" + "," + getShortcutLabel() + "_norm_y," + getShortcutLabel() + "_norm_z"); 129 4 : readInputLine( getShortcutLabel() + "_stackT: TRANSPOSE ARG=" + getShortcutLabel() + "_stack"); 130 : // Create the matrix of weights 131 4 : readInputLine( getShortcutLabel() + "_swd: OUTER_PRODUCT ELEMENTS_ON_DIAGONAL_ARE_ZERO ARG=" + getShortcutLabel() + "_sw," + getShortcutLabel() + "_sw"); 132 : // Avoid double counting 133 4 : readInputLine( getShortcutLabel() + "_wmat: CUSTOM ARG=" + getShortcutLabel() + "_swd FUNC=0.5*x PERIODIC=NO"); 134 : // And the matrix of dot products and the angles 135 4 : readInputLine( getShortcutLabel() + "_dpmat: MATRIX_PRODUCT ELEMENTS_ON_DIAGONAL_ARE_ZERO ARG=" + getShortcutLabel() + "_stack," + getShortcutLabel() + "_stackT"); 136 4 : readInputLine( getShortcutLabel() + "_angles: CUSTOM ARG=" + getShortcutLabel() + "_dpmat FUNC=acos(x) PERIODIC=NO"); 137 : // Read the input 138 2 : Keywords keys; 139 2 : MultiColvarShortcuts::shortcutKeywords( keys ); 140 2 : pruneShortcuts( keys ); 141 : bool do_mean; 142 4 : parseFlag("MEAN",do_mean); 143 : std::map<std::string,std::string> keymap; 144 2 : readShortcutKeywords( keys, keymap ); 145 2 : if( do_mean ) { 146 4 : keymap.insert(std::pair<std::string,std::string>("SUM","")); 147 : } 148 4 : MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_angles", getShortcutLabel() + "_wmat", keymap, this ); 149 2 : if( do_mean ) { 150 4 : readInputLine( getShortcutLabel() + "_denom: SUM ARG=" + getShortcutLabel() + "_wmat PERIODIC=NO"); 151 4 : readInputLine( getShortcutLabel() + "_mean: CUSTOM ARG=" + getShortcutLabel() + "_sum," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO"); 152 : } 153 4 : } 154 : 155 : } 156 : }