Esempio n. 1
0
    def test_add_edge(self):
        """ Make sure we can add 3D edge to canvas correctly.
        """
        canvas = Grid3DCanvas()
        n1 = Node3D([0.5, 0.5, 0.5])
        n2 = Node3D([1.0, 1.0, 1.0])
        edge = Edge3D(n1, n2, n=10)

        canvas.add_edge(edge)

        ref_coordinates = [
            [0.5, 0.5, 0.5],
            [0.5454545454545454, 0.5454545454545454, 0.5454545454545454],
            [0.5909090909090909, 0.5909090909090909, 0.5909090909090909],
            [0.6363636363636364, 0.6363636363636364, 0.6363636363636364],
            [0.6818181818181819, 0.6818181818181819, 0.6818181818181819],
            [0.7272727272727273, 0.7272727272727273, 0.7272727272727273],
            [0.7727272727272727, 0.7727272727272727, 0.7727272727272727],
            [0.8181818181818181, 0.8181818181818181, 0.8181818181818181],
            [0.8636363636363636, 0.8636363636363636, 0.8636363636363636],
            [0.9090909090909092, 0.9090909090909092, 0.9090909090909092],
            [0.9545454545454546, 0.9545454545454546, 0.9545454545454546],
            [1.0, 1.0, 1.0]
        ]
        self.assertListEqual(canvas.edge_coordinates.tolist(), ref_coordinates)

        plt.close(canvas.figure)
Esempio n. 2
0
    def test_clone(self):
        """ Make sure we can clone a new supercell.
        """
        node1 = Node3D([1.0, 1.0, 1.0], color="#595959", width=1)
        node2 = Node3D([0.5, 0.5, 0.5], color="#595959", width=1)
        edge = Edge3D(node1, node2, n=10)
        supercell = SuperCell3D([node1, node2], [edge])

        supercell_clone = supercell.clone([0.5, 0.5, 0.5])

        self.assertListEqual(supercell_clone.nodes[0].coordinate.tolist(),
                             [1.5, 1.5, 1.5])
        self.assertListEqual(supercell_clone.nodes[1].coordinate.tolist(),
                             [1.0, 1.0, 1.0])

        ref_x = [
            1.5, 1.4545454545454546, 1.4090909090909092, 1.3636363636363638,
            1.3181818181818181, 1.2727272727272727, 1.2272727272727273,
            1.1818181818181819, 1.1363636363636362, 1.0909090909090908,
            1.0454545454545454, 1.0
        ]

        self.assertListEqual(supercell_clone.edges[0].x.tolist(), ref_x)
        self.assertListEqual(supercell_clone.edges[0].y.tolist(), ref_x)
        self.assertListEqual(supercell_clone.edges[0].z.tolist(), ref_x)
Esempio n. 3
0
 def test_construction_and_query(self):
     """ Test we can construct SuperCell3D correctly.
     """
     node1 = Node3D([1.0, 1.0, 1.0], color="#595959", width=1)
     node2 = Node3D([0.5, 0.5, 0.5], color="#595959", width=1)
     edge = Edge3D(node1, node2, n=10)
     supercell = SuperCell3D([node1, node2], [edge])
Esempio n. 4
0
    def test_construction_from2d(self):
        """ Make sure we can construct 3D edge from a 2D edge.
        """
        node1 = Node2D([1.0, 1.0])
        node2 = Node2D([1.0, 2.0])
        edge2d = Edge2D(node1, node2)

        edge3d = Edge3D.from2d(edge2d)

        self.assertTrue(isinstance(edge3d, Edge3D))
Esempio n. 5
0
    def test_add(self):
        node1 = Node3D([1.0, 1.0, 1.0], color="#595959", width=1)
        node2 = Node3D([0.5, 0.5, 0.5], color="#595959", width=1)
        edge = Edge3D(node1, node2, n=10)
        s1 = SuperCell3D([node1, node2], [edge])
        s2 = SuperCell3D([node1, node2], [edge])

        s = s1 + s2

        self.assertListEqual(s.nodes, [node1, node2, node1, node2])
        self.assertListEqual(s.edges, [edge, edge])
Esempio n. 6
0
    def test_construction_and_query(self):
        """ Test we can construct Grid2DNode correctly.
        """
        node1 = Node3D([1.0, 1.0, 1.0], color="#595959", width=1)
        node2 = Node3D([0.5, 0.5, 0.5], color="#595959", width=1)
        edge = Edge3D(node1, node2, n=10)

        ref_x = [
            1.0, 0.9545454545454546, 0.9090909090909091, 0.8636363636363636,
            0.8181818181818181, 0.7727272727272727, 0.7272727272727273,
            0.6818181818181819, 0.6363636363636364, 0.5909090909090908,
            0.5454545454545454, 0.5
        ]
        self.assertListEqual(edge.x.tolist(), ref_x)
        self.assertListEqual(edge.y.tolist(), ref_x)
        self.assertListEqual(edge.z.tolist(), ref_x)
Esempio n. 7
0
    def test_move(self):
        """ Test the edge can be moved correctly.
        """
        node1 = Node3D([1.0, 1.0, 1.0], color="#595959", width=1)
        node2 = Node3D([0.5, 0.5, 0.5], color="#595959", width=1)
        edge = Edge3D(node1, node2, n=10)

        edge.move([0.5, 0.5, 0.5])

        ref_x = [
            1.5, 1.4545454545454546, 1.4090909090909092, 1.3636363636363638,
            1.3181818181818181, 1.2727272727272727, 1.2272727272727273,
            1.1818181818181819, 1.1363636363636362, 1.0909090909090908,
            1.0454545454545454, 1.0
        ]

        self.assertListEqual(edge.x.tolist(), ref_x)
        self.assertListEqual(edge.y.tolist(), ref_x)
        self.assertListEqual(edge.z.tolist(), ref_x)
Esempio n. 8
0
    def test_draw(self):
        """ Make sure we can draw in grid canvas without exception raised.
        """
        canvas = Grid3DCanvas()

        n1 = Node3D([0.5, 0.5, 0.5], zorder=3)
        n2 = Node3D([1.0, 1.0, 1.0])
        canvas.add_node(n1)
        canvas.add_node(n2)

        edge = Edge3D(n1, n2)
        canvas.add_edge(edge)

        # Check current zorder here.
        self.assertEqual(canvas.current_zorder, 3)

        canvas.draw()

        plt.close(canvas.figure)