CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigEnumIO_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_enumerator_io_formatter_ConfigEnumIO_impl
2 #define CASM_enumerator_io_formatter_ConfigEnumIO_impl
3 
6 #include "casm/clex/PrimClex.hh"
9 #include "casm/misc/TypeInfo.hh"
10 
11 namespace CASM {
12 
13 // Note:
14 // - The following formatters are all templated to expect a ConfigEnumDataType
15 // that follows the
16 // minimum interface defined by `ConfigEnumData`
17 // - Besides the functions included here, you can also use
18 // `make_datum_formatter_adapter` to adapt
19 // DatumFormatters from ConfigIO or ScelIO for use with ConfigEnumDataType.
20 // Examples:
21 // - `make_datum_formatter_adapter<ConfigEnumDataType,
22 // Configuration>(ConfigIO::scelname())`
23 // - `make_datum_formatter_adapter<ConfigEnumDataType,
24 // Supercell>(ScelIO::TransfMat())`
25 // - Note that `make_datum_formatter_adapter` has overrides that can change
26 // the formatter name
27 // if that is appropriate.
28 // - Using `make_datum_formatter_adapter` requires defining an
29 // adapter::Adapter
30 
31 namespace adapter {
32 
33 template <typename EnumeratorType, typename InitialStateType>
34 Configuration const &
36 operator()(
37  ConfigEnumData<EnumeratorType, InitialStateType> const &adaptable) const {
38  return adaptable.configuration;
39 }
40 
41 template <typename EnumeratorType, typename InitialStateType>
42 Supercell const &
44 operator()(
45  ConfigEnumData<EnumeratorType, InitialStateType> const &adaptable) const {
46  return adaptable.configuration.supercell();
47 }
48 
49 } // namespace adapter
50 
51 namespace ConfigEnumIO {
52 
53 template <typename ConfigEnumDataType>
56  "name", "Configuration name, if inserted, else \"none\"",
57  [](ConfigEnumDataType const &data) -> std::string {
58  if (data.is_excluded_by_filter) {
59  return "none";
60  }
61  if (data.insert_result.canonical_it ==
62  data.primclex.template db<Configuration>().end()) {
63  return "none";
64  }
65  return data.insert_result.canonical_it->name();
66  });
67 }
68 
69 template <typename ConfigEnumDataType>
72  "selected", "True if configuration exists in database, else false",
73  [](ConfigEnumDataType const &data) {
74  if (data.is_excluded_by_filter) {
75  return false;
76  }
77  return data.insert_result.canonical_it !=
78  data.primclex.template db<Configuration>().end();
79  });
80 }
81 
82 template <typename ConfigEnumDataType>
85  "is_new",
86  "True if canonical configuration did not exist before insertion. False "
87  "if not checked or was existing before insertion.",
88  [](ConfigEnumDataType const &data) {
89  if (data.is_excluded_by_filter) {
90  return false;
91  }
92  return data.insert_result.insert_canonical;
93  });
94 }
95 
96 template <typename ConfigEnumDataType>
99  "is_existing",
100  "True if canonical configuration did exist before insertion. False if "
101  "not checked or not existing before insertion.",
102  [](ConfigEnumDataType const &data) {
103  if (data.is_excluded_by_filter) {
104  return false;
105  }
106  return !data.insert_result.insert_canonical;
107  });
108 }
109 
110 template <typename ConfigEnumDataType>
113  "is_excluded_by_filter",
114  "True if configuration was excluded by the filter, else false.",
115  [](ConfigEnumDataType const &data) {
116  return data.is_excluded_by_filter;
117  });
118 }
119 
120 template <typename ConfigEnumDataType>
123  "initial_state_index", "Initial state index. From 0.",
124  [](ConfigEnumDataType const &data) { return data.initial_state_index; });
125 }
126 
127 template <typename ConfigEnumDataType>
130  "initial_state_name",
131  "Initial state name. Typically the initital state configuration name "
132  "plus description of selected sites.",
133  [](ConfigEnumDataType const &data) { return data.initial_state_name; });
134 }
135 
136 template <typename ConfigEnumDataType>
140  "initial_state_configname", "Initial state configuration name.",
141  [](ConfigEnumDataType const &data) {
142  return data.initial_state.configuration().name();
143  });
144 }
145 
146 template <typename ConfigEnumDataType>
150  "selected_sites",
151  "Indices of selected sites in the initial state configuration. JSON "
152  "output only.",
153  [](ConfigEnumDataType const &data) {
154  auto const &sites = data.initial_state->sites();
155  return std::vector<Index>{sites.begin(), sites.end()};
156  });
157 }
158 
159 template <typename ConfigEnumDataType>
162  "n_selected_sites",
163  "Number of selected sites in the initial state configuration.",
164  [](ConfigEnumDataType const &data) {
165  return data.initial_state.sites().size();
166  });
167 }
168 
171 template <typename EnumeratorType>
172 Eigen::VectorXd get_normal_coordinate(EnumeratorType const &enumerator) {
173  std::stringstream msg;
174  msg << "Error in get_normal_coordinate: Not supported for this enumerator '"
175  << type_name<EnumeratorType>() << "'";
176  throw std::runtime_error(msg.str());
177 }
178 
179 template <typename ConfigEnumDataType>
183  "normal_coordinate",
184  "Normal coordinate used to generate DoF value. Supported enumerators "
185  "only.",
186  [=](ConfigEnumDataType const &data) -> Eigen::VectorXd {
187  return get_normal_coordinate(data.enumerator);
188  });
189 }
190 } // namespace ConfigEnumIO
191 
192 } // namespace CASM
193 
194 #endif
A DatumFormatter that returns a 1D value of specified type, via functions that may be specified at ru...
A DatumFormatter that returns a value of specified type, via functions that may be specified at runti...
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
GenericDatumFormatter< std::string, ConfigEnumDataType > name()
GenericDatumFormatter< std::string, ConfigEnumDataType > initial_state_configname()
GenericDatumFormatter< bool, ConfigEnumDataType > is_new()
GenericDatumFormatter< bool, ConfigEnumDataType > is_existing()
GenericDatumFormatter< Index, ConfigEnumDataType > initial_state_index()
GenericDatumFormatter< std::string, ConfigEnumDataType > initial_state_name()
Generic1DDatumFormatter< std::vector< Index >, ConfigEnumDataType > selected_sites()
Generic1DDatumFormatter< Eigen::VectorXd, ConfigEnumDataType > normal_coordinate()
GenericDatumFormatter< bool, ConfigEnumDataType > selected()
GenericDatumFormatter< Index, ConfigEnumDataType > n_selected_sites()
GenericDatumFormatter< bool, ConfigEnumDataType > is_excluded_by_filter()
Eigen::VectorXd get_normal_coordinate(EnumeratorType const &enumerator)
ConfigEnumData< ConfigEnumSiteDoFs, ConfigEnumInput > ConfigEnumDataType
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::VectorXd VectorXd