CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ClusterOrbits_json_io.cc
Go to the documentation of this file.
2 
3 #include "casm/casm_io/Log.hh"
10 // #include "casm/global/enum/json_io.hh"
11 
14 
15 namespace CASM {
16 
19  jsonParser &json) {
20  to_json(orbit_generator.prototype, json);
21  json["include_subclusters"] = orbit_generator.include_subclusters;
22  return json;
23 }
24 
43 void parse(InputParser<std::vector<IntegralClusterOrbitGenerator>> &parser,
44  Structure const &prim) {
45  const jsonParser &json = parser.self;
46 
47  if (!json.is_array()) {
48  parser.error.insert(
49  "Error reading orbit generating clusters: Expected a JSON array");
50  return;
51  }
52 
53  parser.value =
54  notstd::make_unique<std::vector<IntegralClusterOrbitGenerator>>();
55  auto &custom_generators = *parser.value;
56  try {
57  // for each custom orbit
58  Index i = 0;
59  for (auto it = json.begin(); it != json.end(); ++it) {
60  // read orbit generating cluster from JSON
61  fs::path relpath = std::to_string(i);
62  auto subparser = parser.subparse<IntegralCluster>(relpath, prim);
63 
64  if (subparser->valid()) {
65  // check if subclusters should be included (yes by default)
66  bool include_subclusters;
67  parser.optional_else(include_subclusters,
68  relpath / "include_subclusters", true);
69 
70  custom_generators.emplace_back(*(subparser->value),
71  include_subclusters);
72  } else {
73  return;
74  }
75  ++i;
76  }
77  } catch (std::exception &e) {
78  parser.error.insert(
79  std::string("Error: Could not read orbit generating clusters: ") +
80  e.what());
81  }
82 }
83 } // namespace CASM
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:30
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:497
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:520
bool is_array() const
Check if array type.
Definition: jsonParser.cc:275
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
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)