def rotate_and_save(prototype,alpha,beta,gamma):
    rot_arr = calc_rot_array(alpha,beta,gamma)
    rotated = copy.deepcopy(prototype)
    rotate(rotated,rot_arr)
    rotated.write_real_xyz(rotated.filename[:-4] + '_rotated_{0}.{1}.{2}'.format(alpha,beta,gamma)
        + rotated.filename[-4:])
    return rotated
def main():
    prototype = Model(sys.argv[1])
    #polygon   = Model(sys.argv[2])
    alpha = 15
    beta = 45
    gamma = 135
    # Assume no permutation of the atoms
    polygon = rotate_and_save(prototype,alpha,beta,gamma)

    # Take the prototype and the polygon and rotate the polygon to the prototype
    # for every rotation matrix, and calculate the value of epsilon for that
    # rotation. Store the angle,epsilon values in two arrays for later analysis.
    start = 0
    stop = 360
    step = 15
    xdata = []
    ydata = []
    m = (100000,(1,2,3,),)
    #m = 5.9520869802
    count = 0
    for a in xrange(start,stop,step):
        for b in xrange(start,stop,step):
            for c in xrange(start,stop,step):
                rot = calc_rot_array(-a,-b,-c)
                rotpolygon   = copy.deepcopy(polygon)
                rotate(rotpolygon, rot)
                epsilon = sum( dist(prototype.atoms[i].coord,rotpolygon.atoms[i].coord) for i in range(prototype.natoms) )
                #if(epsilon < min[0]): m = (epsilon, (-a,-b,-c,),)
                #if(epsilon == m): print( count, (epsilon, (-a,-b,-c,),) )
                #print(round(epsilon,2))
                xdata.append(a)
                ydata.append(epsilon)
                count += 1
    print(min)

    # Do a fit to abs(sin(...)) based on the data recorded above
    xdata = np.array(xdata)
    ydata = np.array(ydata)
    popt, pcov = curve_fit(sin2, xdata, ydata,p0=[83.5,700,10,0])
    a,b,c,d = tuple(popt)
    #print(a,b,c,d)
    #print(pcov)
    for x,y in zip(xdata,ydata):
        print("{0}\t{1}".format(x,y))
示例#3
0
def create_randomized_model(num,dir=dir):
    lattice_param = 1
    perfect = icosahedron(lattice_param,save=True,filename='icosahedron.perfect.xyz')
    perfect.write(perfect.filename)
    return 0
    for i in range(num):
        print(i)
        a = random.uniform(0,360)
        b = random.uniform(0,360)
        c = random.uniform(0,360)
        #a = random.randrange(0,345,15)
        #b = random.randrange(0,345,15)
        #c = random.randrange(0,345,15)
        rot_arr = calc_rot_array(a,b,c,deg=True)

        imperfect = copy.deepcopy(perfect)
        perturb_atom(imperfect,axis='all')
        #swap_atom(imperfect)
        imperfect.write_real_xyz(dir+'icosahedron.{0}.random.xyz'.format(i))
        convert(imperfect,'polyhedron',dir+'icosahedron.{0}.random.txt'.format(i))
        rotate(imperfect,rot_arr)
        imperfect.write_real_xyz(dir+'icosahedron.{0}.random.rot.xyz'.format(i))
        convert(imperfect,'polyhedron',dir+'icosahedron.{0}.random.rot.txt'.format(i))
示例#4
0
def create_basic_models():
    lattice_param = 1
    a = 30
    b = 135
    c = 45
    rot_arr = calc_rot_array(a,b,c,deg=True)

    perfect = icosahedron(lattice_param,save=True,filename='icosahedron.perfect.xyz')
    convert(perfect,'prototype','icosahedron.perfect.txt')

    sm = copy.deepcopy(perfect)
    swap_atom(sm,2,3)
    sm.write_real_xyz('icosahedron.perfect.swap.xyz')
    convert(sm,'polyhedron','icosahedron.perfect.swap.txt')

    rm = copy.deepcopy(perfect)
    rotate(rm,rot_arr)
    rm.write_real_xyz('icosahedron.perfect.rot.xyz')
    convert(rm,'polyhedron','icosahedron.perfect.rot.txt')

    rm = copy.deepcopy(sm)
    rotate(rm,rot_arr)
    rm.write_real_xyz('icosahedron.perfect.swap.rot.xyz')
    convert(rm,'polyhedron','icosahedron.perfect.swap.rot.txt')

    imperfect = copy.deepcopy(perfect)
    perturb_atom(imperfect,1,0.1,0)
    imperfect.write_real_xyz('icosahedron.imperfect.xyz')
    convert(imperfect,'prototype','icosahedron.imperfect.txt')

    sim = copy.deepcopy(imperfect)
    swap_atom(sim,2,3)
    sim.write_real_xyz('icosahedron.imperfect.swap.xyz')
    convert(sim,'polyhedron','icosahedron.imperfect.swap.txt')

    rim = copy.deepcopy(imperfect)
    rotate(rim,rot_arr)
    rim.write_real_xyz('icosahedron.imperfect.rot.xyz')
    convert(rim,'polyhedron','icosahedron.imperfect.rot.txt')

    rim = copy.deepcopy(sim)
    rotate(rim,rot_arr)
    rim.write_real_xyz('icosahedron.imperfect.swap.rot.xyz')
    convert(rim,'polyhedron','icosahedron.imperfect.swap.rot.txt')