Example #1
0
def msd_index(VW,L):
    k=100
    time = 500

    surface =  util.pickle_load('surface.pkl')
    DV =  util.pickle_load('DV_s.pkl')
    DW =  util.pickle_load('DW_s.pkl')
    CV =  util.pickle_load('CV.pkl')
    CW =  util.pickle_load('CW.pkl')

    defects = []
    print DV.shape
    print DW.shape
    for i in range(DV[k].shape[0]):
        if DV[k][i] == -1:
            index, d = close_neighbors_point(VW[k],CV[i],L)
            defects.append(index)
    for i in range(DW[k].shape[0]):
        if DW[k][i] == -1:
            index, d = close_neighbors_point(VW[k],CW[i],L)
            defects.append(index)
    print len(defects)


    fid = open('large.xyz','r')
    M = readxyz.ReadCord(trajectory = 'large.xyz',frames = 777)
    crystal = M.cord_auto(['V','W'])
    bcc = np.zeros((777,432,1))
    for frame in range(bcc.shape[0]):
        for i in range(bcc.shape[1]):
            if crystal[frame][i][0] > L[0]:
                bcc[frame][i]=0
            else:
                bcc[frame][i]=1
    s = []
    for i in range(len(bcc[k])):
            if surface[k][i]:
                s.append(i)
    gel = []
    for i in range(len(bcc[k])):
            if bcc[k][i] ==0 and surface[k][i] == 0:
                gel.append(i)
    crystal = []
    for i in range(len(bcc[k])):
            if bcc[k][i] == 1:
                crystal.append(i)

    #diffuse.index_msd(VW,s,L,time,save='msd_index_%i_surface_%i'%(k,len(s)))
    x,msd=diffuse.index_msd(VW,gel,L,time,save='msd_index_%i_gel_%i'%(k,len(gel)))
    x2,msd2=diffuse.index_msd(VW,crystal,L,time,save='msd_index_%i_solid_%i'%(k,len(crystal)))
    util.pickle_dump([x,msd,x2,msd2],'msd_index.pkl')
    #diffuse.index_msd(VW,defects,L,time,save='msd_index_%i_defects_%i'%(k,len(defects)))
    #r = list(set(s)-set(defects))
    #diffuse.index_msd(VW,r,L,time,save='msd_index_%i_nodefect%i'%(k,len(r)))
    #print len(defects)
    #print len(s)
    import MD.plot.pyplot_eps as pyplot_eps
    pyplot_eps.plot2(x,msd,x2,msd2,xlabel='t',ylabel='msd',label1='gel',label2='solid',save='msdgelsolid')
Example #2
0
def projection_jump(VW,surface,proj,L,k,save='proj_hist'):
    #skip = VW.shape[0]/len(surface)
    skip = 1
    jump_d = []
    print len(surface)
    print VW.shape
    print proj.shape
    try:
        for i in surface:
            n, dist = close_neighbors_point(proj,VW[i],L)
            jump_d.append(dist)
    except:
        for i in surface:
            n, dist = close_neighbors_point(proj,VW[i-VW.shape[0]],L)
            jump_d.append(dist)
    print jump_d
    hist_s,xs=histogram_reg(jump_d,bins=10)
    pyplot.plot(xs,hist_s,xlabel='distance',ylabel='count',save=save)
    return jump_d
Example #3
0
def jump_lattice(VW,L):
    reload(diffuse)
    k=100
    time = 500

    surface =  util.pickle_load('surface.pkl')
    CV =  util.pickle_load('CV.pkl')
    CW =  util.pickle_load('CW.pkl')
    DV =  util.pickle_load('DV_s.pkl')
    DW =  util.pickle_load('DW_s.pkl')
    defects = []
    for i in range(DV[k].shape[0]):
        if DV[k][i] == -1:
            index, d = close_neighbors_point(VW[k],CV[i],L)
            defects.append(index)
    for i in range(DW[k].shape[0]):
        if DW[k][i] == -1:
            index, d = close_neighbors_point(VW[k],CW[i],L)
            defects.append(index)

    proj = np.zeros((CV.shape[0]*2,CV.shape[1]))
    for i in range(CV.shape[0]):
        proj[i] = CV[i]
    for i in range(CW.shape[0]):
        proj[i+CV.shape[0]] = CW[i]


    fid = open('large.xyz','r')
    M = readxyz.ReadCord(trajectory = 'large.xyz',frames = 777)
    crystal = M.cord_auto(['V','W'])
    bcc = np.zeros((777,432,1))
    for frame in range(bcc.shape[0]):
        for i in range(bcc.shape[1]):
            if crystal[frame][i][0] > L[0]:
                bcc[frame][i]=0
            else:
                bcc[frame][i]=1
    s = []
    for i in range(len(bcc[k])):
            if surface[k][i]:
                s.append(i)
    gel = []
    for i in range(len(bcc[k])):
            if bcc[k][i] ==0 and surface[k][i] == 0:
                gel.append(i)
    crystal = []
    for i in range(len(bcc[k])):
            if bcc[k][i] == 1:
                crystal.append(i)

    diffuse.projection_jump(VW[k],s,proj,L,time,save='msd_index_%i_surface_%i'%(k,len(s)))
    diffuse.projection_jump(VW[k][:216],gel[:216],CW,L,time,save='msd_index_%i_gelV_%i'%(k,len(gel)))
    diffuse.projection_jump(VW[k][216:],gel[216:],CV,L,time,save='msd_index_%i_gelW_%i'%(k,len(gel)))
    diffuse.projection_jump(VW[k],crystal,proj,L,time,save='msd_index_%i_solid_%i'%(k,len(crystal)))
    diffuse.projection_jump(VW[k][:216],crystal[:216],CW,L,time,save='msd_index_%i_solidW_%i'%(k,len(crystal)))
    for i in range(len(crystal)):
        crystal[i] = crystal[i] - CV.shape[0]
    diffuse.projection_jump(VW[k][216:],crystal[216:],CV,L,time,save='msd_index_%i_solidV_%i'%(k,len(crystal)))
    diffuse.projection_jump(VW[k],defects,proj,L,time,save='msd_index_%i_defects_%i'%(k,len(defects)))
    r = list(set(s)-set(defects))
    diffuse.projection_jump(VW,r,proj,L,time,save='msd_index_%i_nodefect%i'%(k,len(r)))
    print len(defects)
    print len(s)
Example #4
0
def find_defects_mod(CV,CW,VW,V,W,L,n_finish=1,n_start=0,delta=20,filters=0.2):
    from MD.analysis.nearest_neighbor import ws_neighbors_point
    from MD.analysis.nearest_neighbor import close_neighbors_point
    #######
    debug = False
    x = np.arange(n_start,n_finish,delta)
    lattice = []
    for i in range(CV.shape[0]):
        lattice.append(int(points.dist(CV[0],CV[i],L)[0]))
    for i in range(CW.shape[0]):
        lattice.append(int(points.dist(CV[0],CW[i],L)[0]))
    points.unique(lattice)
    lattice.sort()
    print lattice
    rmin = lattice[1] / 2.0
    rmax = lattice[2] / 2.0 +1
    #for interstitial
    s = min(W.shape[1],V.shape[1])
    #for vacancy
    #s = max(W.shape[1],V.shape[1])
    DW = np.zeros((len(x),CW.shape[0]))
    DV = np.zeros((len(x),CV.shape[0]))
    vac_count = np.zeros((len(x),1))
    int_count = np.zeros((len(x),1))
    fid = open('defects.txt','w')
    master = [[],[]]
    particle_frame = []
    for index,k in enumerate(x):
        print 'frame',k
        # Identify the points on the bcc Lattice which belong to A and B type
        #lets look at one point first
        # Assign each point to its place on the lattice
        #find the closest point   
        #####################
        N = []
        N_V = []
        N_W = []
        Vn = []
        Wn = []
        for i in V[k]:
            if abs(i[0]) < L[0]:
                Vn.append(i)
        for i in W[k]:
            if abs(i[0]) < L[0]:
                Wn.append(i)
        print 'Wn',len(Wn)
        print 'Vn',len(Vn)
        particle_frame.append(len(Wn)+len(Vn))
        Wn = np.array(Wn)
        Vn = np.array(Vn)

        for i in range(CV.shape[0]):
            N =  ws_neighbors_point(Vn,CV[i],L,i,rmin=rmin,rmax=rmax)[0]
            N_V.extend(N)
            num = len(N)
            if num == 0:
                N2 = ws_neighbors_point(Wn,CV[i],L,i,rmin=rmin,rmax=rmax)[0]
                N_W.extend(N2)
                num = -len(N2)
            DV[index][i] = num
        ###########################
        for i in range(CW.shape[0]):
            N =  ws_neighbors_point(Wn,CW[i],L,i+W.shape[1],rmin=rmin,rmax=rmax)[0]
            N_W.extend(N)
            num = len(N)
            if num == 0:
                N2 = ws_neighbors_point(Vn,CW[i],L,i+V.shape[1],rmin=rmin,rmax=rmax)[0]
                N_V.extend(N2)
                num = -len(N2)
            DW[index][i] = num
        #find the atoms that haven't been placed on the lattice yet
        IV = points.difference(range(Vn.shape[0]),N_V)
        IW = points.difference(range(Wn.shape[0]),N_W)
        ##
        if debug:
            print 'atoms not added listed after first sorting'
            print IV, IW
            print DW[index]
            print DV[index]
        for i in IV:
            #find closest lattice point
            nw, dw = close_neighbors_point(CW,Vn[i],L)
            nv, dv = close_neighbors_point(CV,Vn[i],L)
            if dw <= dv:
                #check to see if there is already an atom at that point
                if DW[index][nw] == 1 or DW[index][nw] == -1:
                    if DV[index][nv] == 0:
                        DV[index][nv] = 1
                        N_V.extend([i])
                    else:
                        DW[index][nw] = -2
                        N_V.extend([i])
                if DW[index][nw] == 0:
                        DW[index][nw] = -1
                        N_V.extend([i])
                #check to see if there is already an atom at that point
            else:
                if DV[index][nv] == 1 or DV[index][nv] == -1:
                    #if there isn't one at the other point add it
                    if DW[index][nw] == 0:
                        DW[index][nw] = -1
                        N_V.extend([i])
                    else:
                        if DV[index][nv] == 1:
                            DV[index][nv] = 2
                        if DV[index][nv] == -1:
                            DV[index][nv] = -2
                        N_V.extend([i])
                if DV[index][nv] == 0:
                    DV[index][nv] = 1
                    N_V.extend([i])
        for i in IW:
            nw, dw = close_neighbors_point(CW,Wn[i],L)
            nv, dv = close_neighbors_point(CV,Wn[i],L)
            if dv <= dw:
                if DV[index][nv] == 1 or DV[index][nv] == -1:
                    if DW[index][nw] == 0:
                        DW[index][nw] = 1
                        N_W.extend([i])
                    else:
                        DV[index][nv] = -2
                        N_W.extend([i])
                if DV[index][nv] == 0:
                    DV[index][nv] = -1
                    N_W.extend([i])
            else:
                if DW[index][nw] == 1 or DW[index][nw] == -1:
                    if DV[index][nv] == 0:
                        DV[index][nv] = -1
                        N_W.extend([i])
                    else:
                        DW[index][nw] = 2
                        N_W.extend([i])
                if DW[index][nw] == 0:
                    DW[index][nw] = 1
                    N_W.extend([i])
        #find the atoms that haven't been placed on the lattice yet
        IV = points.difference(range(Vn.shape[0]),N_V)
        IW = points.difference(range(Wn.shape[0]),N_W)
        ##
        if debug:
            print 'atoms not added list for debugging'
            print IV, IW
            print DW[index]
            print DV[index]
            print 'Defect list for lattice'
        #print out the vacency, substitutions
        def out_defect(A, index, fid, def_list, C=0):
            for i in range(A.shape[1]):
                if A[index][i] == 0:
                    pr =  'vacecy at '+ str(i+C)+ '\n'
                    try:
                        def_list[0].extend(i+C)
                    except:
                        def_list[0].append(i+C)
                    if debug:
                        print pr
                    fid.write(pr)
                if A[index][i] == -1:
                    pr = 'substitution ' + str(i+C)+ '\n'
                    if debug:
                        print pr
                    fid.write(pr)
                if A[index][i] == -2:
                    pr = 'interstitial ' + str(i + C)+ '\n'
                    try:
                        def_list[1].extend(i+C)
                    except:
                        def_list[1].append(i+C)
                    if debug:
                        print pr
                    fid.write(pr)
                if A[index][i] == 2:
                    pr = 'interstitial ' + str(i + C)+ '\n'
                    try:
                        def_list[1].extend(i+C)
                    except:
                        def_list[1].append(i+C)
                    if debug:
                        print pr
                    fid.write(pr)

        frame = 'Frame ' + str(k) + '\n'
        fid.write(frame)
        def_list = [[],[]]
        out_defect(DV, index, fid, def_list)
        out_defect(DW, index, fid, def_list, C = DV.shape[1])
        if len(points.difference(def_list[0], master[0])) != 0:
            vac_count[index] += len(points.difference(def_list[1],master[1]))
            master[0] = def_list[0]
        if len(points.difference(def_list[1],master[1])) != 0:
            int_count[index] += len(points.difference(def_list[1],master[1]))
            master[1] = def_list[1]

        #find the atoms that haven't been placed on the lattice yet
        IV = points.difference(range(V.shape[1]),N_V)
        IW = points.difference(range(W.shape[1]),N_W)

    # Identify the  defects surrounding each point
    #The total number of frames we are going to look at
    # Find the number of defects in each frame
    count = 0
    substitutions = []
    vacancies = []
    intersticial = []
    def count_def(A,check):
        count = 0
        for i in A:
            if i == check:
                count +=1
        return count
    def count_ldef(A,check):
        count = 0
        for i in A:
            if i < check:
                count +=1
        return count
    def count_adef(A,check):
        count = 0
        for i in A:
            if abs(i) == check:
                count +=1
        return count
    for k in range(DW.shape[0]):
        #find the points that are nearest neighbor that are different
        substitutions.append(count_ldef(DW[k],0)+count_ldef(DV[k],0))
        vacancies.append(count_def(DW[k],0)+count_def(DV[k],0))
        intersticial.append(count_adef(DW[k],2.0)+count_adef(DV[k],2.0))
    print 'substitions'
    print substitutions
    print 'vacancies'
    print vacancies
    print 'interstitials'
    print intersticial
    util.pickle_dump(DV,'DV_s.pkl')
    util.pickle_dump(DW,'DW_s.pkl')

    util.pickle_dump([substitutions, vacancies, intersticial, x],'plot_def_s.pkl')
    pyplot.plot3(x, substitutions, x, particle_frame, x, intersticial,
            label1='substitutions',label2='number of particles',label3='intersticial',
            save='defects_per_frame_surface',showleg=True)
    #pyplot.plot(x, vac_count, save='defect_vac_diffusion_count')
    #pyplot.plot(x, int_count, save='defect_int_diffusion_count')
    return DV, DW, [substitutions, vacancies, intersticial, x]