QMCPACK
EinsplineSetBuilder.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
10 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
12 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
13 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
14 //
15 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
16 //////////////////////////////////////////////////////////////////////////////////////
17 
18 
19 /** @file EinsplineSetBuilder.h
20  *
21  * Builder class for einspline-based SPOSet objects.
22  */
23 #ifndef QMCPLUSPLUS_EINSPLINE_SET_BUILDER_H
24 #define QMCPLUSPLUS_EINSPLINE_SET_BUILDER_H
25 
28 #include <filesystem>
29 #include <map>
30 
31 #define PW_COEFF_NORM_TOLERANCE 1e-6
32 
33 class Communicate;
34 
35 namespace qmcplusplus
36 {
37 ///forward declaration of BsplineReader
38 struct BsplineReader;
39 
40 // Helper needed for TwistMap
41 struct Int3less
42 {
43  bool operator()(const TinyVector<int, 3>& a, const TinyVector<int, 3>& b) const
44  {
45  if (a[0] > b[0])
46  return false;
47  if (a[0] < b[0])
48  return true;
49  if (a[1] > b[1])
50  return false;
51  if (a[1] < b[1])
52  return true;
53  if (a[2] > b[2])
54  return false;
55  if (a[2] < b[2])
56  return true;
57  return false;
58  }
59 };
60 struct Int4less
61 {
62  bool operator()(const TinyVector<int, 4>& a, const TinyVector<int, 4>& b) const
63  {
64  for (int i = 0; i < 4; i++)
65  {
66  if (a[i] > b[i])
67  return false;
68  if (a[i] < b[i])
69  return true;
70  }
71  return false;
72  }
73 };
74 
75 
76 /** construct a name for spline SPO set
77  */
78 struct H5OrbSet
79 {
80  ///index for the spin set
81  int SpinSet;
82  ///number of orbitals that belong to this set
83  int NumOrbs;
84  ///name of the HDF5 file
85  std::filesystem::path FileName;
86  /** true if a < b
87  *
88  * The ordering
89  * - name
90  * - spin set
91  * - number of orbitals
92  */
93  bool operator()(const H5OrbSet& a, const H5OrbSet& b) const
94  {
95  if (a.FileName == b.FileName)
96  {
97  if (a.SpinSet == b.SpinSet)
98  return a.NumOrbs < b.NumOrbs;
99  else
100  return a.SpinSet < b.SpinSet;
101  }
102  else
103  return a.FileName < b.FileName;
104  }
105 
106  H5OrbSet(std::filesystem::path name, int spinSet, int numOrbs)
107  : SpinSet(spinSet), NumOrbs(numOrbs), FileName(std::move(name))
108  {}
109  H5OrbSet() = default;
110 };
111 
112 /** EinsplineSet builder
113  */
115 {
116 public:
117  using PSetMap = std::map<std::string, const std::unique_ptr<ParticleSet>>;
119 
120  ///reference to the particleset pool
122  ///quantum particle set
124  ///ionic system
126 
127  /** Helper vector for sorting bands
128  */
129  std::vector<std::unique_ptr<std::vector<BandInfo>>> FullBands;
130 
131  /// reader to use BsplineReader
132  std::unique_ptr<BsplineReader> MixedSplineReader;
133 
134  ///This is true if we have the orbital derivatives w.r.t. the ion positions
136  ///root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version
137  xmlNodePtr XMLRoot;
138 
139  std::map<H5OrbSet, SPOSet*, H5OrbSet> SPOSetMap;
140 
141  ///constructor
142  EinsplineSetBuilder(ParticleSet& p, const PSetMap& psets, Communicate* comm, xmlNodePtr cur);
143 
144  ///destructor
145  ~EinsplineSetBuilder() override;
146 
147  /** initialize the Antisymmetric wave function for electrons
148  * @param cur the current xml node
149  */
150  std::unique_ptr<SPOSet> createSPOSetFromXML(xmlNodePtr cur) override;
151 
152  /** initialize with the existing SPOSet */
153  std::unique_ptr<SPOSet> createSPOSet(xmlNodePtr cur, SPOSetInputInfo& input_info) override;
154 
155  //////////////////////////////////////
156  // HDF5-related data and functions //
157  //////////////////////////////////////
159  std::filesystem::path H5FileName;
160  // HDF5 orbital file version
161  typedef enum
162  {
165  } FormatType;
169  std::vector<int> Occ;
170  bool ReadOrbitalInfo(bool skipChecks = false);
171  bool ReadOrbitalInfo_ESHDF(bool skipChecks = false);
172  void BroadcastOrbitalInfo();
173  bool CheckLattice();
174 
175  /** read gvectors for each twist
176  * @return true, if psi_g is found
177  */
178  bool ReadGvectors_ESHDF();
179 
184  double MeshFactor;
187  std::vector<std::vector<TinyVector<int, 3>>> Gvecs;
188 
191  // mapping the ions in the supercell to the primitive cell
192  std::vector<int> Super2Prim;
193 
194  /////////////////////////////
195  // Twist angle information //
196  /////////////////////////////
197  // The "true" twist number after analyzing twistnum, twist XML input and h5
199  // primitive cell k-points from DFT calculations
200  std::vector<TinyVector<double, OHMMS_DIM>> primcell_kpoints;
201  // primitive cell to supercell tiling matrix
203  // This vector stores which twist indices will be used by this clone
204  std::vector<TinyVector<int, OHMMS_DIM>> UseTwists;
205  std::vector<int> IncludeTwists, DistinctTwists;
206  /// if false, splines are conceptually complex valued
209  // This is true if the corresponding twist in DistinctTwists should
210  // should be used to generate two distinct orbitals from the real and
211  // imaginary parts.
212  std::vector<bool> MakeTwoCopies;
213  // This maps a 3-integer twist index into the twist number in the file
214  std::map<TinyVector<int, OHMMS_DIM>, int, Int3less> TwistMap;
215 
216  bool TwistPair(PosType a, PosType b) const;
217  void TileIons();
218  void OccupyBands(int spin, int sortBands, int numOrbs, bool skipChecks = false);
219  void OccupyBands_ESHDF(int spin, int sortBands, int numOrbs);
220 
221  ////////////////////////////////
222  // Atomic orbital information //
223  ////////////////////////////////
224  struct CenterInfo
225  {
226  std::vector<int> lmax, spline_npoints, GroupID;
228  std::vector<TinyVector<double, OHMMS_DIM>> ion_pos;
229  int Ncenters;
230 
232 
233  void resize(int ncenters)
234  {
235  Ncenters = ncenters;
236  lmax.resize(ncenters, -1);
237  spline_npoints.resize(ncenters, -1);
238  GroupID.resize(ncenters, 0);
239  spline_radius.resize(ncenters, -1.0);
240  inner_cutoff.resize(ncenters, -1.0);
241  non_overlapping_radius.resize(ncenters, -1.0);
242  cutoff.resize(ncenters, -1.0);
243  ion_pos.resize(ncenters);
244  }
246 
247  // This returns the path in the HDF5 file to the group for orbital
248  // with twist ti and band bi
249  std::string OrbitalPath(int ti, int bi);
250 
251  /////////////////////////////////////////////////////////////
252  // Information to avoid storing the same orbitals twice in //
253  // spin-restricted calculations. //
254  /////////////////////////////////////////////////////////////
256 
257  std::string occ_format;
260 
261 protected:
262  /** broadcast SortBands
263  * @param N number of state
264  * @param root true if it is the i/o node
265  */
266  void bcastSortBands(int splin, int N, bool root);
267 
268  /** a specific but clean code path in createSPOSetFromXML, for PBC, double, ESHDF
269  * @param cur the current xml node
270  */
271  void set_metadata(int numOrbs,
272  int twist_num_inp,
273  const TinyVector<double, OHMMS_DIM>& twist_inp,
274  bool skipChecks = false);
275 
276  /** analyze twists of orbitals in h5 and determinine twist_num_
277  * @param twist_num_inp twistnum XML input
278  * @param twist_inp twst XML input
279  */
280  void AnalyzeTwists2(const int twist_num_inp, const TinyVector<double, OHMMS_DIM>& twist_inp);
281 
282  /// twistnum_inp == -9999 to indicate no given input after parsing XML
283  static constexpr int TWISTNUM_NO_INPUT = -9999;
284  /// twist_inp[i] <= -9999 to indicate no given input after parsing XML
285  static constexpr double TWIST_NO_INPUT = -9999;
286 };
287 
288 } // namespace qmcplusplus
289 
290 
291 #endif
std::unique_ptr< SPOSet > createSPOSet(xmlNodePtr cur, SPOSetInputInfo &input_info) override
initialize with the existing SPOSet
bool TwistPair(PosType a, PosType b) const
bool operator()(const TinyVector< int, 4 > &a, const TinyVector< int, 4 > &b) const
int NumOrbs
number of orbitals that belong to this set
const PSetMap & ParticleSets
reference to the particleset pool
Tensor< double, OHMMS_DIM > GGt
Tensor< int, OHMMS_DIM > TileMatrix
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
class to read state range information from sposet input
QTBase::RealType RealType
Definition: Configuration.h:58
std::map< H5OrbSet, SPOSet *, H5OrbSet > SPOSetMap
ParticleSet & TargetPtcl
quantum particle set
std::map< TinyVector< int, OHMMS_DIM >, int, Int3less > TwistMap
std::vector< TinyVector< double, OHMMS_DIM > > ion_pos
Define helper class to sort bands according to the band and twist and functions.
void OccupyBands_ESHDF(int spin, int sortBands, int numOrbs)
struct qmcplusplus::EinsplineSetBuilder::CenterInfo AtomicCentersInfo
ParticleSet * SourcePtcl
ionic system
class to handle hdf file
Definition: hdf_archive.h:51
void AnalyzeTwists2(const int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp)
analyze twists of orbitals in h5 and determinine twist_num_
int SpinSet
index for the spin set
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
std::vector< TinyVector< int, OHMMS_DIM > > UseTwists
Wrapping information on parallelism.
Definition: Communicate.h:68
bool HaveOrbDerivs
This is true if we have the orbital derivatives w.r.t. the ion positions.
Vector< TinyVector< double, OHMMS_DIM > > IonPos
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
base class for the real SPOSet builder
Definition: SPOSetBuilder.h:47
Declaration of a base class of SPOSet Builders.
static constexpr double TWIST_NO_INPUT
twist_inp[i] <= -9999 to indicate no given input after parsing XML
void bcastSortBands(int splin, int N, bool root)
broadcast SortBands
H5OrbSet(std::filesystem::path name, int spinSet, int numOrbs)
bool operator()(const H5OrbSet &a, const H5OrbSet &b) const
true if a < b
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
void OccupyBands(int spin, int sortBands, int numOrbs, bool skipChecks=false)
std::unique_ptr< BsplineReader > MixedSplineReader
reader to use BsplineReader
construct a name for spline SPO set
static constexpr int TWISTNUM_NO_INPUT
twistnum_inp == -9999 to indicate no given input after parsing XML
void set_metadata(int numOrbs, int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp, bool skipChecks=false)
a specific but clean code path in createSPOSetFromXML, for PBC, double, ESHDF
std::filesystem::path FileName
name of the HDF5 file
bool ReadGvectors_ESHDF()
read gvectors for each twist
xmlNodePtr XMLRoot
root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version ...
Tensor< double, OHMMS_DIM > LatticeInv
Tensor< double, OHMMS_DIM > SuperLattice
bool operator()(const TinyVector< int, 3 > &a, const TinyVector< int, 3 > &b) const
std::vector< std::vector< TinyVector< int, 3 > > > Gvecs
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
bool ReadOrbitalInfo_ESHDF(bool skipChecks=false)
std::unique_ptr< SPOSet > createSPOSetFromXML(xmlNodePtr cur) override
initialize the Antisymmetric wave function for electrons
Tensor< double, OHMMS_DIM > RecipLattice
EinsplineSetBuilder(ParticleSet &p, const PSetMap &psets, Communicate *comm, xmlNodePtr cur)
constructor
Tensor< double, OHMMS_DIM > Lattice
bool use_real_splines_
if false, splines are conceptually complex valued
std::string OrbitalPath(int ti, int bi)