LCOV - code coverage report
Current view: top level - symfunc - HexaticParameter.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 49 77.6 %
Date: 2024-10-18 14:00:25 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2017 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/ActionShortcut.h"
      23             : #include "multicolvar/MultiColvarShortcuts.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/ActionSet.h"
      26             : #include "core/ActionRegister.h"
      27             : #include "core/ActionWithValue.h"
      28             : #include "CoordinationNumbers.h"
      29             : 
      30             : #include <complex>
      31             : 
      32             : namespace PLMD {
      33             : namespace symfunc {
      34             : 
      35             : //+PLUMEDOC MCOLVAR HEXACTIC_PARAMETER
      36             : /*
      37             : Calculate the hexatic order parameter
      38             : 
      39             : \bug Virial is not working currently
      40             : 
      41             : \par Examples
      42             : 
      43             : 
      44             : */
      45             : //+ENDPLUMEDOC
      46             : 
      47             : 
      48             : class HexacticParameter : public ActionShortcut {
      49             : private:
      50             :   void createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab );
      51             : public:
      52             :   static void registerKeywords( Keywords& keys );
      53             :   explicit HexacticParameter(const ActionOptions&);
      54             : };
      55             : 
      56             : PLUMED_REGISTER_ACTION(HexacticParameter,"HEXACTIC_PARAMETER")
      57             : 
      58           5 : void HexacticParameter::registerKeywords( Keywords& keys ) {
      59           5 :   CoordinationNumbers::shortcutKeywords( keys );
      60          10 :   keys.add("compulsory","PLANE","the plane to use when calculating the value of the order parameter should be xy, xz or yz");
      61          10 :   keys.addFlag("VMEAN",false,"calculate the norm of the mean vector.");
      62          10 :   keys.addOutputComponent("_vmean","VMEAN","the norm of the mean vector");
      63          10 :   keys.addFlag("VSUM",false,"calculate the norm of the sum of all the vectors");
      64          10 :   keys.addOutputComponent("_vsum","VSUM","the norm of the mean vector");
      65          10 :   keys.needsAction("CYLINDRICAL_HARMONIC_MATRIX"); keys.needsAction("ONES");
      66          10 :   keys.needsAction("MATRIX_VECTOR_PRODUCT"); keys.needsAction("CUSTOM");
      67          15 :   keys.needsAction("MEAN"); keys.needsAction("SUM"); keys.needsAction("COMBINE");
      68           5 : }
      69             : 
      70           1 : HexacticParameter::HexacticParameter( const ActionOptions& ao):
      71             :   Action(ao),
      72           1 :   ActionShortcut(ao)
      73             : {
      74           3 :   std::string sp_str, specA, specB; parse("SPECIES",sp_str); parse("SPECIESA",specA); parse("SPECIESB",specB);
      75           1 :   CoordinationNumbers::expandMatrix( true, getShortcutLabel(), sp_str, specA, specB, this );
      76           2 :   std::string myplane; parse("PLANE",myplane);
      77           1 :   if( myplane=="xy" ) {
      78           2 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.w" );
      79           0 :   } else if( myplane=="xz" ) {
      80           0 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" );
      81           0 :   } else if( myplane=="yz" ) {
      82           0 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" );
      83           0 :   } else error("invalid input for plane -- should be xy, xz or yz");
      84             :   // And coordination number
      85           1 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat");
      86           1 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
      87           1 :   std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size );
      88           2 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
      89           2 :   readInputLine( getShortcutLabel() + "_rm: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".rm," + getShortcutLabel() + "_ones");
      90           2 :   readInputLine( getShortcutLabel() + "_im: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".im," + getShortcutLabel() + "_ones");
      91             :   // Input for denominator (coord)
      92           2 :   readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_mat.w," + getShortcutLabel() + "_ones");
      93             :   // Divide real part by coordination numbers
      94           2 :   readInputLine( getShortcutLabel() + "_rmn: CUSTOM ARG=" + getShortcutLabel() + "_rm," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
      95             :   // Devide imaginary part by coordination number
      96           2 :   readInputLine( getShortcutLabel() + "_imn: CUSTOM ARG=" + getShortcutLabel() + "_im," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
      97             : 
      98             :   // If we are doing VMEAN determine sum of vector components
      99           1 :   bool do_vmean; parseFlag("VMEAN",do_vmean);
     100           1 :   if( do_vmean ) {
     101             :     // Real part
     102           0 :     readInputLine( getShortcutLabel() + "_rms: MEAN ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO");
     103             :     // Imaginary part
     104           0 :     readInputLine( getShortcutLabel() + "_ims: MEAN ARG=" + getShortcutLabel() + "_imn PERIODIC=NO");
     105             :     // Now calculate the total length of the vector
     106           0 :     createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vmean", "ms" );
     107             :   }
     108           1 :   bool do_vsum; parseFlag("VSUM",do_vsum);
     109           1 :   if( do_vsum ) {
     110             :     // Real part
     111           0 :     readInputLine( getShortcutLabel() + "_rmz: SUM ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO");
     112             :     // Imaginary part
     113           0 :     readInputLine( getShortcutLabel() + "_imz: SUM ARG=" + getShortcutLabel() + "_imn PERIODIC=NO");
     114             :     // Now calculate the total length of the vector
     115           0 :     createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vsum", "mz" );
     116             :   }
     117             : 
     118             :   // Now calculate the total length of the vector
     119           2 :   createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_norm", "mn" );
     120           2 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_norm", "", this );
     121           1 : }
     122             : 
     123           1 : void HexacticParameter::createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ) {
     124           2 :   readInputLine( olab + "2: COMBINE PERIODIC=NO ARG=" + ilab + "_r" + vlab + "," + ilab + "_i" + vlab + " POWERS=2,2" );
     125           2 :   readInputLine( olab + ": CUSTOM ARG=" + olab + "2 FUNC=sqrt(x) PERIODIC=NO");
     126           1 : }
     127             : 
     128             : }
     129             : }
     130             : 

Generated by: LCOV version 1.16