LCOV - code coverage report
Current view: top level - crystallization - Tetrahedral.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 25 25 100.0 %
Date: 2020-11-18 11:20:57 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-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 "CubicHarmonicBase.h"
      23             : #include "core/ActionRegister.h"
      24             : 
      25             : #include <string>
      26             : #include <cmath>
      27             : 
      28             : using namespace std;
      29             : 
      30             : namespace PLMD {
      31             : namespace crystallization {
      32             : 
      33             : //+PLUMEDOC MCOLVAR TETRAHEDRAL
      34             : /*
      35             : Calculate the degree to which the environment about ions has a tetrahedral order.
      36             : 
      37             : We can measure the degree to which the first coordination shell around any atom, \f$i\f$ is
      38             : tetrahedrally ordered using the following function.
      39             : 
      40             : \f[
      41             :  s(i) = \frac{1}{\sum_j \sigma( r_{ij} )} \sum_j \sigma( r_{ij} )\left[ \frac{(x_{ij} + y_{ij} + z_{ij})^3}{r_{ij}^3} +
      42             :                                                                         \frac{(x_{ij} - y_{ij} - z_{ij})^3}{r_{ij}^3} +
      43             :                                                                         \frac{(-x_{ij} + y_{ij} - z_{ij})^3}{r_{ij}^3} +
      44             :                                                                         \frac{(-x_{ij} - y_{ij} + z_{ij})^3}{r_{ij}^3} \right]
      45             : \f]
      46             : 
      47             : Here \f$r_{ij}\f$ is the magnitude fo the vector connecting atom \f$i\f$ to atom \f$j\f$ and \f$x_{ij}\f$, \f$y_{ij}\f$ and \f$z_{ij}\f$
      48             : are its three components.  The function  \f$\sigma( r_{ij} )\f$ is a \ref switchingfunction that acts on the distance between
      49             : atoms \f$i\f$ and \f$j\f$.  The parameters of this function should be set so that the function is equal to one
      50             : when atom \f$j\f$ is in the first coordination sphere of atom \f$i\f$ and is zero otherwise.
      51             : 
      52             : \par Examples
      53             : 
      54             : The following command calculates the average value of the tetrahedrality parameter for a set of 64 atoms all of the same type
      55             : and outputs this quantity to a file called colvar.
      56             : 
      57             : \plumedfile
      58             : tt: TETRAHEDRAL SPECIES=1-64 SWITCH={RATIONAL D_0=1.3 R_0=0.2} MEAN
      59             : PRINT ARG=tt.mean FILE=colvar
      60             : \endplumedfile
      61             : 
      62             : The following command calculates the number of tetrahedrality parameters that are greater than 0.8 in a set of 10 atoms.
      63             : In this calculation it is assumed that there are two atom types A and B and that the first coordination sphere of the
      64             : 10 atoms of type A contains atoms of type B.  The formula above is thus calculated for ten different A atoms and within
      65             : it the sum over \f$j\f$ runs over 40 atoms of type B that could be in the first coordination sphere.
      66             : 
      67             : \plumedfile
      68             : tt: TETRAHEDRAL SPECIESA=1-10 SPECIESB=11-40 SWITCH={RATIONAL D_0=1.3 R_0=0.2} MORE_THAN={RATIONAL R_0=0.8}
      69             : PRINT ARG=tt.* FILE=colvar
      70             : \endplumedfile
      71             : 
      72             : */
      73             : //+ENDPLUMEDOC
      74             : 
      75             : 
      76           2 : class Tetrahedral : public CubicHarmonicBase {
      77             : public:
      78             :   static void registerKeywords( Keywords& keys );
      79             :   explicit Tetrahedral(const ActionOptions&);
      80             :   double calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const ;
      81             : };
      82             : 
      83        6453 : PLUMED_REGISTER_ACTION(Tetrahedral,"TETRAHEDRAL")
      84             : 
      85           2 : void Tetrahedral::registerKeywords( Keywords& keys ) {
      86           2 :   CubicHarmonicBase::registerKeywords( keys );
      87           2 : }
      88             : 
      89           1 : Tetrahedral::Tetrahedral(const ActionOptions&ao):
      90             :   Action(ao),
      91           1 :   CubicHarmonicBase(ao)
      92             : {
      93           1 :   checkRead();
      94           1 : }
      95             : 
      96        4032 : double Tetrahedral::calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const {
      97        4032 :   double sp1 = +distance[0]+distance[1]+distance[2];
      98        4032 :   double sp2 = +distance[0]-distance[1]-distance[2];
      99        4032 :   double sp3 = -distance[0]+distance[1]-distance[2];
     100        4032 :   double sp4 = -distance[0]-distance[1]+distance[2];
     101             : 
     102             :   double sp1c = pow( sp1, 3 );
     103             :   double sp2c = pow( sp2, 3 );
     104             :   double sp3c = pow( sp3, 3 );
     105             :   double sp4c = pow( sp4, 3 );
     106             : 
     107        4032 :   double d1 = distance.modulo();
     108             :   double r3 = pow( d1, 3 );
     109             :   double r5 = pow( d1, 5 );
     110             : 
     111        4032 :   double tmp = sp1c/r3 + sp2c/r3 + sp3c/r3 + sp4c/r3;
     112             : 
     113        4032 :   double t1=(3*sp1c)/r5; double tt1=((3*sp1*sp1)/r3);
     114        4032 :   double t2=(3*sp2c)/r5; double tt2=((3*sp2*sp2)/r3);
     115        4032 :   double t3=(3*sp3c)/r5; double tt3=((3*sp3*sp3)/r3);
     116        4032 :   double t4=(3*sp4c)/r5; double tt4=((3*sp4*sp4)/r3);
     117             : 
     118        4032 :   myder[0] = (tt1-(distance[0]*t1))  + (tt2-(distance[0]*t2))  + (-tt3-(distance[0]*t3))  + (-tt4-(distance[0]*t4));
     119        4032 :   myder[1] = (tt1-(distance[1]*t1))  + (-tt2-(distance[1]*t2))  + (tt3-(distance[1]*t3))  + (-tt4-(distance[1]*t4));
     120        4032 :   myder[2] = (tt1-(distance[2]*t1))  + (-tt2-(distance[2]*t2))  + (-tt3-(distance[2]*t3))  + (tt4-(distance[2]*t4));
     121             : 
     122        4032 :   return tmp;
     123             : }
     124             : 
     125             : }
     126        4839 : }
     127             : 

Generated by: LCOV version 1.13