LCOV - code coverage report
Current view: top level - symfunc - SMAC.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 68 69 98.6 %
Date: 2025-11-25 13:55:50 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          13 :   keys.needsAction("VSTACK");
      63          13 :   keys.needsAction("TRANSPOSE");
      64          13 :   keys.needsAction("CONTACT_MATRIX");
      65          13 :   keys.needsAction("TORSIONS_MATRIX");
      66          13 :   keys.needsAction("COMBINE");
      67          13 :   keys.needsAction("CUSTOM");
      68          13 :   keys.needsAction("ONES");
      69          13 :   keys.needsAction("MATRIX_VECTOR_PRODUCT");
      70          13 :   keys.needsAction("MORE_THAN");
      71          13 : }
      72             : 
      73           5 : SMAC::SMAC(const ActionOptions& ao):
      74             :   Action(ao),
      75           5 :   ActionShortcut(ao) {
      76             :   // Create the matrices
      77             :   std::string sw_input;
      78          10 :   parse("SWITCH",sw_input);
      79             :   std::string sp_lab, sp_laba;
      80           5 :   parse("SPECIES",sp_lab);
      81          10 :   parse("SPECIESA",sp_laba);
      82           5 :   if( sp_lab.length()>0 ) {
      83           8 :     readInputLine( getShortcutLabel() + "_vecs: VSTACK ARG=" + sp_lab + ".x," + sp_lab + ".y," + sp_lab + ".z" );
      84           8 :     readInputLine( getShortcutLabel() + "_vecsT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecs" );
      85           8 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUP=" + sp_lab + " SWITCH={" + sw_input + "}");
      86           8 :     readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecs," + getShortcutLabel() + "_vecsT POSITIONS1=" + sp_lab + " POSITIONS2=" + sp_lab );
      87           1 :   } else if( sp_laba.length()>0 ) {
      88             :     std::string sp_labb;
      89           1 :     parse("SPECIESB",sp_labb);
      90           2 :     readInputLine( getShortcutLabel() + "_vecsa: VSTACK ARG=" + sp_laba + ".x," + sp_laba + ".y," + sp_laba + ".z" );
      91           2 :     readInputLine( getShortcutLabel() + "_vecsb: VSTACK ARG=" + sp_labb + ".x," + sp_labb + ".y," + sp_labb + ".z" );
      92           2 :     readInputLine( getShortcutLabel() + "_vecsbT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecsb" );
      93           2 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUPA=" + sp_laba + " GROUPB=" + sp_labb + " SWITCH={" + sw_input + "}");
      94           2 :     readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecsa," + getShortcutLabel() + "_vecsbT POSITIONS1=" + sp_laba + " POSITIONS2=" + sp_labb );
      95             :   }
      96             :   // Now need the Gaussians
      97           5 :   std::string kmap_input= getShortcutLabel() + "_ksum: COMBINE PERIODIC=NO";
      98           5 :   for(unsigned i=1;; ++i) {
      99             :     std::string kstr_inpt, istr;
     100          15 :     Tools::convert( i, istr );
     101          30 :     if( !parseNumbered("KERNEL",i,kstr_inpt ) ) {
     102             :       break;
     103             :     }
     104          10 :     std::vector<std::string> words = Tools::getWords(kstr_inpt);
     105             :     std::string center, var;
     106          10 :     Tools::parse(words,"CENTER",center);
     107          10 :     Tools::parse(words,"SIGMA",var);
     108             :     double nsig;
     109          10 :     Tools::convert( var, nsig );
     110             :     std::string coeff;
     111          10 :     Tools::convert( 1/(nsig*nsig), coeff );
     112          20 :     readInputLine( getShortcutLabel() + "_kf" + istr + "_r2: COMBINE PERIODIC=NO ARG=" + getShortcutLabel() + "_tpmat COEFFICIENTS=" + coeff + " PARAMETERS=" + center + " POWERS=2");
     113          10 :     if( words[0]=="GAUSSIAN" ) {
     114          16 :       readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=exp(-x/2) ARG=" +  getShortcutLabel() + "_kf" + istr + "_r2" );
     115           2 :     } else if( words[0]=="TRIANGULAR" ) {
     116           4 :       readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=step(1-sqrt(x))*(1-sqrt(x)) ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" );
     117             :     } else {
     118           0 :       readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=" + words[0] + " ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" );
     119             :     }
     120          10 :     if( i==1 ) {
     121          10 :       kmap_input += " ARG=" + getShortcutLabel() + "_kf" + istr;
     122             :     } else {
     123          10 :       kmap_input += "," + getShortcutLabel() + "_kf" + istr;
     124             :     }
     125          20 :   }
     126           5 :   readInputLine( kmap_input );
     127             :   // Now create the product matrix
     128          10 :   readInputLine( getShortcutLabel() + "_prod: CUSTOM ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ksum FUNC=x*y PERIODIC=NO");
     129             :   // Now the sum of coordination numbers times the switching functions
     130           5 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_cmap");
     131           5 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
     132             :   std::string size;
     133           5 :   Tools::convert( (av->copyOutput(0))->getShape()[1], size );
     134          10 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
     135          10 :   readInputLine( getShortcutLabel() + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_prod," + getShortcutLabel() + "_ones");
     136             :   // And just the sum of the coordination numbers
     137          10 :   readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ones");
     138             :   // And the transformed switching functions
     139             :   std::string swcoord_str;
     140           5 :   parse("SWITCH_COORD",swcoord_str);
     141          10 :   readInputLine( getShortcutLabel() + "_mtdenom: MORE_THAN ARG=" + getShortcutLabel() + "_denom SWITCH={" + swcoord_str +"}");
     142             : // And matheval to get the final quantity
     143          10 :   readInputLine( getShortcutLabel() + "_smac: CUSTOM ARG=" + getShortcutLabel() + "," + getShortcutLabel() + "_mtdenom," + getShortcutLabel() + "_denom FUNC=(x*y)/z PERIODIC=NO");
     144             :   // And this expands everything
     145          10 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_smac", "", this );
     146           5 : }
     147             : 
     148             : }
     149             : }

Generated by: LCOV version 1.16