QMCPACK
Reptile.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /*
16  * Reptile.h
17  *
18  * This class is a wrapper/utility class for groups of walkers within
19  * MCWalkerConfiguration for Reptation Monte Carlo.
20  *
21  * Walkers are stored as usual in MCWalkerConfiguration. However, this interface
22  * represents the reptile as a circular queue within a segment of the walker list.
23  */
24 
25 #ifndef QMCPLUSPLUS_REPTILE_H
26 #define QMCPLUSPLUS_REPTILE_H
27 
30 #include "Configuration.h"
31 #include "Walker.h"
32 
33 namespace qmcplusplus
34 {
35 class MCWalkerConfiguration;
36 
37 class Reptile : public QMCTraits
38 {
39 public:
42  //using Buffer_t = Walker_t::Buffer_t ;
43  // using Walker_t = MCWalkerConfiguration::Walker_t;
45  using ReptileConfig_t = std::vector<Walker_t::ParticlePos>;
46 
47  std::vector<IndexType> Action;
48  std::vector<IndexType> TransProb;
49 
54 
56 
61 
63  : w(W),
64  repstart(start),
65  repend(end),
66  direction(1),
67  headindex(0),
68  prophead(0) //, r2prop(0.0), r2accept(0.0),tau(0.0)
69  {
70  Action.resize(3);
71  Action[0] = w.addProperty("ActionBackward");
72  Action[1] = w.addProperty("ActionForward");
73  Action[2] = w.addProperty("ActionLocal");
74  TransProb.resize(2);
75  TransProb[0] = w.addProperty("TransProbBackward");
76  TransProb[1] = w.addProperty("TransProbForward");
77 
79  }
80 
81  ~Reptile() {}
82 
83  inline IndexType size() { return nbeads; }
84 
85  inline Walker_t& operator[](IndexType i) { return getWalker(getBeadIndex(i)); }
86 
87  inline IndexType wrapIndex(IndexType repindex) { return (repindex % nbeads + nbeads) % nbeads; }
88 
90  {
91  WalkerIter_t bead = repstart + wrapIndex(i);
92  return **bead;
93  }
94 
96  inline Walker_t& getBead(IndexType i) { return getWalker(getBeadIndex(i)); }
97  inline Walker_t& getHead() { return getWalker(getBeadIndex(0)); }
98  inline Walker_t& getTail() { return getWalker(getBeadIndex(nbeads - 1)); }
99  inline Walker_t& getNext() { return getWalker(getBeadIndex(nbeads - 2)); }
100  inline Walker_t& getCenter() { return getWalker(getBeadIndex((nbeads - 1) / 2)); }
101  //inline void setProposedHead(){
102 
103  inline void flip()
104  {
105  // direction*=-1;
106  // headindex = getBeadIndex(nbeads-1);
108  direction *= -1;
109  }
110 
111  inline void setDirection(IndexType dir) { direction = dir; }
112 
113  inline void setBead(Walker_t& walker, IndexType i)
114  {
115  IndexType index = getBeadIndex(i);
116  Walker_t& newbead(getWalker(index));
117  newbead = walker; //This should be a hard copy
118  }
119 
120  inline void setHead(Walker_t& overwrite)
121  {
122  //overwrite last element.
123  headindex = getBeadIndex(nbeads - 1); //sets to position of tail.
124  Walker_t& newhead(getBead(0));
125  newhead = overwrite;
126  }
127  //This function does two things: 1.) Moves the reptile forward 1 step. 2.) Returns the new head.
129  {
130  //overwrite last element.
131  headindex = getBeadIndex(nbeads - 1); //sets to position of tail.
132  return getWalker(headindex);
133  }
134 
136  {
137  //IndexType repdirection=circbuffer.get_direction();
138  IndexType actionindex = 2;
139  if (direction != 0)
140  actionindex = (1 - d * direction) / 2;
141  walker.Properties(nPsi, Action[actionindex]) = val;
142  }
143 
145  {
146  //IndexType repdirection=circbuffer.get_direction();
147  IndexType actionindex = 2;
148  if (d != 0)
149  actionindex = (1 - direction * d) / 2;
150 
151  return walker.Properties(nPsi, Action[actionindex]);
152  }
153 
154  RealType getLinkAction(Walker_t& new_walker, Walker_t& old_walker, IndexType d, IndexType nPsi = 0)
155  {
156  RealType af = getDirectionalAction(old_walker, +1, nPsi);
157  RealType ab = getDirectionalAction(new_walker, -1, nPsi);
158  RealType a0 = getDirectionalAction(old_walker, 0, nPsi) + getDirectionalAction(new_walker, 0, nPsi);
159  return af + ab + a0;
160  }
161 
163  {
164  //IndexType repdirection=circbuffer.get_direction();
165  IndexType transindex = (1 - d * direction) / 2;
166  walker.Properties(nPsi, TransProb[transindex]) = val;
167  }
168 
170  {
171  //IndexType repdirection=circbuffer.get_direction();
172  IndexType transindex = (1 - d * direction) / 2;
173  W.Properties(nPsi, TransProb[transindex]) = val;
174  }
176  {
177  //IndexType repdirection=circbuffer.get_direction();
178  IndexType transindex = (1 - d * direction) / 2;
179  return walker.Properties(nPsi, TransProb[transindex]);
180  }
182  {
183  //IndexType repdirection=circbuffer.get_direction();
184  IndexType transindex = (1 - d * direction) / 2;
185  return W.Properties(nPsi, TransProb[transindex]);
186  }
187 
188  inline void printState()
189  {
190  app_log() << "********PRINT REPTILE STATE*********\n";
191  app_log() << "Direction=" << direction << " Headindex=" << headindex << " tail=" << getBeadIndex(nbeads - 1)
192  << "\n next=" << getBeadIndex(nbeads - 2) << " nbeads=" << nbeads << std::endl;
193  app_log() << "BeadIndex\tWrapIndex\tEnergy\tAction[0]\tAction[1]\tAction[2]\t\n";
194  for (int i = 0; i < nbeads; i++)
195  {
196  app_log() << i << "\t" << getBeadIndex(i) << "\t" << getBead(i).Properties(WP::LOCALENERGY) << "\t"
197  << getBead(i).Properties(Action[0]) << "\t" << getBead(i).Properties(Action[1]) << "\t"
198  << getBead(i).Properties(Action[2]) << "\n";
199  }
200  app_log() << "POSITIONS===============:\n";
201  for (int i = 0; i < nbeads; i++)
202  {
203  // app_log()<<i<<"\t1"<<1<<"\t"<<getBead(i).R[0]<<"\n";
204  // app_log()<<i<<"\t2"<<2<<"\t"<<getBead(i).R[1]<<"\n";
205  app_log() << "BEAD #" << i << " tau = " << tau * i << std::endl;
206  app_log() << getBead(i).R << std::endl;
207  }
208  app_log() << "GVECS===============:\n";
209  for (int i = 0; i < nbeads; i++)
210  {
211  // app_log()<<i<<"\t1"<<1<<"\t"<<getBead(i).G[0]<<"\n";
212  // app_log()<<i<<"\t2"<<2<<"\t"<<getBead(i).G[1]<<"\n";
213  app_log() << "BEAD #" << i << " tau = " << tau * i << std::endl;
214  app_log() << getBead(i).G << std::endl;
215  }
216  app_log() << "************************************\n";
217  }
218  inline RealType getTau() { return tau; }
219  inline void setTau(RealType t) { tau = t; }
220 
221 
222  //This takes a value of imaginary time "t" and returns a 3N particle position vector, corresponding to a time slice extrapolated
223  // from the current reptile. If t>length of reptile, then return the last bead. if t<0; return the first bead.
225  {
226  IndexType nbead =
227  IndexType(t / tau); //Calculate the lower bound on the timeslice. t is between binnum*Tau and (binnum+1)Tau
228  RealType beadfrac = t / tau - nbead; //the fractional coordinate between n and n+1 bead
229  if (nbead <= 0)
230  {
232  return result;
233  }
234  else if (nbead >= nbeads - 1)
235  {
237  return result;
238  }
239 
240  else
241  {
242  Walker_t::ParticlePos dR(getBead(nbead + 1).R), interpR(getBead(nbead).R);
243  dR = dR - getBead(nbead).R;
244 
245  interpR = getBead(nbead).R + beadfrac * dR;
246  return interpR;
247  }
248  }
250  {
251  IndexType nbeads_new = IndexType(beta / tau);
252  ReptileConfig_t new_reptile_coords(0);
253 
254  for (IndexType i = 0; i < nbeads_new; i++)
255  new_reptile_coords.push_back(linearInterp(tau * i));
256 
257  return new_reptile_coords;
258  }
259 
261  {
262  if (rept.size() == nbeads)
263  {
264  for (int i = 0; i < nbeads; i++)
265  getBead(i).R = rept[i];
266  }
267  else
268  ;
269  }
270 
272  {
273  for (int i = 0; i < nbeads; i++)
274  getBead(i).R = R;
275  }
276 };
277 
278 
279 } // namespace qmcplusplus
280 #endif
ReptileConfig_t getReptileSlicePositions(RealType tau, RealType beta)
Definition: Reptile.h:249
PropertyContainer_t Properties
scalar properties of a walker
Definition: Walker.h:125
A set of walkers that are to be advanced by Metropolis Monte Carlo.
void setReptileSlicePositions(ReptileConfig_t &rept)
Definition: Reptile.h:260
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Walker_t & operator[](IndexType i)
Definition: Reptile.h:85
PropertyContainer_t Properties
properties of the current walker
Definition: ParticleSet.h:119
Walker_t & getTail()
Definition: Reptile.h:98
QTBase::RealType RealType
Definition: Configuration.h:58
typename p_traits::ParticlePos ParticlePos
array of particles
Definition: Walker.h:64
RealType getDirectionalAction(Walker_t &walker, IndexType d, IndexType nPsi=0)
Definition: Reptile.h:144
RealType backwardaction
Definition: Reptile.h:53
std::ostream & app_log()
Definition: OutputManager.h:65
int addProperty(const std::string &pname)
Definition: ParticleSet.h:411
RealType forwardprob
Definition: Reptile.h:50
RealType backwardprob
Definition: Reptile.h:51
void setHead(Walker_t &overwrite)
Definition: Reptile.h:120
Walker_t & getNewHead()
Definition: Reptile.h:128
RealType forwardaction
Definition: Reptile.h:52
RealType getTransProb(ParticleSet &W, IndexType d, RealType nPsi=0)
Definition: Reptile.h:181
IndexType wrapIndex(IndexType repindex)
Definition: Reptile.h:87
Walker_t & getCenter()
Definition: Reptile.h:100
Attaches a unit to a Vector for IO.
QMCTraits::IndexType IndexType
Definition: FSUtilities.h:11
std::vector< IndexType > TransProb
Definition: Reptile.h:48
void setReptileSlicePositions(Walker_t::ParticlePos R)
Definition: Reptile.h:271
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
WalkerList_t::iterator iterator
FIX: a type alias of iterator for an object should not be for just one of many objects it holds...
Walker_t::ParticlePos linearInterp(RealType t)
Definition: Reptile.h:224
std::vector< IndexType > Action
Definition: Reptile.h:47
IndexType getBeadIndex(IndexType i)
Definition: Reptile.h:95
void saveTransProb(ParticleSet &W, IndexType d, RealType val, IndexType nPsi=0)
Definition: Reptile.h:169
RealType getLinkAction(Walker_t &new_walker, Walker_t &old_walker, IndexType d, IndexType nPsi=0)
Definition: Reptile.h:154
void setDirection(IndexType dir)
Definition: Reptile.h:111
MCWalkerConfiguration & w
Definition: Reptile.h:57
RealType getTau()
Definition: Reptile.h:218
Walker_t & getNext()
Definition: Reptile.h:99
OHMMS_INDEXTYPE IndexType
define other types
Definition: Configuration.h:65
Walker_t & getBead(IndexType i)
Definition: Reptile.h:96
Walker_t * prophead
Definition: Reptile.h:60
IndexType headindex
Definition: Reptile.h:59
WalkerConfigurations::Walker_t Walker_t
Reptile(MCWalkerConfiguration &W, WalkerIter_t start, WalkerIter_t end)
Definition: Reptile.h:62
Indexes
an enum denoting index of physical properties
WalkerIter_t repend
Definition: Reptile.h:58
void setTau(RealType t)
Definition: Reptile.h:219
Walker_t & getHead()
Definition: Reptile.h:97
Walker_t & getWalker(IndexType i)
Definition: Reptile.h:89
void saveAction(Walker_t &walker, IndexType d, RealType val, IndexType nPsi=0)
Definition: Reptile.h:135
std::vector< Walker_t::ParticlePos > ReptileConfig_t
Definition: Reptile.h:45
traits for QMC variables
Definition: Configuration.h:49
MCWalkerConfiguration::iterator WalkerIter_t
Definition: Reptile.h:44
void saveTransProb(Walker_t &walker, IndexType d, RealType val, IndexType nPsi=0)
Definition: Reptile.h:162
WalkerIter_t repstart
Definition: Reptile.h:58
void setBead(Walker_t &walker, IndexType i)
Definition: Reptile.h:113
IndexType nbeads
Definition: Reptile.h:59
A container class to represent a walker.
Definition: Walker.h:49
ParticlePos R
The configuration vector (3N-dimensional vector to store the positions of all the particles for a sin...
Definition: Walker.h:114
IndexType size()
Definition: Reptile.h:83
RealType getTransProb(Walker_t &walker, IndexType d, RealType nPsi=0)
Definition: Reptile.h:175
IndexType direction
Definition: Reptile.h:59