CASM  1.1.0
A Clusters Approach to Statistical Mechanics
enumerate_supercells_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_enum_enumerate_supercells_impl
2 #define CASM_enum_enumerate_supercells_impl
3 
6 #include "casm/casm_io/Log.hh"
10 
11 namespace CASM {
12 
29 template <typename EnumeratorType>
31  EnumeratorType &enumerator,
32  DB::Database<Supercell> &supercell_db) {
33  Log &log = CASM::log();
34  std::pair<DB::Database<Supercell>::iterator, bool> insert_result;
35  std::string dry_run_msg = CASM::dry_run_msg(options.dry_run);
36 
37  log.set_verbosity(options.verbosity);
39 
40  for (Supercell const &supercell : enumerator) {
42  if (!supercell.has_primclex()) {
43  supercell.set_primclex(options.primclex_ptr);
44  }
45 
46  if (options.filter && !options.filter(supercell)) {
47  continue;
48  }
49 
50  // checks `is_guaranteed_for_database_insert(enumerator)` to see if
51  // supercell can be directly inserted, else makes canonical before inserting
52  insert_result =
53  make_canonical_and_insert(enumerator, supercell, supercell_db);
54 
55  if (insert_result.second) {
56  log << dry_run_msg << " Generated: " << insert_result.first->name()
57  << "\n";
58  } else {
59  log << dry_run_msg << " Generated: " << insert_result.first->name()
60  << " (already existed)\n";
61  }
62  }
63  log << dry_run_msg << " DONE." << std::endl << std::endl;
64 
65  if (!options.dry_run) {
66  log << "Committing database..." << std::flush;
67  supercell_db.commit();
68  log << " DONE" << std::endl;
69  }
70  log.end_section();
71 }
72 
73 } // namespace CASM
74 
75 #endif
virtual void commit()=0
Definition: Log.hh:48
void end_section()
End a section.
Definition: Log.hh:192
void set_verbosity(int _verbosity)
Definition: Log.cc:57
void begin(const std::string &what)
Definition: Log.hh:114
static const int standard
Definition: Log.hh:52
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
ConfigInsertResult make_canonical_and_insert(Configuration const &configuration, Database< Supercell > &supercell_db, Database< Configuration > &configuration_db, bool primitive_only)
Insert this configuration (in primitive & canonical form) in the database.
Main CASM namespace.
Definition: APICommand.hh:8
Log & log()
Definition: Log.hh:424
void enumerate_supercells(EnumerateSupercellsOptions const &options, EnumeratorType &enumerator, DB::Database< Supercell > &supercell_db)
std::string dry_run_msg(bool dry_run)
Options for the enumerate_supercells function.
std::function< bool(Supercell const &)> filter
If filter(supercell)==true, keep supercell, else skip.
PrimClex const * primclex_ptr
Use while transitioning Supercell to no longer need a PrimClex const *
std::string method_name
Method name, for printing progress.
bool dry_run
If dry_run==true, do not save results, just print to screen.
int verbosity
Printing verbosity level.