Exemple #1
0
def msd(VW,L,step=1):
    from MD.analysis.msd import msd
    #Find the msd of the system
    x,msd=msd(VW,L,step=step)
    print x
    print msd
    pyplot.plot(x,msd,xlabel='time',ylabel='msd',save='MSDtime')
    util.pickle_dump(msd,'msd.pkl')
Exemple #2
0
def vac_msd(DV,DW,CV,CW,L):
    vacancies = np.zeros((DV.shape[0],1,3))
    for k in range(len(DW)):
        print k
        #find the points that are nearest neighbor that are different
        index = np.where(DW[k] == 0)[0]
        if len(index) > 0:
            if len(index) > 1:
                index = index[1]
            vacancies[k][0]  = CW[index]
        else:
            index = np.where(DV[k] == 0)[0]
            if len(index) > 1:
                index = index[1]
            vacancies[k][0] = CV[index]
    from MD.analysis.msd import msd_no_drift as msd
    #Find the msd of the system
    x, msd = msd(vacancies, L)
    msd = msd**0.5
    util.pickle_dump([x,msd],'msd_vac.pkl')
    pyplot.plot(x,msd,xlabel='time',ylabel='msd',save='MSD_vacancey')
Exemple #3
0
def int_msd(DV,DW,V,W,CV,CW,L):
    #we create an active_int which keeps track of the index at the current frame
    #we creat an all_int which keeps track of the intersticals
    #whenever the number of intersticials decerases we find the one that
    #vanished and add its trajectory to all_int
    #whenever teh number of intersticials increases we add a new trajectory 
    #to the active ints
    interstitials = np.zeros((DV.shape[0],1,3))
    last_index = 0
    active_int = []
    all_int = []
    ##########################
    # Functions
    ########################
    def find_nearest(point,CW,CV,L):
        current = 100
        for i in CW:
            d = points.dist(point,i,L)[0]
            if d < current:
                current = d
                new_point = i
        for i in CV:
            d = points.dist(point,i,L)[0]
            if d < current:
                current = d
                new_point = i
        return new_point
    #place the intersticial into the active_int array
    def place_int(new_point, active_int,list_index,L):
        current = 100
        for i in range(len(active_int)):
            if i not in list_index:
                d = points.dist(new_point,active_int[i][-1],L)[0]
                if d < current:
                    current = d
                    index = i
        try:
            index
            active_int[index].append(new_point)
            list_index.append(index)
            return index
        except:
            pass
    #find the distance between the new points and the active_int array 
    def find_int_dist(new_point, active_int,L):
        current = 100
        for i in range(len(active_int)):
            d = points.dist(new_point,active_int[i][-1],L)[0]
            if d < current:
                current = d
        return current
    def find_point(DV,CV,CW,i):
        if i < DV.shape[1]:
            new_point = CV[i]
        if i >= DV.shape[1]:
            new_point = CW[i-DV.shape[1]]
        return new_point
    ###########################################
    # Logic: Run through once
    ###########################################
    index = np.where(abs(DV[0]) == 2)[0]
    index  = np.append(index, np.where(abs(DW[0]) == 2)[0] + DW.shape[1])
    #xtrack keeps track of the frame when an interstitial is added
    x_track = []
    for i in index:
        new_point = find_point(DV,CV,CW,i)
        active_int.append([new_point])
        x_track.append(0)

        #find the point in the activt_interstitals and append it to the
        #the correct index
    last_index = index.shape[0]
    ###########################################
    #loop through the rest
    ###########################################
    for k in range(1,len(DW)):
        print k
        #find the points that are nearest neighbor that are different
        index = np.where(abs(DV[k]) == 2)[0]
        index  = np.append(index, np.where(abs(DW[k]) == 2)[0] + DW.shape[1])
        list_index = []
        #sometimes there are more than one interstitial
        #we only want to make sure we follow the same one 
        #so we look for the closest to that last position
        #if there is the same amount of intersticials
        if index.shape[0] == last_index:
            for i in index:
                new_point = find_point(DV,CV,CW,i)
                #find the point in the activt_interstitals and append it to the
                #the correct index
                place_int(new_point, active_int, list_index, L)
        #if an interstitical has been created
        if index.shape[0] > last_index:
            new_int = []
            dist_int = []
            for i in index:
                new_point = find_point(DV,CV,CW,i)
                #find the new interstitical
                dist_int.append(find_int_dist(new_point,active_int,L))
                new_int.append(new_point)
            #find the index of the max point
            max_index = dist_int.index(max(dist_int))
            for i in range(len(new_int)):
                if i != max_index:
                    place_int(new_int[i], active_int,list_index, L)
            active_int.append([new_int[max_index]])
            x_track.append(k)
        #if an intersticial has been destroyed
        if index.shape[0] < last_index:
            ann_int = []
            dist_int = []
            placed = []
            for i in index:
                new_point = find_point(DV,CV,CW,i)
                #find the annihlated interstitical
                dist_int.append(find_int_dist(new_point,active_int,L))
                ann_int.append(new_point)
            #find the index of the max point
            max_index = dist_int.index(max(dist_int))
            for i in range(len(ann_int)):
                placed.append(place_int(ann_int[i],active_int,list_index,L))
            #find the point to be removed
            dif = points.difference(range(len(active_int)),placed)
            #add the point to the list of all intersticials
            for i in dif:
                all_int.append(active_int[i])
            #remove the point from the active list
            count = 0
            for i in dif:
                del active_int[i-count]
                count+=1
        last_index = index.shape[0]
    for i in active_int:
        all_int.append(i)
    print 'len int'
    print len(all_int)
    final_int = []
    final_x = []
    #lets filter out the short lived interstitials
    for i in range(len(all_int)):
        if len(all_int[i]) > 1:
            final_int.append(all_int[i])
            final_x.append(x_track[i])
    print len(final_int)
    print 'print x'
    print len(final_x)
    from MD.analysis.msd import msd_no_drift as msd
    #Find the msd of each interstitial
    msd_all = []
    x_all = []
    for i in final_int:
        A = np.zeros((len(i),1,3))
        for j in range(len(i)):
            A[j][0][0] = i[j][0]
            A[j][0][1] = i[j][1]
            A[j][0][2] = i[j][2]
        x, msds = msd(A, L)
        msd_all.append(msds)
        x_all.append(x)
    #now we need to relate the msd to the point in time the interstital was
    #active
    msd_total = np.zeros(DV.shape[0])
    for i,k in enumerate(final_x):
        print k
        for j in range(len(msd_all[i])):
            if k+j < msd_total.shape[0]:
                msd_total[k+j] += msd_all[i][j]
    #for i in range(1,msd_total.shape[0]):
    #    msd_total[i] += msd_total[i-1]
    msd_total = msd_total**0.5
    x = range(msd_total.shape[0])
    util.pickle_dump([x,msd_total],'msd_int.pkl')
    pyplot.plot(x,msd_total,xlabel='time',ylabel='msd',save='MSD_int')