예제 #1
0
    def __init__(self, n, **kwargs):
        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(int(n))  # each band will have one point placed on it
        z = bands * dz - 1.0 + (dz / 2.0)  # the height z of each band/point
        r = np.sqrt(1.0 - 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

        if kwargs.get("orientations") is None:
            ports = list()
            for point in points:
                port = Port()
                ports.append(port)
                # Make the top of the port point toward the positive x axis.
                port.spin(-np.pi / 2, [0, 0, 1])
                # Raise up (or down) the top of the port in the z direction.
                port.spin(-np.arcsin(point[2]), [0, 1, 0])
                # Rotate the Port along the z axis.
                port.spin(np.arctan2(point[1], point[0]), [0, 0, 1])
                # Move the Port a bit away from the surface of the Sphere.
                # translate(port, point + 0.07)
            kwargs["orientations"] = {"normal": ports}
        else:
            raise NotImplementedError(
                "Custom orientation support is not yet implemented.")
        super(SpherePattern, self).__init__(points=points, **kwargs)
예제 #2
0
def _add_port(compound,
              label,
              idx,
              separation,
              orientation=None,
              replace=True):
    """Add the ports to the compound at the specified particle index.

    The port will either use that particle as an anchor or replace it entirely.
    """
    if replace:
        atom_bonds = [b for b in compound.bonds() if compound[idx] in b][0]
        anchor = [p for p in atom_bonds if p != compound[idx]][0]
        if orientation is None:
            orientation = compound[idx].pos - anchor.pos
        if separation is None:
            separation = np.linalg.norm(compound[idx].pos - anchor.pos)
    else:
        anchor = compound[idx]

    port = Port(
        anchor=anchor,
        orientation=orientation,
        separation=separation / 2,
    )
    compound.add(port, label=label)
    return separation
예제 #3
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.
            spin_z(port, -np.pi / 2)
            # Raise up (or down) the top of the port in the z direction.
            spin_y(port, -np.arcsin(point[2]))
            # Rotate the Port along the z axis.
            spin_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})
예제 #4
0
파일: pattern.py 프로젝트: ctk3b/mbuild
    def __init__(self, n, **kwargs):
        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.0 + (dz/2.0)  # the height z of each band/point
        r = np.sqrt(1.0 - 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
        if kwargs.get('orientations') is None:
            ports = list()
            for point in points:
                port = Port()
                ports.append(port)
                # Make the top of the port point toward the positive x axis.
                port.spin(-np.pi/2, [0, 0, 1])
                # Raise up (or down) the top of the port in the z direction.
                port.spin(-np.arcsin(point[2]), [0, 1, 0])
                # Rotate the Port along the z axis.
                port.spin(np.arctan2(point[1], point[0]), [0, 0, 1])
                # Move the Port a bit away from the surface of the Sphere.
                # translate(port, point + 0.07)
            kwargs['orientations'] = {'normal': ports}
        else:
            raise NotImplementedError('Custom orientation support is not yet '
                                      'implemented.')
        super(SpherePattern, self).__init__(points=points, **kwargs)