LCOV - code coverage report
Current view: top level - symfunc - RadialTetra.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 46 84.8 %
Date: 2025-04-08 21:11:17 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "core/ActionShortcut.h"
      24             : #include "core/ActionWithValue.h"
      25             : #include "CoordinationNumbers.h"
      26             : #include "multicolvar/MultiColvarShortcuts.h"
      27             : #include "core/PlumedMain.h"
      28             : #include "core/ActionSet.h"
      29             : 
      30             : //+PLUMEDOC MCOLVAR TETRA_RADIAL
      31             : /*
      32             : Calculate the radial tetra CV
      33             : 
      34             : This shortcut calculates a [symmetry function](https://www.plumed-tutorials.org/lessons/23/001/data/SymmetryFunction.html). The particular function that is being
      35             : evaluated for the coordination sphere here is as follows:
      36             : 
      37             : $$
      38             : s_i = 1 - \frac{\sum_{j=1}^4 r_{ij}^2 - z_i\sum_{j=1}^4 r_{ij}}{12 z_i^2} \qquad \textrm{where} \qquad z_i = \frac{1}{4} \sum_{j=1}^4 r_{ij}
      39             : $$
      40             : 
      41             : In this expression the 4 atoms in the sums over $j$ are the four atoms that are nearest to atom $i$ and $r_{ij}$ is the distance between atoms $i$ and $j$.
      42             : The CV is large if the four atoms nearest atom $i$ are arranged on the vertices of a regular tetrahedron
      43             : and small otherwise.  The following example shows how you can use this action to measure the degree of tetrahedral order in a system.
      44             : 
      45             : ```plumed
      46             : # Calculate a vector that contains 64 values for the symmetry function.
      47             : # Sum the elements of the vector and calculate the mean value on the atoms from this sum.
      48             : acv: TETRA_RADIAL SPECIES=1-64 SUM MEAN
      49             : # Print out the positions of the 64 atoms for which the symmetry function was calculated
      50             : # to an xyz file along with the values of the symmetry function
      51             : DUMPATOMS ATOMS=1-64 ARG=acv FILE=mcolv.xyz
      52             : # Print out the average value of the symmetry function and the sum of all the symmetry functions
      53             : PRINT ARG=acv_sum,acv_mean FILE=colvar
      54             : ```
      55             : 
      56             : */
      57             : //+ENDPLUMEDOC
      58             : 
      59             : namespace PLMD {
      60             : namespace symfunc {
      61             : 
      62             : class RadialTetra : public ActionShortcut {
      63             : public:
      64             :   static void registerKeywords( Keywords& keys );
      65             :   explicit RadialTetra(const ActionOptions&ao);
      66             : };
      67             : 
      68             : PLUMED_REGISTER_ACTION(RadialTetra,"TETRA_RADIAL")
      69             : 
      70           3 : void RadialTetra::registerKeywords( Keywords& keys ) {
      71           3 :   CoordinationNumbers::shortcutKeywords( keys );
      72           3 :   keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances");
      73           3 :   keys.add("compulsory","CUTOFF","-1","ignore distances that have a value larger than this cutoff");
      74           6 :   keys.setValueDescription("vector","the value of the radial tetrahedrality parameter for each of the input atoms");
      75           3 :   keys.remove("NN");
      76           3 :   keys.remove("MM");
      77           3 :   keys.remove("D_0");
      78           3 :   keys.remove("R_0");
      79           3 :   keys.remove("SWITCH");
      80           3 :   keys.needsAction("DISTANCE_MATRIX");
      81           3 :   keys.needsAction("NEIGHBORS");
      82           3 :   keys.needsAction("CUSTOM");
      83           3 :   keys.needsAction("ONES");
      84           3 :   keys.needsAction("MATRIX_VECTOR_PRODUCT");
      85           3 : }
      86             : 
      87           1 : RadialTetra::RadialTetra( const ActionOptions& ao):
      88             :   Action(ao),
      89           1 :   ActionShortcut(ao) {
      90             :   // Read species input and create the matrix
      91             :   bool nopbc;
      92           1 :   parseFlag("NOPBC",nopbc);
      93           1 :   std::string pbcstr="";
      94           1 :   if( nopbc ) {
      95             :     pbcstr = " NOPBC";
      96             :   }
      97             :   std::string sp_str, rcut;
      98           1 :   parse("SPECIES",sp_str);
      99           2 :   parse("CUTOFF",rcut);
     100           1 :   if( sp_str.length()>0 ) {
     101           2 :     readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUP=" + sp_str + " CUTOFF=" + rcut + pbcstr );
     102             :   } else {
     103             :     std::string specA, specB;
     104           0 :     parse("SPECIESA",specA);
     105           0 :     parse("SPECIESB",specB);
     106           0 :     if( specA.length()==0 ) {
     107           0 :       error("missing input atoms");
     108             :     }
     109           0 :     if( specB.length()==0 ) {
     110           0 :       error("missing SPECIESB keyword");
     111             :     }
     112           0 :     readInputLine( getShortcutLabel() + "_mat: DISTANCE_MATRIX GROUPA=" + specA + " GROUPB=" + specB + " CUTOFF=" + rcut + pbcstr);
     113             :   }
     114             :   // Get the neighbors matrix
     115           2 :   readInputLine( getShortcutLabel() + "_neigh: NEIGHBORS ARG=" + getShortcutLabel() + "_mat NLOWEST=4");
     116             :   // Now get distance matrix that just contains four nearest distances
     117           2 :   readInputLine( getShortcutLabel() + "_near4: CUSTOM ARG=" + getShortcutLabel() + "_mat," + getShortcutLabel() + "_neigh FUNC=x*y PERIODIC=NO");
     118             :   //Now compute sum of four nearest distances
     119           1 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat");
     120           1 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
     121             :   std::string size;
     122           1 :   Tools::convert( (av->copyOutput(0))->getShape()[1], size );
     123           2 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
     124           2 :   readInputLine( getShortcutLabel() + "_sum4: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4," + getShortcutLabel() + "_ones");
     125             :   // Now compute squares of four nearest distance
     126           2 :   readInputLine( getShortcutLabel() + "_near4_2: CUSTOM ARG=" + getShortcutLabel() + "_near4 FUNC=x*x PERIODIC=NO");
     127             :   // Now compute sum of the squares of the four nearest distances
     128           2 :   readInputLine( getShortcutLabel() + "_sum4_2: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_near4_2," + getShortcutLabel() + "_ones");
     129             :   // Evaluate the average distance to the four nearest neighbors
     130           2 :   readInputLine( getShortcutLabel() + "_meanr: CUSTOM ARG=" + getShortcutLabel() + "_sum4 FUNC=0.25*x PERIODIC=NO");
     131             :   // Now evaluate the actual per atom CV
     132           2 :   readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_sum4," + getShortcutLabel() + "_sum4_2," + getShortcutLabel() + "_meanr " +
     133             :                  "FUNC=(1-(y-x*z)/(12*z*z)) PERIODIC=NO");
     134             :   // And get the things to do with the quantities we have computed
     135             :   std::map<std::string,std::string> keymap;
     136           1 :   multicolvar::MultiColvarShortcuts::readShortcutKeywords( keymap, this );
     137           2 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", keymap, this );
     138           1 : }
     139             : 
     140             : }
     141             : }

Generated by: LCOV version 1.16