LCOV - code coverage report
Current view: top level - multicolvar - XDistances.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 16 38 42.1 %
Date: 2020-11-18 11:20:57 Functions: 9 18 50.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2019 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 "MultiColvarBase.h"
      23             : #include "AtomValuePack.h"
      24             : #include "core/ActionRegister.h"
      25             : 
      26             : #include <string>
      27             : #include <cmath>
      28             : 
      29             : using namespace std;
      30             : 
      31             : namespace PLMD {
      32             : namespace multicolvar {
      33             : 
      34             : //+PLUMEDOC MCOLVAR XDISTANCES
      35             : /*
      36             : Calculate the x components of the vectors connecting one or many pairs of atoms.
      37             : You can then calculate functions of the distribution of
      38             : values such as the minimum, the number less than a certain quantity and so on.
      39             : 
      40             : \par Examples
      41             : 
      42             : The following input tells plumed to calculate the x-component of the vector connecting atom 3 to atom 5 and
      43             : the x-component of the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then
      44             : printed
      45             : \plumedfile
      46             : XDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
      47             : PRINT ARG=d1.min
      48             : \endplumedfile
      49             : (See also \ref PRINT).
      50             : 
      51             : 
      52             : The following input tells plumed to calculate the x-component of the vector connecting atom 3 to atom 5 and
      53             : the x-component of the vector connecting atom 1 to atom 2.  The number of values that are
      54             : less than 0.1nm is then printed to a file.
      55             : \plumedfile
      56             : XDISTANCES ATOMS1=3,5 ATOMS2=1,2 LABEL=d1 LESS_THAN={RATIONAL R_0=0.1}
      57             : PRINT ARG=d1.lt0.1
      58             : \endplumedfile
      59             : (See also \ref PRINT \ref switchingfunction).
      60             : 
      61             : The following input tells plumed to calculate the x-components of all the distinct vectors that can be created
      62             : between atoms 1, 2 and 3 (i.e. the vectors between atoms 1 and 2, atoms 1 and 3 and atoms 2 and 3).
      63             : The average of these quantities is then calculated.
      64             : \plumedfile
      65             : XDISTANCES GROUP=1-3 AVERAGE LABEL=d1
      66             : PRINT ARG=d1.average
      67             : \endplumedfile
      68             : (See also \ref PRINT)
      69             : 
      70             : The following input tells plumed to calculate all the vectors connecting the the atoms in GROUPA to the atoms in GROUPB.
      71             : In other words the vector between atoms 1 and 2 and the vector between atoms 1 and 3.  The number of values
      72             : more than 0.1 is then printed to a file.
      73             : \plumedfile
      74             : XDISTANCES GROUPA=1 GROUPB=2,3 MORE_THAN={RATIONAL R_0=0.1}
      75             : PRINT ARG=d1.gt0.1
      76             : \endplumedfile
      77             : (See also \ref PRINT \ref switchingfunction)
      78             : */
      79             : //+ENDPLUMEDOC
      80             : 
      81             : //+PLUMEDOC MCOLVAR YDISTANCES
      82             : /*
      83             : Calculate the y components of the vectors connecting one or many pairs of atoms.
      84             : You can then calculate functions of the distribution of
      85             : values such as the minimum, the number less than a certain quantity and so on.
      86             : 
      87             : \par Examples
      88             : 
      89             : The following input tells plumed to calculate the y-component of the vector connecting atom 3 to atom 5 and
      90             : the y-component of the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then
      91             : printed
      92             : \plumedfile
      93             : YDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
      94             : PRINT ARG=d1.min
      95             : \endplumedfile
      96             : (See also \ref PRINT).
      97             : 
      98             : 
      99             : The following input tells plumed to calculate the y-component of the vector connecting atom 3 to atom 5 and
     100             : the y-component of the vector connecting atom 1 to atom 2.  The number of values that are
     101             : less than 0.1nm is then printed to a file.
     102             : \plumedfile
     103             : YDISTANCES ATOMS1=3,5 ATOMS2=1,2 LABEL=d1 LESS_THAN={RATIONAL R_0=0.1}
     104             : PRINT ARG=d1.lt0.1
     105             : \endplumedfile
     106             : (See also \ref PRINT \ref switchingfunction).
     107             : 
     108             : The following input tells plumed to calculate the y-components of all the distinct vectors that can be created
     109             : between atoms 1, 2 and 3 (i.e. the vectors between atoms 1 and 2, atoms 1 and 3 and atoms 2 and 3).
     110             : The average of these quantities is then calculated.
     111             : \plumedfile
     112             : YDISTANCES GROUP=1-3 AVERAGE LABEL=d1
     113             : PRINT ARG=d1.average
     114             : \endplumedfile
     115             : (See also \ref PRINT)
     116             : 
     117             : The following input tells plumed to calculate all the vectors connecting the the atoms in GROUPA to the atoms in GROUPB.
     118             : In other words the vector between atoms 1 and 2 and the vector between atoms 1 and 3.  The number of values
     119             : more than 0.1 is then printed to a file.
     120             : \plumedfile
     121             : YDISTANCES GROUPA=1 GROUPB=2,3 MORE_THAN={RATIONAL R_0=0.1}
     122             : PRINT ARG=d1.gt0.1
     123             : \endplumedfile
     124             : (See also \ref PRINT \ref switchingfunction)
     125             : 
     126             : */
     127             : //+ENDPLUMEDOC
     128             : 
     129             : //+PLUMEDOC MCOLVAR ZDISTANCES
     130             : /*
     131             : Calculate the z components of the vectors connecting one or many pairs of atoms.
     132             : You can then calculate functions of the distribution of
     133             : values such as the minimum, the number less than a certain quantity and so on.
     134             : 
     135             : \par Examples
     136             : 
     137             : The following input tells plumed to calculate the z-component of the vector connecting atom 3 to atom 5 and
     138             : the z-component of the vector connecting atom 1 to atom 2.  The minimum of these two quantities is then
     139             : printed
     140             : \plumedfile
     141             : ZDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
     142             : PRINT ARG=d1.min
     143             : \endplumedfile
     144             : (See also \ref PRINT).
     145             : 
     146             : 
     147             : The following input tells plumed to calculate the z-component of the vector connecting atom 3 to atom 5 and
     148             : the z-component of the vector connecting atom 1 to atom 2.  The number of values that are
     149             : less than 0.1nm is then printed to a file.
     150             : \plumedfile
     151             : ZDISTANCES ATOMS1=3,5 ATOMS2=1,2 LABEL=d1 LESS_THAN={RATIONAL R_0=0.1}
     152             : PRINT ARG=d1.lt0.1
     153             : \endplumedfile
     154             : (See also \ref PRINT \ref switchingfunction).
     155             : 
     156             : The following input tells plumed to calculate the z-components of all the distinct vectors that can be created
     157             : between atoms 1, 2 and 3 (i.e. the vectors between atoms 1 and 2, atoms 1 and 3 and atoms 2 and 3).
     158             : The average of these quantities is then calculated.
     159             : \plumedfile
     160             : ZDISTANCES GROUP=1-3 AVERAGE LABEL=d1
     161             : PRINT ARG=d1.average
     162             : \endplumedfile
     163             : (See also \ref PRINT)
     164             : 
     165             : The following input tells plumed to calculate all the vectors connecting the the atoms in GROUPA to the atoms in GROUPB.
     166             : In other words the vector between atoms 1 and 2 and the vector between atoms 1 and 3.  The number of values
     167             : more than 0.1 is then printed to a file.
     168             : \plumedfile
     169             : ZDISTANCES GROUPA=1 GROUPB=2,3 MORE_THAN={RATIONAL R_0=0.1}
     170             : PRINT ARG=d1.gt0.1
     171             : \endplumedfile
     172             : (See also \ref PRINT \ref switchingfunction)
     173             : 
     174             : */
     175             : //+ENDPLUMEDOC
     176             : 
     177             : 
     178           0 : class XDistances : public MultiColvarBase {
     179             : private:
     180             :   unsigned myc;
     181             : public:
     182             :   static void registerKeywords( Keywords& keys );
     183             :   explicit XDistances(const ActionOptions&);
     184             : // active methods:
     185             :   virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
     186             : /// Returns the number of coordinates of the field
     187           0 :   bool isPeriodic() { return false; }
     188             : };
     189             : 
     190        6452 : PLUMED_REGISTER_ACTION(XDistances,"XDISTANCES")
     191        6452 : PLUMED_REGISTER_ACTION(XDistances,"YDISTANCES")
     192        6452 : PLUMED_REGISTER_ACTION(XDistances,"ZDISTANCES")
     193             : 
     194           3 : void XDistances::registerKeywords( Keywords& keys ) {
     195           3 :   MultiColvarBase::registerKeywords( keys );
     196           9 :   keys.use("MAX"); keys.use("ALT_MIN");
     197          12 :   keys.use("MEAN"); keys.use("MIN"); keys.use("LESS_THAN");
     198           9 :   keys.use("LOWEST"); keys.use("HIGHEST");
     199          15 :   keys.use("MORE_THAN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
     200          12 :   keys.add("numbered","ATOMS","the atoms involved in each of the distances you wish to calculate. "
     201             :            "Keywords like ATOMS1, ATOMS2, ATOMS3,... should be listed and one distance will be "
     202             :            "calculated for each ATOM keyword you specify (all ATOM keywords should "
     203             :            "specify the indices of two atoms).  The eventual number of quantities calculated by this "
     204             :            "action will depend on what functions of the distribution you choose to calculate.");
     205           9 :   keys.reset_style("ATOMS","atoms");
     206          12 :   keys.add("atoms-1","GROUP","Calculate the distance between each distinct pair of atoms in the group");
     207          12 :   keys.add("atoms-2","GROUPA","Calculate the distances between all the atoms in GROUPA and all "
     208             :            "the atoms in GROUPB. This must be used in conjuction with GROUPB.");
     209          12 :   keys.add("atoms-2","GROUPB","Calculate the distances between all the atoms in GROUPA and all the atoms "
     210             :            "in GROUPB. This must be used in conjuction with GROUPA.");
     211           3 : }
     212             : 
     213           0 : XDistances::XDistances(const ActionOptions&ao):
     214             :   Action(ao),
     215           0 :   MultiColvarBase(ao)
     216             : {
     217           0 :   if( getName().find("X")!=std::string::npos) myc=0;
     218           0 :   else if( getName().find("Y")!=std::string::npos) myc=1;
     219           0 :   else if( getName().find("Z")!=std::string::npos) myc=2;
     220           0 :   else plumed_error();
     221             : 
     222             :   // Read in the atoms
     223             :   std::vector<AtomNumber> all_atoms;
     224           0 :   readTwoGroups( "GROUP", "GROUPA", "GROUPB", all_atoms );
     225           0 :   if( atom_lab.size()==0 ) readAtomsLikeKeyword( "ATOMS", 2, all_atoms );
     226           0 :   setupMultiColvarBase( all_atoms );
     227             :   // And check everything has been read in correctly
     228           0 :   checkRead();
     229           0 : }
     230             : 
     231           0 : double XDistances::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
     232           0 :   Vector distance;
     233           0 :   distance=getSeparation( myatoms.getPosition(0), myatoms.getPosition(1) );
     234           0 :   const double value=distance[myc];
     235             : 
     236           0 :   Vector myvec; myvec.zero();
     237             :   // And finish the calculation
     238           0 :   myvec[myc]=+1; addAtomDerivatives( 1, 1, myvec, myatoms );
     239           0 :   myvec[myc]=-1; addAtomDerivatives( 1, 0, myvec, myatoms );
     240           0 :   myatoms.addBoxDerivatives( 1, Tensor(distance,myvec) );
     241           0 :   return value;
     242             : }
     243             : 
     244             : }
     245        4839 : }
     246             : 

Generated by: LCOV version 1.13