CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ECIContainer.cc
Go to the documentation of this file.
2 
3 namespace CASM {
4 
6  double operator*(const ECIContainer &_eci, const Correlation &_corr) {
7  double result(0);
8  auto ind_it(_eci.index().cbegin()), ind_end(_eci.index().cend());
9  auto eci_it(_eci.value().cbegin());
10  for(; ind_it != ind_end; ++ind_it, ++eci_it)
11  result += (*eci_it) * _corr[*ind_it];
12  return result;
13  }
14 
16  double operator*(const ECIContainer &_eci, double const *_corr_begin) {
17  double result(0);
18  auto ind_it(_eci.index().cbegin()), ind_end(_eci.index().cend());
19  auto eci_it(_eci.value().cbegin());
20  while(ind_it != ind_end) {
21  result += (*eci_it) * (*(_corr_begin + *ind_it));
22  ++ind_it;
23  ++eci_it;
24  }
25  return result;
26  }
27 
48  ECIContainer read_eci_out(const fs::path &filepath) {
49 
50  std::vector<double> value;
51  std::vector<ECIContainer::size_type> index;
52 
53  //read in from eci,out file
54  std::ifstream ecistream(filepath.string().c_str());
55 
56  //This is where we dump each line of the file as we read
57  std::string stringdump;
58 
59  //skip all the lines until the actual eci values
60  for(int i = 0; i < 7; i++) {
61  std::getline(ecistream, stringdump);
62  }
63 
64  //read the three columns of eci, eci/mult and index line by line
65  while(std::getline(ecistream, stringdump)) {
66  //make a stringstream to split the three values of the line we just read
67  std::istringstream eciline_stream(stringdump);
68  double eci_value, eci_over_mult;
69  Index eci_index;
70 
71  eciline_stream >> eci_value;
72  eciline_stream >> eci_over_mult;
73  eciline_stream >> eci_index;
74 
75  //store the values we just read
76  value.push_back(eci_value);
77  index.push_back(eci_index);
78  }
79  return ECIContainer(value.begin(), value.end(), index.begin());
80  }
81 
82 
115  ECIContainer read_eci(const fs::path &filepath) {
116 
117  std::vector<double> value;
118  std::vector<ECIContainer::size_type> index;
119 
120  jsonParser json(filepath);
121  for(auto it = json["cluster_functions"].begin(); it != json["cluster_functions"].end(); ++it) {
122  auto eci = it->find("eci");
123  if(eci != it->end()) {
124  value.push_back(eci->get<double>());
125  index.push_back(it->find("linear_function_index")->get<ECIContainer::size_type>());
126  }
127  }
128  return ECIContainer(value.begin(), value.end(), index.begin());
129  }
130 
131 }
pair_type eci
Definition: settings.cc:112
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:465
Main CASM namespace.
Definition: complete.cpp:8
Clexulator::size_type size_type
Definition: ECIContainer.hh:16
ECIContainer read_eci(const fs::path &filepath)
Read eci.json file from specified path.
const std::vector< double > & value() const
const Access ECI values
Definition: ECIContainer.hh:44
BasisSet operator*(const SymOp &LHS, const BasisSet &RHS)
Definition: BasisSet.cc:1154
EigenIndex Index
For long integer indexing:
ECIContainer read_eci_out(const fs::path &filepath)
Read eci.out file from specified path (deprecated)
Definition: ECIContainer.cc:48
const std::vector< size_type > & index() const
const Access orbit indices of ECI values
Definition: ECIContainer.hh:49
Eigen::VectorXd Correlation
Definition: Correlation.hh:9
A sparse container of ECI values and their corresponding orbit indices.
Definition: ECIContainer.hh:12