LCOV - code coverage report
Current view: top level - generic - Include.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 13 15 86.7 %
Date: 2020-11-18 11:20:57 Functions: 8 11 72.7 %

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

Generated by: LCOV version 1.13