LCOV - code coverage report
Current view: top level - generic - RandomExchanges.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 5 15 33.3 %
Date: 2025-04-08 21:11:17 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             : This command is typically used if you are using the bias exchange method that is
      36             : discussed in the paper in the bibliography.  When it is present it tells PLUMED
      37             : not do do exchanges between replicas with consecutive indices and instad to use
      38             : use a random pattern.
      39             : 
      40             : The following three example input files show how one can run a bias exchange
      41             : metadynamics simulation using a different angle in each replica.
      42             : Exchanges are randomly tried between replicas 0-1, 0-2 and 1-2
      43             : 
      44             : Here is plumed.0.dat
      45             : 
      46             : ```plumed
      47             : RANDOM_EXCHANGES
      48             : t: TORSION ATOMS=1,2,3,4
      49             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      50             : ```
      51             : 
      52             : Here is plumed.1.dat
      53             : 
      54             : ```plumed
      55             : RANDOM_EXCHANGES
      56             : t: TORSION ATOMS=2,3,4,5
      57             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      58             : ```
      59             : 
      60             : Here is plumed.2.dat
      61             : 
      62             : ```plumed
      63             : RANDOM_EXCHANGES
      64             : t: TORSION ATOMS=3,4,5,6
      65             : METAD ARG=t HEIGHT=0.1 PACE=100 SIGMA=0.3
      66             : ```
      67             : 
      68             : Notice that you can perform the same calculation with the following single PLUMED input file:
      69             : 
      70             : ```plumed
      71             : #SETTINGS NREPLICAS=3
      72             : 
      73             : RANDOM_EXCHANGES
      74             : t1: TORSION ATOMS=1,2,3,4
      75             : t2: TORSION ATOMS=2,3,4,5
      76             : t3: TORSION ATOMS=3,4,5,6
      77             : METAD ARG=@replicas:t1,t2,t3 HEIGHT=0.1 PACE=100 SIGMA=0.3
      78             : ```
      79             : 
      80             : > [!CAUTION]
      81             : > Multi replica simulations are presently only working with gromacs.
      82             : 
      83             : > [!CAUTION]
      84             : > The directive should appear in the input file for every replica. If SEED is specified, it
      85             : > should be the same in all input files.
      86             : 
      87             : */
      88             : //+ENDPLUMEDOC
      89             : 
      90             : class RandomExchanges:
      91             :   public Action {
      92             : public:
      93             :   static void registerKeywords( Keywords& keys );
      94             :   explicit RandomExchanges(const ActionOptions&ao);
      95           0 :   void calculate() override {}
      96           0 :   void apply() override {}
      97             : };
      98             : 
      99             : PLUMED_REGISTER_ACTION(RandomExchanges,"RANDOM_EXCHANGES")
     100             : 
     101           2 : void RandomExchanges::registerKeywords( Keywords& keys ) {
     102           2 :   Action::registerKeywords(keys);
     103           2 :   keys.add("optional","SEED","seed for random exchanges");
     104           2 :   keys.addDOI("10.1021/jp067873l");
     105           2 : }
     106             : 
     107           0 : RandomExchanges::RandomExchanges(const ActionOptions&ao):
     108           0 :   Action(ao) {
     109           0 :   plumed.getExchangePatterns().setFlag(ExchangePatterns::RANDOM);
     110             : // I convert the seed to -seed because I think it is more general to use a positive seed in input
     111           0 :   int seed=-1;
     112           0 :   parse("SEED",seed);
     113           0 :   if(seed>=0) {
     114           0 :     plumed.getExchangePatterns().setSeed(-seed);
     115             :   }
     116           0 : }
     117             : 
     118             : }
     119             : }
     120             : 

Generated by: LCOV version 1.16