CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ScelEnum_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/ScelEnum.hh"
6 //#include "casm/clex/ScelEnum_impl.hh"
7 
9 
10 #include "Common.hh"
11 #include "FCCTernaryProj.hh"
13 
14 using namespace CASM;
15 
16 BOOST_AUTO_TEST_SUITE(ScelEnumTest)
17 
19 
20  test::ZrOProj proj;
21  proj.check_init();
22 
23  PrimClex primclex(proj.dir, null_log());
24  primclex.settings().set_crystallography_tol(1e-5);
25 
26  Eigen::Vector3d a, b, c;
27  std::tie(a, b, c) = primclex.get_prim().lattice().vectors();
28 
29  std::vector<std::string> m_names;
30 
31  // -- Test ScelEnumByProps --------------------
32  {
33  ScelEnumProps enum_props(1, 10);
34  ScelEnumByProps e(primclex, enum_props);
35 
36  BOOST_CHECK_EQUAL(e.name(), "ScelEnumByProps");
37 
38  auto it = e.begin();
39  BOOST_CHECK(true);
40  BOOST_CHECK_EQUAL(it.name(), "ScelEnumByProps");
41 
42  auto end = e.end();
43  BOOST_CHECK(true);
44 
45  Index count = 0;
46  for(; it != end; ++it, ++count) {
47  m_names.push_back(it->get_name());
48 
50  it->get_real_super_lattice(),
51  primclex.get_prim().point_group(),
52  primclex.crystallography_tol());
53 
54  bool check = almost_equal(
55  it->get_real_super_lattice().lat_column_mat(),
56  canon_check.lat_column_mat(),
57  primclex.crystallography_tol());
58 
59  if(!check) {
60  std::cout << "superlat: \n" << it->get_real_super_lattice().lat_column_mat() << std::endl;
61  std::cout << "canon_check: \n" << canon_check.lat_column_mat() << std::endl;
62  }
63 
64  BOOST_CHECK_EQUAL(check, true);
65 
66  BOOST_CHECK_EQUAL(it->is_canonical(), true);
67 
68  }
69  BOOST_CHECK_EQUAL(count, 114);
70  BOOST_CHECK(it == end);
71  }
72 
73  // -- use results to Test ScelEnumByName --------------------
74  {
75  ScelEnumByNameT<false> e(primclex, m_names.begin(), m_names.end());
76  BOOST_CHECK_EQUAL(e.name(), "ScelEnumByName");
77 
78  auto it = e.begin();
79  BOOST_CHECK(true);
80  BOOST_CHECK_EQUAL(it.name(), "ScelEnumByName");
81 
82  auto end = e.end();
83  BOOST_CHECK(true);
84 
85  Index count = 0;
86  for(; it != end; ++it, ++count) {
87  //std::cout << it->get_name() << std::endl;
88  }
89  BOOST_CHECK_EQUAL(count, 114);
90  BOOST_CHECK(it == end);
91  }
92 
93 }
94 
96 
97  // create a project
99  proj.check_init();
100 
101  // in case you want to see what's happening
102  OStringStreamLog ss_log;
103  OStringStreamLog ss_debug_log;
104  OStringStreamLog ss_err_log;
105 
106  // construct PrimClex
107  PrimClex primclex(proj.dir, Logging(ss_log, ss_debug_log, ss_err_log));
108 
109  auto exec = [&](const std::string & args) {
110  CommandArgs cmdargs(args, &primclex, proj.dir, ss_log, ss_err_log);
111  int code = casm_api(cmdargs);
112  //std::cout << ss_log.ss().str() << std::endl;
113  //std::cout << ss_err_log.ss().str() << std::endl;
114  return code;
115  };
116 
117  BOOST_CHECK_EQUAL(exec("casm enum -h"), 0);
118  BOOST_CHECK_EQUAL(exec("casm enum --method ScelEnum --max 4"), 0);
119  BOOST_CHECK_EQUAL(exec("casm enum --method ConfigEnumAllOccupations --all"), 0);
120  BOOST_CHECK_EQUAL(exec("casm enum --method ScelEnum --max 8"), 0);
121  BOOST_CHECK_EQUAL(exec("casm enum --method ConfigEnumAllOccupations --max 6 -i '{\"existing_only\":true}'"), 0);
122 
123 }
124 
125 BOOST_AUTO_TEST_SUITE_END()
Data structure holding basic CASM command info.
BOOST_AUTO_TEST_CASE(Test1)
fs::path dir
Definition: Proj.hh:34
const SymGroup & point_group() const
Definition: Structure.cc:101
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
Data structure for holding supercell enumeration properties.
PrimClex * primclex
Definition: settings.cc:101
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & null_log()
Definition: Log.hh:211
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:104
bool set_crystallography_tol(double _tol)
Set crystallography tolerance.
double crystallography_tol() const
Definition: PrimClex.hh:124
EigenIndex Index
For long integer indexing:
Lattice canonical_equivalent_lattice(const Lattice &in_lat, const SymGroup &point_grp, double compare_tol)
Find the niggli, most standard oriented version of the given orbit (defined by the given SymGroup) of...
Definition: Niggli.cc:276
ProjectSettings & settings()
Definition: PrimClex.hh:116
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
Enumerate over Supercell.
Definition: ScelEnum.hh:36
std::tuple< LatVec, LatVec, LatVec > vectors()
Definition: Lattice.hh:65
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 check_init()
Check project initialization.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.