LCOV - code coverage report
Current view: top level - multicolvar - VolumeInSphere.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 29 100.0 %
Date: 2018-12-19 07:49:13 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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/ActionRegister.h"
      23             : #include "tools/Pbc.h"
      24             : #include "tools/SwitchingFunction.h"
      25             : #include "ActionVolume.h"
      26             : 
      27             : //+PLUMEDOC VOLUMES INSPHERE
      28             : /*
      29             : This quantity can be used to calculate functions of the distribution of collective
      30             : variables for the atoms that lie in a particular, user-specified part of of the cell.
      31             : 
      32             : Each of the base quantities calculated by a multicolvar can can be assigned to a particular point in three
      33             : dimensional space. For example, if we have the coordination numbers for all the atoms in the
      34             : system each coordination number can be assumed to lie on the position of the central atom.
      35             : Because each base quantity can be assigned to a particular point in space we can calculate functions of the
      36             : distribution of base quantities in a particular part of the box by using:
      37             : 
      38             : \f[
      39             : \overline{s}_{\tau} = \frac{ \sum_i f(s_i) w(x_i,y_i,z_i) }{ \sum_i w(x_i,y_i,z_i) }
      40             : \f]
      41             : 
      42             : where the sum is over the collective variables, \f$s_i\f$, each of which can be thought to be at \f$ (x_i,y_i,z_i)\f$.
      43             : The function \f$ w(x_i,y_i,z_i) \f$ measures whether or not the system is in the subregion of interest. It
      44             : is equal to:
      45             : 
      46             : \f[
      47             : w(x_i,y_i,z_i) =
      48             : \f]
      49             : 
      50             : where \f$\sigma\f$ is a \ref switchingfunction.
      51             : The function \f$(s_i)\f$ can be any of the usual LESS_THAN, MORE_THAN, WITHIN etc that are used in all other multicolvars.
      52             : 
      53             : When INCYLINDER is used with the \ref DENSITY action the number of atoms in the specified region is calculated
      54             : 
      55             : \par Examples
      56             : 
      57             : The input below can be use to calculate the average coordination numbers for those atoms that are within a sphere
      58             : of radius 1.5 nm that is centered on the position of atom 101.
      59             : 
      60             : \verbatim
      61             : c1: COORDINATIONNUMBER SPECIES=1-100 SWITCH={RATIONAL R_0=0.1}
      62             : d2: INSPHERE ATOM=101 DATA=d1 RADIUS={TANH R_0=1.5} SIGMA=0.1 LOWER=-0.1 UPPER=0.1 MEAN
      63             : PRINT ARG=d2.* FILE=colvar
      64             : \endverbatim
      65             : 
      66             : */
      67             : //+ENDPLUMEDOC
      68             : 
      69             : namespace PLMD {
      70             : namespace multicolvar {
      71             : 
      72           4 : class VolumeInSphere : public ActionVolume {
      73             : private:
      74             :   Vector origin;
      75             :   SwitchingFunction switchingFunction;
      76             : public:
      77             :   static void registerKeywords( Keywords& keys );
      78             :   explicit VolumeInSphere(const ActionOptions& ao);
      79             :   void setupRegions();
      80             :   double calculateNumberInside( const Vector& cpos, Vector& derivatives, Tensor& vir, std::vector<Vector>& refders ) const ;
      81             : };
      82             : 
      83        2525 : PLUMED_REGISTER_ACTION(VolumeInSphere,"INSPHERE")
      84             : 
      85           3 : void VolumeInSphere::registerKeywords( Keywords& keys ) {
      86           3 :   ActionVolume::registerKeywords( keys );
      87           3 :   keys.add("atoms","ATOM","the atom whose vicinity we are interested in examining");
      88           3 :   keys.add("compulsory","RADIUS","the switching function that tells us the extent of the sphereical region of interest");
      89           3 :   keys.remove("SIGMA");
      90           3 : }
      91             : 
      92           2 : VolumeInSphere::VolumeInSphere(const ActionOptions& ao):
      93             :   Action(ao),
      94           2 :   ActionVolume(ao)
      95             : {
      96           2 :   std::vector<AtomNumber> atom;
      97           2 :   parseAtomList("ATOM",atom);
      98           2 :   if( atom.size()!=1 ) error("should only be one atom specified");
      99           2 :   log.printf("  center of sphere is at position of atom : %d\n",atom[0].serial() );
     100             : 
     101           4 :   std::string sw, errors; parse("RADIUS",sw);
     102           2 :   if(sw.length()==0) error("missing RADIUS keyword");
     103           2 :   switchingFunction.set(sw,errors);
     104           2 :   if( errors.length()!=0 ) error("problem reading RADIUS keyword : " + errors );
     105           2 :   log.printf("  radius of sphere is given by %s \n", ( switchingFunction.description() ).c_str() );
     106             : 
     107           4 :   checkRead(); requestAtoms(atom);
     108           2 : }
     109             : 
     110          40 : void VolumeInSphere::setupRegions() { }
     111             : 
     112       68470 : double VolumeInSphere::calculateNumberInside( const Vector& cpos, Vector& derivatives, Tensor& vir, std::vector<Vector>& refders ) const {
     113             :   // Calculate position of atom wrt to origin
     114       68470 :   Vector fpos=pbcDistance( getPosition(0), cpos );
     115       68473 :   double dfunc, value = switchingFunction.calculateSqr( fpos.modulo2(), dfunc );
     116       68473 :   derivatives.zero(); derivatives = dfunc*fpos; refders[0] = -derivatives;
     117             :   // Add a virial contribution
     118       68473 :   vir -= Tensor(fpos,derivatives);
     119       68471 :   return value;
     120             : }
     121             : 
     122             : }
     123        2523 : }

Generated by: LCOV version 1.13