def test_FCC_primitive(self):
        # Create the simulation cell.
        structure = Cell()
        structure.set_basis(lengths=[0.70710678118655, 0.70710678118655,
                                     1.0], angles=[45, 90, 60])
        structure.add_atom(Atom([0, 0, 0], 0))

        # Run tessellation.
        result = VoronoiTessellationCalculator.compute(structure,
                                                       radical=False)

        # Test results.
        self.assertEqual(structure.n_atoms(), len(result))
        self.assertTrue(result[0].geometry_is_valid())
        self.assertEqual(12, len(result[0].get_faces()))
        poly_index = result[0].get_polyhedron_shape()
        self.assertEqual(12, poly_index[4])
        poly_index = result[0].get_coordination_shell_shape(result)
        self.assertEqual(12, poly_index[4])
    def test_FCC(self):
        # Create the simulation cell.
        structure = Cell()
        structure.add_atom(Atom([0, 0, 0], 0))
        structure.add_atom(Atom([0.5, 0.5, 0], 0))
        structure.add_atom(Atom([0.5, 0, 0.5], 0))
        structure.add_atom(Atom([0, 0.5, 0.5], 0))

        # Run tessellation.
        result = VoronoiTessellationCalculator.compute(structure,
                                                       radical=False)

        # Test results.
        self.assertEqual(structure.n_atoms(), len(result))
        for cell in result:
            self.assertTrue(cell.geometry_is_valid())
            self.assertEqual(12, len(cell.get_faces()))
            self.assertAlmostEqual(0.25, cell.get_volume(), delta=1e-6)
            poly_index = cell.get_polyhedron_shape()
            self.assertEqual(12, poly_index[4])
            poly_index = result[0].get_coordination_shell_shape(result)
            self.assertEqual(12, poly_index[4])
    def test_simple_cubic(self):
        # Create the simulation cell.
        structure = Cell()
        atom = Atom([0, 0, 0], 0)
        structure.add_atom(atom)

        # Run tessellation.
        result = VoronoiTessellationCalculator.compute(structure,
                                                       radical=False)

        # Test results.
        self.assertEqual(structure.n_atoms(), len(result))
        self.assertEqual(6, len(result[0].get_faces()))
        self.assertAlmostEqual(structure.volume(), result[0].get_volume(),
                                delta=1e-6)
        poly_index = result[0].get_polyhedron_shape()
        self.assertEqual(6, poly_index[4])
        poly_index = result[0].get_coordination_shell_shape(result)
        self.assertEqual(6, poly_index[0])

        # Test out the nearest neighbor shells.
        # 1st NN shell.
        nns = result[0].get_neighbor_shell(result, 1)
        self.assertEqual(6, len(nns))

        # 2nd NN shell.
        nns = result[0].get_neighbor_shell(result, 2)
        self.assertEqual(18, len(nns))

        # 3rd - 5th NN shell.
        for s in range(3, 6):
            nns = result[0].get_neighbor_shell(result, s)
            for image in nns:
                cell = image.get_supercell()
                self.assertAlmostEqual(s, sum([abs(cell[i]) for i in range(
                    3)]), delta=1e-6)

        # Test path NNs.
        # 0th NN.
        paths = result[0].get_neighbors_by_walks(result, 0)
        self.assertEqual(1, len(paths))
        total_weight = sum(list(paths.values()))
        self.assertAlmostEqual(1.0, total_weight, delta=1e-6)

        # 1st NN.
        paths = result[0].get_neighbors_by_walks(result, 1)
        self.assertEqual(6, len(paths))
        total_weight = sum(list(paths.values()))
        np_tst.assert_array_almost_equal([1/6.0]*6, list(paths.values()))
        self.assertAlmostEqual(1.0, total_weight, delta=1e-6)

        # 2nd NN.
        paths = result[0].get_neighbors_by_walks(result, 2)
        self.assertEqual(18, len(paths))
        total_weight = sum(list(paths.values()))
        for (k,v) in iteritems(paths):
            if 2 in k.get_supercell() or -2 in k.get_supercell():
                self.assertAlmostEqual(1 / 30.0, v, delta=1e-6)
            else:
                self.assertAlmostEqual(2 / 30.0, v, delta=1e-6)
        self.assertAlmostEqual(1.0, total_weight, delta=1e-6)