コード例 #1
0
ファイル: pattern.py プロジェクト: TengyuMaVandy/mbuild
    def __init__(self, n):
        phi = (1 + np.sqrt(5)) / 2  # the golden ratio
        long_incr = 2*np.pi / phi   # how much to increment the longitude

        dz = 2.0 / float(n)         # a unit sphere has diameter 2
        bands = np.arange(n)        # each band will have one point placed on it
        z = bands * dz - 1 + (dz/2) # the height z of each band/point
        r = np.sqrt(1 - z*z)        # project onto xy-plane
        az = bands * long_incr      # azimuthal angle of point modulo 2 pi
        x = r * np.cos(az)
        y = r * np.sin(az)
        points = np.column_stack((x, y, z))

        from mbuild.port import Port
        ports = list()
        for point in points:
            port = Port()
            ports.append(port)
            # Make the top of the port point toward the positive x axis.
            rotate_around_z(port, -np.pi/2)
            # Raise up (or down) the top of the port in the z direction.
            rotate_around_y(port, -np.arcsin(point[2]))
            # Rotate the Port along the z axis.
            rotate_around_z(port, np.arctan2(point[1], point[0]))
            # Move the Port a bit away from the surface of the Sphere.
            #translate(port, point + 0.07)

        super(SpherePattern, self).__init__(points=points,
                                            orientations={'normal': ports})
コード例 #2
0
 def test_rotate_around_y_away_from_origin(self, sixpoints):
     before = sixpoints.xyz_with_ports
     rotate_around_y(sixpoints, np.pi)
     after = sixpoints.xyz_with_ports
     assert (np.allclose(before[:, 0], -1 * after[:, 0], atol=1e-16)
             and np.allclose(before[:, 2], -1 * after[:, 2], atol=1e-16))
コード例 #3
0
 def test_rotate_around_y(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_y(ch2, np.pi)
     after = ch2.xyz_with_ports
     assert (np.allclose(before[:, 0], -1 * after[:, 0], atol=1e-16)
             and np.allclose(before[:, 2], -1 * after[:, 2], atol=1e-16))
コード例 #4
0
 def test_warn_rotate_y(self, methane):
     with pytest.warns(DeprecationWarning):
         rotate_around_y(methane, np.pi)
コード例 #5
0
 def test_rotate_around_y(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_y(ch2, np.pi)
     after = ch2.xyz_with_ports
コード例 #6
0
 def test_error_rotate_y(self, methane):
     with pytest.raises(RemovedFuncError):
         rotate_around_y(methane, np.pi)
コード例 #7
0
 def test_rotate_around_y_away_from_origin(self, sixpoints):
     before = sixpoints.xyz_with_ports
     rotate_around_y(sixpoints, np.pi)
     after = sixpoints.xyz_with_ports
     assert (    np.allclose(before[:, 0], -1*after[:, 0], atol=1e-16)
             and np.allclose(before[:, 2], -1*after[:, 2], atol=1e-16))
コード例 #8
0
 def test_rotate_around_y(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_y(ch2, np.pi)
     after = ch2.xyz_with_ports
     assert (    np.allclose(before[:, 0], -1*after[:, 0], atol=1e-16)
             and np.allclose(before[:, 2], -1*after[:, 2], atol=1e-16))
コード例 #9
0
 def test_warn_rotate_y(self, methane):
     with pytest.warns(DeprecationWarning):
         rotate_around_y(methane, np.pi)
コード例 #10
0
 def test_rotate_around_y(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_y(ch2, np.pi)
     after = ch2.xyz_with_ports