LCOV - code coverage report
Current view: top level - multicolvar - XAngle.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 26 26 100.0 %
Date: 2024-10-18 13:59:31 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2023 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 COLVAR XANGLES
      27             : /*
      28             : Calculate the angle between an arbitrary vector and the positive x direction
      29             : 
      30             : \par Examples
      31             : 
      32             : */
      33             : //+ENDPLUMEDOC
      34             : 
      35             : //+PLUMEDOC COLVAR YANGLES
      36             : /*
      37             : Calculate the angle between an arbitrary vector and the positive y direction
      38             : 
      39             : \par Examples
      40             : 
      41             : */
      42             : //+ENDPLUMEDOC
      43             : 
      44             : //+PLUMEDOC COLVAR ZANGLES
      45             : /*
      46             : Calculate the angle between an arbitrary vector and the positive z direction
      47             : 
      48             : \par Examples
      49             : 
      50             : */
      51             : //+ENDPLUMEDOC
      52             : 
      53             : 
      54             : namespace PLMD {
      55             : namespace multicolvar {
      56             : 
      57             : class XAngle : public ActionShortcut {
      58             : public:
      59             :   static void registerKeywords(Keywords& keys);
      60             :   explicit XAngle(const ActionOptions&);
      61             : };
      62             : 
      63             : PLUMED_REGISTER_ACTION(XAngle,"XANGLES")
      64             : PLUMED_REGISTER_ACTION(XAngle,"YANGLES")
      65             : PLUMED_REGISTER_ACTION(XAngle,"ZANGLES")
      66             : 
      67           9 : void XAngle::registerKeywords(Keywords& keys) {
      68           9 :   ActionShortcut::registerKeywords( keys );
      69          18 :   keys.add("numbered","ATOMS","the pairs of atoms that you would like to calculate the angles for");
      70          18 :   keys.reset_style("ATOMS","atoms"); MultiColvarShortcuts::shortcutKeywords( keys );
      71          27 :   keys.needsAction("DISTANCE"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM");
      72           9 : }
      73             : 
      74           1 : XAngle::XAngle(const ActionOptions& ao):
      75             :   Action(ao),
      76           1 :   ActionShortcut(ao)
      77             : {
      78             :   // Create distances
      79           1 :   std::string dline = getShortcutLabel() + "_dists: DISTANCE COMPONENTS";
      80           1 :   for(unsigned i=1;; ++i) {
      81           6 :     std::string atstring; parseNumbered("ATOMS",i,atstring);
      82           3 :     if( atstring.length()==0 ) break;
      83           2 :     std::string num; Tools::convert( i, num );
      84           4 :     dline += " ATOMS" + num + "=" + atstring;
      85           2 :   }
      86           1 :   readInputLine( dline );
      87             :   // Normalize the vectors
      88           2 :   readInputLine( getShortcutLabel() + "_norm2: COMBINE ARG=" + getShortcutLabel() + "_dists.x" + "," + getShortcutLabel() + "_dists.y," + getShortcutLabel() + "_dists.z POWERS=2,2,2 PERIODIC=NO");
      89           2 :   readInputLine( getShortcutLabel() + "_norm: CUSTOM ARG=" + getShortcutLabel() + "_norm2 FUNC=sqrt(x) PERIODIC=NO");
      90           2 :   readInputLine( getShortcutLabel() + "_norm_x: CUSTOM ARG=" + getShortcutLabel() + "_dists.x," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
      91           2 :   readInputLine( getShortcutLabel() + "_norm_y: CUSTOM ARG=" + getShortcutLabel() + "_dists.y," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
      92           2 :   readInputLine( getShortcutLabel() + "_norm_z: CUSTOM ARG=" + getShortcutLabel() + "_dists.z," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
      93             :   // Now compute the angles with matheval
      94           2 :   if( getName()=="XANGLES" ) readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_x");
      95           1 :   if( getName()=="YANGLES" ) readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_y");
      96           1 :   if( getName()=="ZANGLES" ) readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_z");
      97             :   // Add shortcuts to label
      98           2 :   MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_ang", "", this );
      99           1 : }
     100             : 
     101             : }
     102             : }

Generated by: LCOV version 1.16