CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ScelEnum_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_ScelEnum_impl
2 #define CASM_ScelEnum_impl
3 
4 #include "casm/clex/ScelEnum.hh"
5 #include "casm/clex/PrimClex.hh"
7 
8 namespace CASM {
9 
10  template<bool IsConst>
11  const std::string ScelEnumByNameT<IsConst>::enumerator_name = "ScelEnumByName";
12 
18  template<bool IsConst>
21  std::initializer_list<std::string> scelnames) :
22  RandomAccessEnumeratorBase<Supercell, IsConst>(scelnames.size()),
23  m_primclex(&primclex) {
24 
25  m_scelptr.reserve(scelnames.size());
26  for(auto it = scelnames.begin(); it != scelnames.end(); ++it) {
27  m_scelptr.push_back(&m_primclex->get_supercell(*it));
28  }
29  _init();
30  }
31 
37  template<bool IsConst>
38  template<typename ScelNameIterator>
41  ScelNameIterator begin,
42  ScelNameIterator end) :
44  m_primclex(&primclex) {
45 
46  for(auto it = begin; it != end; ++it) {
47  m_scelptr.push_back(&m_primclex->get_supercell(*it));
48  }
49  _init();
50  }
51 
57  template<bool IsConst>
60  const jsonParser &input) :
61  RandomAccessEnumeratorBase<Supercell, IsConst>(input.size()),
62  m_primclex(&primclex) {
63 
64  m_scelptr.reserve(input.size());
65  for(auto it = input.begin(); it != input.end(); ++it) {
66  m_scelptr.push_back(&m_primclex->get_supercell(it->get<std::string>()));
67  }
68  _init();
69  }
70 
71  template<bool IsConst>
72  std::string ScelEnumByNameT<IsConst>::name() const {
73  return enumerator_name;
74  }
75 
77  template<bool IsConst>
79  return m_scelptr[n];
80  }
81 
82  template<bool IsConst>
84 
85  this->_set_size(m_scelptr.size());
86  if(this->size() > 0) {
87  this->_initialize(m_scelptr[0]);
88  }
89  else {
90  this->_invalidate();
91  }
92  }
93 
94 
95  template<bool IsConst>
96  const std::string ScelEnumByPropsT<IsConst>::enumerator_name = "ScelEnumByProps";
97 
105  template<bool IsConst>
107  m_primclex(&primclex),
108  m_existing_only(existing_only) {
109 
113  enum_props
114  ));
115 
116  m_lat_it = m_lattice_enum->begin();
117  m_lat_end = m_lattice_enum->end();
118 
119  while(!_include(*m_lat_it) && m_lat_it != m_lat_end) {
120  ++m_lat_it;
121  }
122 
123  if(m_lat_it != m_lat_end) {
125  }
126  else {
127  this->_invalidate();
128  }
129  }
130 
131  namespace {
132 
133  bool _get_else(const jsonParser &json, std::string key, bool default_value) {
134  bool tmp;
135  json.get_else<bool>(tmp, key, default_value);
136  return tmp;
137  }
138  }
139 
150  template<bool IsConst>
152  ScelEnumByPropsT(primclex, make_scel_enum_props(primclex, input), _get_else(input, "existing_only", false)) {}
153 
154  template<bool IsConst>
155  std::string ScelEnumByPropsT<IsConst>::name() const {
156  return enumerator_name;
157  }
158 
160  template<bool IsConst>
162  ++m_lat_it;
163 
164  while(!_include(*m_lat_it) && m_lat_it != m_lat_end) {
165  ++m_lat_it;
166  }
167 
168  if(m_lat_it != m_lat_end) {
169  this->_set_current_ptr(&m_primclex->get_supercell(m_primclex->add_supercell(*m_lat_it)));
170  this->_increment_step();
171  }
172  else {
173  this->_invalidate();
174  }
175  }
176 
178  template<bool IsConst>
180  if(m_existing_only) {
182  *m_lat_it,
183  m_primclex->get_prim().point_group(),
184  m_primclex->crystallography_tol());
185  Supercell tmp(m_primclex, canon_lat);
186  return m_primclex->contains_supercell(tmp);
187  }
188  return true;
189  }
190 
191  template<bool IsConst>
192  std::string ScelEnumT<IsConst>::name() const {
193  return enumerator_name;
194  }
195 
197  template<bool IsConst>
198  const std::string ScelEnumT<IsConst>::enumerator_name = "ScelEnum";
199 
201  template<bool IsConst>
202  const std::string ScelEnumT<IsConst>::interface_help =
203 
204  "ScelEnum: \n\n"
205 
206  " min: int, >0 (default=1)\n"
207  " The minimum volume supercell to enumerate. The volume is measured\n"
208  " relative the unit cell being used to generate supercells.\n"
209  "\n"
210  " max: int, >= min (default=max existing scel_size)\n"
211  " The maximum volume supercell to enumerate. The volume is measured\n"
212  " relative the unit cell being used to generate supercells.\n"
213  "\n"
214  " existing_only: bool (default=true)\n"
215  " If true, only existing supercells are used. This is useful when it\n"
216  " is used as input to a Configuration enumeration method.\n"
217  "\n"
218  " dirs: string (default=\"abc\")\n"
219  " This option may be used to restrict the supercell enumeration to 1, \n"
220  " 2 or 3 of the lattice vectors, to get 1-, 2-, or 3-dimensional \n"
221  " supercells. By specifying combinations of 'a', 'b', and 'c', you \n"
222  " determine which of the unit cell lattice vectors you want to \n"
223  " enumerate over. For example, to enumerate 1-dimensional supercells \n"
224  " along the 'c' use \"dirs\":\"c\". If you want 2-dimensional \n"
225  " supercells along the 'a' and 'c' lattice vectors, specify \n"
226  " \"dirs\":\"ac\". \n"
227  "\n"
228  " unit_cell: 3x3 matrix of int, or string (default=identity matrix) \n"
229  " This option may be used to specify the unit cell. It may be \n"
230  " specified using a 3x3 matrix of int, representing the transformation\n"
231  " matrix, T, such that U = P*T, where P are the primitive lattice \n"
232  " and U are the unit cell lattice vectors. For example, a unit cell \n"
233  " that whose lattice vectors are (2*a+b, b, c) (with respect to the \n"
234  " the primitive cell vectors) could be specified using:\n"
235  "\n"
236  " \"unit_cell\" : [\n"
237  " [2, 0, 0],\n"
238  " [1, 1, 0],\n"
239  " [0, 0, 1]\n"
240  " ]\n"
241  "\n"
242  " Or it may be specified by \n"
243  " the name of the existing supercell to use as the unit cell, for \n"
244  " example: \n"
245  "\n"
246  " \"unit_cell\" : \"SCEL2_1_1_2_0_0_0\"\n"
247  "\n"
248  " name: JSON array of string (optional)\n"
249  " As an alternative to the above options, an array of existing supercell\n"
250  " names to explicitly indicate which supercells to act on. If this is \n"
251  " included, other properties are ignored. This is useful as an input \n"
252  " to other enumeration methods, such as ConfigEnumAllOccupations when \n"
253  " supercells have already been enumerated. \n"
254  "\n"
255  "Examples:\n"
256  "\n"
257  " To enumerate supercells up to and including size 4:\n"
258  " casm enum --method SuperConfigEnum -i '{\"max\": 4}' \n"
259  "\n"
260  " To enumerate 2d supercells up to and including size 4:\n"
261  " casm enum --method SuperConfigEnum -i '{\"max\": 4, \"dirs\": \"ab\"}' \n"
262  "\n"
263  " If the prim is primitive FCC, two dimensional supercells of the \n"
264  " conventional FCC unit cell up to and including 4x the unit cell volume\n"
265  " could be enumerated using:\n"
266  "\n"
267  " casm enum --method SuperConfigEnum -i \n"
268  " '{\n"
269  " \"min\": 1,\n"
270  " \"max\": 4,\n"
271  " \"dirs\": \"ab\",\n"
272  " \"unit_cell\" : [\n"
273  " [-1, 1, 1],\n"
274  " [ 1, -1, 1],\n"
275  " [ 1, 1, -1]\n"
276  " ]\n"
277  " }'\n"
278  "\n";
279 
281  template<bool IsConst>
284  const jsonParser &kwargs,
285  const Completer::EnumOption &enum_opt) {
286 
287  Log &log = primclex.log();
288  log.begin(enumerator_name);
289 
290  auto &supercell_list = primclex.get_supercell_list();
291  Index list_size = supercell_list.size();
292 
293  bool verbose = true;
294 
295  jsonParser input {kwargs};
296  // check supercell shortcuts
297  if(enum_opt.vm().count("min")) {
298  input["min"] = enum_opt.min_volume();
299  }
300  if(enum_opt.vm().count("max")) {
301  input["max"] = enum_opt.max_volume();
302  }
303 
304  ScelEnum scel_enum(primclex, input);
305  for(auto &scel : scel_enum) {
306  if(verbose) {
307  if(supercell_list.size() != list_size) {
308  log << " Generated: " << scel.get_name() << "\n";
309  }
310  else {
311  log << " Generated: " << scel.get_name() << " (already existed)\n";
312  }
313  }
314  list_size = supercell_list.size();
315  }
316  log << " DONE." << std::endl << std::endl;
317 
318  log << "Write SCEL..." << std::endl;
319  primclex.print_supercells();
320  log << " DONE" << std::endl << std::endl;
321 
322  log << "Writing config_list..." << std::endl;
323  primclex.write_config_list();
324  log << " DONE" << std::endl;
325 
326  return 0;
327  }
328 
332  template<bool IsConst>
334 
335  if(input.contains("name")) {
336  m_enum.ptr.reset(new ScelEnumByName(primclex, input["name"]));
337  }
338  else {
339  m_enum.ptr.reset(new ScelEnumByProps(primclex, input));
340  }
341 
342  m_it = m_enum.begin();
343  m_end = m_enum.end();
344 
345  if(m_it != m_end) {
346  this->_initialize(&(*m_it));
347  this->_set_step(0);
348  }
349  else {
350  this->_invalidate();
351  }
352  }
353 
354 
356  template<bool IsConst>
358  ++m_it;
359  if(m_it != m_end) {
360  this->_set_current_ptr(&(*m_it));
361  this->_increment_step();
362  }
363  else {
364  this->_invalidate();
365  }
366  }
367 
368 }
369 
370 #endif
ScelEnumT(PrimClex &primclex, const jsonParser &input)
Construct with PrimClex and JSON settings.
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
Definition: jsonParser.cc:430
boost::container::stable_vector< Supercell > & get_supercell_list()
Access entire supercell_list.
Definition: PrimClex.cc:299
static int run(PrimClex &primclex, const jsonParser &kwargs, const Completer::EnumOption &enum_opt)
void write_config_list(std::set< std::string > scel_to_delete={})
Definition: PrimClex.cc:450
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:465
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
Data structure for holding supercell enumeration properties.
PrimClex * primclex
Definition: settings.cc:101
Supercell * at_step(step_type n) override
Implements at_step.
std::unique_ptr< SupercellEnumerator< Lattice > > m_lattice_enum
Definition: ScelEnum.hh:121
A fake container of supercell matrices.
Definition: Enumerator.hh:407
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & log
Definition: settings.cc:105
Enumerate over Supercell.
Definition: ScelEnum.hh:148
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:37
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:440
std::vector< Supercell * > m_scelptr
Definition: ScelEnum.hh:70
Log & log() const
Definition: Log.hh:255
void begin(const std::string &what)
Definition: Log.hh:71
void increment() override
Implements increment over supercells.
void increment() override
Implements increment over all occupations.
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
ScelEnumProps make_scel_enum_props(PrimClex &primclex, const jsonParser &input)
Make a ScelEnumProps object from JSON input.
EigenIndex Index
For long integer indexing:
void _invalidate()
Call if enumeration complete.
Definition: Enumerator.hh:169
ScelEnumByPropsT(PrimClex &primclex, const ScelEnumProps &enum_props, bool existing_only=false)
Construct with PrimClex and ScelEnumProps settings.
Lattice canonical_equivalent_lattice(const Lattice &in_lat, const SymGroup &point_grp, double compare_tol)
Find the niggli, most standard oriented version of the given orbit (defined by the given SymGroup) of...
Definition: Niggli.cc:276
ScelEnumByNameT(PrimClex &primclex, std::initializer_list< std::string > scelnames)
Construct with PrimClex and ScelEnumProps settings.
Base class for implementing specialized random access enumerators.
bool get_else(T &t, const std::string &key, const T &default_value, Args...args) const
Definition: jsonParser.hh:749
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
SupercellEnumerator< Lattice >::const_iterator m_lat_it
Definition: ScelEnum.hh:122
void print_supercells(std::set< std::string > scel_to_delete={}) const
Definition: PrimClex.cc:557
Index add_supercell(const Lattice &superlat)
Definition: PrimClex.cc:550
po::variables_map & vm()
Get the variables map.
Definition: Handlers.cc:145
const Supercell & get_supercell(Index i) const
const Access supercell by index
Definition: PrimClex.cc:311
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
PrimClex * m_primclex
Definition: ScelEnum.hh:68
bool _include(const Lattice &lat) const
Check for existing supercells.
SupercellEnumerator< Lattice >::const_iterator m_lat_end
Definition: ScelEnum.hh:123
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
Definition: Log.hh:9
Enumerate over Supercell.
Definition: ScelEnum.hh:92
PrimClex * m_primclex
Definition: ScelEnum.hh:119
ScelEnumT< false > ScelEnum
Definition: Enumerator.hh:402
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260