1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 #include<boost/filesystem.hpp>
13 #include "casm/external/Eigen/Dense"
20 BOOST_CHECK_EQUAL(1, 0);
30 Eigen::VectorXi init_diagonal(Eigen::VectorXi::Ones(dims));
31 init_diagonal(0) = det;
33 BOOST_CHECK_EQUAL(init_diagonal, hermit_test.
diagonal());
34 BOOST_CHECK_EQUAL(0, hermit_test.
position());
38 BOOST_CHECK_EQUAL(tricounter.current(), startcount);
42 endcount(0) = (det - 1);
43 endcount(1) = (det - 1);
44 endcount(2) = (det - 1);
45 endcount(3) = (det - 1);
47 auto finalcounterstate = tricounter;
49 for(; tricounter.valid(); ++tricounter) {
50 finalcounterstate = tricounter;
53 BOOST_CHECK_EQUAL(finalcounterstate.current(), endcount);
60 Eigen::VectorXi diagonal0(Eigen::VectorXi::Ones(5));
61 Eigen::VectorXi diagonal1(Eigen::VectorXi::Ones(5));
62 Eigen::VectorXi diagonal2(Eigen::VectorXi::Ones(5));
63 Eigen::VectorXi diagonal3(Eigen::VectorXi::Ones(5));
69 BOOST_CHECK_EQUAL(p0, p + 1);
70 BOOST_CHECK_EQUAL(diagonal0(p), 1);
71 BOOST_CHECK_EQUAL(diagonal0(p + 1), 2);
76 BOOST_CHECK_EQUAL(p1, p + 1);
77 BOOST_CHECK_EQUAL(diagonal1(p), 3);
78 BOOST_CHECK_EQUAL(diagonal1(p + 1), 2);
83 BOOST_CHECK_EQUAL(p2, p + 1);
84 BOOST_CHECK_EQUAL(diagonal2(p), 1);
85 BOOST_CHECK_EQUAL(diagonal2(p + 1), 6);
90 BOOST_CHECK_EQUAL(p3, p + 1);
91 BOOST_CHECK_EQUAL(diagonal3(p), 2);
92 BOOST_CHECK_EQUAL(diagonal3(p + 1), 4);
99 Eigen::VectorXi diagonal(Eigen::VectorXi::Ones(5));
100 Eigen::VectorXi next_diagonal(Eigen::VectorXi::Ones(5));
102 next_diagonal(0) = 3;
103 next_diagonal(1) = 2;
108 BOOST_CHECK_EQUAL(diagonal, next_diagonal);
109 BOOST_CHECK_EQUAL(p, 1);
112 diagonal = Eigen::VectorXi::Ones(5);
113 next_diagonal = Eigen::VectorXi::Ones(5);
118 next_diagonal(2) = 6;
123 BOOST_CHECK_EQUAL(diagonal, next_diagonal);
124 BOOST_CHECK_EQUAL(p, 2);
129 int det = 2 * 3 * 5 * 7;
132 Eigen::VectorXi diag = Eigen::VectorXi::Ones(dims);
136 while(p != diag.size()) {
138 for(
int i = 0; i < diag.size(); i++) {
139 testdet = testdet * diag(i);
141 BOOST_CHECK_EQUAL(det, testdet);
150 BOOST_CHECK_EQUAL(totals, -7 + 7 + 6 + 5 + 4 + 3 + 2 + 1);
155 Eigen::VectorXi mid_diagonal(Eigen::VectorXi::Ones(dims));
161 auto finalcount = countertest;
163 for(; countertest.valid(); countertest++) {
164 finalcount = countertest;
177 end_count_value(0) = 4;
178 end_count_value(1) = 4;
179 end_count_value(2) = 4;
180 end_count_value(3) = 4;
181 end_count_value(4) = 2;
182 end_count_value(5) = 2;
183 end_count_value(6) = 2;
186 BOOST_CHECK_EQUAL(finalcount.current(), end_count_value);
192 Eigen::VectorXi diag;
195 Eigen::VectorXi upper;
196 upper.resize(3 + 2 + 1);
201 Eigen::MatrixXi diagmat;
202 diagmat.resize(4, 4);
203 diagmat << 2, 11, 12, 13,
216 Eigen::MatrixXi hermmat;
217 hermmat.resize(4, 4);
220 hermmat << 6, 0, 0, 0,
225 BOOST_CHECK_EQUAL(hermmat, hermit_test());
229 hermmat << 6, 1, 0, 0,
234 BOOST_CHECK_EQUAL(hermmat, hermit_test());
237 hermmat << 6, 5, 5, 5,
242 while(hermit_test() != hermmat) {
248 hermmat << 3, 0, 0, 0,
253 BOOST_CHECK_EQUAL(hermmat, hermit_test());
256 auto lastherm = hermmat;
258 lastherm = hermit_test();
262 hermmat << 1, 0, 0, 0,
267 BOOST_CHECK_EQUAL(hermmat, lastherm);
274 hermmat << 1, 0, 0, 0,
279 while(hermit_test() != hermmat) {
286 hermmat << 4, 0, 0, 0,
291 BOOST_CHECK_EQUAL(hermmat, hermit_test());
298 Eigen::MatrixXi hermmat;
299 hermmat.resize(3, 3);
302 Eigen::MatrixXi startmat = hermit_test();
309 while(hermit_test() != hermmat) {
319 BOOST_CHECK_EQUAL(hermmat, hermit_test());
323 BOOST_CHECK_EQUAL(startmat, hermit_test());
329 Eigen::MatrixXi expandmat(Eigen::MatrixXi::Ones(5, 5));
330 expandmat = expandmat * 3;
332 Eigen::VectorXi expanddims(8);
333 expanddims << 1, 1, 1, 0, 1, 0, 0, 1;
335 Eigen::MatrixXi expandedmat(8, 8);
336 expandmat << 3, 3, 3, 0, 3, 0, 0, 3,
337 3, 3, 3, 0, 3, 0, 0, 3,
338 3, 3, 3, 0, 3, 0, 0, 3,
339 0, 0, 0, 1, 0, 0, 0, 0,
340 3, 3, 3, 0, 3, 0, 0, 3,
341 0, 0, 0, 0, 0, 1, 0, 0,
342 0, 0, 0, 0, 0, 0, 1, 0,
343 3, 3, 3, 0, 3, 0, 0, 1;
348 for(
int i = 0; i < 12; i++) {
352 Eigen::MatrixXi endcount(4, 4);
353 endcount << 1, 0, 0, 0,
358 BOOST_CHECK_EQUAL(endcount, minicount());
360 Eigen::MatrixXi transmat(Eigen::MatrixXi::Identity(6, 6));
363 Eigen::MatrixXi blockmat(6, 6);
364 blockmat << 1, 0, 0, 0, 0, 0,
371 BOOST_CHECK_EQUAL(blockmat, expanded);
373 Eigen::Matrix2Xi miniherm;
377 Eigen::Matrix3i minitrans;
378 minitrans << 1, 0, 0,
382 Eigen::Matrix3i miniexpand;
383 miniexpand << 2, 1, 0,
405 for(
auto it = test_enumerator.
begin(); it != test_enumerator.
end(); ++it) {
417 BOOST_CHECK_EQUAL(check_niggli,
true);
428 BOOST_CHECK_EQUAL(check,
true);
433 mat_dump[
"input"][
"min_vol"] = minvol;
434 mat_dump[
"input"][
"max_vol"] = maxvol;
435 mat_dump[
"input"][
"source"] = pos_filename;
436 mat_dump[
"output"][
"mats"] = enumerated_mats;
451 lat_dump[
"input"][
"min_vol"] = minvol;
452 lat_dump[
"input"][
"max_vol"] = maxvol;
453 lat_dump[
"input"][
"source"] = pos_filename;
454 lat_dump[
"output"][
"lats"] = enumerated_lats;
464 std::vector<jsonParser> all_mat_tests;
470 all_test_cases[
"mat_test_cases"] = all_mat_tests;
474 std::vector<jsonParser> all_lat_tests;
481 all_test_cases[
"lat_test_cases"] = all_lat_tests;
488 return all_test_cases;
492 Eigen::MatrixXi mat5(5, 5);
493 mat5 << 1, 12, 11, 10, 9,
499 Eigen::VectorXi vec5(5 + 4 + 3 + 2 + 1);
500 vec5 << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15;
506 Eigen::Matrix3i mat3;
511 Eigen::Vector3i vec3(3 + 2 + 1);
512 vec3 << 1, 2, 3, 4, 5, 6;
520 Eigen::Matrix3i low, high;
550 Eigen::Matrix3i transmat;
552 transmat << -1, 1, 1,
561 std::vector<Lattice> enumerated_lat(enumerator.
begin(), enumerator.
end());
563 for(
Index i = 0; i > enumerated_lat.size(); i++) {
564 BOOST_CHECK(enumerated_lat[i].is_supercell_of(bigunit));
571 std::vector<Lattice> all_test_lats;
577 for(
Index t = 0; t < all_test_lats.size(); t++) {
578 Lattice testlat = all_test_lats[t];
587 for(
auto it = enumerator.
begin(); it != enumerator.
end(); ++it) {
588 Eigen::Matrix3i comp_transmat;
589 comp_transmat << (l), 0, 0,
593 BOOST_CHECK(it.matrix() ==
canonical_hnf(comp_transmat, pg, testlat));
602 BOOST_AUTO_TEST_SUITE(SupercellEnumeratorTest)
636 current_test_results.
write(current_test_path);
645 if(!failure_point.empty()) {
646 std::cout <<
"Difference at: " << failure_point <<
"\n" << std::endl;
648 auto &_existing = existing.
at(failure_point);
649 auto &_curr = curr.
at(failure_point);
650 if(_existing.type() != _curr.type()) {
651 std::cout <<
"Different types\n" << std::endl;
653 else if(_existing.is_array() && (_existing.size() != _curr.type())) {
654 std::cout <<
"Different array sizes" << std::endl;
655 std::cout <<
" Expected: " << _existing.
size() << std::endl;
656 std::cout <<
" Found: " << _curr.size() << std::endl;
659 else if(_existing.is_obj() && (_existing.size() != _curr.type())) {
660 std::cout <<
"Different object sizes\n" << std::endl;
661 std::cout <<
" Expected: " << _existing.size() << std::endl;
662 std::cout <<
" Found: " << _curr.size() << std::endl;
666 std::cout <<
"Different values\n" << std::endl;
669 std::cout <<
"Expected: \n" << existing.
at(failure_point) <<
"\n"
670 <<
"Found: \n" << curr.
at(failure_point) << std::endl;
674 BOOST_CHECK(failure_point.empty());
676 current_test_results[
"WARNING"] =
"This has been added as an inconvenience to anyone who is thinking of replacing the \
677 current test_results.json file. Do not replace anything unless you're certain the old \
678 results were incorrect, and these are an improvement. If you are sure you want to proceed, eliminate this key.";
680 current_test_results.
write(current_test_path);
689 BOOST_AUTO_TEST_SUITE_END()
HermiteCounter::Index _spill_factor(Eigen::VectorXi &diag, HermiteCounter::Index position, HermiteCounter::value_type attempt)
Find the next factor of the specified position and share with next element. Use attempt as starting p...
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
value_type determinant() const
Get the current determinant.
Eigen::MatrixXi _expand_dims(const Eigen::MatrixXi &H, const Eigen::MatrixXi &G)
Expand a n x n Hermite normal matrix (H) into a m x m one through a m x m generating matrix (G) (e...
void matrix_construction_test()
boost::filesystem::path find_diff(const jsonParser &A, const jsonParser &B, boost::filesystem::path diff=boost::filesystem::path())
Return the location at which jsonParser 'A' != 'B' as a boost::filesystem::path.
Eigen::VectorXi diagonal() const
void generate_point_group(SymGroup &point_group, double pg_tol=TOL) const
Populate.
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
void push_back(const T &toPush)
static Lattice hexagonal()
Construct cubic primitive cell of unit volume.
Structure specifies the lattice and atomic basis of a crystal.
Data structure for holding supercell enumeration properties.
Eigen::Matrix3i canonical_hnf(const Eigen::Matrix3i &T, const SymGroup &effective_pg, const Lattice &ref_lattice)
Return canonical hermite normal form of the supercell matrix, and op used to find it...
bool _canonical_compare(const Eigen::MatrixXi &H0, const Eigen::MatrixXi &H1)
Compare two integer matrices and see which one is lexicographically greatest. Returns true if H0
boost::filesystem::path testdir("tests/unit/crystallography")
Eigen::MatrixXi _zip_matrix(const Eigen::VectorXi ¤t_diag, const Eigen::VectorXi ¤t_upper_tri)
Assemble a matrix diagonal and unrolled upper triangle values into a matrix.
const_iterator end() const
A const iterator to the past-the-last volume.
Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat)
Returns a super Lattice.
jsonParser & at(const fs::path &path)
jsonParser generate_all_test_cases()
Eigen::MatrixXi _expand_dims_old(const Eigen::MatrixXi &hermit_mat, const Eigen::VectorXi &active_dims)
Expand a n x n Hermite normal matrix into a m x m one (e.g. for 2D supercells)
A fake container of supercell matrices.
void jump_to_determinant(value_type new_det)
Reset the diagonal to the specified determinant and set the other elements to zero.
void next_position_test()
const Lattice & lattice() const
static Lattice bcc()
Construct BCC primitive cell of unit volume.
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
BOOST_AUTO_TEST_CASE(HermiteConstruction)
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.
const MasterSymGroup & factor_group() const
Eigen::VectorXi _canonical_unroll(const Eigen::MatrixXi &hermit_mat)
Unroll a Hermit normal form square matrix into a vector such that it's canonical form is easy to comp...
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...
jsonParser lat_test_case(const std::string &pos_filename, int minvol, int maxvol)
void reset_current()
reset the counter to the first iteration of the current determinant
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...
jsonParser mat_test_case(const std::string &pos_filename, int minvol, int maxvol)
HermiteCounter::Index upper_size(HermiteCounter::Index init_dim)
Determine the number of elements in the upper triangular matrix (excluding diagonal) ...
void triangle_count_test()
HermiteCounter::Index next_spill_position(Eigen::VectorXi &diag, HermiteCounter::Index position)
Spill the next factor of the specified element with its neighbor, and return new position.
EigenVectorXiCounter _upper_tri_counter(const Eigen::VectorXi ¤t_diag)
Create a counter for the elements above the diagonal based on the current diagonal value...
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...
Basic std::vector like container (deprecated)
static Lattice fcc()
Construct FCC primitive cell of unit volume.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
void generate_supercells(Array< Lattice > &supercell, const SymGroup &effective_pg, const ScelEnumProps &enum_props) const
Populate.