예제 #1
0
def makeEllipsoid(S, a, b=None, c=None):
    """Cut a structure out of another one.

    Arguments
    S       --  A Structure instance
    a       --  primary equatorial radius (along x-axis)
    b       --  secondary equatorial radius (along y-axis). If b is None
                (default) then it is set equal to a
    c       --  polar radius (along z-axis). If c is None (default), then it is
                set equal to a.

    Returns a new structure instance
    """
    if b is None: b = a
    if c is None: c = a
    sabc = array([a, b, c])

    # Create a supercell large enough for the ellipsoid
    frac = S.lattice.fractional(sabc)
    mno = map(ceil, 2*frac)
    mno = max(map(ceil, 2*frac))*array([1,1,1])
    # Make the supercell
    from diffpy.Structure.expansion import supercell
    newS = supercell(S, mno)
    lat = newS.lattice

    # Find the central atom
    ncenter = findCenter(newS)

    cxyz = lat.cartesian(newS[ncenter].xyz)

    delList = []
    N = len(newS)
    j = N
    for i in xrange(N):
        j -= 1

        # Calculate (x/a)**2 + (y/b)**2 + (z/c)**2
        xyz = lat.cartesian(newS[j].xyz)
        darray = ((xyz-cxyz)/sabc)**2
        d = sum(darray)**0.5

        # Discard atom if (x/a)**2 + (y/b)**2 + (z/c)**2 > 1
        if d > 1:
            delList.append(j)

    for i in delList:
        newS.pop(i)

    return newS
예제 #2
0
def makeEllipsoid(S, a, b=None, c=None):
    """Cut a structure out of another one.

    Arguments
    S       --  A Structure instance
    a       --  primary equatorial radius (along x-axis)
    b       --  secondary equatorial radius (along y-axis). If b is None
                (default) then it is set equal to a
    c       --  polar radius (along z-axis). If c is None (default), then it is
                set equal to a.

    Returns a new structure instance
    """
    if b is None: b = a
    if c is None: c = a
    sabc = array([a, b, c])

    # Create a supercell large enough for the ellipsoid
    frac = S.lattice.fractional(sabc)
    mno = map(ceil, 2 * frac)
    mno = max(map(ceil, 2 * frac)) * array([1, 1, 1])
    # Make the supercell
    from diffpy.Structure.expansion import supercell
    newS = supercell(S, mno)
    lat = newS.lattice

    # Find the central atom
    ncenter = findCenter(newS)

    cxyz = lat.cartesian(newS[ncenter].xyz)

    delList = []
    N = len(newS)
    j = N
    for i in xrange(N):
        j -= 1

        # Calculate (x/a)**2 + (y/b)**2 + (z/c)**2
        xyz = lat.cartesian(newS[j].xyz)
        darray = ((xyz - cxyz) / sabc)**2
        d = sum(darray)**0.5

        # Discard atom if (x/a)**2 + (y/b)**2 + (z/c)**2 > 1
        if d > 1:
            delList.append(j)

    for i in delList:
        newS.pop(i)

    return newS
def makeCuboctahedron(S, dist):
    """Make a cuboctahedron nanoparticle.

    Arguments
    S       --  A Structure instance
    dist    --  Distance from center to nearest face

    Returns a new structure instance
    """

    # Create a supercell large enough for the ellipsoid
    frac = S.lattice.fractional((dist, dist, dist))
    mno = map(ceil, 2 * frac)
    # Make the supercell
    from diffpy.Structure.expansion import supercell
    newS = supercell(S, mno)
    lat = newS.lattice

    # Find the central atom
    ncenter = findCenter(newS)

    # Make the cuboctahedron template
    from geometry.composites import cuboctahedron
    from geometry.operations import translate, rotate
    c0 = translate(cuboctahedron(dist), lat.cartesian(newS[ncenter].xyz))

    # Cut out an octahedron
    from geometry import locate

    N = len(newS)
    j = N
    for i in xrange(N):

        xyz = lat.cartesian(newS[N - 1 - i].xyz)
        if locate(xyz, c0) == 1:
            newS.pop(N - 1 - i)

    return newS
def makeCuboctahedron(S, dist):
    """Make a cuboctahedron nanoparticle.

    Arguments
    S       --  A Structure instance
    dist    --  Distance from center to nearest face

    Returns a new structure instance
    """

    # Create a supercell large enough for the ellipsoid
    frac = S.lattice.fractional((dist, dist, dist))
    mno = map(ceil, 2*frac)
    # Make the supercell
    from diffpy.Structure.expansion import supercell
    newS = supercell(S, mno)
    lat = newS.lattice

    # Find the central atom
    ncenter = findCenter(newS)

    # Make the cuboctahedron template
    from geometry.composites import cuboctahedron
    from geometry.operations import translate, rotate
    c0 = translate(cuboctahedron(dist), lat.cartesian(newS[ncenter].xyz))

    # Cut out an octahedron
    from geometry import locate

    N = len(newS)
    j = N
    for i in xrange(N):

        xyz = lat.cartesian(newS[N-1-i].xyz)
        if locate(xyz, c0) == 1:
            newS.pop(N-1-i)

    return newS