LCOV - code coverage report
Current view: top level - crystallization - CubicHarmonicBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 75 80 93.8 %
Date: 2020-11-18 11:20:57 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "tools/SwitchingFunction.h"
      24             : 
      25             : #include <string>
      26             : #include <cmath>
      27             : 
      28             : using namespace std;
      29             : 
      30             : namespace PLMD {
      31             : namespace crystallization {
      32             : 
      33           8 : void CubicHarmonicBase::registerKeywords( Keywords& keys ) {
      34           8 :   multicolvar::MultiColvarBase::registerKeywords( keys );
      35          32 :   keys.use("SPECIES"); keys.use("SPECIESA"); keys.use("SPECIESB");
      36          40 :   keys.add("compulsory","NN","6","The n parameter of the switching function ");
      37          40 :   keys.add("compulsory","MM","0","The m parameter of the switching function; 0 implies 2*NN");
      38          40 :   keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
      39          32 :   keys.add("compulsory","R_0","The r_0 parameter of the switching function");
      40          32 :   keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
      41             :            "The following provides information on the \\ref switchingfunction that are available. "
      42             :            "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
      43          40 :   keys.add("compulsory","PHI","0.0","The Euler rotational angle phi");
      44          40 :   keys.add("compulsory","THETA","0.0","The Euler rotational angle theta");
      45          40 :   keys.add("compulsory","PSI","0.0","The Euler rotational angle psi");
      46          24 :   keys.addFlag("UNORMALIZED",false,"calculate the sum of the components of the vector rather than the mean");
      47             :   // Use actionWithDistributionKeywords
      48          40 :   keys.use("MEAN"); keys.use("MORE_THAN"); keys.use("LESS_THAN"); keys.use("MAX");
      49          40 :   keys.use("MIN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
      50          32 :   keys.use("ALT_MIN"); keys.use("LOWEST"); keys.use("HIGHEST");
      51           8 : }
      52             : 
      53           5 : CubicHarmonicBase::CubicHarmonicBase(const ActionOptions&ao):
      54             :   Action(ao),
      55           5 :   MultiColvarBase(ao)
      56             : {
      57             :   // Read in the switching function
      58          10 :   std::string sw, errors; parse("SWITCH",sw);
      59           5 :   if(sw.length()>0) {
      60           5 :     switchingFunction.set(sw,errors);
      61           5 :     if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
      62             :   } else {
      63           0 :     double r_0=-1.0, d_0; int nn, mm;
      64           0 :     parse("NN",nn); parse("MM",mm);
      65           0 :     parse("R_0",r_0); parse("D_0",d_0);
      66           0 :     if( r_0<0.0 ) error("you must set a value for R_0");
      67           0 :     switchingFunction.set(nn,mm,r_0,d_0);
      68             :   }
      69             : 
      70          20 :   double phi, theta, psi; parse("PHI",phi); parse("THETA",theta); parse("PSI",psi);
      71           5 :   log.printf("  creating rotation matrix with Euler angles phi=%f, theta=%f and psi=%f\n",phi,theta,psi);
      72             :   // Calculate the rotation matrix http://mathworld.wolfram.com/EulerAngles.html
      73           5 :   rotationmatrix[0][0]=cos(psi)*cos(phi)-cos(theta)*sin(phi)*sin(psi);
      74           5 :   rotationmatrix[0][1]=cos(psi)*sin(phi)+cos(theta)*cos(phi)*sin(psi);
      75           5 :   rotationmatrix[0][2]=sin(psi)*sin(theta);
      76             : 
      77           5 :   rotationmatrix[1][0]=-sin(psi)*cos(phi)-cos(theta)*sin(phi)*cos(psi);
      78           5 :   rotationmatrix[1][1]=-sin(psi)*sin(phi)+cos(theta)*cos(phi)*cos(psi);
      79           5 :   rotationmatrix[1][2]=cos(psi)*sin(theta);
      80             : 
      81           5 :   rotationmatrix[2][0]=sin(theta)*sin(phi);
      82           5 :   rotationmatrix[2][1]=-sin(theta)*cos(phi);
      83           5 :   rotationmatrix[2][2]=cos(theta);
      84             : 
      85             : 
      86          15 :   log.printf("  measure crystallinity around central atom.  Includes those atoms within %s\n",( switchingFunction.description() ).c_str() );
      87          10 :   parseFlag("UNORMALIZED",unormalized);
      88           5 :   if( unormalized ) log.printf("  output sum of vector functions \n");
      89           5 :   else log.printf("  output mean of vector functions \n");
      90             :   // Set the link cell cutoff
      91           5 :   rcut2 = switchingFunction.get_dmax()*switchingFunction.get_dmax();
      92           5 :   setLinkCellCutoff( switchingFunction.get_dmax() );
      93             :   // And setup the ActionWithVessel
      94           5 :   std::vector<AtomNumber> all_atoms; setupMultiColvarBase( all_atoms );
      95           5 : }
      96             : 
      97       26112 : double CubicHarmonicBase::compute( const unsigned& tindex, multicolvar::AtomValuePack& myatoms ) const {
      98       26112 :   double dfunc; Vector rotatedis;
      99             : 
     100             :   // Calculate the coordination number
     101       26112 :   Vector myder, rotateder, fder; unsigned nat=myatoms.getNumberOfAtoms();
     102             : 
     103     2514408 :   for(unsigned i=1; i<nat; ++i) {
     104             :     Vector& distance=myatoms.getPosition(i);
     105             : 
     106             :     double d2;
     107     3948992 :     if ( (d2=distance[0]*distance[0])<rcut2 &&
     108     2162142 :          (d2+=distance[1]*distance[1])<rcut2 &&
     109     3518048 :          (d2+=distance[2]*distance[2])<rcut2 &&
     110             :          d2>epsilon ) {
     111             : 
     112      328306 :       double sw = switchingFunction.calculateSqr( d2, dfunc );
     113             : 
     114      984918 :       rotatedis[0]=rotationmatrix[0][0]*distance[0]
     115      328306 :                    +rotationmatrix[0][1]*distance[1]
     116      656612 :                    +rotationmatrix[0][2]*distance[2];
     117      984918 :       rotatedis[1]=rotationmatrix[1][0]*distance[0]
     118      328306 :                    +rotationmatrix[1][1]*distance[1]
     119      656612 :                    +rotationmatrix[1][2]*distance[2];
     120      984918 :       rotatedis[2]=rotationmatrix[2][0]*distance[0]
     121      328306 :                    +rotationmatrix[2][1]*distance[1]
     122      656612 :                    +rotationmatrix[2][2]*distance[2];
     123             : 
     124      328306 :       double tmp = calculateCubicHarmonic( rotatedis, d2, rotateder );
     125             : 
     126      984918 :       myder[0]=rotationmatrix[0][0]*rotateder[0]
     127      328306 :                +rotationmatrix[1][0]*rotateder[1]
     128      656612 :                +rotationmatrix[2][0]*rotateder[2];
     129      984918 :       myder[1]=rotationmatrix[0][1]*rotateder[0]
     130      328306 :                +rotationmatrix[1][1]*rotateder[1]
     131      656612 :                +rotationmatrix[2][1]*rotateder[2];
     132      984918 :       myder[2]=rotationmatrix[0][2]*rotateder[0]
     133      328306 :                +rotationmatrix[1][2]*rotateder[1]
     134      656612 :                +rotationmatrix[2][2]*rotateder[2];
     135             : 
     136      328306 :       fder = (+dfunc)*tmp*distance + sw*myder;
     137             : 
     138      328306 :       accumulateSymmetryFunction( 1, i, sw*tmp, fder, Tensor(distance,-fder), myatoms );
     139      328306 :       accumulateSymmetryFunction( -1, i, sw, (+dfunc)*distance, (-dfunc)*Tensor(distance,distance), myatoms );
     140             :     }
     141             :   }
     142             :   // values -> der of... value [0], weight[1], x coord [2], y, z... [more magic]
     143       26112 :   updateActiveAtoms( myatoms );
     144       52224 :   if( !unormalized ) myatoms.getUnderlyingMultiValue().quotientRule( 1, 1 );
     145       26112 :   return myatoms.getValue(1); // this is equivalent to getting an "atomic" CV
     146             : }
     147             : 
     148             : }
     149        4839 : }
     150             : 

Generated by: LCOV version 1.13