CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SupercellIO.cc
Go to the documentation of this file.
2 
8 #include "casm/symmetry/SymOp.hh"
9 
10 namespace CASM {
11 
12 template class BaseDatumFormatter<Supercell>;
13 template class DataFormatterOperator<bool, std::string, Supercell>;
14 template class DataFormatterOperator<bool, bool, Supercell>;
15 template class DataFormatterOperator<bool, double, Supercell>;
16 template class DataFormatterOperator<double, double, Supercell>;
17 template class DataFormatterOperator<Index, double, Supercell>;
18 template class DataFormatter<Supercell>;
20 
21 namespace ScelIO {
22 
23 // --- IsSupercellOf ---
24 
25 const std::string IsSupercellOf::Name = "is_supercell_of";
26 const std::string IsSupercellOf::Desc =
27  "Returns true for all supercells that are a supercell the specified "
28  "supercell. "
29  "All re-orientations allowed by the crystal point group are checked. "
30  "Ex: 'is_supercell_of(SCELV_A_B_C_D_E_F)'";
31 
32 IsSupercellOf::IsSupercellOf() : SupercellCheckBase(Name, Desc) {}
33 
34 bool IsSupercellOf::evaluate(const Supercell &scel) const {
35  return std::get<0>(_evaluate(scel, refcell()));
36 }
37 
39 std::unique_ptr<IsSupercellOf> IsSupercellOf::clone() const {
40  return std::unique_ptr<IsSupercellOf>(this->_clone());
41 }
42 
45  return new IsSupercellOf(*this);
46 }
47 
48 // --- IsUnitcellOf ---
49 
50 const std::string IsUnitcellOf::Name = "is_unitcell_of";
51 const std::string IsUnitcellOf::Desc =
52  "Returns true for all supercells that can tile the specified supercell. "
53  "All re-orientations allowed by the crystal point group are checked. "
54  "Ex: 'is_unitcell_of(SCELV_A_B_C_D_E_F)'";
55 
57 
58 bool IsUnitcellOf::evaluate(const Supercell &unit) const {
59  return std::get<0>(_evaluate(refcell(), unit));
60 }
61 
63 std::unique_ptr<IsUnitcellOf> IsUnitcellOf::clone() const {
64  return std::unique_ptr<IsUnitcellOf>(this->_clone());
65 }
66 
68 IsUnitcellOf *IsUnitcellOf::_clone() const { return new IsUnitcellOf(*this); }
69 
70 // --- TransfMat ---
71 
72 const std::string TransfMat::Name = "transf_mat";
73 const std::string TransfMat::Desc =
74  "For all supercells, S, returns the transformation matrix, T, that can be "
75  "used to create S from the specified unit cell, U, if possible, i.e. "
76  "S.lat = (op*U.lat)*T, where 'op' is an element of the crystal "
77  "point group, and lattices are represented by column vector matrices. "
78  "T is returned in column-major form: (T00, T10, T20, T01, ...) "
79  "If not specified, the primitive cell is used for the unit "
80  "cell. Ex: 'transf_mat', 'transf_mat(SCELV_A_B_C_D_E_F)'";
81 
83 
84 Eigen::VectorXi TransfMat::evaluate(const Supercell &scel) const {
85  // should be column-major anyways, but let's ensure it
86  Eigen::Matrix<int, 3, 3, Eigen::ColMajor> T =
87  std::get<2>(_evaluate(scel, refcell()));
88  return Eigen::Map<Eigen::VectorXi>(T.data(), T.size());
89 }
90 
91 bool TransfMat::validate(const Supercell &scel) const {
92  // should be column-major anyways, but let's ensure it
93  return std::get<0>(_evaluate(scel, refcell()));
94 }
95 
97 std::unique_ptr<TransfMat> TransfMat::clone() const {
98  return std::unique_ptr<TransfMat>(this->_clone());
99 }
100 
102 bool TransfMat::parse_args(const std::string &args) {
103  std::vector<std::string> splt_vec;
104  boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
105 
106  if (splt_vec.size() > 1) {
107  std::stringstream ss;
108  ss << this->name() << " expected 0 or 1 argument. Received: " << args
109  << "\n";
110  throw std::runtime_error(ss.str());
111  } else if (args.empty()) {
112  m_refcell_name = "SCEL1_1_1_1_0_0_0";
113  } else {
114  m_refcell_name = args;
115  }
116  return true;
117 }
118 
120 TransfMat *TransfMat::_clone() const { return new TransfMat(*this); }
121 
122 // --- ConfigCountBase ---
123 
124 ConfigCountBase::ConfigCountBase(std::string name, std::string desc)
126 
128 bool ConfigCountBase::parse_args(const std::string &args) {
129  std::vector<std::string> splt_vec;
130  boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
131 
132  if (splt_vec.size() > 1) {
133  std::stringstream ss;
134  ss << this->name() << " expected 0 or 1 argument. Received: " << args
135  << "\n";
136  throw std::runtime_error(ss.str());
137  }
138 
139  m_type = args;
140  return true;
141 }
142 
144 std::vector<std::string> ConfigCountBase::col_header(
145  const Supercell &_tmplt) const {
146  return std::vector<std::string>{this->name() + "(" + m_type + ")"};
147 }
148 
149 // --- Nconfig ---
150 
151 const std::string Nconfig::Name = "Nconfig";
152 const std::string Nconfig::Desc =
153  "Number of enumerated configurations of (default) all types, or specified "
154  "type, by supercell. Ex: 'Nconfig', 'Nconfig(config)'";
155 
157 
158 Index Nconfig::evaluate(const Supercell &scel) const {
159  if (m_type.empty()) {
160  return DB::config_count(scel.name(), scel.primclex());
161  } else {
162  return DB::config_count(m_type, scel.name(), scel.primclex());
163  }
164 }
165 
167 std::unique_ptr<Nconfig> Nconfig::clone() const {
168  return std::unique_ptr<Nconfig>(this->_clone());
169 }
170 
172 Nconfig *Nconfig::_clone() const { return new Nconfig(*this); }
173 
174 // --- Ncalc ---
175 
176 const std::string Ncalc::Name = "Ncalc";
177 const std::string Ncalc::Desc =
178  "Number of configurations with completed calculations of (default) all "
179  "types, or specified type, by supercell. Ex: 'Ncalc', 'Ncalc(config)'";
180 
181 Ncalc::Ncalc() : ConfigCountBase(Name, Desc) {}
182 
183 Index Ncalc::evaluate(const Supercell &scel) const {
184  if (m_type.empty()) {
185  return DB::config_calculated_count(scel.name(), scel.primclex());
186  } else {
187  return DB::config_calculated_count(m_type, scel.name(), scel.primclex());
188  }
189 }
190 
192 std::unique_ptr<Ncalc> Ncalc::clone() const {
193  return std::unique_ptr<Ncalc>(this->_clone());
194 }
195 
197 Ncalc *Ncalc::_clone() const { return new Ncalc(*this); }
198 
199 // --- Ndata ---
200 
201 const std::string Ndata::Name = "Ndata";
202 const std::string Ndata::Desc =
203  "Number of configurations of (default) all types, or specified "
204  "type, which have any data or files, by supercell. Ex: 'Ndata', "
205  "'Ndata(config)'";
206 
207 Ndata::Ndata() : ConfigCountBase(Name, Desc) {}
208 
209 Index Ndata::evaluate(const Supercell &scel) const {
210  if (m_type.empty()) {
211  return DB::config_data_count(scel.name(), scel.primclex());
212  } else {
213  return DB::config_data_count(m_type, scel.name(), scel.primclex());
214  }
215 }
216 
218 std::unique_ptr<Ndata> Ndata::clone() const {
219  return std::unique_ptr<Ndata>(this->_clone());
220 }
221 
223 Ndata *Ndata::_clone() const { return new Ndata(*this); }
224 
225 // --- GenericDatumFormatter generating functions ---
226 
229  "pointgroup_name", "Supercell point group name.",
230  [](const Supercell &scel) -> std::string {
231  return scel.factor_group().get_name();
232  });
233 }
234 
237  "scel_size",
238  "Supercell volume, given as the integer number of primitive cells",
239  [](const Supercell &scel) -> Index { return scel.volume(); });
240 }
241 
244  "multiplicity", "Number of equivalent supercells",
245  [](const Supercell &scel) -> Index {
246  return scel.prim().factor_group().size() / scel.factor_group().size();
247  });
248 }
249 
251  return GenericScelFormatter<Index>("factorgroup_size",
252  "Supercell factor group size",
253  [](const Supercell &scel) -> Index {
254  return scel.factor_group().size();
255  });
256 }
257 
259  return GenericScelFormatter<double>("volume", "Supercell volume (length^3)",
260  [](const Supercell &scel) -> double {
261  return scel.volume() *
262  scel.lattice().volume();
263  });
264 }
265 
268  "lattice", "Lattice vectors, unrolled: (a0, a1, a2, b0, ...)",
269  [](const Supercell &scel) -> Eigen::VectorXd {
270  Eigen::Matrix<double, 3, 3, Eigen::ColMajor> L =
271  scel.lattice().lat_column_mat();
272  return Eigen::Map<Eigen::VectorXd>(L.data(), L.size());
273  });
274 }
275 
278  "lattice_params", "Lattice parameters, as: (a, b, c, alpha, beta, gamma)",
279  [](const Supercell &scel) -> Eigen::VectorXd {
280  Eigen::VectorXd res(6);
281  res << scel.lattice().length(0), scel.lattice().length(1),
282  scel.lattice().length(2), scel.lattice().angle(0),
283  scel.lattice().angle(1), scel.lattice().angle(2);
284  return res;
285  });
286 }
287 
288 } // namespace ScelIO
289 
290 template <>
291 StringAttributeDictionary<Supercell> make_string_dictionary<Supercell>() {
292  using namespace ScelIO;
293  StringAttributeDictionary<Supercell> dict;
294 
295  dict.insert(name<Supercell>(), alias<Supercell>(), alias_or_name<Supercell>(),
296  pointgroup_name());
297 
298  return dict;
299 }
300 
301 template <>
302 BooleanAttributeDictionary<Supercell> make_boolean_dictionary<Supercell>() {
303  using namespace ScelIO;
304  BooleanAttributeDictionary<Supercell> dict;
305 
306  dict.insert(DB::Selected<Supercell>(), IsSupercellOf(), IsUnitcellOf());
307 
308  return dict;
309 }
310 
311 template <>
312 IntegerAttributeDictionary<Supercell> make_integer_dictionary<Supercell>() {
313  using namespace ScelIO;
314  IntegerAttributeDictionary<Supercell> dict;
315 
316  dict.insert(scel_size(), multiplicity(), factorgroup_size(), Nconfig(),
317  Ncalc(), Ndata());
318 
319  return dict;
320 }
321 
322 template <>
323 ScalarAttributeDictionary<Supercell> make_scalar_dictionary<Supercell>() {
324  using namespace ScelIO;
325  ScalarAttributeDictionary<Supercell> dict;
326 
327  dict.insert(volume());
328 
329  return dict;
330 }
331 
332 template <>
333 VectorXiAttributeDictionary<Supercell> make_vectorxi_dictionary<Supercell>() {
334  using namespace ScelIO;
335  VectorXiAttributeDictionary<Supercell> dict;
336 
337  dict.insert(TransfMat());
338 
339  return dict;
340 }
341 
342 template <>
343 VectorXdAttributeDictionary<Supercell> make_vectorxd_dictionary<Supercell>() {
344  using namespace ScelIO;
345  VectorXdAttributeDictionary<Supercell> dict;
346 
347  dict.insert(lattice(), lattice_params());
348 
349  return dict;
350 }
351 
352 template <>
353 DataFormatterDictionary<Supercell, BaseValueFormatter<jsonParser, Supercell>>
355  return DataFormatterDictionary<Supercell,
356  BaseValueFormatter<jsonParser, Supercell>>();
357 }
358 
359 } // namespace CASM
const std::string & name() const
Returns a name for the formatter, which becomes the tag used for parsing.
Base class for creating scalar DatumFormatter.
std::string name() const
Definition: Named_impl.hh:14
Parsing dictionary for constructing a DataFormatter<DataObject> object.
A DatumFormatter that returns a 1D value of specified type, via functions that may be specified at ru...
A DatumFormatter that returns a value of specified type, via functions that may be specified at runti...
std::vector< std::string > col_header(const Supercell &_tmplt) const override
col_header returns: {'short_name(refcell_name)'}
Definition: SupercellIO.cc:144
std::string m_type
Reference supercell name, given meaning by derived class.
Definition: SupercellIO.hh:129
bool parse_args(const std::string &args) override
Expects arguments of the form 'is_supercell_of(scelname)'.
Definition: SupercellIO.cc:128
ConfigCountBase(std::string name, std::string desc)
Definition: SupercellIO.cc:124
bool evaluate(const Supercell &scel) const override
Definition: SupercellIO.cc:34
std::unique_ptr< IsSupercellOf > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:39
IsSupercellOf * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:44
static const std::string Name
Definition: SupercellIO.hh:78
static const std::string Desc
Definition: SupercellIO.hh:79
std::unique_ptr< IsUnitcellOf > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:63
bool evaluate(const Supercell &unit) const override
Definition: SupercellIO.cc:58
IsUnitcellOf * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:68
static const std::string Desc
Definition: SupercellIO.hh:152
Ncalc * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:197
std::unique_ptr< Ncalc > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:192
static const std::string Name
Definition: SupercellIO.hh:151
Index evaluate(const Supercell &scel) const override
Definition: SupercellIO.cc:183
Index evaluate(const Supercell &scel) const override
Definition: SupercellIO.cc:158
static const std::string Desc
Definition: SupercellIO.hh:135
static const std::string Name
Definition: SupercellIO.hh:134
Nconfig * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:172
std::unique_ptr< Nconfig > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:167
std::unique_ptr< Ndata > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:218
Index evaluate(const Supercell &scel) const override
Definition: SupercellIO.cc:209
static const std::string Name
Definition: SupercellIO.hh:168
static const std::string Desc
Definition: SupercellIO.hh:169
Ndata * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:223
const result_type & _evaluate(const Supercell &scel, const Supercell &unit) const
std::string m_refcell_name
Reference supercell name, given meaning by derived class.
Definition: SupercellIO.hh:46
std::unique_ptr< TransfMat > clone() const
Clone using copy constructor.
Definition: SupercellIO.cc:97
Eigen::VectorXi evaluate(const Supercell &scel) const override
Definition: SupercellIO.cc:84
static const std::string Name
Definition: SupercellIO.hh:95
bool validate(const Supercell &scel) const override
Definition: SupercellIO.cc:91
bool parse_args(const std::string &args) override
Expects arguments of the form 'transf_mat(unitcell_name)'.
Definition: SupercellIO.cc:102
TransfMat * _clone() const override
Clone using copy constructor.
Definition: SupercellIO.cc:120
static const std::string Desc
Definition: SupercellIO.hh:96
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
const PrimClex & primclex() const
Use while transitioning Supercell to no longer need a PrimClex const *
Definition: Supercell.cc:150
const Lattice & lattice() const
The super lattice.
Definition: Supercell.cc:239
Index volume() const
Return number of primitive cells that fit inside of *this.
Definition: Supercell.cc:227
const SymGroup & factor_group() const
Definition: Supercell.cc:260
const Structure & prim() const
Definition: Supercell.cc:113
double length(Index i) const
Return length of i'th lattice vector.
Definition: Lattice.cc:127
double angle(Index i) const
Return angle between lattice vectors (*this)[(i+1)%3] and (*this)[(i+2)%3], in degrees.
Definition: Lattice.cc:132
double volume() const
Return signed volume of this lattice.
Definition: Lattice.hh:88
Index config_count(std::string scelname, const PrimClex &primclex)
Total number of configs of all types in a supercell.
Index config_data_count(std::string scelname, const PrimClex &primclex)
Total number of configs w/ data or files of all types in a supercell.
Index config_calculated_count(std::string scelname, const PrimClex &primclex)
Total number of calculated configs of all types in a supercell.
Generic1DDatumFormatter< Eigen::VectorXd, Supercell > GenericVectorXdScelFormatter
Definition: SupercellIO.hh:189
GenericVectorXdScelFormatter lattice_params()
Definition: SupercellIO.cc:276
GenericVectorXdScelFormatter lattice()
Definition: SupercellIO.cc:266
GenericScelFormatter< Index > multiplicity()
Definition: SupercellIO.cc:242
GenericScelFormatter< std::string > pointgroup_name()
Definition: SupercellIO.cc:227
GenericScelFormatter< Index > scel_size()
Definition: SupercellIO.cc:235
GenericScelFormatter< double > volume()
Definition: SupercellIO.cc:258
GenericScelFormatter< Index > factorgroup_size()
Definition: SupercellIO.cc:250
SharedPrimFormatter< jsonParser > factor_group()
Main CASM namespace.
Definition: APICommand.hh:8
IntegerAttributeDictionary< Supercell > make_integer_dictionary< Supercell >()
Definition: SupercellIO.cc:312
DataFormatterDictionary< Supercell, BaseValueFormatter< jsonParser, Supercell > > make_json_dictionary< Supercell >()
Definition: SupercellIO.cc:354
BooleanAttributeDictionary< Supercell > make_boolean_dictionary< Supercell >()
Definition: SupercellIO.cc:302
VectorXiAttributeDictionary< Supercell > make_vectorxi_dictionary< Supercell >()
Definition: SupercellIO.cc:333
GenericDatumFormatter< std::string, DataObject > name()
VectorXdAttributeDictionary< Supercell > make_vectorxd_dictionary< Supercell >()
Definition: SupercellIO.cc:343
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Eigen::VectorXd VectorXd
StringAttributeDictionary< Supercell > make_string_dictionary< Supercell >()
Definition: SupercellIO.cc:291
ScalarAttributeDictionary< Supercell > make_scalar_dictionary< Supercell >()
Definition: SupercellIO.cc:323
ClexDescription & desc
Definition: settings.cc:138