Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-2020 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 : #ifndef __PLUMED_adjmat_ContactMatrixShortcut_h 23 : #define __PLUMED_adjmat_ContactMatrixShortcut_h 24 : #include "core/ActionShortcut.h" 25 : #include "core/ActionRegister.h" 26 : #include "core/PlumedMain.h" 27 : #include "core/ActionSet.h" 28 : #include "core/Group.h" 29 : 30 : namespace PLMD { 31 : namespace adjmat { 32 : 33 : template <typename CM> 34 : class ContactMatrixShortcut : public ActionShortcut { 35 : public: 36 : static void registerKeywords(Keywords& keys); 37 : explicit ContactMatrixShortcut(const ActionOptions&); 38 : }; 39 : 40 : 41 : template <typename CM> 42 436 : void ContactMatrixShortcut<CM>::registerKeywords(Keywords& keys) { 43 436 : CM::registerKeywords( keys ); 44 436 : keys.remove("GROUP"); 45 872 : keys.remove("SWITCH"); 46 436 : keys.add("numbered","GROUP","specifies the list of atoms that should be assumed indistinguishable"); 47 436 : keys.add("numbered","SWITCH","the input for the switching function that acts upon the distance between each pair of atoms"); 48 872 : keys.linkActionInDocs("SWITCH","LESS_THAN"); 49 436 : keys.addActionNameSuffix("_PROPER"); 50 872 : keys.addActionNameSuffix("_PROPERACC"); 51 436 : if(!keys.exists("USEGPU")) { 52 0 : keys.addFlag("USEGPU",false,"run this calculation on the GPU"); 53 0 : keys.addLinkInDocForFlag("USEGPU","plugin_openaccPTM.md"); 54 : } 55 436 : keys.needsAction("TRANSPOSE"); 56 436 : keys.needsAction("CONCATENATE"); 57 436 : } 58 : 59 : template <typename CM> 60 274 : ContactMatrixShortcut<CM>::ContactMatrixShortcut(const ActionOptions& ao): 61 : Action(ao), 62 274 : ActionShortcut(ao) { 63 274 : std::vector<std::string> grp_str; 64 274 : std::string atomsstr=""; 65 274 : std::vector<std::string> atomsvec; 66 274 : parseVector("ATOMS",atomsvec); 67 274 : bool usegpuFLAG=false; 68 274 : parseFlag("USEGPU",usegpuFLAG); 69 548 : const std::string usegpu=(usegpuFLAG)?"ACC " : " "; 70 274 : if( atomsvec.size()>0 ) { 71 0 : for(unsigned i=0; i<atomsvec.size(); ++i) { 72 0 : Group* gg = plumed.getActionSet().template selectWithLabel<Group*>( atomsvec[i] ); 73 0 : if( gg ) { 74 0 : grp_str.push_back( atomsvec[i] ); 75 : } 76 : } 77 0 : if( grp_str.size()!=atomsvec.size() ) { 78 0 : grp_str.resize(0); 79 0 : atomsstr = " ATOMS=" + atomsvec[0]; 80 0 : for(unsigned i=1; i<atomsvec.size(); ++i) { 81 0 : atomsstr += "," + atomsvec[i]; 82 : } 83 : } 84 : } else { 85 : std::string grp_inpt; 86 4 : for(unsigned i=1;; ++i) { 87 556 : if( !parseNumbered("GROUP",i,grp_inpt) ) { 88 : break; 89 : } 90 4 : grp_str.push_back( grp_inpt ); 91 : } 92 : } 93 274 : if( grp_str.size()>9 ) { 94 0 : error("cannot handle more than 9 groups"); 95 : } 96 274 : if( grp_str.size()==0 ) { 97 816 : readInputLine( getShortcutLabel() + ": CONTACT_MATRIX_PROPER"+usegpu 98 : + atomsstr + " " + convertInputLineToString() ); 99 : return; 100 : } 101 : 102 6 : for(unsigned i=0; i<grp_str.size(); ++i) { 103 : std::string sw_str, num; 104 4 : Tools::convert( i+1, num ); 105 8 : parseNumbered("SWITCH", (i+1)*10 + 1 + i, sw_str ); 106 4 : if( sw_str.length()==0 ) { 107 0 : error("missing SWITCH" + num + num + " keyword"); 108 : } 109 20 : readInputLine( getShortcutLabel() + num + num + ": CONTACT_MATRIX_PROPER"+usegpu 110 : + "GROUP=" + grp_str[i] 111 : +" SWITCH={" + sw_str + "}" ); 112 6 : for(unsigned j=0; j<i; ++j) { 113 : std::string sw_str2, jnum; 114 2 : Tools::convert( j+1, jnum ); 115 4 : parseNumbered("SWITCH", (j+1)*10 + 1 + i, sw_str2); 116 2 : if( sw_str2.length()==0 ) { 117 0 : error("missing SWITCH" + jnum + num + " keyword"); 118 : } 119 12 : readInputLine( getShortcutLabel() + jnum + num + ": CONTACT_MATRIX_PROPER"+usegpu 120 2 : + "GROUPA=" + grp_str[j] 121 : +" GROUPB=" + grp_str[i] 122 : +" SWITCH={" + sw_str2 +"}"); 123 6 : readInputLine( getShortcutLabel() + num + jnum + ": TRANSPOSE ARG=" + getShortcutLabel() + jnum + num ); 124 : } 125 : } 126 2 : std::string join_matrices = getShortcutLabel() + ": CONCATENATE"; 127 6 : for(unsigned i=0; i<grp_str.size(); ++i) { 128 : std::string inum; 129 4 : Tools::convert(i+1,inum); 130 12 : for(unsigned j=0; j<grp_str.size(); ++j) { 131 : std::string jnum; 132 8 : Tools::convert(j+1,jnum); 133 8 : if( i>j ) { 134 6 : join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum; 135 : } else { 136 18 : join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum; 137 : } 138 : } 139 : } 140 2 : readInputLine( join_matrices ); 141 548 : } 142 : 143 : } 144 : } 145 : #endif // __PLUMED_adjmat_ContactMatrixShortcut_h