CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ConfigIO_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
5 #include "casm/clex/ConfigIO.hh"
6 
8 
14 #include "Common.hh"
15 
16 using namespace CASM;
17 
18 BOOST_AUTO_TEST_SUITE(ConfigIOTest)
19 
20 BOOST_AUTO_TEST_CASE(DatumFormatters) {
21 
22  using namespace ConfigIO;
23 
25 
26  auto check = [&](const BaseDatumFormatter<Configuration> &formatter) {
27  auto prev_size = dict.size();
28  dict.insert(formatter);
29  BOOST_CHECK_MESSAGE(prev_size + 1 == dict.size(), formatter.name());
30  };
31 
32  // String
33  check(configname());
34  check(scelname());
35 
36  // Boolean
37  check(OnHull());
38  check(OnClexHull());
42  check(selected_in());
43 
44  // Integer
45  check(scel_size());
47 
48  // Scalar
49  //check(Clex());
50  check(HullDist());
51  check(ClexHullDist());
52  check(Novelty());
59  check(rms_force());
63 
64  // VectorXd
65  check(Corr());
66  check(CompN());
67  check(Comp());
68  check(AtomFrac());
69  check(RelaxationStrain());
70  check(SiteFrac());
71  check(StrucScore());
72 
73 }
74 
76 
77  std::stringstream ss;
79  {
81 
82  using namespace ConfigIO;
83 
84  dict0.insert(
85  Corr(),
86  CompN(),
87  format_operator_add<Configuration>()
88  );
89 
91 
92  dict.insert(
93  dict0,
94  AtomFrac(),
95  SiteFrac()
96  );
97 
98 
99  ss << "\n---\n";
100 
101  ss << "get iterator" << std::endl;
103  ss << "get ref from transform iterator" << std::endl;
104  BaseDatumFormatter<Configuration> &transform_ref = *it;
105  (void) transform_ref;
106  ss << "get const ref from transform iterator" << std::endl;
107  const BaseDatumFormatter<Configuration> &const_transform_ref = *it;
108  (void) const_transform_ref;
109 
110  ss << "get ref from iterator" << std::endl;
111  const BaseDatumFormatter<Configuration> &ref = *(it.base()->second);
112  (void) ref;
113  ss << "get pair ref from base iterator" << std::endl;
114  auto &pair_ref = *(it.base());
115  (void) pair_ref;
116  ss << "get const pair ref from base iterator" << std::endl;
117  const auto &const_pair_ref = *(it.base());
118  (void) const_pair_ref;
119  ss << "use ref from iterator, name: " << ref.name() << std::endl;
120 
121  ss << "\n---\n";
122  for(DataFormatterDictionary<Configuration>::const_iterator it = dict.begin(); it != dict.end(); ++it) {
123  ss << "name: " << it.base()->second->name() << std::endl;
124  }
125  }
126 
127  ss << "\n-----------------------\n";
128  {
129  std::vector<cloner> dict;
130  dict.emplace_back(ConfigIO::Corr());
131  dict.emplace_back(ConfigIO::CompN());
132  dict.emplace_back(format_operator_add<Configuration>());
133  dict.emplace_back(format_operator_sub<Configuration>());
134  dict.emplace_back(format_operator_eq<Configuration>());
135 
136  ss << "get iterator" << std::endl;
137  auto it = dict.begin();
138  ss << "get ref from iterator" << std::endl;
140  ss << "use ref from iterator, name: " << ref.name() << std::endl;
141 
142  for(auto it = dict.begin(); it != dict.end(); ++it) {
143  ss << "name: " << (*it)->name() << std::endl;
144  }
145  }
146 
147  ss << "\n-----------------------\n";
148  {
149  std::map<std::string, cloner > dict;
150  dict["corr"] = cloner(ConfigIO::Corr());
151  dict["comp_n"] = cloner(ConfigIO::CompN());
152  dict["add"] = cloner(format_operator_add<Configuration>());
153  dict["sub"] = cloner(format_operator_sub<Configuration>());
154  dict["eq"] = cloner(format_operator_eq<Configuration>());
155 
156  ss << "get iterator" << std::endl;
157  auto it = dict.begin();
158  ss << "get ref from iterator" << std::endl;
159  const BaseDatumFormatter<Configuration> &ref = *(it->second);
160  ss << "use ref from iterator, name: " << ref.name() << std::endl;
161 
162  for(auto it = dict.begin(); it != dict.end(); ++it) {
163  ss << "name: " << it->second->name() << std::endl;
164  }
165  }
166 
167  ss << "\n-----------------------\n";
168  auto adder = format_operator_add<Configuration>();
169  ss << "adder name: " << adder.name() << std::endl;
170 
171  BaseDatumFormatter<Configuration> *ptr = &adder;
172  ss << "ptr adder name: " << ptr->name() << std::endl;
173 
175  ss << "cl_ptr adder name: " << cl_ptr->name() << std::endl;
176 
177  auto other = cl_ptr;
178  ss << "other adder name: " << other->name() << std::endl;
179 
181  ss << "another adder name: " << another->name() << std::endl;
182 
183  ss << "\n-----------------------\n";
184  {
185 
186  DataFormatterDictionary<Configuration> dict = make_dictionary<Configuration>();
187  for(auto it = dict.begin(); it != dict.end(); ++it) {
188  ss << "name: " << it->name() << std::endl;
189  }
190  }
191 
192  //std::cout << ss.str() << std::endl;
193 }
194 
196 
198  proj.check_init();
199  proj.check_composition();
200  proj.check_enum();
201 
202  Log log = null_log();
203  PrimClex primclex(proj.dir, log);
204 
205  log << "---- Comp -------------" << std::endl;
207  for(auto it = primclex.config_begin(); it != primclex.config_end(); ++it) {
208  log << "name: " << it->name() << " comp: " << comp(*it).transpose() << " print: ";
209  comp.print(*it, log);
210  log << std::endl;
211  }
212 
213  log << "---- BaseValueFormatter Ptr -------------" << std::endl;
215  for(auto it = primclex.config_begin(); it != primclex.config_end(); ++it) {
216  log << "name: " << it->name() << " value: " << (*value_ptr)(*it).transpose() << " print: ";
217  value_ptr->print(*it, log);
218  log << std::endl;
219  }
220 
221  log << "---- BaseDatumFormatter Ptr -------------" << std::endl;
223  for(auto it = primclex.config_begin(); it != primclex.config_end(); ++it) {
224  log << "name: " << it->name() << " print: ";
225  datum_ptr->print(*it, log);
226  log << std::endl;
227  }
228 
229  //std::cout << ss.str() << std::endl;
230 
231 }
232 
233 BOOST_AUTO_TEST_SUITE_END()
const std::string & name() const
Returns a name for the formatter, which becomes the tag used for parsing.
fs::path dir
Definition: Proj.hh:34
void check_composition() override
Check "casm composition".
ConfigIO::Selected selected_in(const ConfigSelection< IsConst > &_selection)
PrimClex * primclex
Definition: settings.cc:101
An iterator over a UniqueMap.
Definition: unique_map.hh:18
size_type size() const
Definition: unique_map.hh:239
ConfigIO::GenericConfigFormatter< double > relaxed_energy()
Definition: ConfigIO.cc:407
Main CASM namespace.
Definition: complete.cpp:8
Log & log
Definition: settings.cc:105
Base class for creating scalar DatumFormatter.
Log & null_log()
Definition: Log.hh:211
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
Calculate number of each species per unit cell.
Definition: ConfigIO.hh:127
config_iterator config_begin()
Configuration iterator: begin.
Definition: PrimClex.cc:371
config_iterator config_end()
Configuration iterator: end.
Definition: PrimClex.cc:379
std::pair< iterator, bool > insert(const value_type &value)
Insert single value.
Definition: unique_map.hh:169
pair_type ref
Definition: settings.cc:110
Calculate param composition of a Configuration.
Definition: ConfigIO.hh:80
BOOST_AUTO_TEST_CASE(DatumFormatters)
ConfigIO::GenericConfigFormatter< double > lattice_deformation()
Definition: ConfigIO.cc:499
iterator begin()
Definition: unique_map.hh:247
ConfigIO::GenericConfigFormatter< double > rms_force()
Definition: ConfigIO.cc:485
ConfigIO::GenericConfigFormatter< double > reference_energy()
Definition: ConfigIO.cc:423
ConfigIO::GenericConfigFormatter< bool > is_primitive()
Definition: ConfigIO.cc:473
virtual void print(const DataObject &_data_obj, std::ostream &_stream, Index pass_index=0) const =0
ConfigIO::GenericConfigFormatter< double > volume_relaxation()
Definition: ConfigIO.cc:506
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
ConfigIO::GenericConfigFormatter< double > formation_energy()
Definition: ConfigIO.cc:439
void check_enum() override
Check "ccasm enum".
MapIteratorType base() const
Definition: unique_map.hh:87
ConfigIO::GenericConfigFormatter< bool > is_calculated()
Definition: ConfigIO.cc:467
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
Definition: ConfigIO.cc:340
bool check(std::string test, const jsonParser &expected, const jsonParser &calculated, fs::path test_cases_path, bool quiet, double tol=0.0)
Check expected JSON vs calculated JSON using BOOST_CHECK_EQUAL.
virtual void print(const DataObject &_data_obj, std::ostream &_stream, Index pass_index=0) const override
Default implementation prints each element in a column.
ConfigIO::GenericConfigFormatter< double > basis_deformation()
Definition: ConfigIO.cc:492
ConfigIO::GenericConfigFormatter< double > reference_energy_per_species()
Definition: ConfigIO.cc:431
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
Definition: Log.hh:9
ConfigIO::GenericConfigFormatter< Index > scel_size()
Definition: ConfigIO.cc:373
ConfigIO::GenericConfigFormatter< std::string > scelname()
Definition: ConfigIO.cc:348
ConfigIO::GenericConfigFormatter< Index > multiplicity()
Definition: ConfigIO.cc:381
Returns correlation values.
Definition: ConfigIO.hh:281
ConfigIO::GenericConfigFormatter< bool > is_canonical()
Definition: ConfigIO.cc:479
ConfigIO::GenericConfigFormatter< double > relaxed_energy_per_species()
Definition: ConfigIO.cc:415
virtual void check_init()
Check project initialization.
virtual void print(const DataObject &_data_obj, std::ostream &_stream, Index pass_index=0) const override
Default implementation prints each element in a column, via operator<<.
Parsing dictionary for constructing a DataFormatter object.
ConfigIO::GenericConfigFormatter< double > formation_energy_per_species()
Definition: ConfigIO.cc:448