QMCPACK
OneBodyDensityMatrices.cpp
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) 2021 QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 // Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File refactored from: QMCHamiltonians/DensityMatrices1B.cpp
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 #include "OneBodyDensityMatrices.h"
15 #include "OhmmsData/AttributeSet.h"
19 #include "Utilities/string_utils.h"
21 #include "Concurrency/OpenMP.h"
22 #include "CPU/math.hpp"
23 
24 namespace qmcplusplus
25 {
29 
31  const Lattice& lattice,
32  const SpeciesSet& species,
33  const SPOMap& spomap,
34  const ParticleSet& pset_target)
36  input_(obdmi),
37  lattice_(lattice),
38  species_(species),
39  basis_functions_("OneBodyDensityMatrices::basis"),
40  is_spinor_(pset_target.isSpinor()),
41  timers_("OneBodyDensityMatrix")
42 {
43  my_name_ = "OneBodyDensityMatrices";
44  lattice_.reset();
45 
47  {
50  }
51  else
52  {
55  else
58  }
59 
62 
63  // Here we discover sampling is derived (this may belong in input class)
64  switch (input_.get_integrator())
65  {
71  for (int d = 1; d < OHMMS_DIM; ++d)
72  ind_dims_[d] = ind_dims_[d - 1] / input_.get_points();
73  break;
78  break;
82  metric_ = 1.0 / samples_;
83  break;
84  }
85  rsamples_.resize(samples_);
86  if (is_spinor_)
87  ssamples_.resize(samples_);
88 
90  throw UniformCommunicateError("OneBodyDensityMatrices::OneBodyDensityMatrices only density sampling implemented "
91  "for calculations using spinors");
92 
93 
94  // get the sposets that form the basis
95  auto& sposets = input_.get_basis_sets();
96 
97  for (int i = 0; i < sposets.size(); ++i)
98  {
99  auto spo_it = spomap.find(sposets[i]);
100  if (spo_it == spomap.end())
101  throw UniformCommunicateError("OneBodyDensityMatrices::OneBodyDensityMatrices sposet " + sposets[i] +
102  " does not exist.");
103  basis_functions_.add(spo_it->second->makeClone());
104  }
106 
107  if (basis_size_ < 1)
108  throw UniformCommunicateError("OneBodyDensityMatrices::OneBodyDensityMatrices basis_size must be greater than one");
109 
110  int nspecies = species.size();
111  if (!species_.hasAttribute("membersize"))
112  throw UniformCommunicateError("OneBodyDensityMatrices::OneBodyDensityMatrices error: Species set does not have the "
113  "required attribute 'membersize'");
114  int isize = species.getAttribute("membersize");
115  // We have the count per species at least a fundamental as the total particles.
116  // the sum of species membersize and total particles should be an invariant.
117  int nparticles = 0;
118  for (int s = 0; s < nspecies; ++s)
119  nparticles += species(isize, s);
120  for (int s = 0; s < nspecies; ++s)
121  species_sizes_.push_back(species(isize, s));
122  for (int s = 0; s < nspecies; ++s)
123  species_names_.push_back(species.speciesName[s]);
124 
127 
128  Real bn_standard = 1.0;
130  bn_standard = 1.0 / std::sqrt(volume_);
131  for (int i = 0; i < basis_size_; ++i)
132  basis_norms_[i] = bn_standard;
133 
135  psi_ratios_.resize(nparticles);
136 
138  {
140  Phi_NB_.reserve(nspecies);
141  Psi_NM_.reserve(nspecies);
142  Phi_Psi_NB_.reserve(nspecies);
143  N_BB_.reserve(nspecies);
144  for (int s = 0; s < nspecies; ++s)
145  {
146  int specs_size = species_sizes_[s];
147  Phi_NB_.emplace_back(specs_size, basis_size_);
148  Psi_NM_.emplace_back(specs_size, samples_);
149  Phi_Psi_NB_.emplace_back(specs_size, basis_size_);
150  N_BB_.emplace_back(basis_size_, basis_size_);
151  }
152  }
153 
155  {
158  if (is_spinor_)
160  }
161 
162  // so if the input is not normalized, normalize it.
163  // with respect to what?
164  if (!input_.get_normalized())
165  {
166  //Since the following is not a const method we copy particle set
167  ParticleSet pset_temp(pset_target);
168  normalizeBasis(pset_temp);
169  }
170 
172 }
173 
175  : OneBodyDensityMatrices(obdm)
176 {
177  data_locality_ = dl;
178 }
179 
180 std::unique_ptr<OperatorEstBase> OneBodyDensityMatrices::spawnCrowdClone() const
181 {
182  std::size_t data_size = data_.size();
183  auto spawn_data_locality = data_locality_;
184 
186  {
187  // This is just a stub until a memory saving optimization is deemed necessary
188  spawn_data_locality = DataLocality::queue;
189  data_size = 0;
190  throw std::runtime_error("There is no memory savings implementation for OneBodyDensityMatrices");
191  }
192 
193  auto spawn = std::make_unique<OneBodyDensityMatrices>(*this, spawn_data_locality);
194  spawn->get_data().resize(data_size, 0.0);
195  return spawn;
196 }
197 
198 size_t OneBodyDensityMatrices::calcFullDataSize(const size_t basis_size, const int nspecies)
199 {
200  if constexpr (IsComplex_t<Value>::value)
201  return 2 * basis_size * basis_size * nspecies;
202  else
203  return basis_size * basis_size * nspecies;
204 }
205 
207 
211  int steps)
212 {
214 
215  // Steps will always be 0 unless these are samples for warmup which is only for metropolis
216  // This is not a clear way to write this
217  // \todo rewrite to make algorithm more clears
218  bool save = false;
219  if (steps == 0)
220  {
221  save = true;
222  steps = samples_;
223  }
224 
225  switch (input_.get_integrator())
226  {
228  generateUniformGrid(rng);
229  break;
230  case Integrator::UNIFORM:
232  break;
233  case Integrator::DENSITY:
234  if (is_spinor_)
235  generateDensitySamplesWithSpin(save, steps, rng, pset_target);
236  else
237  generateDensitySamples(save, steps, rng, pset_target);
238  break;
239  }
240 
241  if (save)
242  {
244  samples_weights_ *= weight;
245  else
246  {
247  std::fill(samples_weights_.begin(), samples_weights_.end(), weight);
248  }
249  }
250 
251  // optional check
252  if (input_.get_rstats() && omp_get_thread_num() == 0)
253  {
254  Position rmin = std::numeric_limits<Real>::max();
255  Position rmax = -std::numeric_limits<Real>::max();
256  Position rmean = 0.0;
257  Position rstd = 0.0;
258  for (int s = 0; s < rsamples_.size(); ++s)
259  for (int d = 0; d < OHMMS_DIM; ++d)
260  {
261  Real rd = rsamples_[s][d];
262  rmin[d] = std::min(rmin[d], rd);
263  rmax[d] = std::max(rmax[d], rd);
264  rmean[d] += rd;
265  rstd[d] += rd * rd;
266  }
267  rmean /= rsamples_.size();
268  rstd /= rsamples_.size();
269  for (int d = 0; d < OHMMS_DIM; ++d)
270  rstd[d] = std::sqrt(rstd[d] - rmean[d] * rmean[d]);
271  app_log() << "\nrsamples properties:" << std::endl;
272  app_log() << " rmin = " << rmin << std::endl;
273  app_log() << " rmax = " << rmax << std::endl;
274  app_log() << " rmean = " << rmean << std::endl;
275  app_log() << " rstd = " << rstd << std::endl;
276  }
277 }
278 
280 {
281  Position rp;
282  Position ushift = 0.0;
284  for (int d = 0; d < OHMMS_DIM; ++d)
285  ushift[d] += rng() * du;
286  for (int s = 0; s < samples_; ++s)
287  {
288  int nrem = s;
289  for (int d = 0; d < OHMMS_DIM - 1; ++d)
290  {
291  int ind = nrem / ind_dims_[d];
292  rp[d] = ind * du + ushift[d];
293  nrem -= ind * ind_dims_[d];
294  }
295  rp[OHMMS_DIM - 1] = nrem * du + ushift[OHMMS_DIM - 1];
297  }
298 }
299 
301 {
302  Position rp;
303  for (int s = 0; s < samples_; ++s)
304  {
305  for (int d = 0; d < OHMMS_DIM; ++d)
306  rp[d] = input_.get_scale() * rng();
308  }
309 }
310 
312  int steps,
315 {
316  const auto timestep = input_.get_timestep();
317  Real sqt = std::sqrt(timestep);
318  Real ot = 1.0 / timestep;
319  Position r = rpcur_; //current position
320  Position d = dpcur_; //current drift
321  Real rho = rhocur_; //current density
322  for (int s = 0; s < steps; ++s)
323  {
324  nmoves_++;
325  Position rp; // trial pos
326  Position dp; // trial drift
327  Position ds; // drift sum
328  Real rhop; // trial density
329  Real ratio; // dens ratio
330  Real Pacc; // acc prob
331  Position diff = diffuse(sqt, rng); // get diffusion
332  if (input_.get_use_drift())
333  {
334  rp = r + diff + d; //update trial position
335  calcDensityDrift(rp, rhop, dp, pset_target); //get trial drift and density
336  ratio = rhop / rho; //density ratio
337  ds = dp + d; //drift sum
338  Pacc = ratio * std::exp(-ot * (dot(diff, ds) + .5 * dot(ds, ds))); //acceptance probability
339  }
340  else
341  {
342  rp = r + diff; //update trial position
343  calcDensity(rp, rhop, pset_target); //get trial density
344  ratio = rhop / rho; //density ratio
345  Pacc = ratio; //acceptance probability
346  }
347  if (rng() < Pacc)
348  { //accept move
349  r = rp;
350  d = dp;
351  rho = rhop;
352  naccepted_++;
353  }
354  if (save)
355  {
356  rsamples_[s] = r;
357  samples_weights_[s] = 1.0 / rho;
358  }
359  }
361 
363  app_log() << "dm1b acceptance_ratio = " << acceptance_ratio_ << std::endl;
364 
365  rpcur_ = r;
366  dpcur_ = d;
367  rhocur_ = rho;
368 }
369 
371  int steps,
374 {
375  const auto timestep = input_.get_timestep();
376  Real sqt = std::sqrt(timestep);
377  Real ot = 1.0 / timestep;
378  Position r = rpcur_; //current position
379  Position d = dpcur_; //current drift
380  Real rho = rhocur_; //current density
381  for (int s = 0; s < steps; ++s)
382  {
383  nmoves_++;
384  Position rp; // trial pos
385  Position dp; // trial drift
386  Position ds; // drift sum
387  Real rhop; // trial density
388  Real ratio; // dens ratio
389  Real Pacc; // acc prob
390  Position diff = diffuse(sqt, rng); // get diffusion
391 
392  //now do spin variables
393  Real spinp; // trial spin
394  Real dspinp = 0; // trial spindrifty
395  Real sdiff = diffuseSpin(sqt, rng); //spin diffusion
396  if (input_.get_use_drift())
397  {
398  rp = r + diff + d; //update trial position
399  spinp = spcur_ + sdiff + dspcur_; //update trial spin
400  calcDensityDriftWithSpin(rp, spinp, rhop, dp, dspinp, pset_target); //get trial drift and density
401  ratio = rhop / rho; //density ratio
402  ds = dp + d; //drift sum
403  auto spin_ds = dspinp + dspcur_; //spin drift sum
404  Pacc = ratio * std::exp(-ot * (dot(diff, ds) + .5 * dot(ds, ds))) *
405  std::exp(-ot * (sdiff * spin_ds) + 0.5 * spin_ds * spin_ds); //acceptance probability
406  }
407  else
408  {
409  rp = r + diff; //update trial position
410  spinp = spcur_ + sdiff; //update trial spin
411  calcDensityWithSpin(rp, spinp, rhop, pset_target); //get trial density
412  ratio = rhop / rho; //density ratio
413  Pacc = ratio; //acceptance probability
414  }
415  if (rng() < Pacc)
416  { //accept move
417  r = rp;
418  d = dp;
419  spcur_ = spinp;
420  dspcur_ = dspinp;
421  rho = rhop;
422  naccepted_++;
423  }
424  if (save)
425  {
426  rsamples_[s] = r;
427  samples_weights_[s] = 1.0 / rho;
428  ssamples_[s] = spcur_;
429  }
430  }
432 
434  app_log() << "dm1b acceptance_ratio = " << acceptance_ratio_ << std::endl;
435 
436  rpcur_ = r;
437  dpcur_ = d;
438  rhocur_ = rho;
439 }
440 
442 {
443  Position diff;
444  assignGaussRand(&diff[0], OHMMS_DIM, rng);
445  diff *= sqt;
446  return diff;
447 }
448 
450 {
451  Real diff;
452  assignGaussRand(&diff, 1, rng);
453  diff *= sqt;
454  return diff;
455 }
456 
458 {
460  dens = 0.0;
461  for (int i = 0; i < basis_size_; ++i)
462  {
463  Value b = basis_values_[i];
464  dens += std::abs(qmcplusplus::conj(b) * b);
465  }
466  dens /= basis_size_;
467 }
468 
470  const Real& s,
471  Real& dens,
473 {
475  dens = 0.0;
476  for (int i = 0; i < basis_size_; ++i)
477  {
478  Value b = basis_values_[i];
479  dens += std::abs(qmcplusplus::conj(b) * b);
480  }
481  dens /= basis_size_;
482 }
483 
485 {
487  dens = 0.0;
488  drift = 0.0;
489  for (int i = 0; i < basis_size_; ++i)
490  {
491  const Grad& bg = basis_gradients_[i];
492  Value b = basis_values_[i];
493  Value bc = qmcplusplus::conj(b);
494  dens += std::abs(bc * b);
495  for (int d = 0; d < OHMMS_DIM; ++d)
496  drift[d] += std::real(bc * bg[d]);
497  }
498  drift *= input_.get_timestep() / dens;
499  dens /= basis_size_;
500 }
501 
503  const Real& s,
504  Real& dens,
505  Position& drift,
506  Real& sdrift,
508 {
510  dens = 0.0;
511  drift = 0.0;
512  sdrift = 0.0;
513  for (int i = 0; i < basis_size_; ++i)
514  {
515  const Grad& bg = basis_gradients_[i];
516  const Value& bsg = basis_spin_gradients_[i];
517  Value b = basis_values_[i];
518  Value bc = qmcplusplus::conj(b);
519  dens += std::abs(bc * b);
520  for (int d = 0; d < OHMMS_DIM; ++d)
521  drift[d] += std::real(bc * bg[d]);
522  sdrift += std::real(bc * bsg);
523  }
524  drift *= input_.get_timestep() / dens;
525  sdrift *= input_.get_timestep() / dens;
526  dens /= basis_size_;
527 }
528 
530  const RefVector<ParticleSet>& psets,
531  const RefVector<TrialWaveFunction>& wfns,
532  const RefVector<QMCHamiltonian>& hams,
534 {
535  implAccumulate(walkers, psets, wfns, rng);
536 }
537 
539  const RefVector<ParticleSet>& psets,
540  const RefVector<TrialWaveFunction>& wfns,
542 {
543  for (int iw = 0; iw < walkers.size(); ++iw)
544  {
545  walkers_weight_ += walkers[iw].get().Weight;
546  evaluateMatrix(psets[iw], wfns[iw], walkers[iw], rng);
547  }
548 }
549 
551  TrialWaveFunction& psi_target,
552  const MCPWalker& walker,
554 {
555  //perform warmup sampling the first time
557  // get weight and single particle energy trace data
558  Real weight = walker.Weight * metric_;
559 
560  // compute sample positions (monte carlo or deterministic)
561  generateSamples(weight, pset_target, rng);
562  // compute basis and wavefunction ratio values in matrix form
563  generateSampleBasis(Phi_MB_, pset_target, psi_target); // basis : samples x basis_size
564  generateSampleRatios(pset_target, psi_target, Psi_NM_); // conj(Psi ratio) : particles x samples
565  generateParticleBasis(pset_target, Phi_NB_); // conj(basis) : particles x basis_size
566 
567  // \todo separate testable and optimizable block, should be function
568  // perform integration via matrix products
569  {
571  for (int s = 0; s < species_.size(); ++s)
572  {
573  Matrix<Value>& Psi_nm = Psi_NM_[s];
574  Matrix<Value>& Phi_Psi_nb = Phi_Psi_NB_[s];
575  Matrix<Value>& Phi_nb = Phi_NB_[s];
576  diag_product(Psi_nm, samples_weights_, Psi_nm);
577  product(Psi_nm, Phi_MB_, Phi_Psi_nb); // ratio*basis : particles x basis_size
578  product_AtB(Phi_nb, Phi_Psi_nb, N_BB_[s]); // conj(basis)^T*ratio*basis : basis_size^2
579  }
580  }
581  // accumulate data for this walker
582  {
583  ScopedTimer local_timer(timers_.accumulate_timer);
584  const int basis_size_sq = basis_size_ * basis_size_;
585  int ij = 0;
586  for (int s = 0; s < species_.size(); ++s)
587  {
588  //int ij=nindex; // for testing
589  const Matrix<Value>& NDM = N_BB_[s];
590  for (int n = 0; n < basis_size_sq; ++n)
591  {
592  Value val = NDM(n);
593  data_[ij] += real(val);
594  ij++;
595 #if defined(QMC_COMPLEX)
596  data_[ij] += imag(val);
597  ij++;
598 #endif
599  }
600  }
601  }
602 }
603 
605 {
607  int p = 0;
608  for (int s = 0; s < species_.size(); ++s)
609  {
610  int nb = 0;
611  Matrix<Value>& P_nb = phi_nb[s];
612  for (int n = 0; n < species_sizes_[s]; ++n, ++p)
613  {
614  if (is_spinor_)
616  else
618  for (int b = 0; b < basis_size_; ++b, ++nb)
619  P_nb(nb) = qmcplusplus::conj(basis_values_[b]);
620  }
621  }
622 }
623 
626  TrialWaveFunction& psi_target)
627 {
629  int mb = 0;
630  for (int m = 0; m < samples_; ++m)
631  {
632  if (is_spinor_)
634  else
636  for (int b = 0; b < basis_size_; ++b, ++mb)
637  Phi_mb(mb) = basis_values_[b];
638  }
639 }
640 
642  TrialWaveFunction& psi_target,
643  std::vector<Matrix<Value>>& psi_nm)
644 {
646  for (int m = 0; m < samples_; ++m)
647  {
648  // get N ratios for the current sample point
649  if (!is_spinor_)
650  {
651  pset_target.makeVirtualMoves(rsamples_[m]);
653  }
654  else
655  {
656  //note: makeVirtualMoves updates distance tables
657  //There is not a corresponding "distance table" for the spins, so we need to brute force this by moving each electron and using makeMoveWithSpin, calcRatio, and rejectMove, and resetPhaseDiff, similar to how NonLocalECP works for evaluating quadrature points without virtual particles
658  int p = 0;
659  for (int s = 0; s < species_.size(); ++s)
660  for (int n = 0; n < species_sizes_[s]; ++n, ++p)
661  {
662  pset_target.makeMoveWithSpin(p, rsamples_[m] - pset_target.R[p], ssamples_[m] - pset_target.spins[p]);
663  psi_ratios_[p] = psi_target.calcRatio(pset_target, p);
664  pset_target.rejectMove(p);
665  psi_target.resetPhaseDiff();
666  }
667  }
668 
669  // collect ratios into per-species matrices
670  int p = 0;
671  for (int s = 0; s < species_.size(); ++s)
672  {
673  Matrix<Value>& P_nm = psi_nm[s];
674  for (int n = 0; n < species_sizes_[s]; ++n, ++p)
675  {
676  P_nm(n, m) = qmcplusplus::conj(psi_ratios_[p]);
677  }
678  }
679  }
680 }
681 
683 {
684  // This is ridiculous in the case of splines, still necessary for hybrid/LCAO
685  pset_target.makeMove(0, r - pset_target.R[0]);
687  pset_target.rejectMove(0);
688  for (int i = 0; i < basis_size_; ++i)
689  basis_values_[i] *= basis_norms_[i];
690 }
691 
693 {
694  // This is ridiculous in the case of splines, still necessary for hybrid/LCAO
695  pset_target.makeMoveWithSpin(0, r - pset_target.R[0], s - pset_target.spins[0]);
697  pset_target.rejectMove(0);
698  for (int i = 0; i < basis_size_; ++i)
699  basis_values_[i] *= basis_norms_[i];
700 }
701 
703 {
704  pset_target.makeMove(0, r - pset_target.R[0]);
706  pset_target.rejectMove(0);
707  for (int i = 0; i < basis_size_; ++i)
708  basis_values_[i] *= basis_norms_[i];
709  for (int i = 0; i < basis_size_; ++i)
711  for (int i = 0; i < basis_size_; ++i)
713 }
714 
716 {
717  pset_target.makeMoveWithSpin(0, r - pset_target.R[0], s - pset_target.spins[0]);
720  pset_target.rejectMove(0);
721  for (int i = 0; i < basis_size_; ++i)
722  {
723  basis_values_[i] *= basis_norms_[i];
727  }
728 }
729 
731 {
733  {
734  if (!warmed_up_)
735  {
737  rpcur_ += center_;
738  if (!is_spinor_)
740  else
741  {
744  }
745  }
747  warmed_up_ = true;
748  }
749 }
750 
752 {
753  int ngrid = std::max(200, input_.get_points());
754  int ngtot = pow(ngrid, OHMMS_DIM);
755  Real du = input_.get_scale() / ngrid;
756  Real dV = volume_ / ngtot;
757  Position rp;
758  Vector<Value> bnorms;
759  int gdims[OHMMS_DIM];
760  gdims[0] = pow(ngrid, OHMMS_DIM - 1);
761  for (int d = 1; d < OHMMS_DIM; ++d)
762  gdims[d] = gdims[d - 1] / ngrid;
763  bnorms.resize(basis_size_);
764  for (int i = 0; i < basis_size_; ++i)
765  bnorms[i] = 0.0;
766  std::fill(basis_norms_.begin(), basis_norms_.end(), 1.0);
767  for (int p = 0; p < ngtot; ++p)
768  {
769  int nrem = p;
770  for (int d = 0; d < OHMMS_DIM - 1; ++d)
771  {
772  int ind = nrem / gdims[d];
773  rp[d] = ind * du + du / 2;
774  nrem -= ind * gdims[d];
775  }
776  rp[OHMMS_DIM - 1] = nrem * du + du / 2;
777  rp = lattice_.toCart(rp) + rcorner_;
779  for (int i = 0; i < basis_size_; ++i)
780  bnorms[i] += qmcplusplus::conj(basis_values_[i]) * basis_values_[i] * dV;
781  }
782  for (int i = 0; i < basis_size_; ++i)
783  basis_norms_[i] = 1.0 / std::sqrt(real(bnorms[i]));
784 }
785 
787 {
788  std::vector<int> my_indexes(2, basis_size_);
789  if constexpr (IsComplex_t<Value>::value)
790  {
791  my_indexes.push_back(2);
792  }
793  int nentries = std::accumulate(my_indexes.begin(), my_indexes.end(), 1);
794 
795  int spin_data_size = 0;
796  if constexpr (IsComplex_t<Value>::value)
797  spin_data_size = 2 * basis_size_ * basis_size_;
798  else
799  spin_data_size = basis_size_ * basis_size_;
800 
801  hdf_path hdf_name{my_name_};
802  hdf_name /= "number_matrix";
803  for (int s = 0; s < species_.size(); ++s)
804  {
805  h5desc_.emplace_back(hdf_name / species_.speciesName[s]);
806  auto& oh = h5desc_.back();
807  oh.set_dimensions(my_indexes, s * spin_data_size);
808  }
809 }
810 
811 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
a class that defines a supercell in D-dimensional Euclean space.
void generateSampleRatios(ParticleSet &pset_target, TrialWaveFunction &psi_target, std::vector< Matrix< Value >> &Psi_nm)
int SuperCellEnum
supercell enumeration
SingleParticlePos Center
Center of the cell sum(Rv[i])/2.
std::vector< std::string > species_names_
Real acceptance_ratio_
running acceptance ratio over all samples
ValueType calcRatio(ParticleSet &P, int iat, ComputeType ct=ComputeType::ALL)
compute psi(R_new) / psi(R_current) ratio It returns a complex value if the wavefunction is complex...
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios)
QMCTraits::RealType real
void reset()
Evaluate the reciprocal vectors, volume and metric tensor.
void updateBasisD012(const Position &r, ParticleSet &pset_target)
evaluates vgl on basis_functions_ for r sideeffects:
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool hasAttribute(const std::string &aname) const
Check for attribute presence This replaces code that gets numAttributes then tries to addAttribute fo...
Definition: SpeciesSet.cpp:70
std::vector< ObservableHelper > h5desc_
Position center_
If not defined in OBDMI taken from lattice_.
Per crowd Estimator for OneBodyDensityMatrices aka 1RDM DensityMatrices1B.
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
void accumulate(const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, const RefVector< QMCHamiltonian > &hams, RandomBase< FullPrecReal > &rng) override
std::ostream & app_log()
Definition: OutputManager.h:65
void calcDensity(const Position &r, Real &dens, ParticleSet &pset_target)
calculate density based on r
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
int size() const
return the size of the orbital set Ye: this needs to be replaced by getOrbitalSetSize(); ...
Definition: SPOSet.h:75
std::unique_ptr< OperatorEstBase > spawnCrowdClone() const override
class to handle hdf file
Definition: hdf_archive.h:51
const char walkers[]
Definition: HDFVersion.h:36
Position rcorner_
with respect to center_ using lattice_;
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
std::vector< Matrix< Value > > Phi_NB_
row major per sample workspaces
size_t calcFullDataSize(size_t basis_size, int num_species)
void generateSampleBasis(Matrix< Value > &Phi_mb, ParticleSet &pset_target, TrialWaveFunction &psi_target)
set Phi_mp to basis vaules per sample sideeffects:
void updateBasisWithSpin(const Position &r, const Real &s, ParticleSet &pset_target)
basis set updates with spin
void calcDensityDrift(const Position &r, Real &dens, Position &drift, ParticleSet &pset_target)
calculate density and drift bashed on r
Matrix< Value > Phi_MB_
basis_values_ at each r of rsamples_ row: sample col: basis_value size: samples * basis_size ...
void normalizeBasis(ParticleSet &pset_target)
int size() const
return the number of species
Definition: SpeciesSet.h:53
DataLocality data_locality_
locality for accumulation of estimator data.
#define OHMMS_DIM
Definition: config.h:64
void generateDensitySamplesWithSpin(bool save, int steps, RandomBase< FullPrecReal > &rng, ParticleSet &pset_target)
same as above, but with spin variables included
T min(T a, T b)
void generateSamples(const Real weight, ParticleSet &pset_target, RandomBase< FullPrecReal > &rng, int steps=0)
Dispatch method to difference methods of generating samples.
void assignGaussRand(T *restrict a, unsigned n, RG &rng)
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
void evaluateMatrix(ParticleSet &pset_target, TrialWaveFunction &psi_target, const MCPWalker &walker, RandomBase< FullPrecReal > &rng)
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Native representation for DensityMatrices1B Estimator&#39;s inputs.
QMCT::FullPrecRealType walkers_weight_
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
Scalar_t Volume
Physical properties of a supercell.
void generateDensitySamples(bool save, int steps, RandomBase< FullPrecReal > &rng, ParticleSet &pset_target)
generate samples for density integration
void warmupSampling(ParticleSet &pset_target, RandomBase< FullPrecReal > &rng)
does some warmup sampling i.e.
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
This a subclass for runtime errors that will occur on all ranks.
void evaluateVGL_spin(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi, ValueVector &dspin_psi) override
evaluate the values, gradients and laplacians and spin gradient of this single-particle orbital set ...
An abstract class for gridded estimators.
Position diffuse(const Real sqt, RandomBase< FullPrecReal > &rng)
produce a position difference vector from timestep
void generateParticleBasis(ParticleSet &pset_target, std::vector< Matrix< Value >> &phi_nb)
set phi_nb to basis values per target particleset particle sideeffects:
OneBodyDensityMatricesInput obdmi(node)
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
void generateUniformGrid(RandomBase< FullPrecReal > &rng)
void add(std::unique_ptr< SPOSet > component)
add a sposet component to this composite sposet
void calcDensityDriftWithSpin(const Position &r, const Real &s, Real &dens, Position &drift, Real &sdrift, ParticleSet &pset_target)
same as above, but with spin move
void calcDensityWithSpin(const Position &r, const Real &s, Real &dens, ParticleSet &pset_target)
same as above, but with spin move
void implAccumulate(const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, RandomBase< FullPrecReal > &rng)
Unfortunate design RandomGenerator type aliasing and virtual inheritance requires this for testing...
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) override
evaluate the values of this single-particle orbital set
Sampling sampling_
Sampling method, this derived values in input_.
float conj(const float &c)
Workaround to allow conj on scalar to return real instead of complex.
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
Declaration of a TrialWaveFunction.
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
std::vector< std::reference_wrapper< T > > RefVector
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
void updateBasis(const Position &r, ParticleSet &pset_target)
basis set updates
Class to represent a many-body trial wave function.
int getAttribute(const std::string &aname) const
When a name species does not exist, return attribute.size()
Definition: SpeciesSet.cpp:60
void set_dimensions(const std::vector< int > &dims, int first)
set the shape of this observable
const std::vector< std::string > & get_basis_sets() const
Real diffuseSpin(const Real sqt, RandomBase< FullPrecReal > &rng)
spin diffusion
std::vector< Matrix< Value > > Phi_Psi_NB_
DataLocality
data locality with respect to walker buffer
Definition: DataLocality.h:19
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
SingleParticlePos toCart(const TinyVector< T1, D > &c) const
Convert a unit vector to a cartesian vector.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
std::vector< Matrix< Value > > N_BB_
Position rpcur_
current position – As long Positions are TinyVectors they are intialized to zero vectors ...
void registerOperatorEstimator(hdf_archive &file) override
create and tie OperatorEstimator&#39;s observable_helper hdf5 wrapper to stat.h5 file ...
int naccepted_
number of accepted samples
void product_AtB(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
OneBodyDensityMatrices(OneBodyDensityMatricesInput &&obdmi, const Lattice &lattice, const SpeciesSet &species, const SPOMap &spomap, const ParticleSet &pset_target)
Standard Constructor Call this to make a new OBDM this is what you should be calling.
A container class to represent a walker.
Definition: Walker.h:49
void generateUniformSamples(RandomBase< FullPrecReal > &rng)
void updateBasisD012WithSpin(const Position &r, const Real &s, ParticleSet &pset_target)
same as above, but includes spin gradients
std::vector< Value > psi_ratios_
, &#39; .
void diag_product(const Matrix< T1 > &A, const Vector< T2 > &B, Matrix< T3 > &C)
C = A*diag(B)
ObservableHelper oh
std::string my_name_
name of this object – only used for debugging and h5 output
std::vector< Matrix< Value > > Psi_NM_
ratio per particle per sample size: particles * samples vector is over species each matrix row: parti...