CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ProtoFuncsPrinter_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_clex_io_ProtoFuncsPrinter_impl
2 #define CASM_clex_io_ProtoFuncsPrinter_impl
3 
5 #include "casm/clex/ClexBasis.hh"
8 
9 namespace CASM {
10 
11 template <typename OrbitType>
12 void ProtoFuncsPrinter::operator()(const OrbitType &orbit, Log &out,
13  Index orbit_index, Index Norbits) const {
14  if (m_align) {
15  print_tex_tabular_cluster_sites(out, orbit.prototype(), *prim_ptr,
16  opt.coord_type);
17 
18  out << "Prototype basis functions:\n\n";
19  Index func_index = 0;
20  for (Index i = 0; i < orbit_index; i++)
21  func_index += clex_basis.clust_basis(i, 0).size();
22 
23  BasisSet tbasis(clex_basis.clust_basis(orbit_index, 0));
24  tbasis.accept(OccFuncLabeler("\\phi_{%b,%f}(s_{%n})"));
25  out << "\\begin{align*}\n";
26  for (Index i = 0; i < tbasis.size(); i++) {
27  out << "\\Phi_{" << func_index + i << "} ={}& ";
28 
29  // wrap formula across multiple lines if its long
30  std::string formula = tbasis[i]->tex_formula();
31  int maxl = opt.max_line_width;
32  int j = 0;
33  int pos = 0;
34  while (formula.size() > maxl) {
35  if (formula[j] == '-' || formula[j] == '+') {
36  if (j > maxl) {
37  if (pos == 0) {
38  pos = j;
39  }
40  out << formula.substr(0, pos) << "\\\\\n";
41  out << " & ";
42  formula = formula.substr(pos, formula.size());
43  j = 0;
44  pos = 0;
45  } else {
46  pos = j;
47  }
48  }
49  ++j;
50  }
51  out << formula;
52 
53  if (i + 1 != tbasis.size()) {
54  out << "\\\\\n";
55  } else {
56  out << "\n";
57  }
58  }
59  out << "\\end{align*}\n\n";
60  } else {
61  out << out.indent_str() << "Prototype"
62  << " of " << orbit.size() << " Equivalent " << element_name
63  << " in Orbit " << orbit_index << std::endl;
64 
65  // out.flags(std::ios::showpoint | std::ios::fixed | std::ios::left);
66  // out.precision(5);
67 
68  xtal::COORD_MODE printer_mode(opt.coord_type);
69 
70  auto const &clust = orbit.prototype();
71  this->increase_indent(out);
72  if (this->opt.print_coordinates) {
73  print_coordinates(*this, orbit.prototype(), out);
74  }
75  if (this->opt.print_invariant_group) {
76  this->print_invariant_group(orbit, orbit.prototype(), out);
77  }
78  this->decrease_indent(out);
79 
80  Index func_index = 0;
81  for (Index i = 0; i < orbit_index; i++)
82  func_index += clex_basis.clust_basis(i, 0).size();
83 
84  // From clust:
85  out.indent() << "Prototype basis functions:\n";
86  BasisSet tbasis(clex_basis.clust_basis(orbit_index, 0));
87  tbasis.accept(OccFuncLabeler("\\phi_{%b,%f}(s_{%n})"));
88  this->increase_indent(out);
89  for (Index i = 0; i < tbasis.size(); i++) {
90  out.indent() << "\\Phi_{" << func_index + i
91  << "} = " << tbasis[i]->tex_formula() << std::endl;
92  }
93  this->decrease_indent(out);
94  out << std::flush;
95  }
96 }
97 
98 template <typename OrbitType>
99 jsonParser &ProtoFuncsPrinter::to_json(const OrbitType &orbit, jsonParser &json,
100  Index orbit_index, Index Norbits) const {
101  json.put_obj();
102  json["prototype"] = orbit.prototype();
103  json["linear_orbit_index"] = orbit_index;
104  json["mult"] = orbit.size();
105  if (this->opt.print_invariant_group) {
106  this->print_invariant_group(orbit, orbit.prototype(), json["prototype"]);
107  }
108 
109  jsonParser &orbitf = json["cluster_functions"];
110  orbitf = jsonParser::array();
111 
112  // basis function info
113  Index func_index = 0;
114  for (Index i = 0; i < orbit_index; i++)
115  func_index += clex_basis.clust_basis(i, 0).size();
116 
117  BasisSet tbasis(clex_basis.clust_basis(orbit_index, 0));
118  tbasis.accept(OccFuncLabeler("\\phi_{%b,%f}(s_{%n})"));
119  for (auto const &labeler : labelers) {
120  tbasis.accept(labeler);
121  }
122 
123  for (Index nf = 0; nf < tbasis.size(); ++nf) {
124  orbitf.push_back(
125  json_pair("\\Phi_{" + std::to_string(func_index + nf) + "}",
126  tbasis[nf]->tex_formula()));
127  }
128 
129  return json;
130 }
131 
132 } // namespace CASM
133 
134 #endif
Index size() const
Definition: Array.hh:131
bool accept(const FunctionVisitor &visitor)
Definition: BasisSet.cc:234
BasisSet const & clust_basis(Index orbit_ind, Index equiv_ind) const
Const access of clust basis of orbit.
Definition: ClexBasis.hh:73
Definition: Log.hh:48
std::string indent_str() const
Definition: Log.hh:273
Log & indent()
Definition: Log.hh:289
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
COORD_MODE specifies the current coordinate mode (Fractional or Cartesian)
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
jsonParser json_pair(const std::string &key, const T &value)
Create pair/value json object without intermediate temporary.
Definition: jsonParser.hh:959
jsonParser & push_back(const T &value, Args &&... args)
Definition: jsonParser.hh:684
Main CASM namespace.
Definition: APICommand.hh:8
void print_tex_tabular_cluster_sites(Log &out, IntegralCluster const &cluster, xtal::BasicStructure const &prim, COORD_TYPE mode)
Print prototype cluster sites as a tex tabular.
void print_coordinates(OrbitPrinter &printer, const Element &element, Log &out)
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
static const std::string element_name
Definition: OrbitPrinter.hh:98
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
jsonParser & to_json(const OrbitType &orbit, jsonParser &json, Index orbit_index, Index Norbits) const
ClexBasis const & clex_basis
void operator()(const OrbitType &orbit, Log &out, Index orbit_index, Index Norbits) const
Print to JSON.
std::vector< SubExpressionLabeler > labelers