CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Enumerator_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_Enumerator_impl
2 #define CASM_Enumerator_impl
3 
6 #include "casm/clex/PrimClex.hh"
9 
10 namespace CASM {
11 
23  template<typename ScelIterator, typename ConfigEnumConstructor>
25  std::string method,
27  ScelIterator begin,
28  ScelIterator end,
29  ConfigEnumConstructor f,
30  std::vector<std::string> filter_expr) {
31 
32  Log &log = primclex.log();
33 
34  Index Ninit = std::distance(primclex.config_begin(), primclex.config_end());
35  log << "# configurations in this project: " << Ninit << "\n" << std::endl;
36 
37  log.begin(method);
38 
39  for(auto scel_it = begin; scel_it != end; ++scel_it) {
40  Supercell &scel = *scel_it;
41  log << "Enumerate configurations for " << scel.get_name() << " ... " << std::flush;
42 
43  auto enumerator_ptr = f(scel);
44  auto &enumerator = *enumerator_ptr;
45  Index num_before = scel.get_config_list().size();
46  if(!filter_expr.empty()) {
47  try {
50  enumerator.begin(),
51  enumerator.end(),
52  filter_expr,
53  primclex.settings().query_handler<Configuration>().dict()),
54  filter_end(enumerator.end())
55  );
56  }
57  catch(std::exception &e) {
58  primclex.err_log() << "Cannot filter configurations using the expression provided: \n" << e.what() << "\nExiting...\n";
59  return ERR_INVALID_ARG;
60  }
61  }
62  else {
63  scel.add_unique_canon_configs(enumerator.begin(), enumerator.end());
64  }
65 
66  log << (scel.get_config_list().size() - num_before) << " configs." << std::endl;
67  }
68  log << " DONE." << std::endl << std::endl;
69 
70  Index Nfinal = std::distance(primclex.config_begin(), primclex.config_end());
71 
72  log << "# new configurations: " << Nfinal - Ninit << "\n";
73  log << "# configurations in this project: " << Nfinal << "\n" << std::endl;
74 
75  log << "Write SCEL..." << std::endl;
76  primclex.print_supercells();
77  log << " DONE" << std::endl << std::endl;
78 
79  log << "Writing config_list..." << std::endl;
80  primclex.write_config_list();
81  log << " DONE" << std::endl;
82 
83  return 0;
84  }
85 
99  template<typename ScelIterator, typename ConfigEnumConstructor>
101  std::string method,
103  ScelIterator begin,
104  ScelIterator end,
105  ConfigEnumConstructor f,
106  std::vector<std::string> filter_expr,
107  bool primitive_only) {
108 
109  Log &log = primclex.log();
110 
111  Index Ninit = std::distance(primclex.config_begin(), primclex.config_end());
112  log << "# configurations in this project: " << Ninit << "\n" << std::endl;
113 
114  log.begin(method);
115 
116  for(auto scel_it = begin; scel_it != end; ++scel_it) {
117  Supercell &scel = *scel_it;
118  log << "Enumerate configurations for " << scel.get_name() << " ... " << std::flush;
119 
120  auto enumerator_ptr = f(scel);
121  auto &enumerator = *enumerator_ptr;
122  Index num_before = scel.get_config_list().size();
123  if(!filter_expr.empty()) {
124  try {
125  auto it = filter_begin(
126  enumerator.begin(),
127  enumerator.end(),
128  filter_expr,
129  primclex.settings().query_handler<Configuration>().dict());
130  auto end = filter_end(enumerator.end());
131  for(; it != end; ++it) {
132  it->insert(primitive_only);
133  }
134  }
135  catch(std::exception &e) {
136  primclex.err_log() << "Cannot filter configurations using the expression provided: \n" << e.what() << "\nExiting...\n";
137  return ERR_INVALID_ARG;
138  }
139  }
140  else {
141  auto it = enumerator.begin();
142  auto end = enumerator.end();
143  for(; it != end; ++it) {
144  it->insert(primitive_only);
145  }
146  }
147 
148  log << (scel.get_config_list().size() - num_before) << " configs." << std::endl;
149  }
150  log << " DONE." << std::endl << std::endl;
151 
152  Index Nfinal = std::distance(primclex.config_begin(), primclex.config_end());
153 
154  log << "# new configurations: " << Nfinal - Ninit << "\n";
155  log << "# configurations in this project: " << Nfinal << "\n" << std::endl;
156 
157  log << "Write SCEL..." << std::endl;
158  primclex.print_supercells();
159  log << " DONE" << std::endl << std::endl;
160 
161  log << "Writing config_list..." << std::endl;
162  primclex.write_config_list();
163  log << " DONE" << std::endl;
164 
165  return 0;
166  }
167 
181  template<typename LatticeIterator, typename ConfigEnumConstructor>
183  std::string method,
185  LatticeIterator begin,
186  LatticeIterator end,
187  ConfigEnumConstructor f,
188  std::vector<std::string> filter_expr,
189  bool primitive_only) {
190 
191  Log &log = primclex.log();
192 
193  Index Ninit = std::distance(primclex.config_begin(), primclex.config_end());
194  log << "# configurations in this project: " << Ninit << "\n" << std::endl;
195 
196  log.begin(method);
197 
198  for(auto scel_lat_it = begin; scel_lat_it != end; ++scel_lat_it) {
199  Supercell scel(&primclex, *scel_lat_it);
200  Supercell &canon_scel = scel.canonical_form();
201  log << "Enumerate configurations for " << canon_scel.get_name() << " ... " << std::flush;
202 
203  auto enumerator_ptr = f(scel);
204  auto &enumerator = *enumerator_ptr;
205  Index num_before = canon_scel.get_config_list().size();
206  if(!filter_expr.empty()) {
207  try {
208  auto it = filter_begin(
209  enumerator.begin(),
210  enumerator.end(),
211  filter_expr,
212  primclex.settings().query_handler<Configuration>().dict());
213  auto end = filter_end(enumerator.end());
214  for(; it != end; ++it) {
215  it->insert(primitive_only);
216  }
217  }
218  catch(std::exception &e) {
219  primclex.err_log() << "Cannot filter configurations using the expression provided: \n" << e.what() << "\nExiting...\n";
220  return ERR_INVALID_ARG;
221  }
222  }
223  else {
224  auto it = enumerator.begin();
225  auto end = enumerator.end();
226  for(; it != end; ++it) {
227  it->insert(primitive_only);
228  }
229  }
230 
231  log << (canon_scel.get_config_list().size() - num_before) << " configs." << std::endl;
232  }
233  log << " DONE." << std::endl << std::endl;
234 
235  Index Nfinal = std::distance(primclex.config_begin(), primclex.config_end());
236 
237  log << "# new configurations: " << Nfinal - Ninit << "\n";
238  log << "# configurations in this project: " << Nfinal << "\n" << std::endl;
239 
240  log << "Write SCEL..." << std::endl;
241  primclex.print_supercells();
242  log << " DONE" << std::endl << std::endl;
243 
244  log << "Writing config_list..." << std::endl;
245  primclex.write_config_list();
246  log << " DONE" << std::endl;
247 
248  return 0;
249  }
250 
251 }
252 
253 #endif
std::string get_name() const
Return supercell name.
Definition: Supercell.cc:123
void write_config_list(std::set< std::string > scel_to_delete={})
Definition: PrimClex.cc:450
FilteredConfigIterator< IteratorType > filter_end(const IteratorType &it_end)
#define ERR_INVALID_ARG
PrimClex * primclex
Definition: settings.cc:101
Supercell & canonical_form() const
Definition: Supercell.cc:910
ConfigList & get_config_list()
Definition: Supercell.hh:279
Main CASM namespace.
Definition: complete.cpp:8
Log & log
Definition: settings.cc:105
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:37
Log & log() const
Definition: Log.hh:255
config_iterator config_begin()
Configuration iterator: begin.
Definition: PrimClex.cc:371
config_iterator config_end()
Configuration iterator: end.
Definition: PrimClex.cc:379
int insert_configs(std::string method, PrimClex &primclex, ScelIterator begin, ScelIterator end, ConfigEnumConstructor f, std::vector< std::string > filter_expr, bool primitive_only)
Standardizes insertion from enumerators that construct configurations.
void begin(const std::string &what)
Definition: Log.hh:71
int insert_configs_via_lattice_enum(std::string method, PrimClex &primclex, LatticeIterator begin, LatticeIterator end, ConfigEnumConstructor f, std::vector< std::string > filter_expr, bool primitive_only)
Standardizes insertion from enumerators that construct configurations.
EigenIndex Index
For long integer indexing:
QueryHandler< DataObject > & query_handler()
ProjectSettings & settings()
Definition: PrimClex.hh:116
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
void print_supercells(std::set< std::string > scel_to_delete={}) const
Definition: PrimClex.cc:557
FilteredConfigIterator< IteratorType > filter_begin(const IteratorType &it, const IteratorType &it_end, const std::vector< std::string > &filter_expr, const DataFormatterDictionary< Configuration > &_dict)
Definition: Log.hh:9
void add_unique_canon_configs(ConfigIterType it_begin, ConfigIterType it_end)
Definition: Supercell.hh:465
int insert_unique_canon_configs(std::string method, PrimClex &primclex, ScelIterator begin, ScelIterator end, ConfigEnumConstructor f, std::vector< std::string > filter_expr)
Standardizes insertion from enumerators that construct unique primitive canonical configurations...
A Configuration represents the values of all degrees of freedom in a Supercell.
Log & err_log() const
Definition: Log.hh:263