CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ECIContainer_json_io.cc
Go to the documentation of this file.
1 #include <vector>
2 
3 #include "casm/casm_io/Log.hh"
6 
7 namespace CASM {
8 
32  std::string orbits_name = "orbits";
33  std::string index_name = "linear_orbit_index";
34 
35  // v0.X compatibility mode:
36  if (parser.self.contains("cluster_functions") &&
37  !parser.self.contains("orbits")) {
38  err_log() << "WARNING: Detected old ECI format (version < 1.0.X): Reading "
39  "\"cluster_functions\" instead of \"orbits\", and "
40  "\"linear_cluster_index\" instead of \"linear_orbit_index\"."
41  << std::endl;
42 
43  orbits_name = "cluster_functions";
44  index_name = "linear_cluster_functions";
45  }
46 
47  if (parser.self.find(orbits_name) == parser.self.end()) {
48  std::stringstream msg;
49  msg << "Error parsing ECI: '" << orbits_name << "' array not found";
50  parser.error.insert(msg.str());
51  return;
52  }
53 
54  std::vector<double> value;
55  std::vector<ECIContainer::size_type> index;
56 
57  jsonParser const &orbits_json = parser.self[orbits_name];
58  fs::path orbits_path{orbits_name};
59  Index i = 0;
60  for (auto const &orbit : orbits_json) {
61  if (orbit.find("eci") != orbit.end()) {
62  double eci_value;
63  ECIContainer::size_type linear_orbit_index;
64  fs::path orbit_path = orbits_path / std::to_string(i);
65  parser.require(eci_value, orbit_path / "eci");
66  parser.require(linear_orbit_index, orbit_path / index_name);
67  value.push_back(eci_value);
68  index.push_back(linear_orbit_index);
69  }
70  ++i;
71  }
72  parser.value = notstd::make_unique<ECIContainer>(value.begin(), value.end(),
73  index.begin());
74 }
75 } // namespace CASM
Clexulator::size_type size_type
Definition: ECIContainer.hh:14
std::unique_ptr< RequiredType > require(fs::path option, Args &&... args)
std::unique_ptr< T > value
Definition: InputParser.hh:234
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:601
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:520
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
Definition: jsonParser.cc:543
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
void parse(InputParser< ConfigEnumOptions > &parser, std::string method_name, PrimClex const &primclex, DataFormatterDictionary< Configuration > const &dict)
Log & err_log()
Definition: Log.hh:426
jsonParser const & self
Definition: InputParser.hh:81
std::set< std::string > error
Definition: Validator.hh:11