CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
BasicStructure_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 #include "ZrOProj.hh"
10 #include "casm/app/AppIO.hh"
11 #include "casm/casm_io/VaspIO.hh"
13 
14 using namespace CASM;
15 
28 
29  double tol = 1e-5;
30 
31  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(0.0, 2.0, 2.0), tol), true);
32  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(2.0, 0.0, 2.0), tol), true);
33  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(2.0, 2.0, 0.0), tol), true);
34  BOOST_CHECK_EQUAL(struc.basis.size(), 1);
35 
36  // basis site 0 has three possible occupants
37  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant().size(), 3);
38 
39  std::string check_name[3] = {"A", "B", "C"};
40 
41  for(int i = 0; i < 3; i++) {
42  // occupants are Molecule with name "A", etc.
43  // Molecule are composed of AtomPosition
44  // An AtomPosition 'is' a Coordinate with a Specie
45  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant()[i].name, check_name[i]);
46  BOOST_CHECK_EQUAL(almost_equal(struc.basis[0].site_occupant()[i][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
47  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant()[i][0].specie.name, check_name[i]);
48  }
49 
50  // FCC motif
51  MasterSymGroup factor_grp;
52  struc.generate_factor_group(factor_grp, tol);
53  BOOST_CHECK_EQUAL(48, factor_grp.size());
54 }
55 
71 
72  double tol = 1e-5;
73 
74  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(4.0, 0.0, 0.0), tol), true);
75  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(0.0, 4.0, 0.0), tol), true);
76  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(0.0, 0.0, 4.0), tol), true);
77  BOOST_CHECK_EQUAL(struc.basis.size(), 4);
78 
79  // basis site 0 has three possible occupants
80  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant().size(), 3);
81 
82  std::string check_name[3] = {"A", "B", "C"};
83  int check_value[4] = {0, 0, 1, 2};
84 
85  for(int i = 0; i < 4; i++) {
86  for(int j = 0; j < 3; j++) {
87  // occupants are Molecule with name "A", etc.
88  // Molecule are composed of AtomPosition
89  // An AtomPosition 'is' a Coordinate with a Specie
90  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[j].name, check_name[j]);
91  BOOST_CHECK_EQUAL(almost_equal(struc.basis[i].site_occupant()[j][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
92  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[j][0].specie.name, check_name[j]);
93 
94  }
95  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant().value(), check_value[i]);
96  }
97 
98  // ordering on FCC motif
99  MasterSymGroup factor_grp;
100  struc.generate_factor_group(factor_grp, tol);
101  BOOST_CHECK_EQUAL(16, factor_grp.size());
102 }
103 
104 
138 
139  double tol = 1e-5;
140 
141  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(4.0, 0.0, 0.0), tol), true);
142  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(0.0, 4.0, 0.0), tol), true);
143  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(0.0, 0.0, 4.0), tol), true);
144  BOOST_CHECK_EQUAL(struc.basis.size(), 4);
145 
146  std::string check_name[4] = {"A", "A", "B", "C"};
147 
148  for(int i = 0; i < 4; i++) {
149  // basis site 0 and 1 have one possible occupant
150  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant().size(), 1);
151 
152  // occupants are Molecule with name "A", etc.
153  // Molecule are composed of AtomPosition
154  // An AtomPosition 'is' a Coordinate with a Specie
155  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[0].name, check_name[i]);
156  BOOST_CHECK_EQUAL(almost_equal(struc.basis[i].site_occupant()[0][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
157  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[0][0].specie.name, check_name[i]);
158  }
159 
160  // FCC structure
161  MasterSymGroup factor_grp;
162  struc.generate_factor_group(factor_grp, tol);
163  BOOST_CHECK_EQUAL(16, factor_grp.size());
164 }
165 
166 BOOST_AUTO_TEST_SUITE(BasicStructureSiteTest)
167 
169 
170  fs::path testdir = "tests/unit/crystallography";
171 
172  // Read in test PRIM and run tests
173  BasicStructure<Site> struc(fs::path(testdir / "PRIM1"));
174  prim1_read_test(struc);
175 
176  // Write test PRIM back out
177  fs::path tmp_file = testdir / "PRIM1_out";
178  write_prim(struc, tmp_file, FRAC);
179 
180  // Read new file and run tests again
181  BasicStructure<Site> struc2(read_prim(tmp_file));
182  prim1_read_test(struc2);
183 
184 }
185 
187 
188  fs::path testdir = "tests/unit/crystallography";
189 
190  // Read in test PRIM and run tests
191  BasicStructure<Site> struc(fs::path(testdir / "PRIM2"));
192  prim2_read_test(struc);
193 }
194 
196 
197  fs::path testdir = "tests/unit/crystallography";
198 
199  // Read in an incorrectly formatted PRIM and check that an exception is thrown
200  BOOST_CHECK_THROW(BasicStructure<Site>(fs::path(testdir / "PRIM3")), std::runtime_error);
201 
202 }
203 
205 
206  fs::path testdir = "tests/unit/crystallography";
207 
208  // Read in test PRIM and run tests
209  BasicStructure<Site> struc(fs::path(testdir / "POS1"));
210  pos1_read_test(struc);
211 
212  // Write test PRIM back out
213  fs::path tmp_file = testdir / "POS1_out";
214  fs::ofstream sout(tmp_file);
215  VaspIO::PrintPOSCAR printer(struc);
216  printer.set_append_atom_names_off();
217  printer.print(sout);
218  sout.close();
219 
220  // Read new file and run tests again
221  BasicStructure<Site> struc2(fs::path(testdir / "POS1_out"));
222  pos1_read_test(struc2);
223 
224 }
225 
226 BOOST_AUTO_TEST_CASE(POS1Vasp5Test) {
227 
228  fs::path testdir = "tests/unit/crystallography";
229 
230  // Read in test PRIM and run tests
231  BasicStructure<Site> struc(fs::path(testdir / "POS1"));
232  pos1_read_test(struc);
233 
234  // Write test PRIM back out
235  fs::path tmp_file = testdir / "POS1_vasp5_out";
236  fs::ofstream sout(tmp_file);
237  VaspIO::PrintPOSCAR(struc).print(sout);
238  sout.close();
239 
240  // Read new file and run tests again
241  BasicStructure<Site> struc2(fs::path(testdir / "POS1_vasp5_out"));
242  pos1_read_test(struc2);
243 
244 }
245 
246 BOOST_AUTO_TEST_CASE(IsPrimitiveTest) {
247 
248  Structure prim(test::ZrO_prim());
249 
250  const SymGroup effective_pg = prim.factor_group();
251 
252  ScelEnumProps enum_props(1, 6);
253  SupercellEnumerator<Lattice> scel_enum(prim.lattice(), effective_pg, enum_props);
254 
255  for(auto it = scel_enum.begin(); it != scel_enum.end(); ++it) {
256 
257  Structure super = prim.create_superstruc(*it);
258  BOOST_CHECK_EQUAL(super.lattice().is_right_handed(), true);
259 
260  Structure new_prim;
261  super.is_primitive(new_prim);
262  BOOST_CHECK_EQUAL(new_prim.lattice().is_right_handed(), true);
263  BOOST_CHECK_EQUAL(new_prim.lattice().is_right_handed(), super.lattice().is_right_handed());
264  }
265 
266 }
267 
268 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PRIM1Test)
Index size() const
Definition: Array.hh:145
void prim2_read_test(BasicStructure< Site > &struc)
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
Data structure for holding supercell enumeration properties.
bool is_primitive(double prim_tol=TOL) const
void prim1_read_test(BasicStructure< Site > &struc)
boost::filesystem::path testdir("tests/unit/crystallography")
void write_prim(const BasicStructure< Site > &prim, fs::path filename, COORD_TYPE mode)
Write prim.json to file.
Definition: AppIO.cc:107
A fake container of supercell matrices.
Definition: Enumerator.hh:407
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
void generate_factor_group(SymGroup &factor_group, double map_tol) const
apply a symmetry operation to the current structure (may change lattice vectors and order of basis at...
BasicStructure< Site > read_prim(fs::path filename)
Definition: AppIO.cc:11
void print(std::ostream &sout)
Print POSCAR to stream.
Definition: VaspIO.hh:509
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
double tol
void pos1_read_test(BasicStructure< Site > &struc)
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
Structure create_superstruc(const Lattice &scel_lat, double map_tol=TOL) const
Shortcut routine to create a supercell structure and fill it with sites.
Definition: Structure.cc:335
BasicStructure< Site > ZrO_prim()
Definition: ZrOProj.hh:13
Print POSCAR with formating options.
Definition: VaspIO.hh:232
bool is_right_handed() const
Check if the lattice is right handed.
Definition: Lattice.cc:1096
void set_append_atom_names_off()
Do not append atom name to end of each coordinate line.
Definition: VaspIO.hh:173
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)