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 5 : keys.needsAction("CONTACT_MATRIX"); 62 5 : keys.needsAction("GSYMFUNC_THREEBODY"); 63 5 : keys.needsAction("ONES"); 64 5 : keys.needsAction("MATRIX_VECTOR_PRODUCT"); 65 5 : } 66 : 67 1 : AtomicSMAC::AtomicSMAC(const ActionOptions& ao): 68 : Action(ao), 69 1 : ActionShortcut(ao) { 70 : // Create the matrices 71 : std::string sw_input; 72 2 : parse("SWITCH",sw_input); 73 : std::string sp_lab, sp_laba; 74 1 : parse("SPECIES",sp_lab); 75 1 : parse("SPECIESA",sp_laba); 76 1 : std::string cmap_input = getShortcutLabel() + "_cmap: CONTACT_MATRIX"; 77 1 : if( sp_lab.length()>0 ) { 78 2 : readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUP=" + sp_lab + " COMPONENTS SWITCH={" + sw_input + "}"); 79 0 : } else if( sp_laba.length()>0 ) { 80 : std::string sp_labb; 81 0 : parse("SPECIESB",sp_labb); 82 0 : readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUPA=" + sp_laba + " GROUPB=" + sp_labb + " COMPONENTS SWITCH={" + sw_input + "}"); 83 : } 84 : // Now need the Gaussians 85 : std::string mykernels; 86 1 : for(unsigned i=1;; ++i) { 87 : std::string kstr_inpt, istr, kern_str; 88 3 : Tools::convert( i, istr ); 89 6 : if( !parseNumbered("KERNEL",i,kstr_inpt ) ) { 90 : break; 91 : } 92 2 : std::vector<std::string> words = Tools::getWords(kstr_inpt); 93 2 : if( words[0]=="GAUSSIAN" ) { 94 : kern_str="gaussian"; 95 : } else { 96 0 : error("unknown kernel type"); 97 : } 98 : std::string center, var; 99 2 : Tools::parse(words,"CENTER",center); 100 4 : Tools::parse(words,"SIGMA",var); 101 2 : if( mykernels.length()==0 ) { 102 2 : mykernels = "exp(-(ajik-" + center + ")^2/(2*" + var + "*" + var + "))"; 103 : } else { 104 2 : mykernels = mykernels + "+exp(-(ajik-" + center + ")^2/(2*" + var + "*" + var + "))"; 105 : } 106 4 : } 107 : // Hard coded switching function on minimum distance here -- should be improved 108 3 : readInputLine( getShortcutLabel() + "_ksum: GSYMFUNC_THREEBODY WEIGHT=" + getShortcutLabel() + "_cmap.w " + 109 3 : "ARG=" + getShortcutLabel() + "_cmap.x," + getShortcutLabel() + "_cmap.y," + getShortcutLabel() + "_cmap.z" 110 2 : " FUNCTION1={FUNC=" + mykernels + " LABEL=n} FUNCTION2={FUNC=1 LABEL=d}" ); 111 : // And just the sum of the coordination numbers 112 1 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_cmap"); 113 1 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 114 : std::string size; 115 1 : Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 116 2 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 117 2 : readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cmap.w," + getShortcutLabel() + "_ones"); 118 : // And the transformed switching functions 119 : std::string swcoord_str; 120 1 : parse("SWITCH_COORD",swcoord_str); 121 2 : readInputLine( getShortcutLabel() + "_mtdenom: MORE_THAN ARG=" + getShortcutLabel() + "_denom SWITCH={" + swcoord_str +"}"); 122 : // And matheval to get the final quantity 123 2 : readInputLine( getShortcutLabel() + "_smac: CUSTOM ARG=" + getShortcutLabel() + "_ksum.n," + getShortcutLabel() + "_mtdenom," + getShortcutLabel() + "_ksum.d FUNC=x*y/z PERIODIC=NO"); 124 : // And this expands everything 125 2 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_smac", "", this ); 126 1 : } 127 : 128 : } 129 : }