CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ZrOProj.hh
Go to the documentation of this file.
1 #ifndef CASMtest_ZrOProj
2 #define CASMtest_ZrOProj
3 
4 #include "Proj.hh"
5 #include "casm/casm_io/Log.hh"
6 #include "casm/clex/PrimClex.hh"
8 
9 using namespace CASM;
10 
11 namespace test {
12 
14 
15  // lattice vectors as rows
16  Eigen::Matrix3d lat;
17  lat << 3.233986860000, 0.000000000000, 0.000000000000,
18  -1.616993430000, 2.800714770000, 0.000000000000,
19  0.000000000000, 0.000000000000, 5.168678340000;
20 
21  BasicStructure<Site> struc(Lattice(lat.transpose()));
22  struc.title = "ZrO";
23 
24  Molecule O = make_atom("O", struc.lattice());
25  Molecule Zr = make_atom("Zr", struc.lattice());
26  Molecule Va = make_vacancy(struc.lattice());
27 
28  struc.basis.push_back(Site(Coordinate(Eigen::Vector3d::Zero(), struc.lattice(), FRAC), {Zr}));
29  struc.basis.push_back(Site(Coordinate(Eigen::Vector3d(2. / 3., 1. / 3., 1. / 2.), struc.lattice(), FRAC), {Zr}));
30  struc.basis.push_back(Site(Coordinate(Eigen::Vector3d(1. / 3., 2. / 3., 1. / 4.), struc.lattice(), FRAC), {Va, O}));
31  struc.basis.push_back(Site(Coordinate(Eigen::Vector3d(1. / 3., 2. / 3., 3. / 4.), struc.lattice(), FRAC), {Va, O}));
32 
33  return struc;
34  }
35 
36  class ZrOProj : public Proj {
37 
38  public:
39 
40  ZrOProj() :
41  //Use PID to get unique naming. Otherwise different tests might obliterate your directory mid testing if you run in parallel
42  Proj(proj_dir("tests/unit/test_projects/ZrO"),
43  ZrO_prim(),
44  "ZrO",
45  "HCP Zr with octahedral interstitial O") {}
46 
48  void check_symmetry() override {
49  _check_symmetry(24, 12, 24, 12, 24, 12, "D6h", "D6h");
50  }
51 
52  jsonParser bspecs() const {
53 
54  std::string str = R"({
55 "basis_functions" : {
56 "site_basis_functions" : "occupation"
57 },
58 "orbit_branch_specs" : {
59 "2" : {"max_length" : 9.0},
60 "3" : {"max_length" : 7.0},
61 "4" : {"max_length" : 6.0}
62 },
63 "orbit_specs" : [
64 {
65 "coordinate_mode" : "Integral",
66 "prototype" : [
67 [ 2, 0, 0, 0 ],
68 [ 2, 3, 0, 0 ]
69 ],
70 "include_subclusters" : false
71 }
72 ]
73 })";
74 
75  return jsonParser::parse(str);
76 
77  }
78 
79  void check_composition() override {
80  std::vector<std::string> axes = {
81  R"(\s+0\s+Zr\(2\)Va\(2\)\s+Zr\(2\)O\(2\)\s+Zr\(2\)Va\(2-2a\)O\(2a\))",
82  R"(\s+1\s+Zr\(2\)O\(2\)\s+Zr\(2\)Va\(2\)\s+Zr\(2\)Va\(2a\)O\(2-2a\))"
83  };
84 
85  _check_composition_axes(axes.begin(), axes.end());
86  }
87 
90  void check_bset() override {
91 
92  // check for success with a valid bspecs
93  bspecs().write(dir / "basis_sets" / "bset.default" / "bspecs.json");
94 
95  m_p.popen(cd_and() + "ccasm bset -u");
96  BOOST_CHECK_MESSAGE(m_p.exit_code() == 0, m_p.gets());
97 
98  BOOST_CHECK_MESSAGE(boost::regex_search(m_p.gets(), m_match, boost::regex(R"(write:.*clust\.json)")) == true, m_p.gets());
99  BOOST_CHECK_MESSAGE(boost::regex_search(m_p.gets(), m_match, boost::regex(R"(write:.*basis\.json)")) == true, m_p.gets());
100  BOOST_CHECK_MESSAGE(boost::regex_search(m_p.gets(), m_match, boost::regex(R"(write:.*)" + title + R"(_Clexulator\.cc)")) == true, m_p.gets());
101 
102  BOOST_CHECK_MESSAGE(true == fs::exists(m_dirs.clust(m_set->default_clex().bset)), m_p.gets());
103  BOOST_CHECK_MESSAGE(true == fs::exists(m_dirs.clexulator_src(m_set->name(), m_set->default_clex().bset)), m_p.gets());
104 
105  std::string str;
106 
107  // check that 4 branches are created (null - 4-pt)
108  // check that --orbits, --clusters, --functions all execute
109  // (derived Proj would have to check the actual results)
110  std::string pattern = R"(\*\* Branch [0-9]+ \*\*)";
111  boost::regex re(pattern);
112 
113  std::vector<std::string> checks = {
114  "ccasm bset --orbits",
115  "ccasm bset --clusters",
116  "ccasm bset --functions"
117  };
118 
119  for(auto it = checks.begin(); it != checks.end(); ++it) {
120  m_p.popen(cd_and() + *it);
121  str = m_p.gets();
122 
123  auto begin = boost::sregex_iterator(str.begin(), str.end(), re);
124  auto end = boost::sregex_iterator();
125  auto count = std::distance(begin, end);
126 
127  BOOST_CHECK_MESSAGE(count == 5, m_p.gets());
128  }
129 
130  // check that you can't overwrite without using -f
131  m_p.popen(cd_and() + "ccasm bset -u");
132  BOOST_CHECK_EQUAL(m_p.exit_code(), 6);
133 
134  m_p.popen(cd_and() + "ccasm bset -uf");
135  BOOST_CHECK_EQUAL(m_p.exit_code(), 0);
136 
137  }
138 
140  void check_enum() override {
141 
142  {
143  m_p.popen(cd_and() + "ccasm enum --method ScelEnum --max 10");
144  std::stringstream ss;
145  Log log(ss);
146  PrimClex primclex(dir, log);
147  BOOST_CHECK_MESSAGE(primclex.get_supercell_list().size() == 147, m_p.gets());
148  }
149 
150  {
151  m_p.popen(cd_and() + "ccasm enum --method ConfigEnumAllOccupations --max 6");
152  std::stringstream ss;
153  Log log(ss);
154  PrimClex primclex(dir, log);
155  BOOST_CHECK_MESSAGE(std::distance(primclex.config_begin(), primclex.config_end()) == 5763, m_p.gets());
156  }
157  }
158 
159  };
160 
161 }
162 
163 #endif
boost::container::stable_vector< Supercell > & get_supercell_list()
Access entire supercell_list.
Definition: PrimClex.cc:299
void check_symmetry() override
Check symmetry.
Definition: ZrOProj.hh:48
void push_back(const T &toPush)
Definition: Array.hh:513
PrimClex * primclex
Definition: settings.cc:101
void check_composition() override
Check "casm composition".
Definition: ZrOProj.hh:79
Definition: Common.hh:7
void check_bset() override
Uses bspecs() and checks that 5 branches are generated, and that –orbits, –clusters, and –functions run without error.
Definition: ZrOProj.hh:90
jsonParser bspecs() const
Definition: ZrOProj.hh:52
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & log
Definition: settings.cc:105
Molecule make_atom(std::string atom_name, const Lattice &lat)
Return an atomic Molecule with specified name and Lattice.
Definition: Molecule.cc:279
config_iterator config_begin()
Configuration iterator: begin.
Definition: PrimClex.cc:371
config_iterator config_end()
Configuration iterator: end.
Definition: PrimClex.cc:379
fs::path proj_dir(fs::path init)
Create a new project directory, appending ".(#)" to ensure it is a new project.
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
std::string title
User-specified name of this Structure.
BasicStructure< Site > ZrO_prim()
Definition: ZrOProj.hh:13
Eigen::Matrix3d Matrix3d
void check_enum() override
Check "ccasm enum".
Definition: ZrOProj.hh:140
DirectoryStructure & dir
Definition: settings.cc:102
static jsonParser parse(const std::string &str)
Construct a jsonParser from a string containing JSON data.
Definition: jsonParser.hh:312
Molecule make_vacancy(const Lattice &lat)
Return an vacancy Molecule with specified Lattice.
Definition: Molecule.cc:287
Definition: Log.hh:9