Ejemplo n.º 1
0
 def test_cdse_supercell(self):
     """check supercell expansion for CdSe.
     """
     cdse_222 = supercell(self.stru_cdse, (2, 2, 2))
     # new atoms should be grouped together
     elems = sum([8*[a.element] for a in self.stru_cdse], [])
     elems_222 = [a.element for a in cdse_222]
     self.assertEqual(elems, elems_222)
     return
Ejemplo n.º 2
0
    def superCell(self, mno, stru=None, replace=False):
        from diffpy.Structure.expansion import supercell
        if stru == None:
            stru = self.convertDiffpyStru('xyz')
            newstru = supercell(stru, mno)

        if replace:
            self.rawstru = newstru
            self.rawstype = 'diffpy'
            self.parseDiffpyStru(newstru)
        return self.addProp(newstru)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def test_ni_supercell(self):
     """check supercell expansion for Ni.
     """
     ni_123 = supercell(self.stru_ni, (1, 2, 3))
     self.assertEqual(6*len(self.stru_ni), len(ni_123))
     a, b, c = self.stru_ni.lattice.abcABG()[:3]
     a1, b2, c3 = ni_123.lattice.abcABG()[:3]
     self.assertAlmostEqual(a, a1, 8)
     self.assertAlmostEqual(b*2, b2, 8)
     self.assertAlmostEqual(c*3, c3, 8)
     x, y, z = self.stru_ni[-1].xyz
     x1, y2, z3 = ni_123[-1*2*3].xyz
     self.assertAlmostEqual(x/1, x1, 8)
     self.assertAlmostEqual(y/2, y2, 8)
     self.assertAlmostEqual(z/3, z3, 8)
     return
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
--------------------Raman Spectroscopy and Neutron Scattering Laboratory
--------------------Professor Dmitry Reznik

Description: You have to go down to where 'masses' is introduced and enter the
masses of the atoms corresponding to the atoms in 'types'
"""

import numpy as np
from diffpy.Structure import loadStructure
from diffpy.Structure.expansion import supercell

infile = 'C_mp-667273_conventional_standard.cif'
outfile = 'c60'

c60 = loadStructure(infile)
c60_2x2x2 = supercell(c60, [12, 2, 2])
c60.write(outfile + '.xyz', 'xyz')
c60_2x2x2.write(outfile + '_2x2x2.xyz', 'xyz')

struct = c60_2x2x2
with open(outfile + '_2x2x2.xyz', 'r') as fid:
    nat = int(fid.readline())  # number of atoms
    fid.readline()  # skip comment line

    pos = np.zeros((nat, 4))
    types = []
    for i in range(nat):
        tmp = fid.readline().strip().split()
        if tmp[0] not in types:
            types.append(tmp[0])
            pos[i, 0] = types.index(tmp[0]) + 1