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 exchanges between replicas with consecutive indices and instead 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 SEED=23 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 : 82 : Multi replica simulations are presently only working with gromacs. 83 : 84 : !!! caution "" 85 : 86 : The directive should appear in the input file for every replica. If SEED is specified, it 87 : should be the same in all input files. 88 : 89 : */ 90 : //+ENDPLUMEDOC 91 : 92 : class RandomExchanges: 93 : public Action { 94 : public: 95 : static void registerKeywords( Keywords& keys ); 96 : explicit RandomExchanges(const ActionOptions&ao); 97 0 : void calculate() override {} 98 0 : void apply() override {} 99 : }; 100 : 101 : PLUMED_REGISTER_ACTION(RandomExchanges,"RANDOM_EXCHANGES") 102 : 103 4 : void RandomExchanges::registerKeywords( Keywords& keys ) { 104 4 : Action::registerKeywords(keys); 105 4 : keys.add("optional","SEED","seed for random exchanges"); 106 4 : keys.addDOI("10.1021/jp067873l"); 107 4 : } 108 : 109 0 : RandomExchanges::RandomExchanges(const ActionOptions&ao): 110 0 : Action(ao) { 111 0 : plumed.getExchangePatterns().setFlag(ExchangePatterns::RANDOM); 112 : // I convert the seed to -seed because I think it is more general to use a positive seed in input 113 0 : int seed=-1; 114 0 : parse("SEED",seed); 115 0 : if(seed>=0) { 116 0 : plumed.getExchangePatterns().setSeed(-seed); 117 : } 118 0 : } 119 : 120 : } 121 : } 122 :