QMCPACK
ParticleSet.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) 2020 QMCPACK developers.
6 //
7 // File developed by: D. Das, University of Illinois at Urbana-Champaign
8 // Bryan Clark, bclark@Princeton.edu, Princeton University
9 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
13 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
14 //
15 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
16 //////////////////////////////////////////////////////////////////////////////////////
17 
18 
19 #ifndef QMCPLUSPLUS_PARTICLESET_H
20 #define QMCPLUSPLUS_PARTICLESET_H
21 
22 #include <memory>
23 #include <Configuration.h>
24 #include "ParticleTags.h"
25 #include "DynamicCoordinates.h"
26 #include "Walker.h"
27 #include "ResourceHandle.h"
28 #include "SpeciesSet.h"
29 #include "Pools/PooledData.h"
30 #include "OhmmsPETE/OhmmsArray.h"
31 #include "Utilities/TimerManager.h"
34 #include "SimulationCell.h"
35 #include "MCCoords.hpp"
36 #include "DTModes.h"
37 
38 namespace qmcplusplus
39 {
40 ///forward declaration of DistanceTable
41 class DistanceTable;
42 class DistanceTableAA;
43 class DistanceTableAB;
44 class ResourceCollection;
45 class StructFact;
46 struct SKMultiWalkerMem;
47 
48 /** Specialized paritlce class for atomistic simulations
49  *
50  * Derived from QMCTraits, ParticleBase<PtclOnLatticeTraits> and OhmmsElementBase.
51  * The ParticleLayout class represents a supercell with/without periodic boundary
52  * conditions. The ParticleLayout class also takes care of spatial decompositions
53  * for efficient evaluations for the interactions with a finite cutoff.
54  */
56 {
57 public:
58  /// walker type
60  /// container type to store the property
62  /// buffer type for a serialized buffer
64 
66  {
70  };
71 
72  ///quantum_domain of the particles, default = classical
74 
75  //@{ public data members
76  ///Species ID
78  ///Position
80  ///internal spin variables for dynamical spin calculations
82  ///gradients of the particles
84  ///laplacians of the particles
86  ///mass of each particle
88  ///charge of each particle
90 
91  ///the index of the active bead for particle-by-particle moves
93  ///the direction reptile traveling
95 
96  ///Particle density in G-space for MPC interaction
97  std::vector<TinyVector<int, OHMMS_DIM>> DensityReducedGvecs;
98  std::vector<ComplexType> Density_G;
100 
101  /// DFT potential
102  std::vector<TinyVector<int, OHMMS_DIM>> VHXCReducedGvecs;
103  std::vector<ComplexType> VHXC_G[2];
105 
106  /** name-value map of Walker Properties
107  *
108  * PropertyMap is used to keep the name-value mapping of
109  * Walker_t::Properties. PropertyList::Values are not
110  * necessarily updated during the simulations.
111  */
113 
114  /** properties of the current walker
115  *
116  * The internal order is identical to PropertyList, which holds
117  * the matching names.
118  */
120 
121  /** observables in addition to those registered in Properties/PropertyList
122  *
123  * Such observables as density, gofr, sk are not stored per walker but
124  * collected during QMC iterations.
125  */
127 
128  ///Property history vector
129  std::vector<std::vector<FullPrecRealType>> PropertyHistory;
130  std::vector<int> PHindex;
131  ///@}
132 
133  ///current MC step
135 
136  ///default constructor
138 
139  ///copy constructor
140  ParticleSet(const ParticleSet& p);
141 
142  ///default destructor
143  ~ParticleSet() override;
144 
145  /** create grouped particles
146  * @param agroup number of particles per group
147  */
148  void create(const std::vector<int>& agroup);
149 
150  /** print particle coordinates to a std::ostream
151  * @param os output stream
152  * @param maxParticlesToPrint maximal number of particles to print. Pass 0 to print all.
153  */
154  void print(std::ostream& os, const size_t maxParticlesToPrint = 0) const;
155 
156  ///dummy. For satisfying OhmmsElementBase.
157  bool get(std::ostream& os) const override;
158  ///dummy. For satisfying OhmmsElementBase.
159  bool put(std::istream&) override;
160  ///dummy. For satisfying OhmmsElementBase.
161  void reset() override;
162 
163  ///initialize ParticleSet from xmlNode
164  bool put(xmlNodePtr cur) override;
165 
166  ///specify quantum_domain of particles
167  void setQuantumDomain(quantum_domains qdomain);
168 
170 
171  inline bool is_classical() const { return quantum_domain == classical; }
172 
173  inline bool is_quantum() const { return quantum_domain == quantum; }
174 
175  ///check whether quantum domain is valid for particles
176  inline bool quantumDomainValid(quantum_domains qdomain) const { return qdomain != no_quantum_domain; }
177 
178  ///check whether quantum domain is valid for particles
179  inline bool quantumDomainValid() const { return quantumDomainValid(quantum_domain); }
180 
181  /** add a distance table
182  * @param psrc source particle set
183  * @param modes bitmask DistanceTable::DTModes
184  *
185  * if this->myName == psrc.getName(), AA type. Otherwise, AB type.
186  */
187  int addTable(const ParticleSet& psrc, DTModes modes = DTModes::ALL_OFF);
188 
189  ///get a distance table by table_ID
190  inline auto& getDistTable(int table_ID) const { return *DistTables[table_ID]; }
191  ///get a distance table by table_ID and dyanmic_cast to DistanceTableAA
192  const DistanceTableAA& getDistTableAA(int table_ID) const;
193  ///get a distance table by table_ID and dyanmic_cast to DistanceTableAB
194  const DistanceTableAB& getDistTableAB(int table_ID) const;
195 
196  /** reset all the collectable quantities during a MC iteration
197  */
198  inline void resetCollectables() { std::fill(Collectables.begin(), Collectables.end(), 0.0); }
199 
200  /** update the internal data
201  *@param skip SK update if skipSK is true
202  */
203  void update(bool skipSK = false);
204 
205  /// batched version of update
206  static void mw_update(const RefVectorWithLeader<ParticleSet>& p_list, bool skipSK = false);
207 
208  /** create Structure Factor with PBCs
209  */
210  void createSK();
211 
212  bool hasSK() const { return bool(structure_factor_); }
213 
214  /** return Structure Factor
215  */
216  const StructFact& getSK() const
217  {
218  assert(structure_factor_);
219  return *structure_factor_;
220  };
221 
222  /** Turn on per particle storage in Structure Factor
223  */
224  void turnOnPerParticleSK();
225 
226  /** Get state (on/off) of per particle storage in Structure Factor
227  */
228  bool getPerParticleSKState() const;
229 
230  ///retrun the SpeciesSet of this particle set
231  inline SpeciesSet& getSpeciesSet() { return my_species_; }
232  ///retrun the const SpeciesSet of this particle set
233  inline const SpeciesSet& getSpeciesSet() const { return my_species_; }
234 
235  ///return parent's name
236  inline const std::string& parentName() const { return ParentName; }
237  inline void setName(const std::string& aname)
238  {
239  myName = aname;
240  if (ParentName == "0")
241  {
242  ParentName = aname;
243  }
244  }
245 
246  inline const DynamicCoordinates& getCoordinates() const { return *coordinates_; }
247 
248  void resetGroups();
249 
250  const auto& getSimulationCell() const { return simulation_cell_; }
251  const auto& getLattice() const { return simulation_cell_.getLattice(); }
252  auto& getPrimitiveLattice() const { return const_cast<ParticleLayout&>(simulation_cell_.getPrimLattice()); }
253  const auto& getLRBox() const { return simulation_cell_.getLRBox(); }
254 
255  inline bool isSameMass() const { return same_mass_; }
256  inline bool isSpinor() const { return is_spinor_; }
257  inline void setSpinor(bool is_spinor) { is_spinor_ = is_spinor; }
258 
259  /// return active particle id
260  inline Index_t getActivePtcl() const { return active_ptcl_; }
261  inline const PosType& getActivePos() const { return active_pos_; }
262  inline Scalar_t getActiveSpinVal() const { return active_spin_val_; }
263 
264  /// return the active position if the particle is active or the return current position if not
265  inline const PosType& activeR(int iat) const
266  {
267  // When active_ptcl_ == iat, a move has been proposed.
268  return (active_ptcl_ == iat) ? active_pos_ : R[iat];
269  }
270 
271  /// return the active spin value if the particle is active or return the current spin value if not
272  inline const Scalar_t& activeSpin(int iat) const
273  {
274  // When active_ptcl_ == iat, a move has been proposed.
275  return (active_ptcl_ == iat) ? active_spin_val_ : spins[iat];
276  }
277 
278  /** move the iat-th particle to active_pos_
279  * @param iat the index of the particle to be moved
280  * @param displ the displacement of the iat-th particle position
281  * @param maybe_accept if false, the caller guarantees that the proposed move will not be accepted.
282  *
283  * Update active_ptcl_ index and active_pos_ position (R[iat]+displ) for a proposed move.
284  * Evaluate the related distance table data DistanceTable::Temp.
285  * If maybe_accept = false, certain operations for accepting moves will be skipped for optimal performance.
286  */
287  void makeMove(Index_t iat, const SingleParticlePos& displ, bool maybe_accept = true);
288  /// makeMove, but now includes an update to the spin variable
289  void makeMoveWithSpin(Index_t iat, const SingleParticlePos& displ, const Scalar_t& sdispl);
290 
291  /// batched version of makeMove
292  template<CoordsType CT>
293  static void mw_makeMove(const RefVectorWithLeader<ParticleSet>& p_list, int iat, const MCCoords<CT>& displs);
294 
295  static void mw_makeMove(const RefVectorWithLeader<ParticleSet>& p_list,
296  int iat,
297  const std::vector<SingleParticlePos>& displs);
298 
299  /// batched version makeMove for spin variable only
300  static void mw_makeSpinMove(const RefVectorWithLeader<ParticleSet>& p_list,
301  int iat,
302  const std::vector<Scalar_t>& sdispls);
303 
304  /** move the iat-th particle to active_pos_
305  * @param iat the index of the particle to be moved
306  * @param displ random displacement of the iat-th particle
307  * @return true, if the move is valid
308  *
309  * Update active_ptcl_ index and active_pos_ position (R[iat]+displ) for a proposed move.
310  * Evaluate the related distance table data DistanceTable::Temp.
311  *
312  * When a Lattice is defined, passing two checks makes a move valid.
313  * outOfBound(displ): invalid move, if displ is larger than half, currently, of the box in any direction
314  * isValid(Lattice.toUnit(active_pos_)): invalid move, if active_pos_ goes out of the Lattice in any direction marked with open BC.
315  * Note: active_pos_ and distances tables are always evaluated no matter the move is valid or not.
316  */
317  bool makeMoveAndCheck(Index_t iat, const SingleParticlePos& displ);
318  /// makeMoveAndCheck, but now includes an update to the spin variable
319  bool makeMoveAndCheckWithSpin(Index_t iat, const SingleParticlePos& displ, const Scalar_t& sdispl);
320 
321  /** Handles virtual moves for all the particles to a single newpos.
322  *
323  * The state active_ptcl_ remains -1 and rejectMove is not needed.
324  * acceptMove can not be used.
325  * See QMCHamiltonians::MomentumEstimator as an example
326  */
327  void makeVirtualMoves(const SingleParticlePos& newpos);
328 
329  /** move all the particles of a walker
330  * @param awalker the walker to operate
331  * @param deltaR proposed displacement
332  * @param dt factor of deltaR
333  * @return true if all the moves are legal.
334  *
335  * If big displacements or illegal positions are detected, return false.
336  * If all good, R = awalker.R + dt* deltaR
337  */
338  bool makeMoveAllParticles(const Walker_t& awalker, const ParticlePos& deltaR, RealType dt);
339 
340  bool makeMoveAllParticles(const Walker_t& awalker, const ParticlePos& deltaR, const std::vector<RealType>& dt);
341 
342  /** move all the particles including the drift
343  *
344  * Otherwise, everything is the same as makeMove for a walker
345  */
346  bool makeMoveAllParticlesWithDrift(const Walker_t& awalker,
347  const ParticlePos& drift,
348  const ParticlePos& deltaR,
349  RealType dt);
350 
351  bool makeMoveAllParticlesWithDrift(const Walker_t& awalker,
352  const ParticlePos& drift,
353  const ParticlePos& deltaR,
354  const std::vector<RealType>& dt);
355 
356  /** accept or reject a proposed move
357  * Two operation modes:
358  * The using and updating distance tables via `ParticleSet` operate in two modes, regular and forward modes.
359  *
360  * Regular mode
361  * The regular mode can only be used when the distance tables for particle pairs are fully up-to-date.
362  * This is the case after calling `ParticleSet::update()` in a unit test or after p-by-p moves in a QMC driver.
363  * In this mode, the distance tables remain up-to-date after calling `ParticleSet::acceptMove`
364  * and calling `ParticleSet::rejectMove` is not mandatory.
365  *
366  * Forward mode
367  * The forward mode assumes that distance table is not fully up-to-date until every particle is accepted
368  * or rejected to move once in order. This is the mode used in the p-by-p part of drivers.
369  * In this mode, calling `ParticleSet::accept_rejectMove` is required to handle accept/reject rather than
370  * calling individual `ParticleSet::acceptMove` and `ParticleSet::reject`.
371  * `ParticleSet::accept_rejectMove(iel)` ensures the distance tables (jel < iel) part is fully up-to-date
372  * regardless a move is accepted or rejected. For this reason, the rejecting operation inside
373  * `ParticleSet::accept_rejectMove` involves writing the distances with respect to the old particle position.
374  */
375  void accept_rejectMove(Index_t iat, bool accepted, bool forward_mode = true);
376 
377  /** accept the move and update the particle attribute by the proposed move in regular mode
378  *@param iat the index of the particle whose position and other attributes to be updated
379  */
380  void acceptMove(Index_t iat);
381 
382  /** reject a proposed move in regular mode
383  * @param iat the electron whose proposed move gets rejected.
384  */
385  void rejectMove(Index_t iat);
386 
387  /// batched version of acceptMove and rejectMove fused, templated on CoordsType
388  template<CoordsType CT>
389  static void mw_accept_rejectMove(const RefVectorWithLeader<ParticleSet>& p_list,
390  Index_t iat,
391  const std::vector<bool>& isAccepted,
392  bool forward_mode = true);
393 
394  /// batched version of acceptMove and rejectMove fused
395  static void mw_accept_rejectMove(const RefVectorWithLeader<ParticleSet>& p_list,
396  Index_t iat,
397  const std::vector<bool>& isAccepted,
398  bool forward_mode = true);
399 
400  /** batched version of acceptMove and reject Move fused, but only for spins
401  *
402  * note: should be called BEFORE mw_accept_rejectMove since the active_ptcl_ gets reset to -1
403  * This would cause the assertion that we have the right particle index to fail if done in the
404  * wrong order
405  */
407  Index_t iat,
408  const std::vector<bool>& isAccepted);
409 
410  void initPropertyList();
411  inline int addProperty(const std::string& pname) { return PropertyList.add(pname.c_str()); }
412 
413  int addPropertyHistory(int leng);
414  // void rejectedMove();
415  // void resetPropertyHistory( );
416  // void addPropertyHistoryPoint(int index, RealType data);
417 
418  void convert(const ParticlePos& pin, ParticlePos& pout);
419  void convert2Unit(const ParticlePos& pin, ParticlePos& pout);
420  void convert2Cart(const ParticlePos& pin, ParticlePos& pout);
421  void convert2Unit(ParticlePos& pout);
422  void convert2Cart(ParticlePos& pout);
423  void convert2UnitInBox(const ParticlePos& pint, ParticlePos& pout);
424  void convert2CartInBox(const ParticlePos& pint, ParticlePos& pout);
425 
426  void applyBC(const ParticlePos& pin, ParticlePos& pout);
427  void applyBC(ParticlePos& pos);
428  void applyBC(const ParticlePos& pin, ParticlePos& pout, int first, int last);
429  void applyMinimumImage(ParticlePos& pinout) const;
430 
431  /** load a Walker_t to the current ParticleSet
432  * @param awalker the reference to the walker to be loaded
433  * @param pbyp true if it is used by PbyP update
434  *
435  * PbyP requires the distance tables and Sk with awalker.R
436  */
437  void loadWalker(Walker_t& awalker, bool pbyp);
438  /** batched version of loadWalker */
439  static void mw_loadWalker(const RefVectorWithLeader<ParticleSet>& p_list,
441  const std::vector<bool>& recompute,
442  bool pbyp);
443 
444  /** save this to awalker
445  *
446  * just the R, G, and L
447  * More duplicate data that makes code difficult to reason about should be removed.
448  */
449  void saveWalker(Walker_t& awalker);
450 
451  /** batched version of saveWalker
452  *
453  * just the R, G, and L
454  */
456 
457  /** update structure factor and unmark active_ptcl_
458  *@param skip SK update if skipSK is true
459  *
460  * The Coulomb interaction evaluation needs the structure factor.
461  * For these reason, call donePbyP after the loop of single
462  * electron moves before evaluating the Hamiltonian. Unmark
463  * active_ptcl_ is more of a safety measure probably not needed.
464  */
465  void donePbyP(bool skipSK = false);
466  /// batched version of donePbyP
467  static void mw_donePbyP(const RefVectorWithLeader<ParticleSet>& p_list, bool skipSK = false);
468 
469  ///return the address of the values of Hamiltonian terms
470  inline FullPrecRealType* restrict getPropertyBase() { return Properties.data(); }
471 
472  ///return the address of the values of Hamiltonian terms
473  inline const FullPrecRealType* restrict getPropertyBase() const { return Properties.data(); }
474 
475  ///return the address of the i-th properties
476  inline FullPrecRealType* restrict getPropertyBase(int i) { return Properties[i]; }
477 
478  ///return the address of the i-th properties
479  inline const FullPrecRealType* restrict getPropertyBase(int i) const { return Properties[i]; }
480 
481  inline void setTwist(const SingleParticlePos& t) { myTwist = t; }
482  inline const SingleParticlePos& getTwist() const { return myTwist; }
483 
484  /** Initialize particles around another ParticleSet
485  * Used to initialize an electron ParticleSet by an ion ParticleSet
486  */
487  void randomizeFromSource(ParticleSet& src);
488 
489  /** get species name of particle i
490  */
491  inline const std::string& species_from_index(int i) { return my_species_.speciesName[GroupID[i]]; }
492 
493  inline size_t getTotalNum() const { return TotalNum; }
494 
495  inline void clear()
496  {
497  TotalNum = 0;
498 
499  R.clear();
500  spins.clear();
501  GroupID.clear();
502  G.clear();
503  L.clear();
504  Mass.clear();
505  Z.clear();
506 
507  coordinates_->resize(0);
508  }
509 
510  ///return the number of groups
511  inline int groups() const { return group_offsets_->size() - 1; }
512 
513  ///return the first index of a group i
514  inline int first(int igroup) const { return (*group_offsets_)[igroup]; }
515 
516  ///return the last index of a group i
517  inline int last(int igroup) const { return (*group_offsets_)[igroup + 1]; }
518 
519  ///return the group id of a given particle in the particle set.
520  inline int getGroupID(int iat) const
521  {
522  assert(iat >= 0 && iat < TotalNum);
523  return GroupID[iat];
524  }
525 
526  ///return the size of a group
527  inline int groupsize(int igroup) const { return (*group_offsets_)[igroup + 1] - (*group_offsets_)[igroup]; }
528 
529  ///add attributes to list for IO
530  template<typename ATList>
531  inline void createAttributeList(ATList& AttribList)
532  {
539  //add basic attributes
540  AttribList.add(R);
541  AttribList.add(spins);
542  AttribList.add(GroupID);
543 
546 
547  G.setObjName("grad");
548  L.setObjName("lap");
549 
550  AttribList.add(G);
551  AttribList.add(L);
552 
553  //more particle attributes
555  Mass.setObjName("mass");
556  AttribList.add(Mass);
557 
559  Z.setObjName("charge");
560  AttribList.add(Z);
561  }
562 
563  inline void setMapStorageToInput(const std::vector<int>& mapping) { map_storage_to_input_ = mapping; }
564  inline const std::vector<int>& get_map_storage_to_input() const { return map_storage_to_input_; }
565 
566  inline int getNumDistTables() const { return DistTables.size(); }
567 
568  inline auto& get_group_offsets() const { return *group_offsets_; }
569 
570  /// initialize a shared resource and hand it to a collection
571  void createResource(ResourceCollection& collection) const;
572  /** acquire external resource and assocaite it with the list of ParticleSet
573  * Note: use RAII ResourceCollectionTeamLock whenever possible
574  */
575  static void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<ParticleSet>& p_list);
576  /** release external resource
577  * Note: use RAII ResourceCollectionTeamLock whenever possible
578  */
579  static void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<ParticleSet>& p_list);
580 
584 
585 protected:
586  /// reference to global simulation cell
588 
589  ///true if the particles have the same mass
591  ///true is a dynamic spin calculation
593  /** the index of the active particle during particle-by-particle moves
594  *
595  * when a single particle move is proposed, the particle id is assigned to active_ptcl_
596  * No matter the move is accepted or rejected, active_ptcl_ is marked back to -1.
597  * This state flag is used for picking coordinates and distances for SPO evaluation.
598  */
600  ///the proposed position of active_ptcl_ during particle-by-particle moves
602  ///the proposed spin of active_ptcl_ during particle-by-particle moves
604 
605  /** Map storage index to the input index.
606  * If not empty, particles were reordered by groups when being loaded from XML input.
607  * When other input data are affected by reordering, its builder should query this mapping.
608  * map_storage_to_input_[5] = 2 means the index 5(6th) particle in this ParticleSet was read from
609  * the index 2(3th) particle in the XML input
610  */
611  std::vector<int> map_storage_to_input_;
612 
613  ///SpeciesSet of particles
615 
616  ///Structure factor
617  std::unique_ptr<StructFact> structure_factor_;
618 
619  ///multi walker structure factor data
621 
622  /** map to handle distance tables
623  *
624  * myDistTableMap[source-particle-tag]= locator in the distance table
625  * myDistTableMap[ObjectTag] === 0
626  */
627  std::map<std::string, int> myDistTableMap;
628 
629  /// distance tables that need to be updated by moving this ParticleSet
630  std::vector<std::unique_ptr<DistanceTable>> DistTables;
631 
632  /// Descriptions from distance table creation. Same order as DistTables.
633  std::vector<std::string> distTableDescriptions;
634 
636 
638 
639  std::string ParentName;
640 
641  ///total number of particles
642  size_t TotalNum;
643 
644  ///array to handle a group of distinct particles per species
645  std::shared_ptr<Vector<int, OMPallocator<int>>> group_offsets_;
646 
647  ///internal representation of R. It can be an SoA copy of R
648  std::unique_ptr<DynamicCoordinates> coordinates_;
649 
650  /** compute temporal DistTables and SK for a new particle position
651  *
652  * @param iat the particle that is moved on a sphere
653  * @param newpos a new particle position
654  * @param maybe_accept if false, the caller guarantees that the proposed move will not be accepted.
655  */
656  void computeNewPosDistTables(Index_t iat, const SingleParticlePos& newpos, bool maybe_accept = true);
657 
658 
659  /** compute temporal DistTables and SK for a new particle position for each walker in a batch
660  *
661  * @param p_list the list of wrapped ParticleSet references in a walker batch
662  * @param iat the particle that is moved on a sphere
663  * @param new_positions new particle positions
664  * @param maybe_accept if false, the caller guarantees that the proposed move will not be accepted.
665  */
667  Index_t iat,
668  const std::vector<SingleParticlePos>& new_positions,
669  bool maybe_accept = true);
670 
671  /** actual implemenation for accepting a proposed move in forward mode
672  *
673  * @param iat the index of the particle whose position and other attributes to be updated
674  */
675  void acceptMoveForwardMode(Index_t iat);
676 
677  /** reject a proposed move in forward mode
678  * @param iat the electron whose proposed move gets rejected.
679  */
680  void rejectMoveForwardMode(Index_t iat);
681 
682  /// resize internal storage
683  inline void resize(size_t numPtcl)
684  {
685  TotalNum = numPtcl;
686 
687  R.resize(numPtcl);
688  spins.resize(numPtcl);
689  GroupID.resize(numPtcl);
690  G.resize(numPtcl);
691  L.resize(numPtcl);
692  Mass.resize(numPtcl);
693  Z.resize(numPtcl);
694 
695  coordinates_->resize(numPtcl);
696  }
697 };
698 
699 } // namespace qmcplusplus
700 #endif
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.
DynamicCoordinateKind
enumerator for DynamicCoordinates kinds
const auto & getLRBox() const
Definition: ParticleSet.h:253
Index_t getActivePtcl() const
return active particle id
Definition: ParticleSet.h:260
void setName(const std::string &aname)
Definition: ParticleSet.h:237
Walker< QMCTraits, PtclOnLatticeTraits > Walker_t
walker type
Definition: ParticleSet.h:59
HamiltonianRef::FullPrecRealType FullPrecRealType
ResourceHandle< SKMultiWalkerMem > mw_structure_factor_data_handle_
multi walker structure factor data
Definition: ParticleSet.h:620
auto & get_group_offsets() const
Definition: ParticleSet.h:568
void convert2UnitInBox(const ParticlePos &pint, ParticlePos &pout)
void acceptMoveForwardMode(Index_t iat)
actual implemenation for accepting a proposed move in forward mode
quantum_domains quantum_domain
quantum_domain of the particles, default = classical
Definition: ParticleSet.h:73
const SpeciesSet & getSpeciesSet() const
retrun the const SpeciesSet of this particle set
Definition: ParticleSet.h:233
static void mw_makeMove(const RefVectorWithLeader< ParticleSet > &p_list, int iat, const MCCoords< CT > &displs)
batched version of makeMove
Index_t active_ptcl_
the index of the active particle during particle-by-particle moves
Definition: ParticleSet.h:599
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const DistanceTableAA & getDistTableAA(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAA
static void mw_accept_rejectSpinMove(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< bool > &isAccepted)
batched version of acceptMove and reject Move fused, but only for spins
timer_manager class.
Scalar_t getActiveSpinVal() const
Definition: ParticleSet.h:262
ParticleScalar spins
internal spin variables for dynamical spin calculations
Definition: ParticleSet.h:81
void applyMinimumImage(ParticlePos &pinout) const
void setTypeName(const std::string &tname)
set the type name
Definition: OhmmsObject.h:60
PropertyContainer_t Properties
properties of the current walker
Definition: ParticleSet.h:119
std::string myName
the name of the node, corresponds to the xml tag
Array< RealType, OHMMS_DIM > Density_r
Definition: ParticleSet.h:99
const std::vector< int > & get_map_storage_to_input() const
Definition: ParticleSet.h:564
ParticleLayout::SingleParticlePos SingleParticlePos
Definition: Configuration.h:87
static std::string indextype_tag
the datatype tag for the index-type attribute
Definition: ParticleTags.h:55
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::vector< T >::iterator end()
return the ending iterator
Definition: PooledData.h:61
static std::string spins_tag
the name for spins attribute
Definition: ParticleTags.h:87
quantum variables of all the particles
size_t TotalNum
total number of particles
Definition: ParticleSet.h:642
ResourceHandle manages the temporary resource referenced from a collection.
static void mw_makeSpinMove(const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< Scalar_t > &sdispls)
batched version makeMove for spin variable only
static void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< ParticleSet > &p_list)
release external resource Note: use RAII ResourceCollectionTeamLock whenever possible ...
static RefVectorWithLeader< StructFact > extractSKRefList(const RefVectorWithLeader< ParticleSet > &p_list)
bool same_mass_
true if the particles have the same mass
Definition: ParticleSet.h:590
static std::string position_tag
names of particle attributes, e.g., position
Definition: ParticleTags.h:84
Soa Container for D-dim vectors.
int addProperty(const std::string &pname)
Definition: ParticleSet.h:411
std::vector< std::vector< FullPrecRealType > > PropertyHistory
Property history vector.
Definition: ParticleSet.h:129
int getNumDistTables() const
Definition: ParticleSet.h:566
ParticleAttrib< QTFull::ValueType > ParticleLaplacian
Definition: Configuration.h:96
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
void applyBC(const ParticlePos &pin, ParticlePos &pout)
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
Vectorized record engine for scalar properties.
const char walkers[]
Definition: HDFVersion.h:36
static std::string postype_tag
the datatype tag for the pos-type attribute
Definition: ParticleTags.h:64
ParticleAttrib< Index_t > ParticleIndex
Definition: Configuration.h:90
int current_step
current MC step
Definition: ParticleSet.h:134
void update(bool skipSK=false)
update the internal data
bool is_classical() const
Definition: ParticleSet.h:171
std::vector< T >::iterator begin()
return the starting iterator
Definition: PooledData.h:59
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
Calculates the structure-factor for a particle set.
Definition: StructFact.h:39
ConstantSizeMatrix< FullPrecRealType, std::allocator< FullPrecRealType > > PropertyContainer_t
typedef for the property container, fixed size
Definition: Walker.h:75
static RefVectorWithLeader< DistanceTable > extractDTRefList(const RefVectorWithLeader< ParticleSet > &p_list, int id)
static void mw_saveWalker(const RefVectorWithLeader< ParticleSet > &psets, const RefVector< Walker_t > &walkers)
batched version of saveWalker
static void mw_accept_rejectMove(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< bool > &isAccepted, bool forward_mode=true)
batched version of acceptMove and rejectMove fused, templated on CoordsType
SingleParticlePos myTwist
Definition: ParticleSet.h:637
Scalar_t active_spin_val_
the proposed spin of active_ptcl_ during particle-by-particle moves
Definition: ParticleSet.h:603
std::map< std::string, int > myDistTableMap
map to handle distance tables
Definition: ParticleSet.h:627
void convert2Unit(const ParticlePos &pin, ParticlePos &pout)
Index_t activeBead
the index of the active bead for particle-by-particle moves
Definition: ParticleSet.h:92
const Scalar_t & activeSpin(int iat) const
return the active spin value if the particle is active or return the current spin value if not ...
Definition: ParticleSet.h:272
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
void rejectMoveForwardMode(Index_t iat)
reject a proposed move in forward mode
PropertySetType PropertyList
name-value map of Walker Properties
Definition: ParticleSet.h:112
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
std::unique_ptr< StructFact > structure_factor_
Structure factor.
Definition: ParticleSet.h:617
void turnOnPerParticleSK()
Turn on per particle storage in Structure Factor.
int groups() const
return the number of groups
Definition: ParticleSet.h:511
ParticleSet(const SimulationCell &simulation_cell, const DynamicCoordinateKind kind=DynamicCoordinateKind::DC_POS)
default constructor
Definition: ParticleSet.cpp:58
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
std::vector< ComplexType > VHXC_G[2]
Definition: ParticleSet.h:103
void createAttributeList(ATList &AttribList)
add attributes to list for IO
Definition: ParticleSet.h:531
const PosType & getActivePos() const
Definition: ParticleSet.h:261
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
const Lattice & getLattice() const
Abstract class to provide xml-compatible I/O interfaces for the derived classes.
bool quantumDomainValid(quantum_domains qdomain) const
check whether quantum domain is valid for particles
Definition: ParticleSet.h:176
int add(const std::string &aname)
AB type of DistanceTable containing storage.
void rejectMove(Index_t iat)
reject a proposed move in regular mode
void setObjName(const std::string &oname)
set the object name
Definition: OhmmsObject.h:63
const FullPrecRealType *restrict getPropertyBase() const
return the address of the values of Hamiltonian terms
Definition: ParticleSet.h:473
void resize(size_t numPtcl)
resize internal storage
Definition: ParticleSet.h:683
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
bool makeMoveAndCheckWithSpin(Index_t iat, const SingleParticlePos &displ, const Scalar_t &sdispl)
makeMoveAndCheck, but now includes an update to the spin variable
void convert2Cart(const ParticlePos &pin, ParticlePos &pout)
static void mw_computeNewPosDistTables(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< SingleParticlePos > &new_positions, bool maybe_accept=true)
compute temporal DistTables and SK for a new particle position for each walker in a batch ...
void saveWalker(Walker_t &awalker)
save this to awalker
std::vector< int > PHindex
Definition: ParticleSet.h:130
int groupsize(int igroup) const
return the size of a group
Definition: ParticleSet.h:527
std::vector< ComplexType > Density_G
Definition: ParticleSet.h:98
void accept_rejectMove(Index_t iat, bool accepted, bool forward_mode=true)
accept or reject a proposed move Two operation modes: The using and updating distance tables via Part...
FullPrecRealType *restrict getPropertyBase(int i)
return the address of the i-th properties
Definition: ParticleSet.h:476
void reset() override
dummy. For satisfying OhmmsElementBase.
int addPropertyHistory(int leng)
void makeMoveWithSpin(Index_t iat, const SingleParticlePos &displ, const Scalar_t &sdispl)
makeMove, but now includes an update to the spin variable
const std::string & parentName() const
return parent&#39;s name
Definition: ParticleSet.h:236
ParticlePos R
Position.
Definition: ParticleSet.h:79
Index_t direction
the direction reptile traveling
Definition: ParticleSet.h:94
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
static std::string ionid_tag
the name for ionid attribute
Definition: ParticleTags.h:93
const StructFact & getSK() const
return Structure Factor
Definition: ParticleSet.h:216
std::vector< std::string > distTableDescriptions
Descriptions from distance table creation. Same order as DistTables.
Definition: ParticleSet.h:633
const PosType & activeR(int iat) const
return the active position if the particle is active or the return current position if not ...
Definition: ParticleSet.h:265
bool is_spinor_
true is a dynamic spin calculation
Definition: ParticleSet.h:592
void setTwist(const SingleParticlePos &t)
Definition: ParticleSet.h:481
ParticleScalar Z
charge of each particle
Definition: ParticleSet.h:89
AA type of DistanceTable containing storage.
void loadWalker(Walker_t &awalker, bool pbyp)
load a Walker_t to the current ParticleSet
auto & getDistTable(int table_ID) const
get a distance table by table_ID
Definition: ParticleSet.h:190
void computeNewPosDistTables(Index_t iat, const SingleParticlePos &newpos, bool maybe_accept=true)
compute temporal DistTables and SK for a new particle position
Buffer_t Collectables
observables in addition to those registered in Properties/PropertyList
Definition: ParticleSet.h:126
const Lattice & getLRBox() const
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
static void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< ParticleSet > &p_list)
acquire external resource and assocaite it with the list of ParticleSet Note: use RAII ResourceCollec...
void setMapStorageToInput(const std::vector< int > &mapping)
Definition: ParticleSet.h:563
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
std::unique_ptr< DynamicCoordinates > coordinates_
internal representation of R. It can be an SoA copy of R
Definition: ParticleSet.h:648
static std::string gradtype_tag
the datatype tag for the gradient-type attribute
Definition: ParticleTags.h:67
const SingleParticlePos & getTwist() const
Definition: ParticleSet.h:482
std::vector< std::reference_wrapper< T > > RefVector
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
std::shared_ptr< Vector< int, OMPallocator< int > > > group_offsets_
array to handle a group of distinct particles per species
Definition: ParticleSet.h:645
SpeciesSet my_species_
SpeciesSet of particles.
Definition: ParticleSet.h:614
void print(std::ostream &os, const size_t maxParticlesToPrint=0) const
print particle coordinates to a std::ostream
void convert(const ParticlePos &pin, ParticlePos &pout)
Particle traits to use UniformGridLayout for the ParticleLayout.
Definition: Configuration.h:77
~ParticleSet() override
default destructor
bool quantumDomainValid() const
check whether quantum domain is valid for particles
Definition: ParticleSet.h:179
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
ParticleScalar Mass
mass of each particle
Definition: ParticleSet.h:87
static RefVectorWithLeader< DynamicCoordinates > extractCoordsRefList(const RefVectorWithLeader< ParticleSet > &p_list)
bool getPerParticleSKState() const
Get state (on/off) of per particle storage in Structure Factor.
SingleParticlePos active_pos_
the proposed position of active_ptcl_ during particle-by-particle moves
Definition: ParticleSet.h:601
std::vector< int > map_storage_to_input_
Map storage index to the input index.
Definition: ParticleSet.h:611
const FullPrecRealType *restrict getPropertyBase(int i) const
return the address of the i-th properties
Definition: ParticleSet.h:479
static void mw_update(const RefVectorWithLeader< ParticleSet > &p_list, bool skipSK=false)
batched version of update
Array< RealType, OHMMS_DIM > VHXC_r[2]
Definition: ParticleSet.h:104
void resetCollectables()
reset all the collectable quantities during a MC iteration
Definition: ParticleSet.h:198
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
static void mw_donePbyP(const RefVectorWithLeader< ParticleSet > &p_list, bool skipSK=false)
batched version of donePbyP
bool put(std::istream &) override
dummy. For satisfying OhmmsElementBase.
void clear()
clear
Definition: OhmmsVector.h:191
const auto & getLattice() const
Definition: ParticleSet.h:251
bool makeMoveAllParticlesWithDrift(const Walker_t &awalker, const ParticlePos &drift, const ParticlePos &deltaR, RealType dt)
move all the particles including the drift
bool makeMoveAndCheck(Index_t iat, const SingleParticlePos &displ)
move the iat-th particle to active_pos_
ParticleAttrib< QTFull::GradType > ParticleGradient
Definition: Configuration.h:95
const std::string & species_from_index(int i)
get species name of particle i
Definition: ParticleSet.h:491
void createSK()
create Structure Factor with PBCs
void setQuantumDomain(quantum_domains qdomain)
specify quantum_domain of particles
void randomizeFromSource(ParticleSet &src)
Initialize particles around another ParticleSet Used to initialize an electron ParticleSet by an ion ...
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
void setSpinor(bool is_spinor)
Definition: ParticleSet.h:257
static void mw_loadWalker(const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< Walker_t > &walkers, const std::vector< bool > &recompute, bool pbyp)
batched version of loadWalker
std::vector< std::unique_ptr< DistanceTable > > DistTables
distance tables that need to be updated by moving this ParticleSet
Definition: ParticleSet.h:630
traits for QMC variables
Definition: Configuration.h:49
void acceptMove(Index_t iat)
accept the move and update the particle attribute by the proposed move in regular mode ...
FullPrecRealType *restrict getPropertyBase()
return the address of the values of Hamiltonian terms
Definition: ParticleSet.h:470
bool makeMoveAllParticles(const Walker_t &awalker, const ParticlePos &deltaR, RealType dt)
move all the particles of a walker
ParticleAttrib< Scalar_t > ParticleScalar
Definition: Configuration.h:91
std::vector< TinyVector< int, OHMMS_DIM > > DensityReducedGvecs
Particle density in G-space for MPC interaction.
Definition: ParticleSet.h:97
A container class to represent a walker.
Definition: Walker.h:49
const SimulationCell & simulation_cell_
reference to global simulation cell
Definition: ParticleSet.h:587
std::vector< TinyVector< int, OHMMS_DIM > > VHXCReducedGvecs
DFT potential.
Definition: ParticleSet.h:102
void convert2CartInBox(const ParticlePos &pint, ParticlePos &pout)
Define a serialized buffer to store anonymous data.
void donePbyP(bool skipSK=false)
update structure factor and unmark active_ptcl_
void makeVirtualMoves(const SingleParticlePos &newpos)
Handles virtual moves for all the particles to a single newpos.
static std::string scalartype_tag
the datatype tag for the scalar-type attribute
Definition: ParticleTags.h:58
const Lattice & getPrimLattice() const
int getGroupID(int iat) const
return the group id of a given particle in the particle set.
Definition: ParticleSet.h:520
static std::string laptype_tag
the datatype tag for the laplacian-type attribute
Definition: ParticleTags.h:70
auto & getPrimitiveLattice() const
Definition: ParticleSet.h:252