示例#1
0
文件: defects.py 项目: cdknorow/MD
def find_lattice(MD,VW,L,n_finish=1,n_start=0,delta=20,filters=0.2):
    # Identify the bcc lattice as a grid and find the recipricol lattice
    #Find Structure Factor
    #print VW.shape
    redo = True
    while redo == True:
        stmp,qx = sf.sfactor(VW[-10:-1],L=L,l=10)
        S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx)
        print np.array(Q)
        Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors,
                filters=filters, save = 'sffilter')
        a,b = MD.analysis.sfactor.recipricol(Q,primitive_vectors)
        #Find the best fit for the qlattice at a particular frame by looking
        #for the lowest value of the msdr
        x = np.arange(n_start,n_finish,delta)
        defects = np.zeros((len(x),15))
        lowest=10000
        for k in x:
            for i in range(10):
                crystal, c = make.make_bcc(a[0], a[1], a[2], VW[k][i], L[0]+5)
                msdr_x =  msdr.msd_r(VW[k], crystal, L)
                if lowest > msdr_x:
                    lowest = msdr_x
                    index = i
                    frame = k
        crystal, cword = make.make_bcc(a[0], a[1], a[2], VW[frame][index], L[0]+5)
        print np.array(b)
        print np.array(a)
        if raw_input('Do you want to retry?[no]/yes  ')  == 'yes':
            redo = True
        else:
            redo = False
    util.pickle_dump(cword,'cword.pkl')
    util.pickle_dump(crystal,'ccrystal.pkl')
    #filter out the comensurate crystal
    C = []
    for i in crystal:
        #make sure there aren't two that are close due to pbc
        if rcut_neighbors_point(np.array(C),i,L,rcut=6) == 0:
            C.append(i)
    #write out the lattice
    fid = open('testlattice.xyz','w')
    fid.write(('%i\n')%(len(C)))
    fid.write('Atoms\n')
    for i in range(len(C)):
        fid.write(('%c   %f   %f   %f\n')%('A',C[i][0],C[i][1], C[i][2]))
    fid.close()
    util.pickle_dump(C,'C.pkl')

    return crystal, C
示例#2
0
文件: defects.py 项目: cdknorow/MD
def filter_lattice(C, Vshape, Wshape, L):
    import random
    #### find the neighbors to a point
    def find_neighbors(M,point,L,rcut=17):
        neighbors = []
        for i in range(len(M)):
            if points.dist(M[i],point,L)[0]>1:
                if points.dist(M[i],point,L)[0]<rcut:
                    neighbors.append(M[i])
        return neighbors

    CB = []
    CA = []

    point = C[0]

    CA.append([point[0],point[1],point[2]])

    for i in range(len(C)):
        neighbors = find_neighbors(C,point,L)
        point = neighbors[random.randint(0,len(neighbors)-1)]
        for i in neighbors:
            CB.append([i[0],i[1],i[2]])
        neighbors = find_neighbors(C,point,L)
        point = neighbors[random.randint(0,len(neighbors)-1)]
        for i in neighbors:
            CA.append([i[0],i[1],i[2]])

    CV = np.zeros((len(C)/2,3))
    CW = np.zeros((len(C)/2,3))
    CV += L[0]*2
    CW += L[0]*2
    print 'print info'
    print CA[0]
    print CV.shape
    print len(C)
    print len(CA)
    print Vshape

    count = 0
    for i, point in enumerate(CA):
        if rcut_neighbors_point(CV,point,L,rcut=6) == 0:
            print count
            CV[count] = point
            count += 1
    count = 0
    for i, point in enumerate(CB):
        if rcut_neighbors_point(CW,point,L,rcut=6) == 0:
            CW[count] = point
            count += 1

    print CW.shape
    print CV.shape
    #write out hte lattice
    fid = open('projlattice.xyz','w')
    fid.write(('%i\n')%(len(C)))
    fid.write('Atoms\n')
    for i in range(len(CV)):
        if CV[i][0] != 0:
            fid.write(('%c   %f   %f   %f\n')%('A',CV[i][0],CV[i][1], CV[i][2]))
    for i in range(len(CW)):
        #there is a problem with writing one to many when putting in
        #interstitials
        if CW[i][0] != 0:
            fid.write(('%c   %f   %f   %f\n')%('B',CW[i][0],CW[i][1], CW[i][2]))
    fid.close()
    util.pickle_dump(CV,'CV.pkl')
    util.pickle_dump(CW,'CW.pkl')
    return CV, CW