LCOV - code coverage report
Current view: top level - symfunc - AtomicSMAC.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 42 46 91.3 %
Date: 2024-10-18 13:59:31 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/PlumedMain.h"
      25             : #include "core/ActionSet.h"
      26             : #include "core/ActionWithValue.h"
      27             : #include "multicolvar/MultiColvarShortcuts.h"
      28             : 
      29             : //+PLUMEDOC MCOLVAR ATOMIC_SMAC
      30             : /*
      31             : Calculate the atomic smac CV
      32             : 
      33             : \par Examples
      34             : 
      35             : */
      36             : //+ENDPLUMEDOC
      37             : 
      38             : namespace PLMD {
      39             : namespace symfunc {
      40             : 
      41             : class AtomicSMAC : public ActionShortcut {
      42             : public:
      43             :   static void registerKeywords(Keywords& keys);
      44             :   explicit AtomicSMAC(const ActionOptions&);
      45             : };
      46             : 
      47             : PLUMED_REGISTER_ACTION(AtomicSMAC,"ATOMIC_SMAC")
      48             : 
      49           5 : void AtomicSMAC::registerKeywords(Keywords& keys) {
      50           5 :   ActionShortcut::registerKeywords( keys );
      51          10 :   keys.add("optional","SPECIES","");
      52          10 :   keys.add("optional","SPECIESA","");
      53          10 :   keys.add("optional","SPECIESB","");
      54          10 :   keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
      55             :            "The following provides information on the \\ref switchingfunction that are available. "
      56             :            "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
      57          10 :   keys.add("numbered","KERNEL","The kernels used in the function of the angle");
      58          10 :   keys.add("optional","SWITCH_COORD","This keyword is used to define the coordination switching function.");
      59          10 :   keys.reset_style("KERNEL","optional");
      60           5 :   multicolvar::MultiColvarShortcuts::shortcutKeywords( keys );
      61          15 :   keys.needsAction("CONTACT_MATRIX"); keys.needsAction("GSYMFUNC_THREEBODY"); keys.needsAction("ONES");
      62           5 :   keys.needsAction("MATRIX_VECTOR_PRODUCT");
      63           5 : }
      64             : 
      65           1 : AtomicSMAC::AtomicSMAC(const ActionOptions& ao):
      66             :   Action(ao),
      67           1 :   ActionShortcut(ao)
      68             : {
      69             :   // Create the matrices
      70           2 :   std::string sw_input; parse("SWITCH",sw_input);
      71           2 :   std::string sp_lab, sp_laba; parse("SPECIES",sp_lab); parse("SPECIESA",sp_laba);
      72           1 :   std::string cmap_input = getShortcutLabel() + "_cmap: CONTACT_MATRIX";
      73           1 :   if( sp_lab.length()>0 ) {
      74           2 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUP=" + sp_lab + " COMPONENTS SWITCH={" + sw_input + "}");
      75           0 :   } else if( sp_laba.length()>0 ) {
      76           0 :     std::string sp_labb; parse("SPECIESB",sp_labb);
      77           0 :     readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUPA=" + sp_laba + " GROUPB=" + sp_labb + " COMPONENTS SWITCH={" + sw_input + "}");
      78             :   }
      79             :   // Now need the Gaussians
      80             :   std::string mykernels;
      81           1 :   for(unsigned i=1;; ++i) {
      82           3 :     std::string kstr_inpt, istr, kern_str; Tools::convert( i, istr );
      83           6 :     if( !parseNumbered("KERNEL",i,kstr_inpt ) ) { break; }
      84           2 :     std::vector<std::string> words = Tools::getWords(kstr_inpt);
      85           2 :     if( words[0]=="GAUSSIAN" ) kern_str="gaussian";
      86           0 :     else error("unknown kernel type");
      87           6 :     std::string center, var; Tools::parse(words,"CENTER",center); Tools::parse(words,"SIGMA",var);
      88           3 :     if( mykernels.length()==0 ) mykernels = "exp(-(ajik-" + center + ")^2/(2*" + var + "*" + var + "))";
      89           2 :     else mykernels = mykernels + "+exp(-(ajik-" + center + ")^2/(2*" + var + "*" + var + "))";
      90           4 :   }
      91             :   // Hard coded switching function on minimum distance here -- should be improved
      92           3 :   readInputLine( getShortcutLabel() + "_ksum: GSYMFUNC_THREEBODY WEIGHT=" + getShortcutLabel() + "_cmap.w " +
      93           3 :                  "ARG=" + getShortcutLabel() + "_cmap.x," + getShortcutLabel() + "_cmap.y," + getShortcutLabel() + "_cmap.z"
      94           2 :                  " FUNCTION1={FUNC=" + mykernels + " LABEL=n} FUNCTION2={FUNC=1 LABEL=d}" );
      95             :   // And just the sum of the coordination numbers
      96           1 :   ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_cmap");
      97           1 :   plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 );
      98           1 :   std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size );
      99           2 :   readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size );
     100           2 :   readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cmap.w," + getShortcutLabel() + "_ones");
     101             :   // And the transformed switching functions
     102           1 :   std::string swcoord_str; parse("SWITCH_COORD",swcoord_str);
     103           2 :   readInputLine( getShortcutLabel() + "_mtdenom: MORE_THAN ARG=" + getShortcutLabel() + "_denom SWITCH={" + swcoord_str +"}");
     104             :   // And matheval to get the final quantity
     105           2 :   readInputLine( getShortcutLabel() + "_smac: CUSTOM ARG=" + getShortcutLabel() + "_ksum.n," + getShortcutLabel() + "_mtdenom," + getShortcutLabel() + "_ksum.d FUNC=x*y/z PERIODIC=NO");
     106             :   // And this expands everything
     107           2 :   multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_smac", "", this );
     108           1 : }
     109             : 
     110             : }
     111             : }

Generated by: LCOV version 1.16