Ejemplo n.º 1
0
Archivo: uctool.py Proyecto: ont/cbox
def voron( to_ipe = False ):
    from draw_gl import drawgl
    from voron import Voron
    import vec_gl
    import ucell_gl
    import voron_gl
    import voron_inout

    def draw_with( eng ):
        eng.clear()
        vo = Voron( *u.rep )
        eng( vo )
        u.to_decart()
        for n, vs in u*1:                 ## for each atoms in extended unitcell
            r, col = UCell.data[ n ]
            col = [ x/255.0 for x in col ]

            for v in vo.touch( vs ):
                eng( v, r = r, color = col, invis = False )
                eng( n, pos = v )

            for v in vo.has( vs ):        ## only draw atoms which are in Voron cell
                if not vo.touch( v ):
                    eng( v, r = r, color = col, invis = False )
                    eng( n, pos = v )


    def save2ipe( *args ):
        from draw_ipe import drawipe
        i = 0
        fname = '/tmp/out_%s.ipe'
        while os.path.exists( fname % i ):
            i += 1
        fname = fname % i
        print 'saving to %s...' % fname
        drawipe.setup_drawgl( drawgl )
        draw_with( drawipe )
        drawipe.save( fname )

    def minimize( *args ):
        global u
        u = u.to_min()
        draw_with( drawgl )

    draw_with( drawgl )

    if to_ipe:
        drawgl.button( 'save to ipe', save2ipe )

    if args.min:
        drawgl.button( 'minimize', minimize )

    drawgl.start()
Ejemplo n.º 2
0
def voron(to_ipe=False):
    from draw_gl import drawgl
    from voron import Voron
    import vec_gl
    import ucell_gl
    import voron_gl
    import voron_inout

    def draw_with(eng):
        eng.clear()
        vo = Voron(*u.rep)
        eng(vo)
        u.to_decart()
        for n, vs in u * 1:  ## for each atoms in extended unitcell
            r, col = UCell.data[n]
            col = [x / 255.0 for x in col]

            for v in vo.touch(vs):
                eng(v, r=r, color=col, invis=False)
                eng(n, pos=v)

            for v in vo.has(vs):  ## only draw atoms which are in Voron cell
                if not vo.touch(v):
                    eng(v, r=r, color=col, invis=False)
                    eng(n, pos=v)

    def save2ipe(*args):
        from draw_ipe import drawipe
        i = 0
        fname = '/tmp/out_%s.ipe'
        while os.path.exists(fname % i):
            i += 1
        fname = fname % i
        print 'saving to %s...' % fname
        drawipe.setup_drawgl(drawgl)
        draw_with(drawipe)
        drawipe.save(fname)

    def minimize(*args):
        global u
        u = u.to_min()
        draw_with(drawgl)

    draw_with(drawgl)

    if to_ipe:
        drawgl.button('save to ipe', save2ipe)

    if args.min:
        drawgl.button('minimize', minimize)

    drawgl.start()
Ejemplo n.º 3
0
print 'translateional matrix:', m.inv()
print 'invert translateional matrix:', m
print 'lattice reper', r
print 'sublattice reper', sr
vo = Voron(*r)
vos = Voron(*sr)
drawgl(vo)
drawgl(vos)
drawipe(vo)
drawipe(vos)

drawgl(sr[0], style='line')
drawgl(sr[1], style='line')
drawgl(sr[2], style='line')


## button for output camera angles and distance
def pinfo(some):
    print drawgl.gl.alpha, drawgl.gl.theta, drawgl.gl.dist


drawgl.button('camera info', pinfo)

## save picture to ipe file
import math
drawipe.setup(24.0 * math.pi / 180, 128.0 * math.pi / 180, 27.207602388)
#drawipe.setup( -13.0 * math.pi / 180, +65.0 * math.pi / 180, 15.559717968 )
drawipe.save('/tmp/test4.ipe')

drawgl.start()
Ejemplo n.º 4
0
            #else:
            #    print '---', s, 'no'


#def symmup( *args ):
#    global nelem
#    nelem += 1
#    if nelem >= len( s ):
#        nelem -= 1
#    symmdraw()
#
#def symmdown( *args ):
#    global nelem
#    nelem -= 1
#    if nelem < 0:
#        nelem += 1
#    symmdraw()

drawgl.button('up', up)
drawgl.button('down', down)
drawgl.button('fill', fill_hex)
drawgl.button('2ipe', to_ipe)
drawgl.button('symm', symm)
drawgl.button('symmtest', symmtest)
drawgl.button('view2ipe', view2ipe)
#drawgl.button( 'symmup', symmup )
#drawgl.button( 'symmdown', symmdown )
drawgl.select(sel)

drawgl.start()
Ejemplo n.º 5
0
    vo1.draw()

    for p in plns[n].touch(fd1):
        p.draw(r=0.02, color=(0, 1, 0))

    for p in plns[n].touch(fd2):
        p.draw(r=0.04, color=(1, 0, 0))


nl, n = None, 1


def up(*args):
    global nl, n
    if n < len(plns) - 1:
        nl, n = n, n + 1
    draw(nl, n)


def down(*args):
    global nl, n
    if n > 0:
        nl, n = n, n - 1
    draw(nl, n)


drawgl.button('up', up)
drawgl.button('down', down)

drawgl.start()
Ejemplo n.º 6
0
            for n, ats in u_exp:
                r, col = UCell.data[ n ]
                col = [ x/255.0 for x in col ]

                for v in vo.has( ats ):
                    drawgl( v, r = r, color = col, invis = False )

            ## now draw all cloned Voronoi cells
            #import reper2dots
            #for v in vo.cut( u.rep.to_dots( 1, 1, 1 ) ):
            #    drawgl( Voron( *u.rep, pos = v ) )
            drawgl( Voron( *u.rep ) )
                    

        ## usual minimization process
        else:
            u = u.to_min()
            print '------------'
            print 'sort of minimized cell: ', u.rep.to_zell().to_sort().name
            print 'zell of minimized cell: ', u.rep.to_zell().norm()
            draw_with( drawgl )
            


    draw_with( drawgl )

    drawgl.button( 'save to ipe', save2ipe )
    drawgl.button( 'minimize', minimize )

    drawgl.start()
Ejemplo n.º 7
0
        print obj


def w_zn(*args):
    drawgl.clear()
    drawgl(vo)
    for v in zn:
        drawgl(v)
        for vv in o:
            if abs((v - vv).vlen() - d1) < 0.1:
                drawgl(Vec(*vv), style='line', start=v)
                drawgl(Vec(*vv), r=0.1, color=(0, 0, 1))


def w_si(*args):
    drawgl.clear()
    drawgl(vo)
    for v in si:
        drawgl(v)
        for vv in o:
            if abs((v - vv).vlen() - d2) < 0.1:
                drawgl(Vec(*vv), style='line', start=v)
                drawgl(Vec(*vv), r=0.1, color=(0, 0, 1))


drawgl.select(sel)
drawgl.button('w_zn', w_zn)
drawgl.button('w_si', w_si)

drawgl.start()
Ejemplo n.º 8
0
    #ths = ( th, -th, th + pi / 2, th - pi / 2 )
    #for ai, al in enumerate( als ):
    #    for ti, th in enumerate( ths ):
    #        drawipe.setup( al, th, drawgl.gl.dist )
    #        drawipe.clear()
    #        drawipe.group()
    #        drawipe( v1, style = 'line' )
    #        drawipe( v2, style = 'line' )
    #        drawipe( v3, style = 'line' )
    #        drawipe.save( '/tmp/out_%s_%s.ipe' % ( ai, ti ) )
            
    #for i in xrange( 1,9 ):
    #    getattr( drawipe, 'setup_drawgl' + str( i ) )( drawgl )
    #    drawipe.clear()
    #    drawipe.group()
    #    drawipe( vo )
    #    drawipe.save( '/tmp/out%s.ipe' % i )

    drawipe.setup_drawgl( drawgl )
    drawipe.clear()
    drawipe.group()
    drawipe( vo )
    drawipe.save( '/tmp/out.ipe' )

#drawgl( v1, style = 'line' )
#drawgl( v2, style = 'line' )
#drawgl( v3, style = 'line' )
drawgl( vo )
drawgl.button( "to_ipe", to_ipe )
drawgl.start()
Ejemplo n.º 9
0
#def symmup( *args ):
#    global nelem
#    nelem += 1
#    if nelem >= len( s ):
#        nelem -= 1
#    symmdraw()
#
#def symmdown( *args ):
#    global nelem
#    nelem -= 1
#    if nelem < 0:
#        nelem += 1
#    symmdraw()




drawgl.button( 'up', up )
drawgl.button( 'down', down )
drawgl.button( 'fill', fill_hex )
drawgl.button( '2ipe', to_ipe )
drawgl.button( 'symm', symm )
drawgl.button( 'symmtest', symmtest )
drawgl.button( 'view2ipe', view2ipe )
#drawgl.button( 'symmup', symmup )
#drawgl.button( 'symmdown', symmdown )
drawgl.select( sel )

drawgl.start()
Ejemplo n.º 10
0
        drawipe( x, r=0.04, color=(1,0,0) )

    for x in vo_h.has( ds2_h ):
        drawipe( x, color=(0,1,0) )


def ipe2file( *args ):
    drawipe.save( '/tmp/test.ipe' )
    drawipe.clear()


def bnext( *args ):
    global pos
    pos += 1
    redraw()


def bprev( *args ):
    global pos
    pos -= 1
    redraw()


drawgl.button( "next", bnext )
drawgl.button( "prev", bprev )
drawgl.button( "toipe", to_ipe )
drawgl.button( "toipe2", to_ipe2 )
drawgl.button( "ipe2file", ipe2file )
drawgl.select( select )
drawgl.start()
Ejemplo n.º 11
0
    print 'len( basisA ) = ', len( basisA )
    print 'len( basisB ) = ', len( basisB )


    f.write( "rprim %s %s %s\n      %s %s %s\n      %s %s %s\n" % ( tuple( r[0] ) + tuple( r[1] ) + tuple( r[2] ) )  )

    f.write( '-----------\n' )
    for v in basisA:
        f.write( "%s %s %s\n" % tuple( v ) )
        drawgl( r.frac2dec( v ), r=0.05, color = (0,0,1) )

    f.write( '-----------\n' )
    for v in basisB:
        f.write( "%s %s %s\n" % tuple( v ) )
        drawgl( r.frac2dec( v ), r=0.05, color = (0,1,1) )

    f.close()



drawgl.button( "up"  , up   )
drawgl.button( "down", down )
drawgl.button( "toipe", to_ipe )
drawgl.button( "toipe2", to_ipe2 )
drawgl.button( "ipe2file", ipe2file )
drawgl.button( "mincell", min_cell )
drawgl.button( "cubic", cubic )
drawgl.select( select )
drawgl.start()
Ejemplo n.º 12
0
    basisA = basisA - basisB

    print 'len( basisA ) = ', len(basisA)
    print 'len( basisB ) = ', len(basisB)

    f.write("rprim %s %s %s\n      %s %s %s\n      %s %s %s\n" %
            (tuple(r[0]) + tuple(r[1]) + tuple(r[2])))

    f.write('-----------\n')
    for v in basisA:
        f.write("%s %s %s\n" % tuple(v))
        drawgl(r.frac2dec(v), r=0.05, color=(0, 0, 1))

    f.write('-----------\n')
    for v in basisB:
        f.write("%s %s %s\n" % tuple(v))
        drawgl(r.frac2dec(v), r=0.05, color=(0, 1, 1))

    f.close()


drawgl.button("up", up)
drawgl.button("down", down)
drawgl.button("toipe", to_ipe)
drawgl.button("toipe2", to_ipe2)
drawgl.button("ipe2file", ipe2file)
drawgl.button("mincell", min_cell)
drawgl.button("cubic", cubic)
drawgl.select(select)
drawgl.start()
Ejemplo n.º 13
0
drawgl( vo )
drawgl( vos )
drawipe( vo )
drawipe( vos )

drawgl( sr[ 0 ], style = 'line' )
drawgl( sr[ 1 ], style = 'line' )
drawgl( sr[ 2 ], style = 'line' )

## additional testing for conversion of cubic sublattice to volume-centered...
m_vc = Mat( 1.0, 0.0, 0.0,
            0.0, 1.0, 0.0,
            0.5, 0.5, 0.5 )

print mv * m_vc.inv()


## button for output camera angles and distance
def pinfo( some ):
    print drawgl.gl.alpha, drawgl.gl.theta, drawgl.gl.dist
drawgl.button( 'camera info', pinfo )

import math
drawipe.setup( -13.0 * math.pi / 180, +65.0 * math.pi / 180, 15.559717968 )
drawipe.save( '/tmp/test3.ipe' )

drawgl.gl.alpha, drawgl.gl.theta, drawgl.gl.dist = -65.0, 13.0, 15.559717968   ## beauty parameters
drawgl.start()


Ejemplo n.º 14
0
    redraw()

def inc_2( *args ):
    global p2
    p2 += 0.1
    redraw()

def dec_2( *args ):
    global p2
    p2 -= 0.1
    redraw()

def inc_3( *args ):
    global p3
    p3 += 0.1
    redraw()

def dec_3( *args ):
    global p3
    p3 -= 0.1
    redraw()

drawgl.button( '+1', inc_1 )
drawgl.button( '-1', dec_1 )
drawgl.button( '+2', inc_2 )
drawgl.button( '-2', dec_2 )
drawgl.button( '+3', inc_3 )
drawgl.button( '-3', dec_3 )

drawgl.start()
Ejemplo n.º 15
0
    vo1.draw()

    for p in plns[n].touch(fd1):
        p.draw(r=0.02, color=(0, 1, 0))

    for p in plns[n].touch(fd2):
        p.draw(r=0.04, color=(1, 0, 0))


nl, n = None, 1


def up(*args):
    global nl, n
    if n < len(plns) - 1:
        nl, n = n, n + 1
    draw(nl, n)


def down(*args):
    global nl, n
    if n > 0:
        nl, n = n, n - 1
    draw(nl, n)


drawgl.button("up", up)
drawgl.button("down", down)

drawgl.start()
Ejemplo n.º 16
0
        drawipe(x, r=0.04, color=(1, 0, 0))

    for x in vo_h.has(ds2_h):
        drawipe(x, color=(0, 1, 0))


def ipe2file(*args):
    drawipe.save('/tmp/test.ipe')
    drawipe.clear()


def bnext(*args):
    global pos
    pos += 1
    redraw()


def bprev(*args):
    global pos
    pos -= 1
    redraw()


drawgl.button("next", bnext)
drawgl.button("prev", bprev)
drawgl.button("toipe", to_ipe)
drawgl.button("toipe2", to_ipe2)
drawgl.button("ipe2file", ipe2file)
drawgl.select(select)
drawgl.start()
Ejemplo n.º 17
0
            drawgl(vo)

            ## draw all atoms which are in "vo"
            for n, ats in u_exp:
                r, col = UCell.data[n]
                col = [x / 255.0 for x in col]

                for v in vo.has(ats):
                    drawgl(v, r=r, color=col, invis=False)

            ## now draw all cloned Voronoi cells
            #import reper2dots
            #for v in vo.cut( u.rep.to_dots( 1, 1, 1 ) ):
            #    drawgl( Voron( *u.rep, pos = v ) )
            drawgl(Voron(*u.rep))

        ## usual minimization process
        else:
            u = u.to_min()
            print '------------'
            print 'sort of minimized cell: ', u.rep.to_zell().to_sort().name
            print 'zell of minimized cell: ', u.rep.to_zell().norm()
            draw_with(drawgl)

    draw_with(drawgl)

    drawgl.button('save to ipe', save2ipe)
    drawgl.button('minimize', minimize)

    drawgl.start()
Ejemplo n.º 18
0
    if type( obj ) is Vec:
        print obj


def w_zn( *args ):
    drawgl.clear()
    drawgl( vo )
    for v in zn:
        drawgl( v )
        for vv in o:
            if abs( (v - vv).vlen() - d1 ) < 0.1:
                drawgl( Vec( *vv ), style='line', start=v )
                drawgl( Vec( *vv ), r=0.1, color=(0,0,1) )

def w_si( *args ):
    drawgl.clear()
    drawgl( vo )
    for v in si:
        drawgl( v )
        for vv in o:
            if abs( (v - vv).vlen() - d2 ) < 0.1:
                drawgl( Vec( *vv ), style='line', start=v )
                drawgl( Vec( *vv ), r=0.1, color=(0,0,1) )

drawgl.select( sel )
drawgl.button( 'w_zn', w_zn )
drawgl.button( 'w_si', w_si )

drawgl.start()

Ejemplo n.º 19
0
    p2 += 0.1
    redraw()


def dec_2(*args):
    global p2
    p2 -= 0.1
    redraw()


def inc_3(*args):
    global p3
    p3 += 0.1
    redraw()


def dec_3(*args):
    global p3
    p3 -= 0.1
    redraw()


drawgl.button('+1', inc_1)
drawgl.button('-1', dec_1)
drawgl.button('+2', inc_2)
drawgl.button('-2', dec_2)
drawgl.button('+3', inc_3)
drawgl.button('-3', dec_3)

drawgl.start()
Ejemplo n.º 20
0
    drawgl( vo2 )

    print r1, r2


def bnext( *args ):
    global pos, reps
    pos = pos < len( reps ) - 1 and pos + 1 or pos
    redraw()

def bprev( *args ):
    global pos, reps
    pos = pos > 1 and pos - 1 or pos
    redraw()

drawgl.button( 'next', bnext )
drawgl.button( 'prev', bprev )


#### loading matrices from file
reps = []
ls = open( 'solutions_K3-K3.txt' ).readlines()
ls.reverse()
while ls:
    ls.pop()

    mx = []
    for i in xrange( 3 ):
        t = ls.pop().split()
        mx.extend(  map( int, [ t[ 2 ], t[ 5 ], t[ 8 ] ] ) )
    mx = Mat( *mx )