QMCPACK
SkParserScalarDat.cpp
Go to the documentation of this file.
1 #include "SkParserScalarDat.h"
3 #include "Configuration.h"
4 #include <fstream>
5 #include <iostream>
6 
7 
8 namespace qmcplusplus
9 {
12 
13 void SkParserScalarDat::read_sk_file(const std::string& fname)
14 {
15  IndexType IDENT = 7; //This is the position of character which denotes difference
16  //between rhok_e_e_X, rhok_e_i_X, and rhok_e_r_X. Either e,i, or r.
17  std::vector<std::vector<RealType>> skdata(0);
18 
19  std::vector<RealType> rho_ee(0);
20  std::vector<RealType> rho_ee_err(0);
21  std::vector<RealType> rho_i(0);
22  std::vector<RealType> rho_r(0);
23  std::vector<RealType> rho_i_err(0);
24  std::vector<RealType> rho_r_err(0);
25 
26  std::ifstream f;
27  f.open(fname.c_str(), std::ifstream::in);
28 
29  std::string obsname(""), eq(""), pm(""); //just a sink for getline.
30  RealType val_tmp(0.0), err_tmp(0.0);
31 
32 
33  while (!f.eof())
34  {
35  f >> obsname >> eq >> val_tmp >> pm >> err_tmp;
36 
37  if (obsname.find("rhok_e_") != std::string::npos)
38  {
39  //Great. Found the sk data. Now to determine if its rhok*rhok, Re(Rhok), or Im(rhok)
40  if (obsname[IDENT] == 'e')
41  {
42  // app_log()<<" rho_ee_"<<rho_ee.size()<<" = "<<val_tmp<<" +/- "<<err_tmp<<endl;
43  rho_ee.push_back(val_tmp);
44  rho_ee_err.push_back(err_tmp);
45  }
46  else if (obsname[IDENT] == 'i')
47  {
48  // app_log()<<" rho_i_"<<rho_i.size()<<" = "<<val_tmp<<" +/- "<<err_tmp<<endl;
49  rho_i.push_back(val_tmp);
50  rho_i_err.push_back(err_tmp);
51  }
52  else if (obsname[IDENT] == 'r')
53  {
54  // app_log()<<" rho_r_"<<rho_r.size()<<" = "<<val_tmp<<" +/- "<<err_tmp<<endl;
55  rho_r.push_back(val_tmp);
56  rho_r_err.push_back(err_tmp);
57  }
58  else
59  APP_ABORT("ERROR SkParserScalarDat. Unexpected rhok_e_X... found. ");
60 
61  obsname = "";
62  }
63  else
64  continue;
65  //corresponds to kx, ky, kz, S(k), err
66  }
67 
68  //check to make sure all vectors have the same length;
69  IndexType Nk = rho_ee.size();
70  if (rho_ee_err.size() != Nk)
71  APP_ABORT("ERROR SkParserScalarDat: density data not the same size");
72  if (rho_i.size() != Nk || rho_i_err.size() != Nk)
73  APP_ABORT("ERROR SkParserScalarDat: density data not the same size");
74  if (rho_r.size() != Nk || rho_r_err.size() != Nk)
75  APP_ABORT("ERROR SkParserScalarDat: density data not the same size");
76 
77  skraw.resize(Nk);
78  skerr_raw.resize(Nk);
79  //Now we have all the data. Need to build Ne*dS(k)=<rho-k*rhok> - <rho-k><rhok>
80  // app_log()<<"DEBUG:\n";
81  // app_log()<<"i sk skerr rho_ee rho_ee_err rho_r rho_r_err rho_i rho_i_err\n";
82  for (IndexType i = 0; i < Nk; i++)
83  {
84  RealType r_r(0.0);
85  RealType r_i(0.0);
86  //The 3.0 in the following statements is the standard deviation.
87  // If function value is greater than 3standard deviations above error,
88  // then we set it. Otherwise default to zero.
89  if (rho_r_err[i] == 0 || std::abs(rho_r[i]) / rho_r_err[i] > 3.0)
90  r_r = rho_r[i];
91  if (rho_i_err[i] == 0 || std::abs(rho_i[i]) / rho_i_err[i] > 3.0)
92  r_i = rho_i[i];
93 
94  skraw[i] = rho_ee[i] - (r_r * r_r + r_i * r_i); //<rho_-k><rho_k> = |rho_k|^2
95  skerr_raw[i] = rho_ee_err[i]; //Actual error distribution is a gaussian + a product distribution.
96  //However, error in rho-k*rhok is drastically larger than rhok, so
97  //we ignore the rhok contribution.
98 
99  // app_log()<<i<<" "<<skraw[i]<<" "<<skerr_raw[i]<<" "<<rho_ee[i]<<" "<<rho_ee_err[i]<<" "<<rho_r[i]<<" "<<rho_r_err[i]<<" "<<rho_i[i]<<" "<<rho_i_err[i]<<endl;
100  }
101 
102  return;
103 }
104 
105 
106 void SkParserScalarDat::parse(const std::string& fname)
107 {
108  // vector<vector<RealType> > rawdata(0);
109  read_sk_file(fname);
110  // kgridraw=get_grid_from_data(rawdata);
111  // skraw=get_sk_from_data(rawdata);
112  // skerr_raw=get_skerr_from_data(rawdata);
113 
114 
115  // cout<<"Ok. In SkParserScalarDat\n";
116  // cout<<" print kgridraw, skraw, skerr\n";
117  // for(int i=0; i<kgridraw.size();i++) cout<<kgridraw[i][0]<<" "<<kgridraw[i][1]<<" "<<kgridraw[i][2]<<" "<<skraw[i]<<" "<<skerr_raw[i]<<endl;
118  hasGrid = false;
119  isNormalized = false;
120  isParseSuccess = true;
121 }
122 } // namespace qmcplusplus
std::vector< RealType > skerr_raw
Definition: SkParserBase.h:60
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::vector< RealType > skraw
Definition: SkParserBase.h:59
QMCTraits::PosType PosType
QTBase::PosType PosType
Definition: Configuration.h:61
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
OHMMS_INDEXTYPE IndexType
define other types
Definition: Configuration.h:65
void parse(const std::string &fname) override
QMCTraits::RealType RealType
void read_sk_file(const std::string &fname)