LCOV - code coverage report
Current view: top level - multicolvar - XDistances.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 14 36 38.9 %
Date: 2018-12-19 07:49:13 Functions: 9 18 50.0 %

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

Generated by: LCOV version 1.13