Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-2019 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/Action.h" 23 : #include "core/ActionAnyorder.h" 24 : #include "core/ActionRegister.h" 25 : #include "core/PlumedMain.h" 26 : #include "tools/Exception.h" 27 : 28 : using namespace std; 29 : 30 : namespace PLMD { 31 : namespace generic { 32 : 33 : //+PLUMEDOC GENERIC INCLUDE 34 : /* 35 : Includes an external input file, similar to "#include" in C preprocessor. 36 : 37 : Useful to split very large plumed.dat files. Notice that in PLUMED 2.4 this action 38 : cannot be used before the initial setup part of the file (e.g. in the part with \ref UNITS, \ref MOLINFO, etc). 39 : As of PLUMED 2.5, \ref INCLUDE can be used in any position of the file. 40 : 41 : \par Examples 42 : 43 : This input: 44 : \plumedfile 45 : c1: COM ATOMS=1-100 46 : c2: COM ATOMS=101-202 47 : d: DISTANCE ATOMS=c1,c2 48 : PRINT ARG=d 49 : \endplumedfile 50 : can be replaced with this input: 51 : \plumedfile 52 : INCLUDE FILE=pippo.dat 53 : d: DISTANCE ATOMS=c1,c2 54 : PRINT ARG=d 55 : \endplumedfile 56 : where the content of file pippo.dat is 57 : \plumedfile 58 : #SETTINGS FILENAME=pippo.dat 59 : # this is pippo.dat 60 : c1: COM ATOMS=1-100 61 : c2: COM ATOMS=101-202 62 : \endplumedfile 63 : 64 : The files in this example are rather short, but imagine a case like this one: 65 : \plumedfile 66 : INCLUDE FILE=groups.dat 67 : c: COORDINATION GROUPA=groupa GROUPB=groupb R_0=0.5 68 : METAD ARG=c HEIGHT=0.2 PACE=100 SIGMA=0.2 BIASFACTOR=5 69 : \endplumedfile 70 : Here `groups.dat` could be huge file containing group definitions such as 71 : \plumedfile 72 : #SETTINGS FILENAME=groups.dat 73 : # this is groups.dat 74 : groupa: GROUP ... 75 : ATOMS={ 76 : 10 77 : 50 78 : 60 79 : ## imagine a long list here 80 : 70 81 : 80 82 : 120 83 : } 84 : ... 85 : groupb: GROUP ... 86 : ATOMS={ 87 : 11 88 : 51 89 : 61 90 : ## imagine a long list here 91 : 71 92 : 81 93 : 121 94 : } 95 : ... 96 : \endplumedfile 97 : So, included files are the best place where one can store long definitions. 98 : 99 : Another case where INCLUDE is very useful is when running multi-replica simulations. 100 : Here different replicas might have different input files, but perhaps a large part of the 101 : input is shared. This part can be put in a common included file. For instance you could have 102 : `common.dat`: 103 : \plumedfile 104 : #SETTINGS FILENAME=common.dat 105 : # this is common.dat 106 : t: TORSION ATOMS=1,2,3,4 107 : \endplumedfile 108 : Then `plumed.0.dat`: 109 : \plumedfile 110 : # this is plumed.0.dat 111 : INCLUDE FILE=common.dat 112 : RESTRAINT ARG=t AT=1.0 KAPPA=10 113 : \endplumedfile 114 : And `plumed.1.dat`: 115 : \plumedfile 116 : # this is plumed.1.dat 117 : INCLUDE FILE=common.dat 118 : RESTRAINT ARG=t AT=1.2 KAPPA=10 119 : \endplumedfile 120 : 121 : \warning 122 : Remember that when using multi replica simulations whenever plumed tried to open 123 : a file for reading it looks for a file with the replica suffix first. 124 : This is true also for files opened by INCLUDE! 125 : 126 : As an example, the same result of the inputs above could have been obtained using 127 : the following `plumed.dat` file: 128 : \plumedfile 129 : #SETTINGS NREPLICAS=2 130 : t: TORSION ATOMS=1,2,3,4 131 : INCLUDE FILE=other.inc 132 : \endplumedfile 133 : Then `other.0.inc`: 134 : \plumedfile 135 : #SETTINGS FILENAME=other.0.inc 136 : # this is other.0.inc 137 : RESTRAINT ARG=t AT=1.0 KAPPA=10 138 : \endplumedfile 139 : And `other.1.inc`: 140 : \plumedfile 141 : #SETTINGS FILENAME=other.1.inc 142 : # this is other.1.inc 143 : RESTRAINT ARG=t AT=1.2 KAPPA=10 144 : \endplumedfile 145 : 146 : 147 : 148 : 149 : 150 : */ 151 : //+ENDPLUMEDOC 152 : 153 28 : class Include : 154 : public ActionAnyorder 155 : { 156 : public: 157 : static void registerKeywords( Keywords& keys ); 158 : explicit Include(const ActionOptions&ao); 159 0 : void calculate() override {} 160 0 : void apply() override {} 161 : }; 162 : 163 7860 : PLUMED_REGISTER_ACTION(Include,"INCLUDE") 164 : 165 15 : void Include::registerKeywords( Keywords& keys ) { 166 15 : Action::registerKeywords(keys); 167 60 : keys.add("compulsory","FILE","file to be included"); 168 15 : } 169 : 170 14 : Include::Include(const ActionOptions&ao): 171 : Action(ao), 172 14 : ActionAnyorder(ao) 173 : { 174 : std::string f; 175 28 : parse("FILE",f); 176 14 : checkRead(); 177 28 : plumed.readInputFile(f); 178 14 : } 179 : 180 : } 181 5874 : } 182 :