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

Generated by: LCOV version 1.16