CASM  1.1.0
A Clusters Approach to Statistical Mechanics
BasisFunctionSpecs_json_io.cc
Go to the documentation of this file.
2 
9 
10 namespace CASM {
11 
13 
14 // TODO: JCT, check this, particularly the continuous DoF options documentation
15 
16 void parse(InputParser<BasisFunctionSpecs> &parser, Structure const &prim,
87  ParsingDictionary<DoFType::Traits> const *dof_dict) {
88  // read generic JSON into a BasisFunctionSpecs object
89  parser.value = notstd::make_unique<BasisFunctionSpecs>();
90  auto &basis_function_specs = *parser.value;
91 
92  // parse "dofs", using all dof types in prim as default value
93  auto all_dof_keys = all_dof_types(prim.structure());
94  parser.optional_else(basis_function_specs.dof_keys, "dofs", all_dof_keys);
95 
96  // parse "global_max_poly_order"
97  parser.optional_else(basis_function_specs.global_max_poly_order,
98  "global_max_poly_order", Index{-1});
99 
100  // parse "orbit_branch_max_poly_order"
101  if (parser.self.contains("orbit_branch_max_poly_order")) {
102  std::stringstream err_msg;
103  err_msg << "Error: could not read 'orbit_branch_max_poly_order': Expected "
104  "an object with "
105  "pairs of \"<branch>\":<max_poly_order>, where <branch> is the "
106  "number of sites in a cluster "
107  "(as a string), and <max_poly_order> is an integer.";
108 
109  auto const &json = parser.self["orbit_branch_max_poly_order"];
110 
111  try {
112  for (auto it = json.begin(); it != json.end(); ++it) {
113  Index branch = std::stoi(it.name());
114  Index max_poly_order = it->get<Index>();
115  parser.value->orbit_branch_max_poly_order[branch] = max_poly_order;
116  }
117  } catch (std::exception &e) {
118  parser.error.insert(err_msg.str());
119  }
120  }
121 
122  // parse "include_functions", "exclude_functions"
123  parser.optional(basis_function_specs.include_functions, "include_functions");
124  parser.optional(basis_function_specs.exclude_functions, "exclude_functions");
125 
126  // parse "param_pack_type"
127  parser.optional_else(basis_function_specs.param_pack_type, "param_pack_type",
129 
130  // parse & validate "dof_specs" for each DoF type here...
131  for (const auto &key : all_dof_keys) {
132  dof_dict->lookup(key).parse_dof_specs(parser, prim);
133  }
134 }
135 
136 jsonParser &to_json(const BasisFunctionSpecs &basis_function_specs,
137  jsonParser &json, Structure const &prim,
138  ParsingDictionary<DoFType::Traits> const *dof_dict) {
139  json = jsonParser::object();
140  json["dofs"] = basis_function_specs.dof_keys;
141  json["global_max_poly_order"] = basis_function_specs.global_max_poly_order;
142  for (auto const &pair : basis_function_specs.orbit_branch_max_poly_order) {
143  json["orbit_branch_max_poly_order"][std::to_string(pair.first)] =
144  pair.second;
145  }
146  json["param_pack_type"] = basis_function_specs.param_pack_type;
147  if (basis_function_specs.include_functions.size()) {
148  json["include_functions"] = basis_function_specs.include_functions;
149  }
150  if (basis_function_specs.exclude_functions.size()) {
151  json["exclude_functions"] = basis_function_specs.exclude_functions;
152  }
153 
154  // parse & validate specialized DoFType specs from JSON here...
155  auto all_dof_keys = all_dof_types(prim.structure());
156  for (const auto &key : all_dof_keys) {
157  dof_dict->lookup(key).dof_specs_to_json(basis_function_specs, json, prim);
158  }
159 
160  return json;
161 }
162 
163 } // namespace CASM
#define ENUM_JSON_IO_DEF(ENUM)
Definition: json_io.hh:15
Parsing dictionary for obtaining the correct MoleculeAttribute given a name.
T const & lookup(const key_type &_name) const
Equivalent to find, but set 'home' and throws error with suggestion if.
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:30
const xtal::BasicStructure & structure() const
Definition: Structure.hh:92
static jsonParser object()
Returns an empty json object.
Definition: jsonParser.hh:395
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
std::vector< DoFKey > all_dof_types(BasicStructure const &_struc)
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)
Specify how to construct basis functions.
PARAM_PACK_TYPE param_pack_type
Specify the Clexulator underlying data structure type.
std::vector< Index > include_functions
std::map< OrbitBranchSize, MaxPolyOrder > orbit_branch_max_poly_order
std::vector< Index > exclude_functions
std::vector< DoFKey > dof_keys
Which DoF types to include in the basis functions.