LCOV - code coverage report
Current view: top level - multicolvar - XAngle.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 32 93.8 %
Date: 2025-04-08 21:11:17 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             : The following input tells plumed to calculate the angles between the x-axis and the vector connecting atom 3 to atom 5 and between the x-axis
      31             : and the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then output
      32             : 
      33             : ```plumed
      34             : d1: XANGLES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1}
      35             : PRINT ARG=d1.min FILE=colvar
      36             : ```
      37             : 
      38             : Notice that this command is a shortcut. You can thus learn more about how to use PLUMED by examining the expanded version of the input above.
      39             : 
      40             : */
      41             : //+ENDPLUMEDOC
      42             : 
      43             : //+PLUMEDOC COLVAR YANGLES
      44             : /*
      45             : Calculate the angle between an arbitrary vector and the positive y direction
      46             : 
      47             : The following input tells plumed to calculate the angles between the y-axis and the vector connecting atom 3 to atom 5 and between the y-axis
      48             : and the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then output
      49             : 
      50             : ```plumed
      51             : d1: YANGLES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1}
      52             : PRINT ARG=d1.min FILE=colvar
      53             : ```
      54             : 
      55             : Notice that this command is a shortcut. You can thus learn more about how to use PLUMED by examining the expanded version of the input above.
      56             : 
      57             : */
      58             : //+ENDPLUMEDOC
      59             : 
      60             : //+PLUMEDOC COLVAR ZANGLES
      61             : /*
      62             : Calculate the angle between an arbitrary vector and the positive z direction
      63             : 
      64             : The following input tells plumed to calculate the angles between the z-axis and the vector connecting atom 3 to atom 5 and between the z-axis
      65             : and the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then output
      66             : 
      67             : ```plumed
      68             : d1: ZANGLES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1}
      69             : PRINT ARG=d1.min FILE=colvar
      70             : ```
      71             : 
      72             : Notice that this command is a shortcut. You can thus learn more about how to use PLUMED by examining the expanded version of the input above.
      73             : 
      74             : */
      75             : //+ENDPLUMEDOC
      76             : 
      77             : 
      78             : namespace PLMD {
      79             : namespace multicolvar {
      80             : 
      81             : class XAngle : public ActionShortcut {
      82             : public:
      83             :   static void registerKeywords(Keywords& keys);
      84             :   explicit XAngle(const ActionOptions&);
      85             : };
      86             : 
      87             : PLUMED_REGISTER_ACTION(XAngle,"XANGLES")
      88             : PLUMED_REGISTER_ACTION(XAngle,"YANGLES")
      89             : PLUMED_REGISTER_ACTION(XAngle,"ZANGLES")
      90             : 
      91           9 : void XAngle::registerKeywords(Keywords& keys) {
      92           9 :   ActionShortcut::registerKeywords( keys );
      93           9 :   keys.add("numbered","ATOMS","the pairs of atoms that you would like to calculate the angles for");
      94          18 :   keys.reset_style("ATOMS","atoms");
      95           9 :   MultiColvarShortcuts::shortcutKeywords( keys );
      96           9 :   keys.needsAction("DISTANCE");
      97           9 :   keys.needsAction("COMBINE");
      98           9 :   keys.needsAction("CUSTOM");
      99           9 : }
     100             : 
     101           1 : XAngle::XAngle(const ActionOptions& ao):
     102             :   Action(ao),
     103           1 :   ActionShortcut(ao) {
     104             :   // Create distances
     105           1 :   std::string dline = getShortcutLabel() + "_dists: DISTANCE COMPONENTS";
     106           1 :   for(unsigned i=1;; ++i) {
     107             :     std::string atstring;
     108           6 :     parseNumbered("ATOMS",i,atstring);
     109           3 :     if( atstring.length()==0 ) {
     110             :       break;
     111             :     }
     112             :     std::string num;
     113           2 :     Tools::convert( i, num );
     114           4 :     dline += " ATOMS" + num + "=" + atstring;
     115           2 :   }
     116           1 :   readInputLine( dline );
     117             :   // Normalize the vectors
     118           2 :   readInputLine( getShortcutLabel() + "_norm2: COMBINE ARG=" + getShortcutLabel() + "_dists.x" + "," + getShortcutLabel() + "_dists.y," + getShortcutLabel() + "_dists.z POWERS=2,2,2 PERIODIC=NO");
     119           2 :   readInputLine( getShortcutLabel() + "_norm: CUSTOM ARG=" + getShortcutLabel() + "_norm2 FUNC=sqrt(x) PERIODIC=NO");
     120           2 :   readInputLine( getShortcutLabel() + "_norm_x: CUSTOM ARG=" + getShortcutLabel() + "_dists.x," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     121           2 :   readInputLine( getShortcutLabel() + "_norm_y: CUSTOM ARG=" + getShortcutLabel() + "_dists.y," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     122           2 :   readInputLine( getShortcutLabel() + "_norm_z: CUSTOM ARG=" + getShortcutLabel() + "_dists.z," + getShortcutLabel() + "_norm FUNC=x/y PERIODIC=NO");
     123             :   // Now compute the angles with matheval
     124           1 :   if( getName()=="XANGLES" ) {
     125           2 :     readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_x");
     126             :   }
     127           1 :   if( getName()=="YANGLES" ) {
     128           0 :     readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_y");
     129             :   }
     130           1 :   if( getName()=="ZANGLES" ) {
     131           0 :     readInputLine( getShortcutLabel() + "_ang: CUSTOM FUNC=acos(x) PERIODIC=NO ARG=" + getShortcutLabel() + "_norm_z");
     132             :   }
     133             :   // Add shortcuts to label
     134           2 :   MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_ang", "", this );
     135           1 : }
     136             : 
     137             : }
     138             : }

Generated by: LCOV version 1.16