QMCPACK
WriteEshdf.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 ) 2018 QMCPACK developers
6 //
7 // File developed by : Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
8 //
9 // File created by : Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
10 /////////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef WRITE_ESHDF_H
14 #define WRITE_ESHDF_H
15 #include "hdf/hdf_archive.h"
16 #include <string>
17 #include <fstream>
18 #include <vector>
19 #include <cmath>
20 #include <map>
21 #include <complex>
22 
23 class XmlNode;
24 class FftContainer;
25 class KPoint;
26 
27 /*! helper class meant to control access ot the eshdf file that is being
28  created and provide helper functions so that the proper xml data
29  from QBOX or quantum espresso can be handed to it and the data can
30  be processed and written to the eshdf file
31 */
32 class EshdfFile
33 {
34  using momap_t = std::map<std::vector<int>, std::complex<double>>;
35  using mopair_t = std::pair<std::vector<int>, std::complex<double>>;
36 
37 private:
39 
40  /*! helper indexing function to go from the interval [0,size) to (-size/2,size/2) */
41  int wrapped(int i, int size) const;
42  /*! helper function that takes a string and returns an int consisting of only the numerals in the string */
43  int getIntsOnly(const std::string& str) const;
44  /*! writes to the application field of outfile_ (code -> appName), (version -> major,minor,sub) */
45  void writeApplication(const std::string& appName, int major, int minor, int sub);
46  /*! writes to the creator field of outfile_ (program_name -> convertpw4qmc), (version -> 0,1,0) */
47  void writeCreator();
48  /*! writes to the format field of outfile_ (format -> ES-HDF) */
49  void writeFormat();
50  /*! writes to the version field of outfile_ (version -> 2,1,0) */
51  void writeVersion();
52 
53  // helper functions meant for qbox
54  /*! to be handed a grid_function tag of the qbox sample file. Will then read in the
55  eigenfunciton (spo) in real-space and use the FftContainer cont to transform
56  them to k-space */
57  void readInEigFcn(const XmlNode& nd, FftContainer& cont);
58  /*! to be handed a slater_determinant tag of the qbox sample file. Will read in the
59  occupations and call readInEigFcn for each state, also needs an FftContainer to
60  pass on to readInEigFcn */
61  void handleSpinGroup(const XmlNode* nd, double& nocc, FftContainer& cont);
62  /*! to be handed a slater_determinant tag from the qbox sample file. Will read in
63  the occupations from the density_matrix subnode add the total which will be
64  returned as output */
65  double getOccupation(const XmlNode* nd) const;
66 
67  // helper functions meant for espresso
68  /*! to be handed the top level xml node from data-file-schema, also a string naming
69  the directory where the charge-density.hdf5 file is located and an integer
70  spinpol which is 0 for a non spin polarized calculation and 1 for one that is */
71  void handleDensity(const XmlNode& qeXml, const std::string& dir_name, int spinpol);
72  /*! to be handed the top level xml node from data-file-schema, reads the
73  reciprocal lattice vectors from the xml, calculates the primitive translation
74  vectors and puts them sequentially in a 9 element long std::vector */
75  std::vector<double> getPtvs(const XmlNode& qeXml);
76  /*! to be handed a band_structure xml node from data-file-schema as well as the 9
77  element vector of ptvs. Then will populate the eigenvalues per kpoint,
78  occupations per kpoint, kpoints,
79  and the weights and number of g-vectors for each kpoint */
80  void processKPts(const XmlNode& band_structure_xml,
81  const std::vector<double>& ptvs,
82  std::vector<std::vector<double>>& eigenvals,
83  std::vector<std::vector<double>>& occupations,
84  std::vector<KPoint>& kpts,
85  std::vector<double>& weights,
86  std::vector<int>& ngvecs);
87  /*! will use the occupations and weights to figure out the total number
88  of up and down electrons (nup,ndn). Also needs a flag to see if the
89  calculation was spin_polarized (0 for no, 1 for yes) and another to
90  see if noncolinear spins were used (0 for no, 1 for yes)
91  */
92  void getNumElectrons(std::vector<std::vector<double>>& occupations,
93  std::vector<double>& weights,
94  int& nup,
95  int& ndn,
96  int spinpol,
97  int ncol);
98  /*! helper function to read in the data from the wfc(kpt_num).hdf5 files located in
99  directory dir_name. Needs to know the KPoint, its eigenvalues, weight, the
100  flags for spinolarized and noncolinear as well as the momap_t that handles
101  the global mapping from g_vectors at individual k_points to global ones
102  */
103  void handleKpt(int kpt_num,
104  const std::string& dir_name,
105  KPoint& kpt,
106  const std::vector<double>& eigenvalues,
107  double weight,
108  int spinpol,
109  int noncol,
110  const momap_t& moref);
111  /*! handles reading in the g-vectors for a particular k-point so that they can be inserted
112  into a momap_t. Needs to know the number of the kpoint (kpt_num), the directory where
113  it is located (dir_name) and whether it is spin polarized (spinpol)
114  */
115  void readKptGvecs(int kpt_num, const std::string& dir_name, int spinpol, momap_t& morefmap);
116  /*! will open the hdf file fname and will make an hdf_archive */
117  qmcplusplus::hdf_archive openHdfFileForRead(const std::string& fname);
118 
119  EshdfFile(const EshdfFile& f); // no copy constructor
120  EshdfFile& operator=(const EshdfFile& f); // operator= not allowed
121 public:
122  /*! constructor that sets up the hdf_archive data structure that will hold the eshdf
123  file to be created. Needs to be give the name for that file (hdfFileName)
124  */
125  EshdfFile(const std::string& hdfFileName);
126  ~EshdfFile();
127 
128  /*! functions to get the boilerplate written for qbox or quantum espresso
129  calls writeApplication, writeVersion, writeCreator and writeFormat
130  nees to be handed the top level xml node (data-file-schema or qbox.sample)
131  */
132  void writeQEBoilerPlate(const XmlNode& qeXml);
133  void writeQboxBoilerPlate(const XmlNode& qboxSample);
134 
135  /*! functions to write the supercell and primitive_vectors sections of the
136  eshdf file. Needs to be handed the top level xml node (data-file-schema or qbox.sample)
137  */
138  void writeQESupercell(const XmlNode& qeXml);
139  void writeQboxSupercell(const XmlNode& qboxSample);
140 
141  /*! functions to write the atoms section of the eshdf file
142  needs to be handed the top level xml node (data-file-schema or qbox.sample)
143  */
144  void writeQEAtoms(const XmlNode& qeXml);
145  void writeQboxAtoms(const XmlNode& qboxSample);
146 
147  /*! functions to write the electrons section of the eshdf file
148  need to be handed the top level xml node (data-file-schema or qbox.sample)
149  in the case of espresso, also needs to be handed the directory name
150  where the wfc.hdf5 and charge-density.hdf5 files are located
151  */
152  void writeQEElectrons(const XmlNode& qeXml, const std::string& dir_name);
153  void writeQboxElectrons(const XmlNode& qboxSample);
154 };
155 
156 #endif
qmcplusplus::hdf_archive outfile_
Definition: WriteEshdf.h:38
void writeVersion()
Definition: WriteEshdf.cpp:218
double getOccupation(const XmlNode *nd) const
Definition: WriteEshdf.cpp:96
EshdfFile & operator=(const EshdfFile &f)
void writeFormat()
Definition: WriteEshdf.cpp:234
Definition: XmlRep.h:81
void processKPts(const XmlNode &band_structure_xml, const std::vector< double > &ptvs, std::vector< std::vector< double >> &eigenvals, std::vector< std::vector< double >> &occupations, std::vector< KPoint > &kpts, std::vector< double > &weights, std::vector< int > &ngvecs)
Definition: WriteEshdf.cpp:568
void handleDensity(const XmlNode &qeXml, const std::string &dir_name, int spinpol)
Definition: WriteEshdf.cpp:492
std::vector< double > getPtvs(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:660
int getIntsOnly(const std::string &str) const
Definition: WriteEshdf.cpp:261
class to handle hdf file
Definition: hdf_archive.h:51
void readKptGvecs(int kpt_num, const std::string &dir_name, int spinpol, momap_t &morefmap)
Definition: WriteEshdf.cpp:684
qmcplusplus::hdf_archive openHdfFileForRead(const std::string &fname)
Definition: WriteEshdf.cpp:477
void writeCreator()
Definition: WriteEshdf.cpp:224
void handleSpinGroup(const XmlNode *nd, double &nocc, FftContainer &cont)
Definition: WriteEshdf.cpp:110
std::map< std::vector< int >, std::complex< double > > momap_t
Definition: WriteEshdf.h:34
void writeQEElectrons(const XmlNode &qeXml, const std::string &dir_name)
Definition: WriteEshdf.cpp:980
void writeQEAtoms(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:352
void readInEigFcn(const XmlNode &nd, FftContainer &cont)
Definition: WriteEshdf.cpp:152
void handleKpt(int kpt_num, const std::string &dir_name, KPoint &kpt, const std::vector< double > &eigenvalues, double weight, int spinpol, int noncol, const momap_t &moref)
Definition: WriteEshdf.cpp:713
void writeQboxBoilerPlate(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:240
void getNumElectrons(std::vector< std::vector< double >> &occupations, std::vector< double > &weights, int &nup, int &ndn, int spinpol, int ncol)
Definition: WriteEshdf.cpp:608
void writeQEBoilerPlate(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:279
EshdfFile(const EshdfFile &f)
void writeApplication(const std::string &appName, int major, int minor, int sub)
Definition: WriteEshdf.cpp:206
int wrapped(int i, int size) const
Definition: WriteEshdf.cpp:84
std::pair< std::vector< int >, std::complex< double > > mopair_t
Definition: WriteEshdf.h:35
void writeQboxElectrons(const XmlNode &qboxSample)
void writeQboxAtoms(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:412
void writeQESupercell(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:327
void writeQboxSupercell(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:304