CASM  1.1.0
A Clusters Approach to Statistical Mechanics
enumerate_configurations_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_enum_enumerate_configurations_impl
2 #define CASM_enum_enumerate_configurations_impl
3 
12 
13 namespace CASM {
14 
78 template <typename MakeEnumeratorFunction, typename InputNameValuePairIterator,
79  typename ConfigEnumDataType>
81  PrimClex const &primclex, ConfigEnumOptions const &options,
82  MakeEnumeratorFunction make_enumerator_f,
83  InputNameValuePairIterator name_value_pairs_begin,
84  InputNameValuePairIterator name_value_pairs_end,
85  DataFormatter<ConfigEnumDataType> const &formatter) {
86  Log &log = CASM::log();
87  std::pair<DB::Database<Configuration>::iterator, bool> insert_result;
88  std::string dry_run_msg = CASM::dry_run_msg(options.dry_run);
89 
90  auto &supercell_db = primclex.db<Supercell>();
91  auto &configuration_db = primclex.db<Configuration>();
92 
93  Index Ninit = configuration_db.size();
95  log << dry_run_msg << "# configurations in this project: " << Ninit
96  << std::endl;
97  log << dry_run_msg << "Begin enumeration" << std::endl << std::endl;
98 
99  typedef FormattedDataFile<ConfigEnumDataType> FormattedDataFileType;
100  std::unique_ptr<FormattedDataFileType> data_out_ptr;
101  if (options.output_configurations) {
102  data_out_ptr =
103  notstd::make_unique<FormattedDataFileType>(options.output_options);
104  }
105 
107  auto it = name_value_pairs_begin;
108  for (; it != name_value_pairs_end; ++it) {
109  auto const &input_name_value_pair = *it;
110 
111  Index count = 0;
112  Index count_filtered = 0;
113  Index num_before = configuration_db.size();
114  log << dry_run_msg
115  << "Enumerate configurations for: " << input_name_value_pair.first
116  << std::endl;
117 
118  auto enumerator =
119  make_enumerator_f(initial_state_index, input_name_value_pair.first,
120  input_name_value_pair.second);
121 
122  for (Configuration const &configuration : enumerator) {
125  input_name_value_pair.first,
126  input_name_value_pair.second,
127  enumerator,
128  configuration};
129 
132  if (!configuration.supercell().has_primclex()) {
133  configuration.supercell().set_primclex(options.primclex_ptr);
134  }
135 
136  ++count;
137  if (options.filter && !options.filter(configuration)) {
138  data.is_excluded_by_filter = true;
139  ++count_filtered;
140  } else {
141  // checks `is_guaranteed_for_database_insert(enumerator)` to see if
142  // configuration can be directly inserted, else makes canonical before
143  // inserting
144  data.insert_result =
145  make_canonical_and_insert(enumerator, configuration, supercell_db,
146  configuration_db, options.primitive_only);
147  }
148 
149  if (data_out_ptr && (options.output_filtered_configurations ||
150  !data.is_excluded_by_filter)) {
151  (*data_out_ptr)(formatter, data);
152  }
153  }
154 
155  Index num_after = configuration_db.size();
156  log << dry_run_msg << count << " configurations"
157  << " (" << (num_after - num_before) << " new, " << count_filtered
158  << " excluded by filter)." << std::endl
159  << std::endl;
160 
162  }
163  log << dry_run_msg << "Enumeration complete" << std::endl << std::endl;
164 
165  Index Nfinal = configuration_db.size();
166  log << dry_run_msg << "# new configurations: " << Nfinal - Ninit << "\n";
167  log << dry_run_msg << "# configurations in this project: " << Nfinal << "\n"
168  << std::endl;
169 
170  if (!options.dry_run) {
171  log << "Write supercell database... " << std::flush;
172  supercell_db.commit();
173  log << "DONE" << std::endl;
174 
175  log << "Write configuration database... " << std::flush;
176  configuration_db.commit();
177  log << "DONE" << std::endl;
178  }
179  if (data_out_ptr) {
180  log << "Write enumerated configurations: "
181  << options.output_options.file_path << std::endl;
182  data_out_ptr.reset();
183  }
184  log.end_section();
185 }
186 
187 } // namespace CASM
188 
189 #endif
Index count
Extract data from objects of 'DataObject' class.
Definition: Log.hh:48
void end_section()
End a section.
Definition: Log.hh:192
void begin_section()
Begin a section, without header.
Definition: Log.hh:158
Log & subsection()
Create a subsection.
Definition: Log.hh:186
static const int standard
Definition: Log.hh:52
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
DB::Database< T > & db() const
Definition: PrimClex.cc:302
GenericDatumFormatter< Index, ConfigEnumDataType > initial_state_index()
ConfigEnumData< ConfigEnumSiteDoFs, ConfigEnumInput > ConfigEnumDataType
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
std::string dry_run_msg(bool dry_run)
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.
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
PrimClex * primclex
Definition: settings.cc:135
Options for the enumerate_configurations function.
bool dry_run
If dry_run==true, do not save results, just print to screen.
FormattedDataFileOptions output_options
Options for construcing FormattedDataFile object.
std::function< bool(Configuration const &)> filter
If filter(configuration)==true, keep configuration, else skip.
bool output_filtered_configurations
If true, include output for configurations that were filtered out.
PrimClex const * primclex_ptr
Use while transitioning Supercell to no longer need a PrimClex const *