LCOV - code coverage report
Current view: top level - crystallization - SimpleCubic.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 27 27 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 SIMPLECUBIC
      34             : /*
      35             : Calculate whether or not the coordination spheres of atoms are arranged as they would be in a simple
      36             : cubic structure.
      37             : 
      38             : We can measure how similar the environment around atom \f$i\f$ is to a simple cubic structure is by evaluating
      39             : the following quantity:
      40             : 
      41             : \f[
      42             : s_i = \frac{ \sum_{i \ne j} \sigma(r_{ij}) \left[ \frac{ x_{ij}^4 + y_{ij}^4 + z_{ij}^4 }{r_{ij}^4} \right] }{ \sum_{i \ne j} \sigma(r_{ij}) }
      43             : \f]
      44             : 
      45             : In this expression \f$x_{ij}\f$, \f$y_{ij}\f$ and \f$z_{ij}\f$ are the \f$x\f$, \f$y\f$ and \f$z\f$ components of the vector connecting atom \f$i\f$ to
      46             : atom \f$j\f$ and \f$r_{ij}\f$ is the magnitude of this vector.  \f$\sigma(r_{ij})\f$ is a \ref switchingfunction that acts on the distance between atom \f$i\f$ and atom \f$j\f$ and its inclusion in the numerator and the denominator of the above expression as well as the fact that we are summing
      47             : over all of the other atoms in the system ensures that we are calculating an average
      48             : of the function of \f$x_{ij}\f$, \f$y_{ij}\f$ and \f$z_{ij}\f$ for the atoms in the first coordination sphere around atom \f$i\f$.
      49             : This quantity is once again a multicolvar so you can compute it for multiple atoms using a single PLUMED action and then compute
      50             : the average value for the atoms in your system, the number of atoms that have an \f$s_i\f$ value that is more that some target and
      51             : so on.  Notice also that you can rotate the reference frame if you are using a non-standard unit cell.
      52             : 
      53             : 
      54             : \par Examples
      55             : 
      56             : The following input tells plumed to calculate the simple cubic parameter for the atoms 1-100 with themselves.
      57             : The mean value is then calculated.
      58             : \plumedfile
      59             : SIMPLECUBIC SPECIES=1-100 R_0=1.0 MEAN
      60             : \endplumedfile
      61             : 
      62             : The following input tells plumed to look at the ways atoms 1-100 are within 3.0 are arranged about atoms
      63             : from 101-110.  The number of simple cubic parameters that are greater than 0.8 is then output
      64             : \plumedfile
      65             : SIMPLECUBIC SPECIESA=101-110 SPECIESB=1-100 R_0=3.0 MORE_THAN={RATIONAL R_0=0.8 NN=6 MM=12 D_0=0}
      66             : \endplumedfile
      67             : 
      68             : */
      69             : //+ENDPLUMEDOC
      70             : 
      71             : 
      72           2 : class SimpleCubic : public CubicHarmonicBase {
      73             : public:
      74             :   static void registerKeywords( Keywords& keys );
      75             :   explicit SimpleCubic(const ActionOptions&);
      76             :   double calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const ;
      77             : };
      78             : 
      79        6453 : PLUMED_REGISTER_ACTION(SimpleCubic,"SIMPLECUBIC")
      80             : 
      81           2 : void SimpleCubic::registerKeywords( Keywords& keys ) {
      82           2 :   CubicHarmonicBase::registerKeywords( keys );
      83           2 : }
      84             : 
      85           1 : SimpleCubic::SimpleCubic(const ActionOptions&ao):
      86             :   Action(ao),
      87           1 :   CubicHarmonicBase(ao)
      88             : {
      89           1 :   checkRead();
      90           1 : }
      91             : 
      92        4032 : double SimpleCubic::calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const {
      93        4032 :   double x2 = distance[0]*distance[0];
      94        4032 :   double x3 = distance[0]*x2;
      95        4032 :   double x4 = distance[0]*x3;
      96             : 
      97        4032 :   double y2 = distance[1]*distance[1];
      98        4032 :   double y3 = distance[1]*y2;
      99        4032 :   double y4 = distance[1]*y3;
     100             : 
     101        4032 :   double z2 = distance[2]*distance[2];
     102        4032 :   double z3 = distance[2]*z2;
     103        4032 :   double z4 = distance[2]*z3;
     104             : 
     105        4032 :   double r4 = pow( d2, 2 );
     106        4032 :   double tmp = ( x4 + y4 + z4 ) / r4;
     107             : 
     108        4032 :   double t1=(x2+y2+z2), t2=t1*t1, t3=(x4+y4+z4)/(t1*t2);
     109        4032 :   myder[0] = 4*x3/t2-4*distance[0]*t3;
     110        4032 :   myder[1] = 4*y3/t2-4*distance[1]*t3;
     111        4032 :   myder[2] = 4*z3/t2-4*distance[2]*t3;
     112        4032 :   return tmp;
     113             : }
     114             : 
     115             : }
     116        4839 : }
     117             : 

Generated by: LCOV version 1.13