CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
NeighborList_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
8 
9 #include "Common.hh"
10 
11 using namespace CASM;
12 
13 BOOST_AUTO_TEST_SUITE(NeighborListTest)
14 
15 BOOST_AUTO_TEST_CASE(PrimNeighborListBasics) {
17  std::set<int> sublat_indices;
18  for(int i = 0; i < prim.basis.size(); i++) {
19  sublat_indices.insert(i);
20  }
21 
22  // construct
23  PrimNeighborList nlist(
25  sublat_indices.begin(),
26  sublat_indices.end()
27  );
28 
29  // weight matrix
31  W << 2, 1, 1,
32  1, 2, 1,
33  1, 1, 2;
34  BOOST_CHECK_EQUAL(nlist.weight_matrix() == W, true);
35 
36  // expand
37  std::set<UnitCellCoord> nbors;
38  nbors.insert(UnitCellCoord(0, UnitCell(3, 0, 0)));
39  nlist.expand(nbors.begin(), nbors.end());
40 
41  // size
42  BOOST_CHECK_EQUAL(nlist.size(), 177);
43 
44  // copy
45  PrimNeighborList nlist2 = nlist;
46  BOOST_CHECK_EQUAL(nlist2.size(), 177);
47 
48  // clone
50  BOOST_CHECK_EQUAL(ptr1->size(), 177);
51  std::unique_ptr<PrimNeighborList> ptr2 = nlist.clone();
52  BOOST_CHECK_EQUAL(ptr2->size(), 177);
53 
54 }
55 
56 BOOST_AUTO_TEST_CASE(SuperNeighborListBasics) {
58  std::set<int> sublat_indices;
59  for(int i = 0; i < prim.basis.size(); i++) {
60  sublat_indices.insert(i);
61  }
62 
63  // construct
64  PrimNeighborList nlist(
66  sublat_indices.begin(),
67  sublat_indices.end()
68  );
69 
70  // expand
71  std::set<UnitCellCoord> nbors;
72  nbors.insert(UnitCellCoord(0, UnitCell(3, 0, 0)));
73  nlist.expand(nbors.begin(), nbors.end());
74 
75  // size
76  BOOST_CHECK_EQUAL(nlist.size(), 177);
77 
78  // construct SuperNeighborList
79  Eigen::Matrix3i T;
80  T << 2, 0, 0,
81  0, 2, 0,
82  0, 0, 2;
83  Lattice super_lat = make_supercell(prim.lattice(), T);
84  PrimGrid grid(prim.lattice(), super_lat);
85  SuperNeighborList super_nlist(grid, nlist);
86 
87  // size
88  for(int i = 0; i < grid.size(); ++i) {
89  BOOST_CHECK_EQUAL(super_nlist.sites(i).size(), 177);
90  }
91 
92  for(int i = 0; i < grid.size(); ++i) {
93  BOOST_CHECK_EQUAL(super_nlist.unitcells(i).size(), 177);
94  }
95 
96  // overlaps
97  BOOST_CHECK_EQUAL(super_nlist.overlaps(), true);
98 
99  // copy
100  SuperNeighborList super_nlist2 = super_nlist;
101 
102  // clone
104  std::unique_ptr<SuperNeighborList> ptr2 = super_nlist.clone();
106 
107 }
108 
109 BOOST_AUTO_TEST_CASE(NeighborListTestLatticeTests) {
110 
111  Eigen::Matrix3d latvec;
112  latvec.col(0) << 2.955270000000, 0.000000000000, 0.000000000000;
113  latvec.col(1) << 1.477635000000, 2.559338895042, 0.000000000000;
114  latvec.col(2) << 1.477635000000, 0.853112965014, 11.758280000000;
115 
117 
119  W_check.row(0) << 2, 1, 1;
120  W_check.row(1) << 1, 2, 1;
121  W_check.row(2) << 1, 1, 32;
122 
123  BOOST_CHECK_EQUAL(W == W_check, true);
124 }
125 
127 
129  proj.check_init();
130 
131  PrimClex primclex(proj.dir, null_log());
133  double tol = primclex.crystallography_tol();
134  Structure prim = primclex.get_prim();
135 
136  const ProjectSettings &set = primclex.settings();
137 
138  // initialize nlist
139  PrimNeighborList nlist(
140  set.nlist_weight_matrix(),
141  set.nlist_sublat_indices().begin(),
142  set.nlist_sublat_indices().end()
143  );
144 
145  // generate orbitree
146  SiteOrbitree tree(prim.lattice(), tol);
147  jsonParser bspecs_json(proj.bspecs());
148  tree = make_orbitree(prim, bspecs_json, tol);
149 
150  // expand the nlist to contain 'tree'
151  std::set<UnitCellCoord> nbors;
152  neighborhood(std::inserter(nbors, nbors.begin()), tree, prim, TOL);
153 
154  //std::cout << "expand nlist" << std::endl;
155  nlist.expand(nbors.begin(), nbors.end());
156  BOOST_CHECK_EQUAL(nlist.size(), 177);
157 
158  //std::cout << "expand nlist again" << std::endl;
159  nbors.clear();
160  nbors.insert(UnitCellCoord(0, UnitCell(4, 0, 0)));
161  nlist.expand(nbors.begin(), nbors.end());
162  BOOST_CHECK_EQUAL(nlist.size(), 381);
163 
164 }
165 
166 BOOST_AUTO_TEST_SUITE_END()
fs::path dir
Definition: Proj.hh:34
Eigen::Matrix3l nlist_weight_matrix() const
Get neighbor list weight matrix.
Index size() const
Definition: Array.hh:145
BOOST_AUTO_TEST_CASE(PrimNeighborListBasics)
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
PrimClex * primclex
Definition: settings.cc:101
Unit Cell Coordinates.
Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat)
Returns a super Lattice.
Definition: Lattice.hh:377
const std::set< int > & nlist_sublat_indices() const
Get set of sublattice indices to include in neighbor lists.
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & null_log()
Definition: Log.hh:211
const double TOL
void expand(UnitCellCoord uccoord)
Expand the neighbor list to include the given UnitCellCoord.
Definition: NeighborList.cc:14
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:104
Unit Cell Indices.
ProjectSettings & set
Definition: settings.cc:103
The SuperNeighborList gives the linear indices of neighboring sites and unitcells in a particular Sup...
double tol
bool set_crystallography_tol(double _tol)
Set crystallography tolerance.
double crystallography_tol() const
Definition: PrimClex.hh:124
Read/modify settings of an already existing CASM project.
OutputIterator neighborhood(OutputIterator result, const TreeType &tree, const StrucType &struc, double tol)
Iterate over all sites in an orbitree and insert a UnitCellCoord.
Definition: Orbitree.hh:314
BasicStructure< Site > FCC_ternary_prim()
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
ProjectSettings & settings()
Definition: PrimClex.hh:116
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
static Matrix3Type make_weight_matrix(const Eigen::Matrix3d lat_column_mat, Index max_element_value, double tol)
Returns a NeighborList weighting matrix appropriate for a particular lattice.
Eigen::Matrix3d Matrix3d
The PrimNeighborList gives the coordinates of UnitCell that are neighbors of the origin UnitCell...
Definition: NeighborList.hh:24
static jsonParser bspecs()
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
Matrix< long int, 3, 3 > Matrix3l
Eigen::Matrix3l Matrix3Type
Definition: NeighborList.hh:31
SiteOrbitree make_orbitree(Structure &prim, const jsonParser &json, double _tol)
Make orbitree. For now specifically global.
Definition: PrimClex.cc:1097
virtual void check_init()
Check project initialization.
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260