LCOV - code coverage report
Current view: top level - generic - RandomExchanges.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 4 13 30.8 %
Date: 2024-10-18 13:59:31 Functions: 1 4 25.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-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/Action.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "tools/Exception.h"
      26             : #include "core/ExchangePatterns.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace generic {
      30             : 
      31             : //+PLUMEDOC GENERIC RANDOM_EXCHANGES
      32             : /*
      33             : Set random pattern for exchanges.
      34             : 
      35             : In this way, exchanges will not be done between replicas with consecutive index, but
      36             : will be done using a random pattern.  Typically used in bias exchange \cite piana.
      37             : 
      38             : \par Examples
      39             : 
      40             : Using the following three input files one can run a bias exchange
      41             : metadynamics simulation using a different angle in each replica.
      42             : Exchanges will be randomly tried between replicas 0-1, 0-2 and 1-2
      43             : 
      44             : Here is plumed.0.dat
      45             : \plumedfile
      46             : RANDOM_EXCHANGES
      47             : t: TORSION ATOMS=1,2,3,4
      48             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      49             : \endplumedfile
      50             : 
      51             : Here is plumed.1.dat
      52             : \plumedfile
      53             : RANDOM_EXCHANGES
      54             : t: TORSION ATOMS=2,3,4,5
      55             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      56             : \endplumedfile
      57             : 
      58             : Here is plumed.2.dat
      59             : \plumedfile
      60             : RANDOM_EXCHANGES
      61             : t: TORSION ATOMS=3,4,5,6
      62             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      63             : \endplumedfile
      64             : 
      65             : \warning Multi replica simulations are presently only working with gromacs.
      66             : 
      67             : \warning The directive should appear in input files for every replicas. In case SEED is specified, it
      68             : should be the same in all input files.
      69             : 
      70             : */
      71             : //+ENDPLUMEDOC
      72             : 
      73             : class RandomExchanges:
      74             :   public Action
      75             : {
      76             : public:
      77             :   static void registerKeywords( Keywords& keys );
      78             :   explicit RandomExchanges(const ActionOptions&ao);
      79           0 :   void calculate() override {}
      80           0 :   void apply() override {}
      81             : };
      82             : 
      83             : PLUMED_REGISTER_ACTION(RandomExchanges,"RANDOM_EXCHANGES")
      84             : 
      85           2 : void RandomExchanges::registerKeywords( Keywords& keys ) {
      86           2 :   Action::registerKeywords(keys);
      87           4 :   keys.add("optional","SEED","seed for random exchanges");
      88           2 : }
      89             : 
      90           0 : RandomExchanges::RandomExchanges(const ActionOptions&ao):
      91           0 :   Action(ao)
      92             : {
      93           0 :   plumed.getExchangePatterns().setFlag(ExchangePatterns::RANDOM);
      94             : // I convert the seed to -seed because I think it is more general to use a positive seed in input
      95           0 :   int seed=-1;
      96           0 :   parse("SEED",seed);
      97           0 :   if(seed>=0) plumed.getExchangePatterns().setSeed(-seed);
      98           0 : }
      99             : 
     100             : }
     101             : }
     102             : 

Generated by: LCOV version 1.16