LCOV - code coverage report
Current view: top level - adjmat - Bridge.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 28 30 93.3 %
Date: 2026-11-05 10:19:04 Functions: 2 3 66.7 %

          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             : 
      25             : //+PLUMEDOC MCOLVAR BRIDGE
      26             : /*
      27             : Calculate the number of briding atoms between two groups
      28             : 
      29             : This quantity calculates:
      30             : 
      31             : $$
      32             : f(x) = \sum_{ijk} s_A(r_{ij})s_B(r_{ik})
      33             : $$
      34             : 
      35             : where the sum over $i$ is over all the "bridging atoms" and
      36             : $s_A$ and $s_B$ are switching functions.
      37             : 
      38             : The following example instructs plumed to calculate the number of water molecules
      39             : that are bridging between atoms 1-10 and atoms 11-20 and to print the value
      40             : to a file
      41             : 
      42             : ```plumed
      43             : w1: BRIDGE BRIDGING_ATOMS=100-200 GROUPA=1-10 GROUPB=11-20 SWITCH={RATIONAL R_0=0.2}
      44             : PRINT ARG=w1 FILE=colvar
      45             : ```
      46             : 
      47             : You can use the following input instead to calculate the number of atoms that bridge between the
      48             : 45 pairs of distinct pairs of atoms that can be selected from the set of atoms with indexes between
      49             : 1 and 10.
      50             : 
      51             : ```plumed
      52             : w1: BRIDGE BRIDGING_ATOMS=100-200 GROUP=1-10 SWITCH={RATIONAL R_0=0.2}
      53             : PRINT ARG=w1 FILE=colvar
      54             : ```
      55             : 
      56             : In the above inputs the switching functions $s_A$ and $s_B$ are identical.  If you want to use two different
      57             : switching functions you would use an input like the one shown below:
      58             : 
      59             : ```plumed
      60             : w1: BRIDGE ...
      61             :   BRIDGING_ATOMS=100-200 GROUPA=1-10 GROUPB=11-20
      62             :   SWITCHA={RATIONAL R_0=0.2}
      63             :   SWITCHB={RATIONAL R_0=0.4}
      64             : ...
      65             : PRINT ARG=w1 FILE=colvar
      66             : ```
      67             : 
      68             : With this input an atom is calculated as bridging if it is (approximately) within 0.2 nm of one of the atoms in
      69             : GROUPA and within 0.4 nm of one of the atoms in GROUPB.
      70             : 
      71             : */
      72             : //+ENDPLUMEDOC
      73             : 
      74             : namespace PLMD {
      75             : namespace adjmat {
      76             : 
      77             : class Bridge : public ActionShortcut {
      78             : public:
      79             :   static void registerKeywords(Keywords& keys);
      80             :   explicit Bridge(const ActionOptions&);
      81             : };
      82             : 
      83             : PLUMED_REGISTER_ACTION(Bridge,"BRIDGE")
      84             : 
      85          12 : void Bridge::registerKeywords(Keywords& keys) {
      86          12 :   ActionShortcut::registerKeywords(keys);
      87          12 :   keys.add("atoms","GROUP","the atoms for which you would like to calculate the adjacency matrix");
      88          12 :   keys.add("atoms","GROUPA","when you are calculating the adjacency matrix between two sets of atoms this keyword is used to specify the atoms along with the keyword GROUPB");
      89          12 :   keys.add("atoms","GROUPB","when you are calculating the adjacency matrix between two sets of atoms this keyword is used to specify the atoms along with the keyword GROUPA");
      90          12 :   keys.add("atoms","BRIDGING_ATOMS","The list of atoms that can form the bridge between the two interesting parts "
      91             :            "of the structure.");
      92          12 :   keys.add("optional","SWITCH","The parameters of the two switching functions in the above formula");
      93          24 :   keys.linkActionInDocs("SWITCH","LESS_THAN");
      94          12 :   keys.add("optional","SWITCHA","The switching function on the distance between bridging atoms and the atoms in group A");
      95          24 :   keys.linkActionInDocs("SWITCHA","LESS_THAN");
      96          12 :   keys.add("optional","SWITCHB","The switching function on the distance between the bridging atoms and the atoms in group B");
      97          24 :   keys.linkActionInDocs("SWITCHB","LESS_THAN");
      98          12 :   keys.needsAction("BRIDGE_MATRIX");
      99          12 :   keys.needsAction("SUM");
     100          24 :   keys.setValueDescription("scalar","the number of bridging atoms between the two groups");
     101          12 : }
     102             : 
     103           8 : Bridge::Bridge(const ActionOptions& ao):
     104             :   Action(ao),
     105           8 :   ActionShortcut(ao) {
     106             :   // Need to read in switch
     107             :   std::string s_inp, sfinput;
     108          16 :   parse("SWITCH",sfinput);
     109           8 :   if( sfinput.length()>0 ) {
     110           8 :     s_inp += "SWITCH={" + sfinput +"} ";
     111             :   }
     112             :   std::string sfinputa;
     113          16 :   parse("SWITCHA",sfinputa);
     114           8 :   if( sfinputa.length()>0 ) {
     115           0 :     s_inp += "SWITCHA={" + sfinputa +"} ";
     116             :   }
     117             :   std::string sfinputb;
     118          16 :   parse("SWITCHB",sfinputb);
     119           8 :   if( sfinputb.length()>0 ) {
     120           0 :     s_inp += "SWITCHB={" + sfinputb +"} ";
     121             :   }
     122             :   // Create the matrix object
     123          16 :   readInputLine( getShortcutLabel() + "_mat: BRIDGE_MATRIX " + s_inp + convertInputLineToString() );
     124             :   // Add all the elements of the matrix together
     125          24 :   readInputLine( getShortcutLabel() + ": SUM ARG=" + getShortcutLabel() + "_mat PERIODIC=NO");
     126          16 : }
     127             : 
     128             : }
     129             : }

Generated by: LCOV version 1.16