LCOV - code coverage report
Current view: top level - symfunc - HexaticParameter.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 50 78.0 %
Date: 2024-10-18 13:59:31 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.setValueDescription("matrix","the value of the cylindrical harmonic for each bond vector specified");
      62          10 :   keys.addFlag("VMEAN",false,"calculate the norm of the mean vector.");
      63          10 :   keys.addOutputComponent("_vmean","VMEAN","scalar","the norm of the mean vector");
      64          10 :   keys.addFlag("VSUM",false,"calculate the norm of the sum of all the vectors");
      65          10 :   keys.addOutputComponent("_vsum","VSUM","scalar","the norm of the mean vector");
      66          10 :   keys.needsAction("CYLINDRICAL_HARMONIC_MATRIX"); keys.needsAction("ONES");
      67          10 :   keys.needsAction("MATRIX_VECTOR_PRODUCT"); keys.needsAction("CUSTOM");
      68          15 :   keys.needsAction("MEAN"); keys.needsAction("SUM"); keys.needsAction("COMBINE");
      69           5 : }
      70             : 
      71           1 : HexacticParameter::HexacticParameter( const ActionOptions& ao):
      72             :   Action(ao),
      73           1 :   ActionShortcut(ao)
      74             : {
      75           3 :   std::string sp_str, specA, specB; parse("SPECIES",sp_str); parse("SPECIESA",specA); parse("SPECIESB",specB);
      76           1 :   CoordinationNumbers::expandMatrix( true, getShortcutLabel(), sp_str, specA, specB, this );
      77           2 :   std::string myplane; parse("PLANE",myplane);
      78           1 :   if( myplane=="xy" ) {
      79           2 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.w" );
      80           0 :   } else if( myplane=="xz" ) {
      81           0 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.x," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" );
      82           0 :   } else if( myplane=="yz" ) {
      83           0 :     readInputLine( getShortcutLabel() + ": CYLINDRICAL_HARMONIC_MATRIX DEGREE=6 ARG=" + getShortcutLabel() + "_mat.y," + getShortcutLabel() + "_mat.z," + getShortcutLabel() + "_mat.w" );
      84           0 :   } else error("invalid input for plane -- should be xy, xz or yz");
      85             :   // And coordination number
      86           1 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_mat");
      87           1 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
      88           1 :   std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size );
      89           2 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
      90           2 :   readInputLine( getShortcutLabel() + "_rm: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".rm," + getShortcutLabel() + "_ones");
      91           2 :   readInputLine( getShortcutLabel() + "_im: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + ".im," + getShortcutLabel() + "_ones");
      92             :   // Input for denominator (coord)
      93           2 :   readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_mat.w," + getShortcutLabel() + "_ones");
      94             :   // Divide real part by coordination numbers
      95           2 :   readInputLine( getShortcutLabel() + "_rmn: CUSTOM ARG=" + getShortcutLabel() + "_rm," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
      96             :   // Devide imaginary part by coordination number
      97           2 :   readInputLine( getShortcutLabel() + "_imn: CUSTOM ARG=" + getShortcutLabel() + "_im," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
      98             : 
      99             :   // If we are doing VMEAN determine sum of vector components
     100           1 :   bool do_vmean; parseFlag("VMEAN",do_vmean);
     101           1 :   if( do_vmean ) {
     102             :     // Real part
     103           0 :     readInputLine( getShortcutLabel() + "_rms: MEAN ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO");
     104             :     // Imaginary part
     105           0 :     readInputLine( getShortcutLabel() + "_ims: MEAN ARG=" + getShortcutLabel() + "_imn PERIODIC=NO");
     106             :     // Now calculate the total length of the vector
     107           0 :     createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vmean", "ms" );
     108             :   }
     109           1 :   bool do_vsum; parseFlag("VSUM",do_vsum);
     110           1 :   if( do_vsum ) {
     111             :     // Real part
     112           0 :     readInputLine( getShortcutLabel() + "_rmz: SUM ARG=" + getShortcutLabel() + "_rmn PERIODIC=NO");
     113             :     // Imaginary part
     114           0 :     readInputLine( getShortcutLabel() + "_imz: SUM ARG=" + getShortcutLabel() + "_imn PERIODIC=NO");
     115             :     // Now calculate the total length of the vector
     116           0 :     createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vsum", "mz" );
     117             :   }
     118             : 
     119             :   // Now calculate the total length of the vector
     120           2 :   createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_norm", "mn" );
     121           2 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_norm", "", this );
     122           1 : }
     123             : 
     124           1 : void HexacticParameter::createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ) {
     125           2 :   readInputLine( olab + "2: COMBINE PERIODIC=NO ARG=" + ilab + "_r" + vlab + "," + ilab + "_i" + vlab + " POWERS=2,2" );
     126           2 :   readInputLine( olab + ": CUSTOM ARG=" + olab + "2 FUNC=sqrt(x) PERIODIC=NO");
     127           1 : }
     128             : 
     129             : }
     130             : }
     131             : 

Generated by: LCOV version 1.16