CASM  1.1.0
A Clusters Approach to Statistical Mechanics
OrbitPrinter_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_cluterography_io_OrbitPrinter_impl
2 #define CASM_cluterography_io_OrbitPrinter_impl
3 
11 
12 namespace CASM {
13 
14 template <typename OrbitPrinter, typename Element>
15 void print_coordinates(OrbitPrinter &printer, const Element &element,
16  Log &out) {
17  out << out.indent_str() << "Coordinates:" << std::endl;
18  printer.increase_indent(out);
19  printer.print(element, out);
20  printer.decrease_indent(out);
21 }
22 
23 template <typename OrbitType>
24 void PrinterBase::print_equivalence_map(const OrbitType &orbit,
25  Index equiv_index, Log &out) const {
26  out << out.indent_str() << "Equivalence map: " << std::endl;
27  this->increase_indent(out);
28  int j = 0;
29  SymInfoOptions topt = this->opt.sym_info_opt;
30  for (const auto &op : orbit.equivalence_map()[equiv_index]) {
31  out << out.indent_str() << j << ": (" << op.index() << ") "
32  << brief_description(op, orbit.prototype().prim().lattice(), topt)
33  << std::endl;
34  ++j;
35  }
36  this->decrease_indent(out);
37 }
38 
39 template <typename OrbitType>
40 void PrinterBase::print_equivalence_map(const OrbitType &orbit,
41  Index equiv_index,
42  jsonParser &json) const {
43  SymInfoOptions topt = this->opt.sym_info_opt;
44 
45  std::vector<Index> master_group_indices;
46  for (const auto &op : orbit.equivalence_map()[equiv_index]) {
47  master_group_indices.push_back(op.index());
48  }
49  json["equivalence_map"] = master_group_indices;
50 
51  std::vector<std::string> desc;
52  for (const auto &op : orbit.equivalence_map()[equiv_index]) {
53  desc.push_back(
54  brief_description(op, orbit.prototype().prim().lattice(), topt));
55  }
56  json["equivalence_map_descriptions"] = desc;
57  json["equivalence_map_descriptions"].set_force_column();
58 }
59 
60 template <typename OrbitType>
61 void PrinterBase::print_equivalence_map(const OrbitType &orbit,
62  Log &out) const {
63  out << out.indent_str() << "Orbit equivalence map: " << std::endl;
64  this->increase_indent(out);
65  SymInfoOptions topt = this->opt.sym_info_opt;
66  for (int i = 0; i < orbit.size(); ++i) {
67  out << out.indent_str() << "Element: " << i << std::endl;
68  this->increase_indent(out);
69  int j = 0;
70  for (const auto &op : orbit.equivalence_map()[i]) {
71  out << out.indent_str() << j << ": (" << op.index() << ") "
72  << brief_description(op, orbit.prototype().prim().lattice(), topt)
73  << std::endl;
74  ++j;
75  }
76  this->decrease_indent(out);
77  }
78  this->decrease_indent(out);
79 }
80 
81 template <typename OrbitType, typename Element>
82 void PrinterBase::print_invariant_group(const OrbitType &orbit,
83  const Element &element,
84  Log &out) const {
85  out << out.indent_str() << "Invariant group:" << std::endl;
86  SymGroup invariant_group = make_invariant_subgroup(
87  element, orbit.generating_group(), orbit.sym_compare());
88  this->increase_indent(out);
89  SymInfoOptions topt = this->opt.sym_info_opt;
90  brief_description(out, invariant_group, orbit.prototype().prim().lattice(),
91  topt);
92  this->decrease_indent(out);
93 }
94 
95 template <typename OrbitType, typename Element>
96 void PrinterBase::print_invariant_group(const OrbitType &orbit,
97  const Element &element,
98  jsonParser &json) const {
99  SymInfoOptions topt = this->opt.sym_info_opt;
100  SymGroup invariant_group = make_invariant_subgroup(
101  element, orbit.generating_group(), orbit.sym_compare());
102 
103  std::vector<Index> master_group_indices;
104  for (const auto &op : invariant_group) {
105  master_group_indices.push_back(op.index());
106  }
107  json["invariant_group"] = master_group_indices;
108 
109  std::vector<std::string> desc;
110  for (const auto &op : invariant_group) {
111  desc.push_back(
112  brief_description(op, orbit.prototype().prim().lattice(), topt));
113  }
114  json["invariant_group_descriptions"] = desc;
115  json["invariant_group_descriptions"].set_force_column();
116 }
117 
118 // --- OrbitPrinter templates ---
119 
120 template <typename _Element>
121 template <typename OrbitType>
123  const OrbitType &orbit, Log &out, Index orbit_index, Index Norbits) const {
124  out << out.indent_str() << "Prototype"
125  << " of " << orbit.size() << " Equivalent " << element_name
126  << " in Orbit " << orbit_index << std::endl;
127  this->increase_indent(out);
128 
129  if (this->opt.print_coordinates) {
130  print_coordinates(*this, orbit.prototype(), out);
131  }
132  if (this->opt.print_invariant_group) {
133  this->print_invariant_group(orbit, orbit.prototype(), out);
134  }
135  this->decrease_indent(out);
136 }
137 
141 template <typename _Element>
142 template <typename OrbitType>
144  const OrbitType &orbit, jsonParser &json, Index orbit_index,
145  Index Norbits) const {
146  json.put_obj();
147  json["prototype"] = orbit.prototype();
148  json["linear_orbit_index"] = orbit_index;
149  json["mult"] = orbit.size();
150  if (this->opt.print_invariant_group) {
151  this->print_invariant_group(orbit, orbit.prototype(), json["prototype"]);
152  }
153 
154  return json;
155 }
156 
157 template <typename _Element>
158 template <typename OrbitType>
160  const OrbitType &orbit, Log &out, Index orbit_index, Index Norbits) const {
161  for (Index equiv_index = 0; equiv_index != orbit.size(); ++equiv_index) {
162  out << out.indent_str() << equiv_index << " of " << orbit.size()
163  << " Equivalent " << element_name << " in Orbit " << orbit_index
164  << std::endl;
165  this->increase_indent(out);
166 
167  if (this->opt.print_coordinates) {
168  print_coordinates(*this, orbit[equiv_index], out);
169  }
170  if (this->opt.print_invariant_group) {
171  this->print_invariant_group(orbit, orbit[equiv_index], out);
172  }
173  if (this->opt.print_equivalence_map) {
174  this->print_equivalence_map(orbit, equiv_index, out);
175  }
176  this->decrease_indent(out);
177  }
178 }
179 
183 template <typename _Element>
184 template <typename OrbitType>
186  const OrbitType &orbit, jsonParser &json, Index orbit_index,
187  Index Norbits) const {
188  json.put_obj();
189  json["linear_orbit_index"] = orbit_index;
190  json["prototype"] = orbit.prototype();
191  if (this->opt.print_invariant_group) {
192  this->print_invariant_group(orbit, orbit.prototype(), json["prototype"]);
193  }
194  json["elements"].put_array(orbit.begin(), orbit.end());
195  for (Index equiv_index = 0; equiv_index != orbit.size(); ++equiv_index) {
196  if (this->opt.print_invariant_group) {
197  this->print_invariant_group(orbit, orbit[equiv_index],
198  json["elements"][equiv_index]);
199  }
200  if (this->opt.print_equivalence_map) {
201  this->print_equivalence_map(orbit, equiv_index,
202  json["elements"][equiv_index]);
203  }
204  }
205  return json;
206 }
207 
221 template <typename ClusterOrbitIterator, typename OrbitPrinter>
222 void print_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end, Log &out,
223  OrbitPrinter printer) {
224  if (!printer.opt.itemize_orbits) {
225  printer.coord_type(out);
226  }
227 
228  out.ostream().flags(std::ios::showpoint | std::ios::fixed | std::ios::left);
229  out.ostream().precision(5);
230 
231  Index branch = -1;
232  Index orbit_index = 0;
233  Index Norbits = std::distance(begin, end);
234 
235  for (auto it = begin; it != end; ++it) {
236  if (printer.opt.itemize_orbits) {
237  if (it == begin) {
238  out << "\\begin{itemize}\n";
239  }
240  out << "\\item Orbit " << orbit_index + 1 << "\n\n";
241  double min_length = 0.0;
242  double max_length = 0.0;
243  if (it->invariants().displacement().size()) {
244  min_length = it->invariants().displacement().front();
245  max_length = it->invariants().displacement().back();
246  }
247  out << "\\begin{itemize}\n";
248  out << "\\item Number of cluster sites: " << it->prototype().size()
249  << "\n";
250  out << "\\item Multiplicity: " << it->size() << "\n";
251  out << "\\item Minimum length: " << min_length << "\n";
252  out << "\\item Maximum length: " << max_length << "\n";
253  out << "\\end{itemize}\n\n";
254 
255  printer(*it, out, orbit_index, Norbits);
256  auto next = it;
257  ++next;
258  if (next == end) {
259  out << "\\end{itemize}\n\n";
260  }
261  } else {
262  if (it->prototype().size() != branch) {
263  branch = it->prototype().size();
264  out << out.indent_str() << "** Branch " << branch << " ** "
265  << std::endl;
266  }
267  printer.increase_indent(out);
268  double min_length = 0.0;
269  double max_length = 0.0;
270  if (it->invariants().displacement().size()) {
271  min_length = it->invariants().displacement().front();
272  max_length = it->invariants().displacement().back();
273  }
274  out << out.indent_str() << "** " << orbit_index << " of " << Norbits
275  << " Orbits **"
276  << " Points: " << it->prototype().size() << " Mult: " << it->size()
277  << " MinLength: " << min_length << " MaxLength: " << max_length
278  << std::endl;
279  printer.increase_indent(out);
280  printer(*it, out, orbit_index, Norbits);
281  out << std::endl;
282  printer.decrease_indent(out);
283  printer.decrease_indent(out);
284  }
285  ++orbit_index;
286  }
287 }
288 
290 template <typename ClusterOrbitIterator>
291 void print_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end, Log &out,
292  const OrbitPrinterOptions &opt) {
293  // typedef typename ClusterOrbitIterator::container_type container_type;
294  // typedef typename container_type::value_type orbit_type;
295  typedef typename std::iterator_traits<ClusterOrbitIterator>::value_type
296  orbit_type;
297  typedef typename orbit_type::Element Element;
298 
301  print_clust(begin, end, out, orbit_printer);
302  } else if (opt.orbit_print_mode == ORBIT_PRINT_MODE::FULL) {
304  print_clust(begin, end, out, orbit_printer);
305  }
306 }
307 
308 // ---------- clust.json IO
309 // ------------------------------------------------------------------
310 
317 template <typename ClusterOutputIterator, typename SymCompareType>
318 ClusterOutputIterator read_clust(ClusterOutputIterator result,
319  const jsonParser &json, const Structure &prim,
320  const SymGroup &generating_grp,
321  const SymCompareType &sym_compare) {
322  typedef Orbit<SymCompareType> orbit_type;
323 
324  for (const auto &j : json["orbits"]) {
325  *result++ = orbit_type(j["prototype"].get<IntegralCluster>(prim),
326  generating_grp, sym_compare);
327  }
328  return result;
329 }
330 
337 template <typename ClusterOutputIterator>
338 ClusterOutputIterator read_clust(ClusterOutputIterator result,
339  const jsonParser &json,
340  const Structure &prim) {
341  for (const auto &j : json["orbits"]) {
342  *result++ = j["prototype"].get<IntegralCluster>(prim);
343  }
344  return result;
345 }
346 
366 template <typename ClusterOrbitIterator, typename Printer>
367 jsonParser &write_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end,
368  jsonParser &json, Printer printer) {
369  Index Norbits = std::distance(begin, end);
370  json["orbits"] = jsonParser::array(Norbits, jsonParser::object());
371  Index orbit_index = 0;
372  for (auto it = begin; it != end; ++it, ++orbit_index) {
373  printer.to_json(*it, json["orbits"][orbit_index], orbit_index, Norbits);
374  }
375  write_prim(begin->prototype().prim(), json["prim"], FRAC);
376  return json;
377 }
378 
380 template <typename ClusterOrbitIterator>
381 jsonParser &write_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end,
382  jsonParser &json, const OrbitPrinterOptions &opt) {
383  // typedef typename ClusterOrbitIterator::container_type container_type;
384  // typedef typename container_type::value_type orbit_type;
385  typedef typename std::iterator_traits<ClusterOrbitIterator>::value_type
386  orbit_type;
387  typedef typename orbit_type::Element Element;
388 
391  write_clust(begin, end, json, orbit_printer);
392  } else if (opt.orbit_print_mode == ORBIT_PRINT_MODE::FULL) {
394  write_clust(begin, end, json, orbit_printer);
395  }
396  return json;
397 }
398 
419 template <typename ClusterOrbitIterator, typename Printer>
420 jsonParser &write_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end,
421  jsonParser &json, Printer printer,
422  const jsonParser &bspecs) {
423  write_clust(begin, end, json, printer);
424  json["bspecs"] = bspecs;
425  return json;
426 }
427 
428 } // namespace CASM
429 
430 #endif
Definition: Log.hh:48
std::string indent_str() const
Definition: Log.hh:273
std::ostream & ostream()
Definition: Log.hh:262
An Orbit of Element.
Definition: Orbit.hh:43
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:30
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:42
const Lattice & lattice() const
Lattice used for periodic comparisons (for instance, to generate multiplcation table)
Definition: SymGroup.cc:950
static jsonParser object()
Returns an empty json object.
Definition: jsonParser.hh:395
size_type size() const
Definition: jsonParser.cc:487
static jsonParser array()
Returns an empty json array.
Definition: jsonParser.hh:409
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:354
jsonParser & put_array()
Puts new empty JSON array.
Definition: jsonParser.hh:362
std::vector< PermuteIterator > make_invariant_subgroup(ConfigEnumInput const &config_enum_input)
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & write_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end, jsonParser &json, Printer printer)
Write Orbit<SymCompareType> to JSON.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void print_clust(ClusterOrbitIterator begin, ClusterOrbitIterator end, Log &out, OrbitPrinter printer)
Print IntegralCluster orbits.
void write_prim(const xtal::BasicStructure &prim, fs::path filename, COORD_TYPE mode, bool include_va=false)
Write prim.json to file.
std::string brief_description(const SymOp &op, const xtal::Lattice &lat, SymInfoOptions opt=SymInfoOptions())
Print SymInfo to brief string.
const COORD_TYPE FRAC
Definition: enum.hh:8
void print_coordinates(OrbitPrinter &printer, const Element &element, Log &out)
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
ClusterOutputIterator read_clust(ClusterOutputIterator result, const jsonParser &json, const Structure &prim, const SymGroup &generating_grp, const SymCompareType &sym_compare)
Read JSON containing Orbit<SymCompareType> prototypes.
ClexDescription & desc
Definition: settings.cc:138
SymInfoOptions sym_info_opt
Definition: OrbitPrinter.hh:30
ORBIT_PRINT_MODE orbit_print_mode
Definition: OrbitPrinter.hh:29
void decrease_indent(Log &out) const
Definition: OrbitPrinter.hh:58
void print_invariant_group(const OrbitType &orbit, const Element &element, Log &out) const
OrbitPrinterOptions opt
Definition: OrbitPrinter.hh:49
void increase_indent(Log &out) const
Definition: OrbitPrinter.hh:55
void print_equivalence_map(const OrbitType &orbit, Index equiv_index, Log &out) const
Options for printing SymInfo.