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 26 : keys.setValueDescription("vector","the value of the smac parameter for each of the input molecules"); 62 13 : multicolvar::MultiColvarShortcuts::shortcutKeywords( keys ); 63 39 : keys.needsAction("VSTACK"); keys.needsAction("TRANSPOSE"); keys.needsAction("CONTACT_MATRIX"); 64 39 : keys.needsAction("TORSIONS_MATRIX"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM"); 65 39 : keys.needsAction("ONES"); keys.needsAction("MATRIX_VECTOR_PRODUCT"); keys.needsAction("MORE_THAN"); 66 13 : } 67 : 68 5 : SMAC::SMAC(const ActionOptions& ao): 69 : Action(ao), 70 5 : ActionShortcut(ao) 71 : { 72 : // Create the matrices 73 10 : std::string sw_input; parse("SWITCH",sw_input); 74 15 : std::string sp_lab, sp_laba; parse("SPECIES",sp_lab); parse("SPECIESA",sp_laba); 75 5 : if( sp_lab.length()>0 ) { 76 8 : readInputLine( getShortcutLabel() + "_vecs: VSTACK ARG=" + sp_lab + ".x," + sp_lab + ".y," + sp_lab + ".z" ); 77 8 : readInputLine( getShortcutLabel() + "_vecsT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecs" ); 78 8 : readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUP=" + sp_lab + " SWITCH={" + sw_input + "}"); 79 8 : readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecs," + getShortcutLabel() + "_vecsT POSITIONS1=" + sp_lab + " POSITIONS2=" + sp_lab ); 80 1 : } else if( sp_laba.length()>0 ) { 81 1 : std::string sp_labb; parse("SPECIESB",sp_labb); 82 2 : readInputLine( getShortcutLabel() + "_vecsa: VSTACK ARG=" + sp_laba + ".x," + sp_laba + ".y," + sp_laba + ".z" ); 83 2 : readInputLine( getShortcutLabel() + "_vecsb: VSTACK ARG=" + sp_labb + ".x," + sp_labb + ".y," + sp_labb + ".z" ); 84 2 : readInputLine( getShortcutLabel() + "_vecsbT: TRANSPOSE ARG=" + getShortcutLabel() + "_vecsb" ); 85 2 : readInputLine( getShortcutLabel() + "_cmap: CONTACT_MATRIX GROUPA=" + sp_laba + " GROUPB=" + sp_labb + " SWITCH={" + sw_input + "}"); 86 2 : readInputLine( getShortcutLabel() + "_tpmat: TORSIONS_MATRIX ARG=" + getShortcutLabel() + "_vecsa," + getShortcutLabel() + "_vecsbT POSITIONS1=" + sp_laba + " POSITIONS2=" + sp_labb ); 87 : } 88 : // Now need the Gaussians 89 5 : std::string kmap_input= getShortcutLabel() + "_ksum: COMBINE PERIODIC=NO"; 90 5 : for(unsigned i=1;; ++i) { 91 15 : std::string kstr_inpt, istr; Tools::convert( i, istr ); 92 30 : if( !parseNumbered("KERNEL",i,kstr_inpt ) ) { break; } 93 10 : std::vector<std::string> words = Tools::getWords(kstr_inpt); 94 20 : std::string center, var; Tools::parse(words,"CENTER",center); Tools::parse(words,"SIGMA",var); 95 10 : double nsig; Tools::convert( var, nsig ); std::string coeff; Tools::convert( 1/(nsig*nsig), coeff ); 96 20 : readInputLine( getShortcutLabel() + "_kf" + istr + "_r2: COMBINE PERIODIC=NO ARG=" + getShortcutLabel() + "_tpmat COEFFICIENTS=" + coeff + " PARAMETERS=" + center + " POWERS=2"); 97 18 : if( words[0]=="GAUSSIAN" ) readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=exp(-x/2) ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" ); 98 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" ); 99 0 : else readInputLine( getShortcutLabel() + "_kf" + istr + ": CUSTOM PERIODIC=NO FUNC=" + words[0] + " ARG=" + getShortcutLabel() + "_kf" + istr + "_r2" ); 100 15 : if( i==1 ) kmap_input += " ARG=" + getShortcutLabel() + "_kf" + istr; 101 10 : else kmap_input += "," + getShortcutLabel() + "_kf" + istr; 102 20 : } 103 5 : readInputLine( kmap_input ); 104 : // Now create the product matrix 105 10 : readInputLine( getShortcutLabel() + "_prod: CUSTOM ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ksum FUNC=x*y PERIODIC=NO"); 106 : // Now the sum of coordination numbers times the switching functions 107 5 : ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( getShortcutLabel() + "_cmap"); 108 5 : plumed_assert( av && av->getNumberOfComponents()>0 && (av->copyOutput(0))->getRank()==2 ); 109 5 : std::string size; Tools::convert( (av->copyOutput(0))->getShape()[1], size ); 110 10 : readInputLine( getShortcutLabel() + "_ones: ONES SIZE=" + size ); 111 10 : readInputLine( getShortcutLabel() + ": MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_prod," + getShortcutLabel() + "_ones"); 112 : // And just the sum of the coordination numbers 113 10 : readInputLine( getShortcutLabel() + "_denom: MATRIX_VECTOR_PRODUCT ARG=" + getShortcutLabel() + "_cmap," + getShortcutLabel() + "_ones"); 114 : // And the transformed switching functions 115 5 : std::string swcoord_str; parse("SWITCH_COORD",swcoord_str); 116 10 : readInputLine( getShortcutLabel() + "_mtdenom: MORE_THAN ARG=" + getShortcutLabel() + "_denom SWITCH={" + swcoord_str +"}"); 117 : // And matheval to get the final quantity 118 10 : readInputLine( getShortcutLabel() + "_smac: CUSTOM ARG=" + getShortcutLabel() + "," + getShortcutLabel() + "_mtdenom," + getShortcutLabel() + "_denom FUNC=(x*y)/z PERIODIC=NO"); 119 : // And this expands everything 120 10 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel() + "_smac", "", this ); 121 5 : } 122 : 123 : } 124 : }