Exemplo n.º 1
0
    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})
Exemplo n.º 2
0
    def __init__(self, anchor=None):
        super(Port, self).__init__(name='Port', port_particle=True)
        self.anchor = anchor

        up = Compound(name='subport', port_particle=True)
        up.add(Particle(name='G', pos=[0, 0, 0], port_particle=True), 'middle')
        up.add(Particle(name='G', pos=[0, 0.02, 0], port_particle=True), 'top')
        up.add(Particle(name='G', pos=[-0.02, -0.01, 0], port_particle=True), 'left')
        up.add(Particle(name='G', pos=[0.0, -0.02, 0.01], port_particle=True), 'right')

        down = clone(up)

        rotate_around_z(down, np.pi)

        self.add(up, 'up')
        self.add(down, 'down')
Exemplo n.º 3
0
    def __init__(self, anchor=None):
        super(Port, self).__init__(name='Port', port_particle=True)
        self.anchor = anchor

        up = Compound(name='subport', port_particle=True)
        up.add(Particle(name='G', pos=[0, 0, 0], port_particle=True), 'middle')
        up.add(Particle(name='G', pos=[0, 0.02, 0], port_particle=True), 'top')
        up.add(Particle(name='G', pos=[-0.02, -0.01, 0], port_particle=True), 'left')
        up.add(Particle(name='G', pos=[0.0, -0.02, 0.01], port_particle=True), 'right')

        down = clone(up)
        rotate_around_z(down, np.pi)

        self.add(up, 'up')
        self.add(down, 'down')
        self.used = False

        if anchor:
            translate_to(self, anchor.pos)
Exemplo n.º 4
0
 def test_rotate_around_z_away_from_origin(self, sixpoints):
     before = sixpoints.xyz_with_ports
     rotate_around_z(sixpoints, np.pi)
     after = sixpoints.xyz_with_ports
     assert (np.allclose(before[:, 1], -1 * after[:, 1], atol=1e-16)
             and np.allclose(before[:, 0], -1 * after[:, 0], atol=1e-16))
Exemplo n.º 5
0
 def test_rotate_around_z(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_z(ch2, np.pi)
     after = ch2.xyz_with_ports
     assert (np.allclose(before[:, 0], -1 * after[:, 0], atol=1e-16)
             and np.allclose(before[:, 1], -1 * after[:, 1], atol=1e-16))
Exemplo n.º 6
0
 def test_warn_rotate_z(self, methane):
     with pytest.warns(DeprecationWarning):
         rotate_around_z(methane, np.pi)
Exemplo n.º 7
0
 def test_rotate_around_z(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_z(ch2, np.pi)
     after = ch2.xyz_with_ports
Exemplo n.º 8
0
 def test_error_rotate_z(self, methane):
     with pytest.raises(RemovedFuncError):
         rotate_around_z(methane, np.pi)
Exemplo n.º 9
0
 def test_rotate_around_z_away_from_origin(self, sixpoints):
     before = sixpoints.xyz_with_ports
     rotate_around_z(sixpoints, np.pi)
     after = sixpoints.xyz_with_ports
     assert (    np.allclose(before[:, 1], -1*after[:, 1], atol=1e-16)
             and np.allclose(before[:, 0], -1*after[:, 0], atol=1e-16))
Exemplo n.º 10
0
 def test_rotate_around_z(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_z(ch2, np.pi)
     after = ch2.xyz_with_ports
     assert (    np.allclose(before[:, 0], -1*after[:, 0], atol=1e-16)
             and np.allclose(before[:, 1], -1*after[:, 1], atol=1e-16))
Exemplo n.º 11
0
 def test_warn_rotate_z(self, methane):
     with pytest.warns(DeprecationWarning):
         rotate_around_z(methane, np.pi)
Exemplo n.º 12
0
 def test_rotate_around_z(self, ch2):
     before = ch2.xyz_with_ports
     rotate_around_z(ch2, np.pi)
     after = ch2.xyz_with_ports