LCOV - code coverage report
Current view: top level - crystallization - SimpleCubic.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 25 25 100.0 %
Date: 2024-10-11 08:09:47 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-2023 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 cubic structure.
      36             : 
      37             : We can measure how similar the environment around atom \f$i\f$ is to a simple cubic structure is by evaluating
      38             : the following quantity:
      39             : 
      40             : \f[
      41             : 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}) }
      42             : \f]
      43             : 
      44             : 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
      45             : 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
      46             : over all of the other atoms in the system ensures that we are calculating an average
      47             : 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$.
      48             : This quantity is once again a multicolvar so you can compute it for multiple atoms using a single PLUMED action and then compute
      49             : 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
      50             : so on.  Notice also that you can rotate the reference frame if you are using a non-standard unit cell.
      51             : 
      52             : 
      53             : \par Examples
      54             : 
      55             : The following input tells plumed to calculate the simple cubic parameter for the atoms 1-100 with themselves.
      56             : The mean value is then calculated.
      57             : \plumedfile
      58             : SIMPLECUBIC SPECIES=1-100 R_0=1.0 MEAN
      59             : \endplumedfile
      60             : 
      61             : The following input tells plumed to look at the ways atoms 1-100 are within 3.0 are arranged about atoms
      62             : from 101-110.  The number of simple cubic parameters that are greater than 0.8 is then output
      63             : \plumedfile
      64             : 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}
      65             : \endplumedfile
      66             : 
      67             : */
      68             : //+ENDPLUMEDOC
      69             : 
      70             : 
      71             : class SimpleCubic : public CubicHarmonicBase {
      72             : public:
      73             :   static void registerKeywords( Keywords& keys );
      74             :   explicit SimpleCubic(const ActionOptions&);
      75             :   double calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const override;
      76             : };
      77             : 
      78       10421 : PLUMED_REGISTER_ACTION(SimpleCubic,"SIMPLECUBIC")
      79             : 
      80           2 : void SimpleCubic::registerKeywords( Keywords& keys ) {
      81           2 :   CubicHarmonicBase::registerKeywords( keys );
      82           2 : }
      83             : 
      84           1 : SimpleCubic::SimpleCubic(const ActionOptions&ao):
      85             :   Action(ao),
      86           1 :   CubicHarmonicBase(ao)
      87             : {
      88           1 :   checkRead();
      89           1 : }
      90             : 
      91        4032 : double SimpleCubic::calculateCubicHarmonic( const Vector& distance, const double& d2, Vector& myder ) const {
      92        4032 :   double x2 = distance[0]*distance[0];
      93        4032 :   double x3 = distance[0]*x2;
      94        4032 :   double x4 = distance[0]*x3;
      95             : 
      96        4032 :   double y2 = distance[1]*distance[1];
      97        4032 :   double y3 = distance[1]*y2;
      98        4032 :   double y4 = distance[1]*y3;
      99             : 
     100        4032 :   double z2 = distance[2]*distance[2];
     101        4032 :   double z3 = distance[2]*z2;
     102        4032 :   double z4 = distance[2]*z3;
     103             : 
     104        4032 :   double r4 = pow( d2, 2 );
     105        4032 :   double tmp = ( x4 + y4 + z4 ) / r4;
     106             : 
     107        4032 :   double t1=(x2+y2+z2), t2=t1*t1, t3=(x4+y4+z4)/(t1*t2);
     108        4032 :   myder[0] = 4*x3/t2-4*distance[0]*t3;
     109        4032 :   myder[1] = 4*y3/t2-4*distance[1]*t3;
     110        4032 :   myder[2] = 4*z3/t2-4*distance[2]*t3;
     111        4032 :   return tmp;
     112             : }
     113             : 
     114             : }
     115             : }
     116             : 

Generated by: LCOV version 1.15