CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigEnumAllOccupationsInterface.cc
Go to the documentation of this file.
2 
3 #include "casm/app/APICommand.hh"
13 #include "casm/clex/PrimClex.hh"
16 
17 namespace CASM {
18 
20  std::string custom_options = "";
21 
22  std::string examples =
23  " Examples:\n"
24  " To enumerate all occupations in supercells up to and including size "
25  "4:\n"
26  " casm enum --method ConfigEnumAllOccupations -i '{\"supercells\": "
27  "{\"max\": 4}}' \n"
28  "\n"
29  " To enumerate all occupations in all existing supercells:\n"
30  " casm enum --method ConfigEnumAllOccupations --all\n"
31  "\n"
32  " To enumerate all occupations in particular supercells:\n"
33  " casm enum --method ConfigEnumAllOccupations -i \n"
34  " '{ \n"
35  " \"scelnames\": [\n"
36  " \"SCEL1_1_1_1_0_0_0\",\n"
37  " \"SCEL2_1_2_1_0_0_0\",\n"
38  " \"SCEL4_1_4_1_0_0_0\"\n"
39  " ]\n"
40  " }' \n\n";
41 
42  return name() + ": \n\n" + custom_options + standard_ConfigEnumInput_help() +
43  examples;
44 }
45 
48 }
49 
51  PrimClex &primclex, jsonParser const &json_options,
52  jsonParser const &cli_options_as_json) const {
53  Log &log = CASM::log();
54 
55  log.subsection().begin("ConfigEnumAllOccupations");
56  ParentInputParser parser =
57  make_enum_parent_parser(log, json_options, cli_options_as_json);
58  std::runtime_error error_if_invalid{
59  "Error reading ConfigEnumAllOccupations JSON input"};
60 
61  log.custom("Checking input");
62 
63  // 1) Parse ConfigEnumOptions ------------------
64 
65  auto options_parser_ptr = parser.parse_as<ConfigEnumOptions>(
67  primclex.settings().query_handler<Configuration>().dict());
68  report_and_throw_if_invalid(parser, log, error_if_invalid);
69  ConfigEnumOptions const &options = *options_parser_ptr->value;
70  print_options(log, options);
71  log.set_verbosity(options.verbosity);
72 
73  // 2) Parse initial enumeration states ------------------
74 
75  auto input_parser_ptr =
76  parser.parse_as<std::vector<std::pair<std::string, ConfigEnumInput>>>(
77  primclex.shared_prim(), &primclex, primclex.db<Supercell>(),
78  primclex.db<Configuration>());
79  report_and_throw_if_invalid(parser, log, error_if_invalid);
80  auto const &named_initial_states = *input_parser_ptr->value;
81  print_initial_states(log, named_initial_states);
82 
83  // 3) Enumerate configurations ------------------
84 
85  auto make_enumerator_f = [&](Index index, std::string name,
86  ConfigEnumInput const &initial_state) {
87  return ConfigEnumAllOccupations{initial_state};
88  };
89 
93  formatter.push_back(ConfigEnumIO::name<ConfigEnumDataType>(),
94  ConfigEnumIO::selected<ConfigEnumDataType>(),
95  ConfigEnumIO::is_new<ConfigEnumDataType>(),
96  ConfigEnumIO::is_existing<ConfigEnumDataType>());
97  if (options.filter) {
98  formatter.push_back(
99  ConfigEnumIO::is_excluded_by_filter<ConfigEnumDataType>());
100  }
101  formatter.push_back(
102  ConfigEnumIO::initial_state_index<ConfigEnumDataType>(),
103  ConfigEnumIO::initial_state_name<ConfigEnumDataType>(),
104  ConfigEnumIO::initial_state_configname<ConfigEnumDataType>(),
105  ConfigEnumIO::n_selected_sites<ConfigEnumDataType>());
106 
107  log << std::endl;
108  log.begin("ConfigEnumAllOccupations enumeration");
109 
110  enumerate_configurations(primclex, options, make_enumerator_f,
111  named_initial_states.begin(),
112  named_initial_states.end(), formatter);
113 
114  log.end_section();
115 }
116 
117 } // namespace CASM
static const std::string enumerator_name
void run(PrimClex &primclex, jsonParser const &json_options, jsonParser const &cli_options_as_json) const override
std::string name() const override
Enumeration method name (i.e. "ConfigEnumAllOccupations")
Extract data from objects of 'DataObject' class.
void push_back(const BaseDatumFormatter< DataObject > &new_formatter, const std::string &args)
std::shared_ptr< InputParser< RequiredType > > parse_as(Args &&... args)
Definition: Log.hh:48
void end_section()
End a section.
Definition: Log.hh:192
void set_verbosity(int _verbosity)
Definition: Log.cc:57
void custom(const std::string &what)
Definition: Log.hh:139
Log & subsection()
Create a subsection.
Definition: Log.hh:186
void begin(const std::string &what)
Definition: Log.hh:114
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
ConfigEnumData< ConfigEnumSiteDoFs, ConfigEnumInput > ConfigEnumDataType
Main CASM namespace.
Definition: APICommand.hh:8
std::string standard_ConfigEnumInput_help()
void print_initial_states(Log &log, NamedInitialStatesType const &named_initial_states)
Log & log()
Definition: Log.hh:424
ParentInputParser make_enum_parent_parser(Log &log, jsonParser const &json_options, jsonParser const &cli_options_as_json)
Combine –input / –settings JSON with CLI options.
void enumerate_configurations(PrimClex const &primclex, ConfigEnumOptions const &options, MakeEnumeratorFunction make_enumerator_f, InputNameValuePairIterator name_value_pairs_begin, InputNameValuePairIterator name_value_pairs_end, DataFormatter< ConfigEnumDataType > const &formatter)
Enumerate configurations.
void report_and_throw_if_invalid(KwargsParser const &parser, Log &log, ErrorType error)
void print_options(Log &log, ConfigEnumOptions const &options)
Definition: stream_io.cc:6
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
PrimClex * primclex
Definition: settings.cc:135
Options for the enumerate_configurations function.
int verbosity
Printing verbosity level.
std::function< bool(Configuration const &)> filter
If filter(configuration)==true, keep configuration, else skip.