CASM  1.1.0
A Clusters Approach to Statistical Mechanics
OrbitPrinter.cc
Go to the documentation of this file.
5 
6 namespace CASM {
7 
8 const std::string traits<ORBIT_PRINT_MODE>::name = "orbit_print_mode";
9 
10 const std::multimap<ORBIT_PRINT_MODE, std::vector<std::string> >
11  traits<ORBIT_PRINT_MODE>::strval = {
12  {ORBIT_PRINT_MODE::PROTO, {"PROTO", "Proto", "proto"}},
13  {ORBIT_PRINT_MODE::FULL, {"FULL", "Full", "full"}}};
14 
17 
19  json.put_obj();
20  json["indent_space"] = opt.indent_space;
21  // just keep default delim
22  json["prec"] = opt.prec;
23  json[traits<COORD_TYPE>::name] = opt.coord_type;
24  json[traits<ORBIT_PRINT_MODE>::name] = opt.orbit_print_mode;
25  json["print_coordinates"] = opt.print_coordinates;
26  json["print_equivalence_map"] = opt.print_equivalence_map;
27  json["print_invariant_group"] = opt.print_invariant_group;
28  json["sym_info_opt"] = opt.sym_info_opt;
29  return json;
30 }
31 
33 void from_json(OrbitPrinterOptions &opt, const jsonParser &json) {
34  json.get_if(opt.indent_space, "indent_space");
35  // just keep default delim
36  json.get_if(opt.prec, "prec");
39  json.get_if(opt.print_coordinates, "print_coordinates");
40  json.get_if(opt.print_equivalence_map, "print_equivalence_map");
41  json.get_if(opt.print_invariant_group, "print_invariant_group");
42  json.get_if(opt.sym_info_opt, "sym_info_opt");
43 }
44 
46  const jsonParser &json) {
48  CASM::from_json(res, json);
49  return res;
50 }
51 
52 PrinterBase::PrinterBase(const OrbitPrinterOptions &_opt) : opt(_opt) {}
53 
55  out << out.indent_str() << "COORD_MODE = " << opt.coord_type << std::endl
56  << std::endl;
57 }
58 
59 const std::string Printer<IntegralCluster>::element_name = "Clusters";
60 
62  Log &out) const {
63  if (!out.print()) {
64  return;
65  }
66 
67  COORD_TYPE _mode = this->opt.coord_type;
68  if (_mode == COORD_DEFAULT) {
69  _mode = xtal::COORD_MODE::CHECK();
70  }
71  xtal::COORD_MODE printer_mode(_mode);
72  if (_mode != INTEGRAL) {
73  // calculate nice widths
74  int prec = this->opt.prec;
75  int width = prec;
76  Eigen::Vector3d vec;
77  out.ostream().precision(prec);
78  out.ostream().flags(std::ios::showpoint | std::ios::fixed |
79  std::ios::right);
80  for (const auto &coord : clust) {
81  if (_mode == CART)
82  vec = coord.coordinate(clust.prim()).cart();
83  else if (_mode == FRAC)
84  vec = coord.coordinate(clust.prim()).frac();
85  width = print_matrix_width(out, vec.transpose(), width);
86  }
87 
88  // calculate nice widths
89  Eigen::IOFormat format(prec, width + 1);
90  for (const auto &coord : clust) {
91  out << out.indent_str();
92  coord.site(clust.prim()).print(out, format);
93  if (this->opt.delim) out << this->opt.delim;
94  out << std::flush;
95  }
96  } else {
97  // calculate nice widths
98  int prec = 1;
99  int width = prec;
100  out.ostream().flags(std::ios::showpoint | std::ios::fixed |
101  std::ios::right);
102  for (const auto &coord : clust) {
103  width = print_matrix_width(out, coord.unitcell().transpose(), width);
104  }
105 
106  // print
107  Eigen::IOFormat format(prec, width);
108  for (const auto &coord : clust) {
109  out << out.indent_str() << coord << " ";
110  xtal::Site::print_occupant_dof(coord.site(clust.prim()).occupant_dof(),
111  out);
112 
113  out << std::flush;
114  if (this->opt.delim) out << this->opt.delim;
115  out << std::flush;
116  }
117  }
118 }
119 
120 // // explicit template instantiations
121 //
122 // #define PRINT_CLUST_INST(ITERATOR, INSERTER, PRINTER) \
123 // template void print_clust<ITERATOR, PRINTER>(ITERATOR begin, ITERATOR end,
124 // \
125 // Log & out, PRINTER printer); \
126 // template jsonParser &write_clust<ITERATOR>( \
127 // ITERATOR begin, ITERATOR end, jsonParser & json, PRINTER printer); \
128 // template jsonParser &write_clust<ITERATOR>( \
129 // ITERATOR begin, ITERATOR end, jsonParser & json, PRINTER printer, \
130 // const jsonParser &bspecs);
131 //
132 // #define ORBIT_CONTAINER_INST(ITERATOR, INSERTER, ORBIT) \
133 // PRINT_CLUST_INST(ITERATOR, INSERTER, ProtoSitesPrinter) \
134 // PRINT_CLUST_INST(ITERATOR, INSERTER, FullSitesPrinter) \
135 // PRINT_CLUST_INST(ITERATOR, INSERTER, ProtoFuncsPrinter) \
136 // template void print_clust<ITERATOR>(ITERATOR begin, ITERATOR end, Log &
137 // out, \
138 // const OrbitPrinterOptions &opt); \
139 // template INSERTER read_clust<INSERTER, typename ORBIT::SymCompareType>( \
140 // INSERTER result, const jsonParser &json, const Structure &prim, \
141 // const SymGroup &generating_grp, \ const typename ORBIT::SymCompareType
142 // &sym_compare);
143 //
144 // #define _VECTOR_IT(ORBIT) std::vector<ORBIT>::iterator
145 // #define _VECTOR_INSERTER(ORBIT) std::back_insert_iterator<std::vector<ORBIT>
146 // >
147 //
148 // #define _SET_IT(ORBIT) std::set<ORBIT>::iterator
149 // #define _SET_INSERTER(ORBIT) std::insert_iterator<std::set<ORBIT> >
150 //
151 // #define ORBIT_VECTOR_INST(ORBIT) \
152 // ORBIT_CONTAINER_INST(_VECTOR_IT(ORBIT), _VECTOR_INSERTER(ORBIT), ORBIT)
153 // #define ORBIT_SET_INST(ORBIT) \
154 // ORBIT_CONTAINER_INST(_SET_IT(ORBIT), _SET_INSERTER(ORBIT), ORBIT)
155 //
156 // ORBIT_VECTOR_INST(LocalIntegralClusterOrbit)
157 // ORBIT_VECTOR_INST(PrimPeriodicIntegralClusterOrbit)
158 // ORBIT_VECTOR_INST(ScelPeriodicIntegralClusterOrbit)
159 //
160 // ORBIT_SET_INST(LocalIntegralClusterOrbit)
161 // ORBIT_SET_INST(PrimPeriodicIntegralClusterOrbit)
162 // ORBIT_SET_INST(ScelPeriodicIntegralClusterOrbit)
163 
164 } // namespace CASM
#define ENUM_JSON_IO_DEF(ENUM)
Definition: json_io.hh:15
#define ENUM_IO_DEF(ENUM)
Definition: stream_io.hh:13
Definition: Log.hh:48
std::string indent_str() const
Definition: Log.hh:273
bool print() const
Definition: Log.cc:260
std::ostream & ostream()
Definition: Log.hh:262
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:354
COORD_MODE specifies the current coordinate mode (Fractional or Cartesian)
static COORD_TYPE CHECK()
get the current mode (call using COORD_MODE::CHECK())
static void print_occupant_dof(const std::vector< Molecule > &allowed_occupants, std::ostream &out_stream)
Definition: Site.cc:407
bool get_if(T &t, const std::string &key, Args &&... args) const
Definition: jsonParser.hh:740
GenericDatumFormatter< std::string, ConfigEnumDataType > name()
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
COORD_TYPE
Definition: enum.hh:6
const COORD_TYPE FRAC
Definition: enum.hh:8
const COORD_TYPE INTEGRAL
Definition: enum.hh:10
ORBIT_PRINT_MODE
Definition: OrbitPrinter.hh:18
void from_json(ClexDescription &desc, const jsonParser &json)
const COORD_TYPE COORD_DEFAULT
Definition: enum.hh:11
const COORD_TYPE CART
Definition: enum.hh:9
Index print_matrix_width(std::ostream &s, const Derived &m, Index width)
SymInfoOptions sym_info_opt
Definition: OrbitPrinter.hh:30
ORBIT_PRINT_MODE orbit_print_mode
Definition: OrbitPrinter.hh:29
void coord_type(Log &out)
Definition: OrbitPrinter.cc:54
OrbitPrinterOptions opt
Definition: OrbitPrinter.hh:49
PrinterBase(const OrbitPrinterOptions &_opt=OrbitPrinterOptions())
Definition: OrbitPrinter.cc:52
void print(const Element &element, Log &out) const
Definition: OrbitPrinter.hh:89
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
Definition: jsonParser.hh:551