LCOV - code coverage report
Current view: top level - multicolvar - CoordAngles.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 61 61 100.0 %
Date: 2025-04-08 21:11:17 Functions: 3 4 75.0 %

          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             : */
      50             : //+ENDPLUMEDOC
      51             : 
      52             : namespace PLMD {
      53             : namespace multicolvar {
      54             : 
      55             : class CoordAngles : public ActionShortcut {
      56             : public:
      57             :   static void registerKeywords(Keywords& keys);
      58             :   static void pruneShortcuts(Keywords& keys);
      59             :   explicit CoordAngles(const ActionOptions&);
      60             : };
      61             : 
      62             : PLUMED_REGISTER_ACTION(CoordAngles,"COORD_ANGLES")
      63             : 
      64           6 : void CoordAngles::registerKeywords(Keywords& keys) {
      65           6 :   ActionShortcut::registerKeywords( keys );
      66           6 :   keys.add("atoms","CATOMS","all the angles between the bonds that radiate out from these central atom are computed");
      67           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");
      68           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");
      69           6 :   MultiColvarShortcuts::shortcutKeywords( keys );
      70           6 :   pruneShortcuts( keys );
      71           6 :   keys.needsAction("DISTANCE");
      72           6 :   keys.needsAction("COMBINE");
      73           6 :   keys.needsAction("CUSTOM");
      74           6 :   keys.needsAction("VSTACK");
      75           6 :   keys.needsAction("TRANSPOSE");
      76           6 :   keys.needsAction("OUTER_PRODUCT");
      77           6 :   keys.needsAction("MATRIX_PRODUCT");
      78           6 : }
      79             : 
      80           8 : void CoordAngles::pruneShortcuts(Keywords& keys) {
      81           8 :   keys.remove("ALT_MIN");
      82           8 :   keys.remove("MIN");
      83           8 :   keys.remove("MAX");
      84           8 :   keys.remove("HIGHEST");
      85           8 :   keys.remove("LOWEST");
      86           8 : }
      87             : 
      88           2 : CoordAngles::CoordAngles(const ActionOptions& ao):
      89             :   Action(ao),
      90           2 :   ActionShortcut(ao) {
      91             :   // Parse the central atoms
      92             :   std::vector<std::string> catoms;
      93           2 :   parseVector("CATOMS",catoms);
      94           2 :   Tools::interpretRanges(catoms);
      95             :   // Parse the coordination sphere
      96             :   std::vector<std::string> group;
      97           2 :   parseVector("GROUP",group);
      98           2 :   Tools::interpretRanges(group);
      99             :   // Create the list of atoms
     100             :   std::string atlist;
     101           2 :   unsigned k=1;
     102           4 :   for(unsigned i=0; i<catoms.size(); ++i) {
     103         200 :     for(unsigned j=0; j<group.size(); ++j) {
     104             :       std::string num;
     105         198 :       Tools::convert( k, num );
     106         396 :       atlist += " ATOMS" + num + "=" + catoms[i] + "," + group[j];
     107         198 :       k++;
     108             :     }
     109             :   }
     110             :   // Calculate the distances
     111           4 :   readInputLine( getShortcutLabel() + "_dd: DISTANCE" + atlist );
     112             :   // Transform with the switching function
     113             :   std::string switch_input;
     114           2 :   parse("SWITCH",switch_input);
     115           4 :   readInputLine( getShortcutLabel() + "_sw: LESS_THAN ARG=" + getShortcutLabel() + "_dd SWITCH={" + switch_input +"}");
     116             :   // Now get the normalised vectors
     117           4 :   readInputLine( getShortcutLabel() + "_comp: DISTANCE" + atlist + " COMPONENTS");
     118           4 :   readInputLine( getShortcutLabel() + "_norm2: COMBINE ARG=" + getShortcutLabel() + "_comp.x" + "," + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_comp.z POWERS=2,2,2 PERIODIC=NO");
     119           4 :   readInputLine( getShortcutLabel() + "_norm: CUSTOM ARG=" + getShortcutLabel() + "_norm2 FUNC=sqrt(x) PERIODIC=NO");
     120           4 :   readInputLine( getShortcutLabel() + "_norm_x: CUSTOM ARG=" + getShortcutLabel() + "_comp.x," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     121           4 :   readInputLine( getShortcutLabel() + "_norm_y: CUSTOM ARG=" + getShortcutLabel() + "_comp.y," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     122           4 :   readInputLine( getShortcutLabel() + "_norm_z: CUSTOM ARG=" + getShortcutLabel() + "_comp.z," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     123           4 :   readInputLine( getShortcutLabel() + "_stack: VSTACK ARG=" + getShortcutLabel() + "_norm_x" + "," + getShortcutLabel() + "_norm_y," + getShortcutLabel() + "_norm_z");
     124           4 :   readInputLine( getShortcutLabel() + "_stackT: TRANSPOSE ARG=" + getShortcutLabel() + "_stack");
     125             :   // Create the matrix of weights
     126           4 :   readInputLine( getShortcutLabel() + "_swd: OUTER_PRODUCT ELEMENTS_ON_DIAGONAL_ARE_ZERO ARG=" + getShortcutLabel() + "_sw," + getShortcutLabel() + "_sw");
     127             :   // Avoid double counting
     128           4 :   readInputLine( getShortcutLabel() + "_wmat: CUSTOM ARG=" + getShortcutLabel() + "_swd FUNC=0.5*x PERIODIC=NO");
     129             :   // And the matrix of dot products and the angles
     130           4 :   readInputLine( getShortcutLabel() + "_dpmat: MATRIX_PRODUCT ARG=" + getShortcutLabel() + "_stack," + getShortcutLabel() + "_stackT");
     131           4 :   readInputLine( getShortcutLabel() + "_angles: CUSTOM ARG=" + getShortcutLabel() + "_dpmat FUNC=acos(x) PERIODIC=NO");
     132             :   // Read the input
     133           2 :   Keywords keys;
     134           2 :   MultiColvarShortcuts::shortcutKeywords( keys );
     135           2 :   pruneShortcuts( keys );
     136             :   bool do_mean;
     137           4 :   parseFlag("MEAN",do_mean);
     138             :   std::map<std::string,std::string> keymap;
     139           2 :   readShortcutKeywords( keys, keymap );
     140           2 :   if( do_mean ) {
     141           4 :     keymap.insert(std::pair<std::string,std::string>("SUM",""));
     142             :   }
     143           4 :   MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_angles", getShortcutLabel() + "_wmat", keymap, this );
     144           2 :   if( do_mean ) {
     145           4 :     readInputLine( getShortcutLabel() + "_denom: SUM ARG=" + getShortcutLabel() + "_wmat PERIODIC=NO");
     146           4 :     readInputLine( getShortcutLabel() + "_mean: CUSTOM ARG=" + getShortcutLabel() + "_sum," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
     147             :   }
     148           4 : }
     149             : 
     150             : }
     151             : }

Generated by: LCOV version 1.16