def test_NaI(self):
     """check supercell expansion for Al.
     """       
     at1 = Atom('Na', [0.0, 0.0, 0.0])
     at2 = Atom('Na', [0.0, 0.5, 0.5])
     at3 = Atom('Na', [0.5, 0.0, 0.5])
     at4 = Atom('Na', [0.5, 0.5, 0.0])
     at5 = Atom('I', [0.5, 0.5, 0.5])
     at6 = Atom('I', [0.0, 0.0, 0.5])
     at7 = Atom('I', [0.0, 0.5, 0.0])
     at8 = Atom('I', [0.5, 0.0, 0.0])
     naI = Structure( [ at1, at2, at3, at4, at5, at6, at7, at8], 
                            lattice = Lattice(6.482, 6.482, 6.482, 90, 90, 90),
                            sgid = 225 )
     lines = []
     for sym,pos in zip(naI.symbols, naI.xyz_cartn):
         lines.append( sym+' %f %f %f' % tuple(pos) )
     lines.append('\n')
     naI_sup = supercell(naI, (2,2,2))
     for sym,pos in zip(naI_sup.symbols, naI_sup.xyz_cartn):
         lines.append(sym+' %f %f %f' % tuple(pos))
     expected = open('expected-test_NaI-TestSuperCell').readlines()
     self.assertEqual(len(lines), len(expected))
     for l1, l2 in zip(lines, expected):
         self.assertEqual(l1.strip(), l2.strip())
     return
 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.symbol] for a in self.stru_cdse], [])
     elems_222 = [a.symbol for a in cdse_222]
     self.assertEqual(elems, elems_222)
     return
 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.symbol] for a in self.stru_cdse], [])
     elems_222 = [a.symbol for a in cdse_222]
     self.assertEqual(elems, elems_222)
     return
Example #4
0
 def test_writeStr_xyz_Supercell(self):
     at1 = Atom('Al', [0.0, 0.0, 0.0])
     at2 = Atom('Al', [0.0, 0.5, 0.5])
     at3 = Atom('Al', [0.5, 0.0, 0.5])
     at4 = Atom('Al', [0.5, 0.5, 0.0])
     self.stru4 = Structure([at1, at2, at3, at4],
                            lattice=Lattice(4.05, 4.05, 4.05, 90, 90, 90),
                            sgid=225)
     from matter.expansion import supercell
     al_333 = supercell(self.stru4, (3, 3, 3))
     s1 = al_333.writeStr(self.format)
 def test_writeStr_xyz_Supercell(self):
     at1 = Atom('Al', [0.0, 0.0, 0.0])
     at2 = Atom('Al', [0.0, 0.5, 0.5])
     at3 = Atom('Al', [0.5, 0.0, 0.5])
     at4 = Atom('Al', [0.5, 0.5, 0.0])
     self.stru4 = Structure( [ at1, at2, at3, at4], 
                     lattice=Lattice(4.05, 4.05, 4.05, 90, 90, 90),
                     sgid = 225 )
     from matter.expansion import supercell
     al_333 = supercell(self.stru4, (3, 3, 3))
     s1 = al_333.writeStr(self.format)
 def test_al_supercell(self):
     """check supercell expansion for Al.
     """       
     at1 = Atom('Al', [0.0, 0.0, 0.0])
     at2 = Atom('Al', [0.0, 0.5, 0.5])
     at3 = Atom('Al', [0.5, 0.0, 0.5])
     at4 = Atom('Al', [0.5, 0.5, 0.0])
     self.stru4 = Structure( [ at1, at2, at3, at4], 
                            lattice=Lattice(4.05, 4.05, 4.05, 90, 90, 90),
                            sgid = 225 )
     al_sup = supercell(self.stru4, (3,3,3))
     #print al_sup
     return
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 matter.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
Example #8
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 matter.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 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
 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
 def test_naI_supercell(self):
     """check supercell expansion for Al.
     """
     at1 = Atom('Na', [0.0, 0.0, 0.0])
     at2 = Atom('Na', [0.0, 0.5, 0.5])
     at3 = Atom('Na', [0.5, 0.0, 0.5])
     at4 = Atom('Na', [0.5, 0.5, 0.0])
     at5 = Atom('I', [0.5, 0.5, 0.5])
     at6 = Atom('I', [0.0, 0.0, 0.5])
     at7 = Atom('I', [0.0, 0.5, 0.0])
     at8 = Atom('I', [0.5, 0.0, 0.0])
     naI = Structure([at1, at2, at3, at4, at5, at6, at7, at8],
                     lattice=Lattice(6.482, 6.482, 6.482, 90, 90, 90),
                     sgid=225)
     for sym, pos in zip(naI.symbols, naI.xyz_cartn):
         print sym + ' %f %f %f' % tuple(pos)
     print
     naI_sup = supercell(naI, (2, 2, 2))
     for sym, pos in zip(naI_sup.symbols, naI_sup.xyz_cartn):
         print sym + ' %f %f %f' % tuple(pos)
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 matter.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 matter.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
from matter.Lattice import Lattice
from matter.orm.BigStructure import Structure

at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0])
at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0])
hexag = Lattice(2.456, 2.456, 6.696, 90, 90, 120)

graphite = Structure( [ at1, at2], lattice = hexag, sgid = 194)
graphite.id = 'graphite'
print graphite
#lattice=Lattice(a=2.456, b=2.456, c=6.696, alpha=90, beta=90, gamma=120)
#C    0.333333 0.666667 0.000000 1.0000
#C    0.666667 0.333333 0.000000 1.0000

from matter.expansion import supercell
graphite_sheet = supercell(graphite, (10,10,1))
graphite_sheet.id = 'sheet'
print graphite_sheet.getChemicalFormula()
#C200

orm.save(graphite_sheet)

#orm.destroyAllTables()
    



    


from dsaw.db import connect
db = connect(db='postgres:///test', echo=True)
db.autocommit(True)
from dsaw.model.visitors.OrmManager import OrmManager
orm = OrmManager(db)

from matter.Atom import Atom
from matter.Lattice import Lattice
from matter.orm.BigStructure import Structure

at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0])
at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0])
hexag = Lattice(2.456, 2.456, 6.696, 90, 90, 120)

graphite = Structure([at1, at2], lattice=hexag, sgid=194)
graphite.id = 'graphite'
print graphite
#lattice=Lattice(a=2.456, b=2.456, c=6.696, alpha=90, beta=90, gamma=120)
#C    0.333333 0.666667 0.000000 1.0000
#C    0.666667 0.333333 0.000000 1.0000

from matter.expansion import supercell
graphite_sheet = supercell(graphite, (10, 10, 1))
graphite_sheet.id = 'sheet'
print graphite_sheet.getChemicalFormula()
#C200

orm.save(graphite_sheet)

#orm.destroyAllTables()