Ejemplo n.º 1
0
    def test_primitive_cell_for_rhombohedral_lattice(self):
        with self.assertRaises(ValueError):
            PrimitiveCell.for_rhombohedral_lattice(-1, np.pi / 4)

        with self.assertRaises(ValueError):
            PrimitiveCell.for_rhombohedral_lattice(1, np.pi)

        with self.assertRaises(ValueError):
            # angle too big
            PrimitiveCell.for_rhombohedral_lattice(1, np.pi * 2. / 3. + 0.1)

        cosa = np.cos(self.alpha)
        sina = np.sin(self.alpha)

        p1 = (self.a, 0, 0)
        p2 = (self.a * cosa, self.a * sina, 0)
        p3 = (self.a * cosa, self.a * (cosa - cosa**2) / sina,
              self.a * np.sqrt(sina**2 - ((cosa - cosa**2) / sina)**2))

        pc = PrimitiveCell.for_rhombohedral_lattice(self.a, self.alpha)
        self.assertIsInstance(pc, PrimitiveCell)
        self.assertEqual(pc.bravais_lattice, BravaisLattice.RHOMBOHEDRAL)
        assert_array_equal(pc.p1, p1)
        assert_array_equal(pc.p2, p2)
        assert_array_equal(pc.p3, p3)
    def test_primitive_cell_for_rhombohedral_lattice(self):
        with self.assertRaises(ValueError):
            PrimitiveCell.for_rhombohedral_lattice(-1, np.pi/4)

        with self.assertRaises(ValueError):
            PrimitiveCell.for_rhombohedral_lattice(1, np.pi)

        with self.assertRaises(ValueError):
            # angle too big
            PrimitiveCell.for_rhombohedral_lattice(1, np.pi*2./3.+0.1)

        cosa = np.cos(self.alpha)
        sina = np.sin(self.alpha)

        p1 = (self.a, 0, 0)
        p2 = (self.a*cosa, self.a*sina, 0)
        p3 = (self.a*cosa, self.a*(cosa-cosa**2) / sina,
              self.a*np.sqrt(sina**2 - ((cosa-cosa**2) / sina)**2))

        pc = PrimitiveCell.for_rhombohedral_lattice(self.a, self.alpha)
        self.assertIsInstance(pc, PrimitiveCell)
        self.assertEqual(pc.bravais_lattice,
                         BravaisLattice.RHOMBOHEDRAL)
        assert_array_equal(pc.p1, p1)
        assert_array_equal(pc.p2, p2)
        assert_array_equal(pc.p3, p3)
    def test_exception_guess_vectors_with_unsorted_points(self):
        # given
        primitive_cell = PrimitiveCell.for_rhombohedral_lattice(0.1, 0.7)

        # when
        p1, p2, p3 = self._get_primitive_vectors(primitive_cell)
        points = create_points_from_pc(p1, p2, p3, (4, 5, 3))
        numpy.random.shuffle(points)

        # then
        with self.assertRaises(ValueError):
            lattice_tools.guess_primitive_vectors(points)
Ejemplo n.º 4
0
    def test_exception_guess_vectors_with_unsorted_points(self):
        # given
        primitive_cell = PrimitiveCell.for_rhombohedral_lattice(0.1, 0.7)

        # when
        p1, p2, p3 = self._get_primitive_vectors(primitive_cell)
        points = create_points_from_pc(p1, p2, p3, (4, 5, 3))
        numpy.random.shuffle(points)

        # then
        with self.assertRaises(ValueError):
            lattice_tools.guess_primitive_vectors(points)
Ejemplo n.º 5
0
def make_rhombohedral_lattice(name, h, angle, size, origin=(0, 0, 0)):
    """Create and return a 3D rhombohedral lattice.

    Parameters
    ----------
    name : str
    h : float
        lattice spacing
    angle : float
        angle between the (conventional) unit cell edges (in radians)
    size : int[3]
        Number of lattice nodes in each axis direction.
    origin : float[3], default value = (0, 0, 0)
        lattice origin

    Returns
    -------
    lattice : Lattice
        A reference to a Lattice object.
    """
    pc = PrimitiveCell.for_rhombohedral_lattice(h, angle)
    return Lattice(name, pc, size, origin)

# a cubic lattice on a rotated coordinates represented using PolyData
pcs = rotate_primitive_cell(PrimitiveCell.for_cubic_lattice(1.))
datasets.append(create_polydata_from_pc(*pcs))

# BCC lattice in a rotated coor. sys.
pcs = rotate_primitive_cell(PrimitiveCell.for_body_centered_cubic_lattice(1.))
datasets.append(create_polydata_from_pc(*pcs))

# FCC lattice in a rotated coor. sys.
pcs = rotate_primitive_cell(PrimitiveCell.for_face_centered_cubic_lattice(1.))
datasets.append(create_polydata_from_pc(*pcs))

# rhombohedral lattice in a rotated coor. sys.
pcs = rotate_primitive_cell(PrimitiveCell.for_rhombohedral_lattice(1., 1.))
datasets.append(create_polydata_from_pc(*pcs))

# tetragonal lattice in a rotated coor. sys.
pcs = rotate_primitive_cell(PrimitiveCell.for_tetragonal_lattice(0.5, 1.))
datasets.append(create_polydata_from_pc(*pcs))

# body_centered_tetragonal lattice in a rotated coor. sys.
factory = PrimitiveCell.for_body_centered_tetragonal_lattice
pcs = rotate_primitive_cell(factory(1., 0.5))
datasets.append(create_polydata_from_pc(*pcs))

# hexagonal lattice in a rotated coor. sys.
pcs = rotate_primitive_cell(PrimitiveCell.for_hexagonal_lattice(1., 0.5))
datasets.append(create_polydata_from_pc(*pcs))