CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ConfigEnumAllOccupations_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
10 #include "casm/clex/PrimClex.hh"
11 #include "casm/app/AppIO.hh"
13 #include "Common.hh"
14 
15 using namespace CASM;
16 using namespace test;
17 
18 BOOST_AUTO_TEST_SUITE(ConfigEnumTest)
19 
20 BOOST_AUTO_TEST_CASE(ConfigEnumAllOccupationsTest) {
21 
22  // tests ConfigEnumAllOccupations and ConfigEnumEquivalents
23 
24  // read test file
25  fs::path test_cases_path("tests/unit/clex/ConfigEnumAllOccupations_test_cases.json");
26  jsonParser tests(test_cases_path);
27  // double tol = TOL;
28  fs::path test_proj_dir("tests/unit/clex/test_proj");
29 
30  for(auto test_it = tests.begin(); test_it != tests.end(); ++test_it) {
31 
32  // input and expected output data
33  jsonParser &j = *test_it;
34 
35  // if false: print calculated results if no test data; if true: suppress
36  bool quiet = false;
37  j.get_else(quiet, "quiet", false);
38 
39  BOOST_CHECK_MESSAGE(j.contains("title"), "test case 'title' is required");
40  BOOST_CHECK_MESSAGE(j.contains("prim"), "test case 'prim' is required");
41  BOOST_CHECK_MESSAGE(j.contains("min_vol"), "test case 'min_vol' is required");
42  BOOST_CHECK_MESSAGE(j.contains("max_vol"), "test case 'max_vol' is required");
43 
44  // generate prim
45  Structure prim(read_prim(j["prim"]));
46 
47  // clean up test proj
48  if(fs::exists(test_proj_dir / ".casm")) {
49  fs::remove_all(test_proj_dir);
50  }
51 
52  fs::create_directory(test_proj_dir);
53 
54  j["prim"].write(test_proj_dir / "prim.json");
55 
56  // build a project
57  ProjectBuilder builder(test_proj_dir, j["title"].get<std::string>(), "formation_energy");
58  builder.build();
59 
60  // read primclex
61  PrimClex primclex(test_proj_dir, null_log());
62 
63  // generate supercells
64  ScelEnumProps enum_props(j["min_vol"].get<int>(), j["max_vol"].get<int>() + 1);
65  primclex.generate_supercells(enum_props);
66 
67  // run checks:
68  jsonParser json_scel;
69  json_scel = (Index) primclex.get_supercell_list().size();
70  check("Nscel", j, json_scel, test_cases_path, quiet);
71 
72  // generate configurations
74  for(auto &scel : primclex.get_supercell_list()) {
76  json.push_back(std::distance(e.begin(), e.end()));
77  }
78 
79  // run checks:
80  check("Nconfigs", j, json, test_cases_path, quiet);
81 
82  // ... add more here ...
83 
84 
85  // clean up test proj
86  if(fs::exists(test_proj_dir / ".casm")) {
87  fs::remove_all(test_proj_dir);
88  }
89  }
90 }
91 
92 BOOST_AUTO_TEST_SUITE_END()
Enumerate over all possible occupations in a particular Supercell.
boost::container::stable_vector< Supercell > & get_supercell_list()
Access entire supercell_list.
Definition: PrimClex.cc:299
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:465
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
Definition: jsonParser.cc:191
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
Data structure for holding supercell enumeration properties.
PrimClex * primclex
Definition: settings.cc:101
Definition: Common.hh:7
BOOST_AUTO_TEST_CASE(ConfigEnumAllOccupationsTest)
Main CASM namespace.
Definition: complete.cpp:8
Log & null_log()
Definition: Log.hh:211
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:440
void generate_supercells(const ScelEnumProps &enum_props)
Use the given CSPECS.
Definition: PrimClex.cc:492
BasicStructure< Site > read_prim(fs::path filename)
Definition: AppIO.cc:11
Sets up directories and files for a new CASM project.
EigenIndex Index
For long integer indexing:
bool get_else(T &t, const std::string &key, const T &default_value, Args...args) const
Definition: jsonParser.hh:749
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
void build() const
Builds a new CASM project.
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.
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
Definition: jsonParser.hh:696
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
static jsonParser array()
Returns an empty json array.
Definition: jsonParser.hh:342