CASM  1.1.0
A Clusters Approach to Statistical Mechanics
enumerate_configurations_json_io.cc
Go to the documentation of this file.
2 
8 
9 namespace CASM {
10 
17  jsonParser const &json_options, jsonParser const &cli_options_as_json) {
18  jsonParser json_combined{json_options};
19 
29 
30  if (cli_options_as_json.contains("min")) {
31  json_combined["supercells"]["min"] = cli_options_as_json["min"];
32  }
33  if (cli_options_as_json.contains("max")) {
34  json_combined["supercells"]["max"] = cli_options_as_json["max"];
35  }
36  if (cli_options_as_json.contains("scelnames")) {
37  json_combined["scelnames"] = cli_options_as_json["scelnames"];
38  }
39  if (cli_options_as_json.contains("confignames")) {
40  json_combined["confignames"] = cli_options_as_json["scelnames"];
41  }
42  if (cli_options_as_json.contains("all") &&
43  cli_options_as_json["all"] == true) {
44  if (json_combined.contains("supercells")) {
45  json_combined.erase("supercells");
46  }
47  if (json_combined.contains("scelnames")) {
48  json_combined.erase("scelnames");
49  }
50  if (json_combined.contains("confignames")) {
51  json_combined.erase("confignames");
52  }
53  if (json_combined.contains("config_selection")) {
54  json_combined.erase("config_selection");
55  }
56  json_combined["supercell_selection"] = "ALL";
57  }
58  if (cli_options_as_json.contains("filter")) {
59  json_combined["filter"] = cli_options_as_json["filter"];
60  }
61  if (cli_options_as_json.contains("verbosity")) {
62  json_combined["verbosity"] = cli_options_as_json["verbosity"];
63  }
64  if (cli_options_as_json.contains("dry_run")) {
65  json_combined["dry_run"] = cli_options_as_json["dry_run"];
66  }
67 
68  return json_combined;
69 }
70 
71 // Enable InputParser<ConfigEnumOptions>
72 void parse(InputParser<ConfigEnumOptions> &parser, std::string method_name,
73  PrimClex const &primclex,
75  parser.value = notstd::make_unique<ConfigEnumOptions>(primclex);
76  auto &options = *parser.value;
77 
78  options.method_name = method_name;
79 
80  parser.optional_else(options.primitive_only, "primitive_only", true);
81 
82  parser.optional_else(options.dry_run, "dry_run", false);
83 
84  options.verbosity = parse_verbosity(parser);
85 
86  parser.optional(options.filter_expression, "filter");
87  if (!options.filter_expression.empty()) {
88  options.filter =
89  make_data_formatter_filter(options.filter_expression, dict);
90  }
91 
92  parser.optional_else(options.output_configurations, "output_configurations",
93  false);
94 
95  if (options.output_configurations) {
96  // TODO: separate parser for FormattedDataFileOptions
97 
98  fs::path base{"output_configurations_options"};
99 
100  std::string file_path_str;
101  parser.optional_else<std::string>(file_path_str, base / "path", "enum.out");
102  fs::path file_path{file_path_str};
103 
104  bool json_output;
105  parser.optional_else(json_output, base / "json", false);
106 
107  bool json_arrays_output;
108  parser.optional_else(json_arrays_output, base / "json_arrays", false);
109 
110  bool compress;
111  parser.optional_else(compress, base / "compress", false);
112 
113  if (compress) {
114  if (file_path.extension() != ".gz" && file_path.extension() != ".GZ") {
115  file_path += ".gz";
116  }
117  }
118 
119  bool output_filtered_configurations;
120  parser.optional_else(output_filtered_configurations,
121  base / "output_filtered_configurations", false);
122 
123  options.output_options = FormattedDataFileOptions{
124  file_path, json_output, json_arrays_output, compress};
125  options.output_filtered_configurations = output_filtered_configurations;
126  }
127 }
128 } // namespace CASM
Parsing dictionary for constructing a DataFormatter<DataObject> object.
std::unique_ptr< RequiredType > optional(fs::path option, Args &&... args)
RequiredType optional_else(fs::path option, const RequiredType &_default, Args &&... args)
std::unique_ptr< T > value
Definition: InputParser.hh:234
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:601
size_type erase(const std::string &name)
Erase key:value pair from an object.
Definition: jsonParser.cc:607
Main CASM namespace.
Definition: APICommand.hh:8
DataFormatterFilter< DataObject > make_data_formatter_filter(std::string const &filter_expr, DataFormatterDictionary< DataObject > const &_dict)
int parse_verbosity(KwargsParser &parser, int default_verbosity=10)
Definition: InputParser.cc:123
jsonParser combine_configuration_enum_json_options(jsonParser const &json_options, jsonParser const &cli_options_as_json)
void parse(InputParser< ConfigEnumOptions > &parser, std::string method_name, PrimClex const &primclex, DataFormatterDictionary< Configuration > const &dict)
PrimClex * primclex
Definition: settings.cc:135