QMCPACK
SkParserScalarDat Class Reference

Class to handle Sk parsing from scalar.dat This reads a processed scalar.dat from energy.pl format. More...

+ Inheritance diagram for SkParserScalarDat:
+ Collaboration diagram for SkParserScalarDat:

Public Types

enum  data_layout {
  KX, KY, KZ, SK,
  SKERR
}
 
- Public Types inherited from SkParserBase
using Grid_t = LinearGrid< RealType >
 
- Public Types inherited from QMCTraits
enum  { DIM = OHMMS_DIM, DIM_VGL = OHMMS_DIM + 2 }
 
using QTBase = QMCTypes< OHMMS_PRECISION, DIM >
 
using QTFull = QMCTypes< OHMMS_PRECISION_FULL, DIM >
 
using RealType = QTBase::RealType
 
using ComplexType = QTBase::ComplexType
 
using ValueType = QTBase::ValueType
 
using PosType = QTBase::PosType
 
using GradType = QTBase::GradType
 
using TensorType = QTBase::TensorType
 
using IndexType = OHMMS_INDEXTYPE
 define other types More...
 
using FullPrecRealType = QTFull::RealType
 
using FullPrecValueType = QTFull::ValueType
 
using PropertySetType = RecordNamedProperty< FullPrecRealType >
 define PropertyList_t More...
 
using PtclGrpIndexes = std::vector< std::pair< int, int > >
 

Public Member Functions

void parse (const std::string &fname) override
 
- Public Member Functions inherited from SkParserBase
 SkParserBase ()
 
virtual ~SkParserBase ()
 
void get_grid (Grid_t &xgrid, Grid_t &ygrid, Grid_t &zgrid)
 
void get_sk (std::vector< RealType > &sk, std::vector< RealType > &skerr)
 
std::vector< PosTypeget_grid_raw ()
 
std::vector< RealTypeget_sk_raw ()
 
std::vector< RealTypeget_skerr_raw ()
 
void compute_sk ()
 
void set_grid (const std::vector< PosType > &gridpoints)
 
void set_grid (const std::vector< TinyVector< int, OHMMS_DIM >> &gridpoints)
 
void compute_grid ()
 
bool is_normalized ()
 
bool has_grid ()
 
void setName (std::string in_name)
 

Private Member Functions

void read_sk_file (const std::string &fname)
 

Additional Inherited Members

- Protected Attributes inherited from SkParserBase
bool isParseSuccess
 
bool isGridComputed
 
bool isSkComputed
 
bool hasGrid
 
bool isNormalized
 
Grid_t xgrid
 
Grid_t ygrid
 
Grid_t zgrid
 
std::vector< RealTypeskraw
 
std::vector< RealTypeskerr_raw
 
std::vector< PosTypekgridraw
 
std::vector< RealTypesk
 
std::vector< RealTypeskerr
 
std::vector< PosTypekgrid
 
std::string skname
 

Detailed Description

Class to handle Sk parsing from scalar.dat This reads a processed scalar.dat from energy.pl format.

Data to be read must have rhok_e_e val err rhok_e_r val err rhok_e_i val err

Definition at line 17 of file SkParserScalarDat.h.

Member Enumeration Documentation

◆ data_layout

Member Function Documentation

◆ parse()

void parse ( const std::string &  fname)
overridevirtual

Implements SkParserBase.

Definition at line 106 of file SkParserScalarDat.cpp.

References SkParserBase::hasGrid, SkParserBase::isNormalized, SkParserBase::isParseSuccess, and SkParserScalarDat::read_sk_file().

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 }
void read_sk_file(const std::string &fname)

◆ read_sk_file()

void read_sk_file ( const std::string &  fname)
private

Definition at line 13 of file SkParserScalarDat.cpp.

References qmcplusplus::abs(), APP_ABORT, qmcplusplus::Units::distance::pm, SkParserBase::skerr_raw, and SkParserBase::skraw.

Referenced by SkParserScalarDat::parse().

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 }
std::vector< RealType > skerr_raw
Definition: SkParserBase.h:60
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
#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
QMCTraits::RealType RealType

The documentation for this class was generated from the following files: