CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Structure_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 "casm/clex/PrimClex.hh"
9 #include "casm/app/AppIO.hh"
10 #include "casm/casm_io/VaspIO.hh"
11 
12 using namespace CASM;
13 
25 void prim1_read_test(Structure &struc) {
26 
27  double tol = 1e-5;
28 
29  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(0.0, 2.0, 2.0), tol), true);
30  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(2.0, 0.0, 2.0), tol), true);
31  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(2.0, 2.0, 0.0), tol), true);
32  BOOST_CHECK_EQUAL(struc.basis.size(), 1);
33 
34  // basis site 0 has three possible occupants
35  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant().size(), 3);
36 
37  std::string check_name[3] = {"A", "B", "C"};
38 
39  for(int i = 0; i < 3; i++) {
40  // occupants are Molecule with name "A", etc.
41  // Molecule are composed of AtomPosition
42  // An AtomPosition 'is' a Coordinate with a Specie
43  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant()[i].name, check_name[i]);
44  BOOST_CHECK_EQUAL(almost_equal(struc.basis[0].site_occupant()[i][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
45  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant()[i][0].specie.name, check_name[i]);
46  }
47 
48  // FCC motif
49  BOOST_CHECK_EQUAL(48, struc.factor_group().size());
50 }
51 
66 void prim2_read_test(Structure &struc) {
67 
68  double tol = 1e-5;
69 
70  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(4.0, 0.0, 0.0), tol), true);
71  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(0.0, 4.0, 0.0), tol), true);
72  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(0.0, 0.0, 4.0), tol), true);
73  BOOST_CHECK_EQUAL(struc.basis.size(), 4);
74 
75  // basis site 0 has three possible occupants
76  BOOST_CHECK_EQUAL(struc.basis[0].site_occupant().size(), 3);
77 
78  std::string check_name[3] = {"A", "B", "C"};
79  int check_value[4] = {0, 0, 1, 2};
80 
81  for(int i = 0; i < 4; i++) {
82  for(int j = 0; j < 3; j++) {
83  // occupants are Molecule with name "A", etc.
84  // Molecule are composed of AtomPosition
85  // An AtomPosition 'is' a Coordinate with a Specie
86  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[j].name, check_name[j]);
87  BOOST_CHECK_EQUAL(almost_equal(struc.basis[i].site_occupant()[j][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
88  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[j][0].specie.name, check_name[j]);
89 
90  }
91  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant().value(), check_value[i]);
92  }
93 
94  // ordering on FCC motif
95  BOOST_CHECK_EQUAL(16, struc.factor_group().size());
96 }
97 
98 
131 void pos1_read_test(Structure &struc) {
132 
133  double tol = 1e-5;
134 
135  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[0], Eigen::Vector3d(4.0, 0.0, 0.0), tol), true);
136  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[1], Eigen::Vector3d(0.0, 4.0, 0.0), tol), true);
137  BOOST_CHECK_EQUAL(almost_equal(struc.lattice()[2], Eigen::Vector3d(0.0, 0.0, 4.0), tol), true);
138  BOOST_CHECK_EQUAL(struc.basis.size(), 4);
139 
140  std::string check_name[4] = {"A", "A", "B", "C"};
141 
142  for(int i = 0; i < 4; i++) {
143  // basis site 0 and 1 have one possible occupant
144  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant().size(), 1);
145 
146  // occupants are Molecule with name "A", etc.
147  // Molecule are composed of AtomPosition
148  // An AtomPosition 'is' a Coordinate with a Specie
149  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[0].name, check_name[i]);
150  BOOST_CHECK_EQUAL(almost_equal(struc.basis[i].site_occupant()[0][0].const_frac(), Eigen::Vector3d(0.0, 0.0, 0.0), tol), true);
151  BOOST_CHECK_EQUAL(struc.basis[i].site_occupant()[0][0].specie.name, check_name[i]);
152  }
153 
154  // FCC structure
155  BOOST_CHECK_EQUAL(16, struc.factor_group().size());
156 }
157 
158 BOOST_AUTO_TEST_SUITE(StructureTest)
159 
161 
162  fs::path testdir = "tests/unit/crystallography";
163 
164  // Read in test PRIM and run tests
165  Structure struc(fs::path(testdir / "PRIM1"));
166  prim1_read_test(struc);
167 
168  // Write test PRIM back out
169  fs::path tmp_file = testdir / "PRIM1_out";
170  write_prim(struc, tmp_file, FRAC);
171 
172  // Read new file and run tests again
173  Structure struc2(read_prim(tmp_file));
174  prim1_read_test(struc2);
175 
176 }
177 
179 
180  fs::path testdir = "tests/unit/crystallography";
181 
182  // Read in test PRIM and run tests
183  Structure struc(fs::path(testdir / "PRIM2"));
184  prim2_read_test(struc);
185 }
186 
188 
189  fs::path testdir = "tests/unit/crystallography";
190 
191  // Read in test PRIM and run tests
192  Structure struc(fs::path(testdir / "POS1"));
193  pos1_read_test(struc);
194 
195  // Write test PRIM back out
196  fs::path tmp_file = testdir / "POS1_out";
197  fs::ofstream sout(tmp_file);
198  VaspIO::PrintPOSCAR printer(struc);
199  printer.set_append_atom_names_off();
200  printer.print(sout);
201  sout.close();
202 
203  // Read new file and run tests again
204  Structure struc2(fs::path(testdir / "POS1_out"));
205  pos1_read_test(struc2);
206 
207 }
208 
209 BOOST_AUTO_TEST_CASE(POS1Vasp5Test) {
210 
211  fs::path testdir = "tests/unit/crystallography";
212 
213  // Read in test PRIM and run tests
214  Structure struc(fs::path(testdir / "POS1"));
215  pos1_read_test(struc);
216 
217  // Write test PRIM back out
218  fs::path tmp_file = testdir / "POS1_vasp5_out";
219  fs::ofstream sout(tmp_file);
220  VaspIO::PrintPOSCAR(struc).print(sout);
221  sout.close();
222 
223  // Read new file and run tests again
224  Structure struc2(fs::path(testdir / "POS1_vasp5_out"));
225  pos1_read_test(struc2);
226 
227 }
228 
229 BOOST_AUTO_TEST_CASE(POS1jsonPrimTest) {
230 
231  fs::path testdir = "tests/unit/crystallography";
232 
233  // Read in test PRIM and run tests
234  Structure struc(fs::path(testdir / "POS1"));
235  pos1_read_test(struc);
236 
237  // Write test PRIM back out
238  fs::path tmp_file = testdir / "POS1_prim.json";
239  jsonParser json;
240  write_prim(struc, json, FRAC);
241  fs::ofstream sout(tmp_file);
242  json.print(sout);
243  sout.close();
244 
245  // Read new file and run tests again
246  struc = Structure(read_prim(tmp_file));
247  pos1_read_test(struc);
248 
249 }
250 
251 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PRIM1Test)
Index size() const
Definition: Array.hh:145
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
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
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
void prim2_read_test(Structure &struc)
BasicStructure< Site > read_prim(fs::path filename)
Definition: AppIO.cc:11
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
Definition: jsonParser.cc:185
void print(std::ostream &sout)
Print POSCAR to stream.
Definition: VaspIO.hh:509
double tol
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
void pos1_read_test(Structure &struc)
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
Print POSCAR with formating options.
Definition: VaspIO.hh:232
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)
void prim1_read_test(Structure &struc)