def setUp(self): self.parser_tise2 = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_tise2.out") self.parser_snse = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_snse.out") self.parser_graphite = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_graphite.out")
def test_pwscf_reciprocal_vectors_alat(): """Test the parsing of reciprocal vectors in alat units""" parser_tise2 = PWSCFParser( Path(__file__).parent / "data" / "pwscf_tise2.out") b1, b2, b3 = parser_tise2.reciprocal_vectors_alat() assert np.allclose(b1, np.array([1.011_138, 0.585_904, 0.001_336])) assert np.allclose(b2, np.array([0.001_839, 1.168_623, -0.001_336])) assert np.allclose(b3, np.array([0.001_203, -0.000_695, 0.598_942]))
def test_pwscf_lattice_vectors_alat(): """Test the parsing of lattice vectors in alat units""" parser_tise2 = PWSCFParser( Path(__file__).parent / "data" / "pwscf_tise2.out") a1, a2, a3 = parser_tise2.lattice_vectors_alat() assert np.allclose(a1, np.array([0.989_891, -0.001_560, -0.001_990])) assert np.allclose(a2, np.array([-0.496_296, 0.856_491, 0.001_990])) assert np.allclose(a3, np.array([-0.003_315, 0.001_914, 1.669_621]))
def test_pwscf_crystal_instance(file, expected_spg): """Test the construction of Crystal instances, and check against expected symmetry properties""" parser = PWSCFParser(file) crystal = Crystal.from_pwscf(file) # COmparison of lattice vectors assert np.allclose( np.array(crystal.lattice_vectors), np.array(parser.lattice_vectors()), ) # Comparison requires slighly relaxed precision assert crystal.symmetry( symprec=1e-1)["international_number"] == expected_spg
def test_pwscf_alat(file, alat): """Test the parsing of the lattice parameter (alat)""" parser = PWSCFParser(file) assert parser.alat == alat assert round(abs(parser.alat - parser.celldm[1]), 4) == 0
class TestPWSCFParser(unittest.TestCase): def setUp(self): self.parser_tise2 = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_tise2.out") self.parser_snse = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_snse.out") self.parser_graphite = PWSCFParser( Path(".") / "tests" / "data" / "pwscf_graphite.out") def test_alat(self): """ Test the parsing of the lattice parameter (alat) """ self.assertEqual(self.parser_tise2.alat, 6.6764) self.assertEqual(self.parser_snse.alat, 21.4862) self.assertEqual(self.parser_graphite.alat, 4.6563) self.assertAlmostEqual(self.parser_tise2.alat, self.parser_tise2.celldm[1], places=4) self.assertAlmostEqual(self.parser_snse.alat, self.parser_snse.celldm[1], places=4) self.assertAlmostEqual(self.parser_graphite.alat, self.parser_graphite.celldm[1], places=4) def test_natoms(self): """ Test the parsing of the number of unit cell atoms """ self.assertEqual(self.parser_tise2.natoms, 3) self.assertEqual(self.parser_snse.natoms, 8) self.assertEqual(self.parser_graphite.natoms, 4) def test_lattice_vectors_alat(self): """ Test the parsing of lattice vectors in alat units """ a1, a2, a3 = self.parser_tise2.lattice_vectors_alat() self.assertTrue( np.allclose(a1, np.array([0.989_891, -0.001_560, -0.001_990]))) self.assertTrue( np.allclose(a2, np.array([-0.496_296, 0.856_491, 0.001_990]))) self.assertTrue( np.allclose(a3, np.array([-0.003_315, 0.001_914, 1.669_621]))) def test_reciprocal_vectors_alat(self): """ Test the parsing of reciprocal vectors in alat units """ b1, b2, b3 = self.parser_tise2.reciprocal_vectors_alat() self.assertTrue( np.allclose(b1, np.array([1.011_138, 0.585_904, 0.001_336]))) self.assertTrue( np.allclose(b2, np.array([0.001_839, 1.168_623, -0.001_336]))) self.assertTrue( np.allclose(b3, np.array([0.001_203, -0.000_695, 0.598_942]))) def test_atoms(self): for parser in (self.parser_tise2, self.parser_snse, self.parser_graphite): atoms = parser.atoms() self.assertEqual(len(atoms), parser.natoms) def test_crystal_instance(self): """ Test the construction of Crystal instances, and check against expected symmetry properties """ for parser, expected_spg in zip( (self.parser_tise2, self.parser_snse, self.parser_graphite), (164, 62, 194)): with self.subTest(parser.filename): crystal = Crystal.from_pwscf(parser.filename) # COmparison of lattice vectors self.assertTrue( np.allclose( np.array(crystal.lattice_vectors), np.array(parser.lattice_vectors()), )) # Comparison requires slighly relaxed precision self.assertEqual( crystal.symmetry(symprec=1e-1)["international_number"], expected_spg)
def test_pwscf_atoms(file): parser = PWSCFParser(file) atoms = parser.atoms() assert len(atoms) == parser.natoms
def test_pwscf_natoms(file, natoms): """Test the parsing of the number of unit cell atoms""" parser = PWSCFParser(file) assert parser.natoms == natoms