CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Niggli_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
11 #include "ZrOProj.hh"
12 
13 namespace CASM {
14 
15  void confirm_lattice(const Lattice &known_niggli_form, const Eigen::Matrix3i &skewed_unimodular) {
16  assert(skewed_unimodular.determinant() == 1);
17  assert(is_niggli(known_niggli_form, CASM::TOL));
18 
19  Lattice non_niggli(known_niggli_form.lat_column_mat()*skewed_unimodular.cast<double>());
20 
21  BOOST_CHECK(!is_niggli(non_niggli, CASM::TOL));
22 
23  Lattice reniggli = niggli(non_niggli, CASM::TOL);
24 
25  BOOST_CHECK(known_niggli_form == reniggli);
26 
27  BOOST_CHECK(niggli(niggli(non_niggli, CASM::TOL), CASM::TOL) == niggli(non_niggli, CASM::TOL));
28 
29  //known_niggli_form.print(std::cout);
30  //reniggli.print(std::cout);
31  //std::cout<<spatial_unroll(known_niggli_form.lat_column_mat(), CASM::TOL)<<" vs "<<spatial_unroll(reniggli.lat_column_mat(), CASM::TOL)<<std::endl;
32 
33  return;
34  }
35 
36 
37  void confirm_fcc_lattice(const Eigen::Matrix3i &skewed_unimodular) {
38  BOOST_TEST_MESSAGE("Checking fcc lattice");
39  CASM::confirm_lattice(CASM::Lattice::fcc(), skewed_unimodular);
40  CASM::confirm_lattice(CASM::Lattice::fcc(), skewed_unimodular.transpose());
41  return;
42  }
43 
44  void confirm_bcc_lattice(const Eigen::Matrix3i &skewed_unimodular) {
45  BOOST_TEST_MESSAGE("Checking bcc lattice");
46  CASM::confirm_lattice(CASM::Lattice::bcc(), skewed_unimodular);
47  CASM::confirm_lattice(CASM::Lattice::bcc(), skewed_unimodular.transpose());
48  return;
49  }
50 
51  void confirm_hexagonal_lattice(const Eigen::Matrix3i &skewed_unimodular) {
52  BOOST_TEST_MESSAGE("Checking hexagonal lattice");
53  CASM::confirm_lattice(CASM::Lattice::hexagonal(), skewed_unimodular);
54  CASM::confirm_lattice(CASM::Lattice::hexagonal(), skewed_unimodular.transpose());
55  return;
56  }
57 
58  void confirm_cubic_lattice(const Eigen::Matrix3i &skewed_unimodular) {
59  BOOST_TEST_MESSAGE("Checking cubic lattice");
60  CASM::confirm_lattice(CASM::Lattice::cubic(), skewed_unimodular);
61  CASM::confirm_lattice(CASM::Lattice::cubic(), skewed_unimodular.transpose());
62  return;
63  }
64 
65  //Test for checking whether matrices are symmetric or persymmetric
67  Eigen::MatrixXd symmat(5, 5), persymmat(4, 4), nonsymmat;
68 
69  symmat << 1, 2, 3, 4, 5,
70  2, 6, 7, 8, 9,
71  3, 7, 10, 11, 12,
72  4, 8, 11, 13, 14,
73  5, 9, 12, 14, 15;
74 
75  BOOST_CHECK(is_symmetric(symmat));
76  BOOST_CHECK(!is_persymmetric(symmat));
77 
78  persymmat << 4, 3, 2, 1,
79  7, 6, 5, 2,
80  9, 8, 6, 3,
81  10, 9, 7, 4;
82 
83  BOOST_CHECK(!is_symmetric(persymmat));
84  BOOST_CHECK(is_persymmetric(persymmat));
85  }
86 
87  //See issue #153 on github: https://github.com/prisms-center/CASMcode-dev/issues/153
89  Lattice testlat = Lattice::fcc();
90  SymGroup pg;
91  testlat.generate_point_group(pg);
92 
93  std::string dirs = "a";
94  int minvol = 1;
95  int maxvol = 10;
96 
97  ScelEnumProps enum_props(minvol, maxvol + 1, dirs);
98  SupercellEnumerator<Lattice> latenumerator(testlat, pg, enum_props);
99  std::vector<Lattice> enumerated_lat(latenumerator.begin(), latenumerator.end());
100 
101 
102  int l = 1;
103  for(auto it = enumerated_lat.begin(); it != enumerated_lat.end(); ++it) {
104  Eigen::Matrix3i comp_transmat;
105  comp_transmat << (l), 0, 0,
106  0, 1, 0,
107  0, 0, 1;
108 
109  Lattice comparelat = make_supercell(testlat, comp_transmat);
110 
111  Lattice nigglicompare = canonical_equivalent_lattice(comparelat, pg, TOL);
112  Lattice nigglitest = canonical_equivalent_lattice(*it, pg, TOL);
113 
114  BOOST_CHECK(nigglicompare == nigglitest);
115  l++;
116  }
117  return;
118  }
119 
121 
122  BOOST_TEST_MESSAGE("Checking known ZrO lattices");
123 
124  // ZrO prim
125  Structure prim(test::ZrO_prim());
126  PrimClex primclex(prim, null_log());
127 
128  // enumerate size 5 supercells
129  // bool verbose = false;
130  ScelEnumProps enum_props(5, 6);
131  primclex.generate_supercells(enum_props);
132 
133  // there will be 7
134  int scel_list_size = 7;
135  BOOST_CHECK_EQUAL(primclex.get_supercell_list().size(), scel_list_size);
136 
137  // check if the canonical equivalent lattice of this volume 5 left handed
138  // lattice is among the enumerated lattices
139  Eigen::Matrix3d test_lat_mat;
140  test_lat_mat << 3.2339869, 0.0, -1.6169934,
141  0.0, 0.0, 14.003574,
142  0.0, 5.1686783, 0.0;
143  Lattice test_lat(test_lat_mat);
144 
145  // this should generate the canonical equivalent lattice and add it, but
146  // since we already enumerated supercells the supercell list size should
147  // not increase
148  primclex.add_supercell(test_lat);
149  BOOST_CHECK_EQUAL(primclex.get_supercell_list().size(), scel_list_size);
150  }
151 
153 
154  BOOST_TEST_MESSAGE("Checking niggli and canonical_equivalent_lattice");
155 
156  const Structure test_struc(test::ZrO_prim());
157  const Lattice test_lat = test_struc.lattice();
158  const SymGroup effective_pg = test_struc.factor_group();
159 
160  ScelEnumProps enum_props(1, 11);
161  SupercellEnumerator<Lattice> test_enumerator(test_lat, effective_pg, enum_props);
162 
163  // check that niggli cell and canonical lattice don't change when re-applied
164 
165  double tol = TOL;
166  for(auto it = test_enumerator.begin(); it != test_enumerator.end(); ++it) {
167 
168  // -- check niggli generation
169 
170  Lattice niggli1 = niggli(*it, tol);
171  Lattice niggli2 = niggli(niggli1, tol);
172  bool check_niggli = almost_equal(
173  niggli1.lat_column_mat(),
174  niggli2.lat_column_mat(),
175  tol);
176 
177  BOOST_CHECK_EQUAL(check_niggli, true);
178 
179  // -- check canonical generation
180 
181  Lattice canon = canonical_equivalent_lattice(*it, effective_pg, tol);
182  Lattice canon2 = canonical_equivalent_lattice(canon, effective_pg, tol);
183  bool check = almost_equal(
184  canon.lat_column_mat(),
185  canon2.lat_column_mat(),
186  tol);
187 
188  BOOST_CHECK_EQUAL(check, true);
189 
190  }
191  }
192 
194 
195  BOOST_TEST_MESSAGE("Checking standard_orientation_compare");
196 
197  double tol = TOL;
198 
199  //This is a known supercell of ZrO
200 
201  Eigen::Matrix3d lat_mat_A;
202  lat_mat_A << 3.233986860000, 0.000000000000, 0.000000000000,
203  0.000000000000, 0.000000000000, 5.601429540000,
204  0.000000000000, -5.168678340000, 0.000000000000;
205 
206  Lattice lat_A(lat_mat_A);
207 
208  Eigen::Matrix3d lat_mat_A2;
209  lat_mat_A2 << 3.233986860000, 0.000000000000, 0.000000000000,
210  2.22045e-16, 0.000000000000, 5.601429540000,
211  0.000000000000, -5.168678340000, 0.000000000000;
212 
213  Lattice lat_A2(lat_mat_A2);
214 
215  Eigen::Matrix3d lat_mat_B;
216  lat_mat_B << 3.233986860000, 0.000000000000, 0.000000000000,
217  0.000000000000, 0.000000000000, -5.601429540000,
218  0.000000000000, 5.168678340000, 0.000000000000;
219 
220  Lattice lat_B(lat_mat_B);
221 
222  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_A, lat_mat_B, tol), true);
223  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_B, lat_mat_A, tol), false);
224 
225  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_A2, lat_mat_B, tol), true);
226  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_B, lat_mat_A2, tol), false);
227 
228  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_A, lat_mat_A2, tol), false);
229  BOOST_CHECK_EQUAL(standard_orientation_compare(lat_mat_A2, lat_mat_A, tol), false);
230 
231  Structure prim(test::ZrO_prim());
232  Lattice canon_A = canonical_equivalent_lattice(lat_A, prim.point_group(), tol);
233  Lattice canon_A2 = canonical_equivalent_lattice(lat_A2, prim.point_group(), tol);
234  Lattice canon_B = canonical_equivalent_lattice(lat_B, prim.point_group(), tol);
235 
236  BOOST_CHECK_EQUAL(canon_A == canon_A2, true);
237  BOOST_CHECK_EQUAL(canon_A2 == canon_B, true);
238  BOOST_CHECK_EQUAL(canon_A == canon_B, true);
239 
240  };
241 }
242 
243 BOOST_AUTO_TEST_SUITE(NiggliTest)
244 
245 BOOST_AUTO_TEST_CASE(SymmetricTest) {
247 }
248 
249 BOOST_AUTO_TEST_CASE(EeasyTests) {
250  Eigen::Matrix3i skewed_unimodular;
251  skewed_unimodular << 1, 2, 3,
252  0, 1, 4,
253  0, 0, 1;
254 
255  CASM::confirm_fcc_lattice(skewed_unimodular);
256  CASM::confirm_bcc_lattice(skewed_unimodular);
257  CASM::confirm_cubic_lattice(skewed_unimodular);
258  CASM::confirm_hexagonal_lattice(skewed_unimodular);
259 }
260 
261 BOOST_AUTO_TEST_CASE(EvilNiggliTest) {
263 }
264 
265 BOOST_AUTO_TEST_CASE(ZrOScelEnumTest) {
269 }
270 
271 
272 BOOST_AUTO_TEST_SUITE_END()
Eigen::MatrixXd MatrixXd
boost::container::stable_vector< Supercell > & get_supercell_list()
Access entire supercell_list.
Definition: PrimClex.cc:299
void confirm_lattice(const Lattice &known_niggli_form, const Eigen::Matrix3i &skewed_unimodular)
Definition: Niggli_test.cpp:15
void standard_orientation_compare_test()
void generate_point_group(SymGroup &point_group, double pg_tol=TOL) const
Populate.
Definition: Lattice.cc:304
const SymGroup & point_group() const
Definition: Structure.cc:101
static Lattice hexagonal()
Construct cubic primitive cell of unit volume.
Definition: Lattice.cc:75
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
void confirm_hexagonal_lattice(const Eigen::Matrix3i &skewed_unimodular)
Definition: Niggli_test.cpp:51
const_iterator end() const
A const iterator to the past-the-last volume.
bool standard_orientation_compare(const Eigen::Matrix3d &low_score_lat_mat, const Eigen::Matrix3d &high_score_lat_mat, double compare_tol)
Determine whether high_score has a more standard format than low_score.
Definition: Niggli.cc:391
Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat)
Returns a super Lattice.
Definition: Lattice.hh:377
A fake container of supercell matrices.
Definition: Enumerator.hh:407
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & null_log()
Definition: Log.hh:211
static Lattice bcc()
Construct BCC primitive cell of unit volume.
Definition: Lattice.cc:57
const double TOL
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:104
void generate_supercells(const ScelEnumProps &enum_props)
Use the given CSPECS.
Definition: PrimClex.cc:492
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
double tol
const_iterator begin() const
A const iterator to the beginning volume, specify here how the iterator should jump through the enume...
static Lattice cubic()
Construct simple cubic primitive cell of unit volume.
Definition: Lattice.cc:69
void symmetric_testing()
Definition: Niggli_test.cpp:66
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
bool is_niggli(const Eigen::Matrix3d &test_lat_mat, double compare_tol)
Check whether the given lattice (represented as a matrix) is in niggli TYPE ?? reduced form (does not...
Definition: Niggli.cc:218
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
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
bool is_persymmetric(const Eigen::MatrixBase< Derived > &test_mat, double test_tol=CASM::TOL)
Definition: CASM_math.hh:517
void single_dimension_test()
Definition: Niggli_test.cpp:88
BasicStructure< Site > ZrO_prim()
Definition: ZrOProj.hh:13
void ZrO_supercell_enum_test()
Index add_supercell(const Lattice &superlat)
Definition: PrimClex.cc:550
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.
bool is_symmetric(const Eigen::MatrixBase< Derived > &test_mat, double test_tol=CASM::TOL)
Definition: CASM_math.hh:504
Eigen::Matrix3d Matrix3d
BOOST_AUTO_TEST_CASE(SymmetricTest)
void ZrO_supercell_enum_test2()
void confirm_bcc_lattice(const Eigen::Matrix3i &skewed_unimodular)
Definition: Niggli_test.cpp:44
void confirm_cubic_lattice(const Eigen::Matrix3i &skewed_unimodular)
Definition: Niggli_test.cpp:58
Lattice niggli(const Lattice &in_lat, double compare_tol, bool keep_handedness=false)
Convert the given lattice into it's niggli reduced form, with the most standard orientation possilbe...
Definition: Niggli.cc:240
void confirm_fcc_lattice(const Eigen::Matrix3i &skewed_unimodular)
Definition: Niggli_test.cpp:37
static Lattice fcc()
Construct FCC primitive cell of unit volume.
Definition: Lattice.cc:45
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)