Exemplo n.º 1
0
def main():
    #print(rotate([[2,0,0],[0,1,0],[0,0,1]], 90, 'y'))
    #print(calc_rot_array_from_hkl(19,-24,28))
    modelfile = sys.argv[1]
    m = Model(modelfile)
    rot_arr = calc_rot_array_from_hkl(41,60,-6)
    rot(m,rot_arr)
    m.write_real_xyz('temp.real.xyz')
    return

    # Below is a (the?) rotation matrix of Pei's t1 that gives some planes. Oriented for a specific plane ~.
    #rot_arr = [ -0.977103, -0.123352, -0.173361, -0.130450, 0.990997, 0.030118, 0.168085, 0.052043, -0.984398 ]
    #rot(m,rot_arr)

    # Angles in radians
    # Note that these are semi difficult to figure out from the vesta rotation matrix,
    # partly because there are negative angles, so you may need to do 2pi - angle you found.
    #t1 = np.pi*2 - 0.0371505
    #t2 = 0.162790
    #t3 = 0
    #rot_arr = calc_rot_array(m,t1,t2,t3)
    #rot(m,rot_arr)

    kx = -0.76094085
    ky = 0.028182994
    kz = -0.648208872
    t2 = np.arctan(-ky/kx)
    t3 = 0.0
    t1 = np.arctan( (kx*np.cos(t2)-ky*cos(t2))/kz )
    t1 = 0.0
    print(t1,t2,t3)
    rot_arr = calc_rot_array(t1,t2,t3)
    rot(m,rot_arr)
Exemplo n.º 2
0
def main():
    # NOTE: Cutoff can either be a single integer or it
    # can be a dictionary where the keys are two-tuples
    # of atomic numbers (e.g. (40,13)=3.5 for Zr,Al).
    modelfile = sys.argv[1]
    submodelfile = sys.argv[2]
    rotatedsubmodelfile = sys.argv[3]
    m = Model(modelfile)
    try:
        cut = 3.5  # float(sys.argv[2])
        cutoff = {}
        for z1 in m.atomtypes:
            for z2 in m.atomtypes:
                cutoff[(z1, z2)] = cut
                cutoff[(z2, z1)] = cut
    except:
        print("You didn't input a cutoff so you much define it in the code.")
    voronoi_3d(m, cutoff)

    subm = Model(submodelfile)
    rotsubm = Model(rotatedsubmodelfile)
    for atom in subm.atoms:
        if atom in m.atoms:
            rotsubm.atoms[atom.id].vp = m.atoms[m.atoms.index(atom)].vp
        else:
            print("Couldn't find atom {0} in full model!".format(atom))
    icofrac(rotsubm)
    # rotsubm.write_real_xyz()
    rotsubm.write_real_xyz(rotatedsubmodelfile[:-4] + ".icofrac.real.xyz")
Exemplo n.º 3
0
def dodecahedron(b,save=False,filename=None):
    # http://en.wikipedia.org/wiki/Dodecahedron#Regular_dodecahedron
    # b is the nearest-neighbor interatomic bond distance
    p = 1.61803398875 # golden ratio
    b = b * 0.5 * p
    coords = [[0,0,0]]

    coords.append([p,0,1./p])
    coords.append([-p,0,1./p])
    coords.append([-p,0,-1./p])
    coords.append([p,0,-1./p])

    coords.append([1./p, p, 0])
    coords.append([1./p, -p, 0])
    coords.append([-1./p, -p, 0])
    coords.append([-1./p, p, 0])

    coords.append([0, 1./p, p])
    coords.append([0, 1./p, -p])
    coords.append([0, -1./p, -p])
    coords.append([0, -1./p, p])

    coords.append([1,1,1])
    coords.append([1,-1,1])
    coords.append([-1,-1,1])
    coords.append([-1,1,1])

    coords.append([-1,1,-1])
    coords.append([1,1,-1])
    coords.append([1,-1,-1])
    coords.append([-1,-1,-1])

    coords = [ [b*x for x in c] for c in coords]
    m = 0
    for coord in coords:
        for x in coord:
            if(abs(x) > m): m = abs(x)

    atoms = [Atom(i,14,c[0],c[1],c[2]) for i,c in enumerate(coords)]
    model = Model(comment='dodecahedron', xsize=m, ysize=m, zsize=m, atoms=atoms)

    if(save):
        model.write_real_xyz(model.filename)
        if(filename == None):
            filename = 'dodecahedron.xyz'
        else:
            model.filename = filename
        #f = open(filename,'w')
        #f.write(str(len(coords))+'\n')
        #f.write('{0} {0} {0} comment\n'.format(m))
        #for c in coords:
        #    f.write('Si ' + ' '.join([str(x) for x in c]) + '\n')
        #f.close()
    return model
Exemplo n.º 4
0
def dump_to_modelfiles(dump,masses,base_modelname):
    flag = None
    for line in open(dump):
        if('ITEM: TIMESTEP' in line):
            if(flag):
                # Save the model
                comment = 'timestep {0}'.format(timestep)
                lx = bounds[0]
                ly = bounds[1]
                lz = bounds[2]
                m = Model(comment,lx,ly,lz, atoms)
                m.atoms = sorted(m.atoms, key=operator.itemgetter('id'))
                filename = base_modelname + '_' + str(timestep) + '.xyz'
                m.write_real_xyz(filename)
            flag = 'TIMESTEP'
            continue
        elif('ITEM: NUMBER OF ATOMS' in line):
            flag = 'NUMBER OF ATOMS'
            continue
        elif('ITEM: BOX BOUNDS pp pp pp' in line):
            flag = 'BOX BOUNDS'
            bounds = []
            continue
        elif('ITEM: ATOMS id type xs ys zs' in line):
            flag = 'ATOMS'
            atoms = []
            continue

        if(flag == 'TIMESTEP'):
            timestep = int(line.strip())
        elif(flag == 'NUMBER OF ATOMS'):
            natoms = int(line.strip())
        elif(flag == 'BOX BOUNDS'):
            bounds.append( [float(x) for x in line.strip().split()] )
            bounds[-1] = sum([abs(x) for x in bounds[-1]])
        elif(flag == 'ATOMS'):
            line = line.strip().split()
            id = int(line[0])
            znum = masses[ int(line[1]) ]
            x,y,z = frac_to_cart(float(line[2]), float(line[3]), float(line[4]), bounds[0],bounds[1],bounds[2])
            atoms.append( Atom(id,znum,x,y,z) )
    # Save the last model
    comment = 'timestep {0}'.format(timestep)
    lx = bounds[0]
    ly = bounds[1]
    lz = bounds[2]
    m = Model(comment,lx,ly,lz, atoms)
    m.atoms = sorted(m.atoms, key=operator.itemgetter('id'))
    filename = base_modelname + '_' + str(timestep) + '.xyz'
    m.write_real_xyz(filename)
Exemplo n.º 5
0
def icosahedron(b,save=False,filename=None):
    # http://en.wikipedia.org/wiki/Regular_icosahedron
    # b is the nearest-neighbor interatomic bond distance
    b = b * sqrt(2)* 1.113516364 / 1.84375
    coords = [atom.coord for atom in dodecahedron(b).atoms]
    vertices = range(1,21)
    faces = [
        [15, 2, 12, 16, 9],
        [11, 19, 10, 4, 18],
        [6, 7, 14, 15, 12],
        [10, 18, 17, 5, 8],
        [9, 16, 13, 8, 5],
        [7, 6, 20, 19, 11],
        [5, 1, 13, 4, 18],
        [4, 19, 6, 14, 1],
        [1, 9, 13, 12, 14],
        [2, 3, 20, 7, 15],
        [2, 16, 8, 17, 3],
        [3, 20, 11, 10, 17]]
    face_coords = [(0,0,0)]
    for f in faces:
        center = (sum(coords[i][0] for i in f)/5., sum(coords[i][1] for i in f)/5., sum(coords[i][2] for i in f)/5.)
        face_coords.append(center)
    m = 0
    for coord in face_coords:
        for x in coord:
            if(abs(x) > m): m = abs(x)

    atoms = [Atom(i,14,c[0],c[1],c[2]) for i,c in enumerate(face_coords)]
    model = Model(comment='icosahedron', xsize=m, ysize=m, zsize=m, atoms=atoms)
    if(save):
        model.write_real_xyz(model.filename)
        if(filename == None):
            filename = 'icosahedron.xyz'
        else:
            model.filename = filename
        #f = open(filename,'w')
        #f.write(str(len(face_coords))+'\n')
        #f.write('{0} {0} {0} comment\n'.format(m))
        #for c in face_coords:
        #    f.write('Si ' + ' '.join([str(x) for x in c]) + '\n')
        #f.close()
    return model