LCOV - code coverage report
Current view: top level - symfunc - SMAC.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 56 57 98.2 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "core/ActionShortcut.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "core/ActionWithValue.h"
      25             : #include "core/PlumedMain.h"
      26             : #include "core/ActionSet.h"
      27             : #include "multicolvar/MultiColvarShortcuts.h"
      28             : 
      29             : //+PLUMEDOC MCOLVAR SMAC
      30             : /*
      31             : Calculate the SMAC order parameter for a set of molecules
      32             : 
      33             : \par Examples
      34             : 
      35             : 
      36             : */
      37             : //+ENDPLUMEDOC
      38             : 
      39             : namespace PLMD {
      40             : namespace symfunc {
      41             : 
      42             : class SMAC : public ActionShortcut {
      43             : public:
      44             :   static void registerKeywords(Keywords& keys);
      45             :   explicit SMAC(const ActionOptions&);
      46             : };
      47             : 
      48             : PLUMED_REGISTER_ACTION(SMAC,"SMAC")
      49             : 
      50          13 : void SMAC::registerKeywords(Keywords& keys) {
      51          13 :   ActionShortcut::registerKeywords( keys );
      52          26 :   keys.add("optional","SPECIES","");
      53          26 :   keys.add("optional","SPECIESA","");
      54          26 :   keys.add("optional","SPECIESB","");
      55          26 :   keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
      56             :            "The following provides information on the \\ref switchingfunction that are available. "
      57             :            "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
      58          26 :   keys.add("numbered","KERNEL","The kernels used in the function of the angle");
      59          26 :   keys.add("optional","SWITCH_COORD","This keyword is used to define the coordination switching function.");
      60          26 :   keys.reset_style("KERNEL","optional");
      61          13 :   multicolvar::MultiColvarShortcuts::shortcutKeywords( keys );
      62          39 :   keys.needsAction("VSTACK"); keys.needsAction("TRANSPOSE"); keys.needsAction("CONTACT_MATRIX");
      63          39 :   keys.needsAction("TORSIONS_MATRIX"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM");
      64          39 :   keys.needsAction("ONES"); keys.needsAction("MATRIX_VECTOR_PRODUCT"); keys.needsAction("MORE_THAN");
      65          13 : }
      66             : 
      67           5 : SMAC::SMAC(const ActionOptions& ao):
      68             :   Action(ao),
      69           5 :   ActionShortcut(ao)
      70             : {
      71             :   // Create the matrices
      72          10 :   std::string sw_input; parse("SWITCH",sw_input);
      73          15 :   std::string sp_lab, sp_laba; parse("SPECIES",sp_lab); parse("SPECIESA",sp_laba);
      74           5 :   if( sp_lab.length()>0 ) {
      75           8 :     readInputLine( getShortcutLabel() + "_vecs: VSTACK ARG=" + sp_lab + ".x," + sp_lab + ".y," + sp_lab + ".z" );
      76           8 :     readInputLine( getShortcutLabel() + "_vecsT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecs" );
      77           8 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUP=" + sp_lab + " SWITCH={" + sw_input + "}");
      78           8 :     readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecs," + getShortcutLabel() + "_vecsT POSITIONS1=" + sp_lab + " POSITIONS2=" + sp_lab );
      79           1 :   } else if( sp_laba.length()>0 ) {
      80           1 :     std::string sp_labb; parse("SPECIESB",sp_labb);
      81           2 :     readInputLine( getShortcutLabel() + "_vecsa: VSTACK ARG=" + sp_laba + ".x," + sp_laba + ".y," + sp_laba + ".z" );
      82           2 :     readInputLine( getShortcutLabel() + "_vecsb: VSTACK ARG=" + sp_labb + ".x," + sp_labb + ".y," + sp_labb + ".z" );
      83           2 :     readInputLine( getShortcutLabel() + "_vecsbT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecsb" );
      84           2 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUPA=" + sp_laba + " GROUPB=" + sp_labb + " SWITCH={" + sw_input + "}");
      85           2 :     readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecsa," + getShortcutLabel() + "_vecsbT POSITIONS1=" + sp_laba + " POSITIONS2=" + sp_labb );
      86             :   }
      87             :   // Now need the Gaussians
      88           5 :   std::string kmap_input= getShortcutLabel() + "_ksum: COMBINE PERIODIC=NO";
      89           5 :   for(unsigned i=1;; ++i) {
      90          15 :     std::string kstr_inpt, istr; Tools::convert( i, istr );
      91          30 :     if( !parseNumbered("KERNEL",i,kstr_inpt ) ) { break; }
      92          10 :     std::vector<std::string> words = Tools::getWords(kstr_inpt);
      93          20 :     std::string center, var; Tools::parse(words,"CENTER",center); Tools::parse(words,"SIGMA",var);
      94          10 :     double nsig; Tools::convert( var, nsig ); std::string coeff; Tools::convert( 1/(nsig*nsig), coeff );
      95          20 :     readInputLine( getShortcutLabel() + "_kf" + istr + "_r2: COMBINE PERIODIC=NO ARG=" + getShortcutLabel() + "_tpmat COEFFICIENTS=" + coeff + " PARAMETERS=" + center + " POWERS=2");
      96          18 :     if( words[0]=="GAUSSIAN" ) readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=exp(-x/2) ARG=" +  getShortcutLabel() + "_kf" + istr + "_r2" );
      97           4 :     else if( words[0]=="TRIANGULAR" ) readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=step(1-sqrt(x))*(1-sqrt(x)) ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" );
      98           0 :     else readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=" + words[0] + " ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" );
      99          15 :     if( i==1 ) kmap_input += " ARG=" + getShortcutLabel() + "_kf" + istr;
     100          10 :     else kmap_input += "," + getShortcutLabel() + "_kf" + istr;
     101          20 :   }
     102           5 :   readInputLine( kmap_input );
     103             :   // Now create the product matrix
     104          10 :   readInputLine( getShortcutLabel() + "_prod: CUSTOM ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ksum FUNC=x*y PERIODIC=NO");
     105             :   // Now the sum of coordination numbers times the switching functions
     106           5 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_cmap");
     107           5 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
     108           5 :   std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size );
     109          10 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
     110          10 :   readInputLine( getShortcutLabel() + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_prod," + getShortcutLabel() + "_ones");
     111             :   // And just the sum of the coordination numbers
     112          10 :   readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ones");
     113             :   // And the transformed switching functions
     114           5 :   std::string swcoord_str; parse("SWITCH_COORD",swcoord_str);
     115          10 :   readInputLine( getShortcutLabel() + "_mtdenom: MORE_THAN ARG=" + getShortcutLabel() + "_denom SWITCH={" + swcoord_str +"}");
     116             : // And matheval to get the final quantity
     117          10 :   readInputLine( getShortcutLabel() + "_smac: CUSTOM ARG=" + getShortcutLabel() + "," + getShortcutLabel() + "_mtdenom," + getShortcutLabel() + "_denom FUNC=(x*y)/z PERIODIC=NO");
     118             :   // And this expands everything
     119          10 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_smac", "", this );
     120           5 : }
     121             : 
     122             : }
     123             : }

Generated by: LCOV version 1.16