예제 #1
0
파일: animate.py 프로젝트: cdknorow/MD
def animate_beads(frames=[0,1]):
    #print out directory
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = M.box_volume()
    last = M.frames
    try:
        VW = util.pickle_load('VW.pkl')
        npType = M.get_type(['V','W'])
    except:
        VW=M.cord_auto(['V','W'])
        npType = M.get_type(['V','W'])
        util.pickle_dump(VW,'VW.pkl')
    #for binary systems use this A
    for k in frames:
        fid = open('animate/Color%i.tcl'%k,'w')
        fid.write('%i\n\n'%VW.shape[1])
        V = Average(VW,L,k-5,5)
        A = read_color_index(frame=k)
        for i in range(VW.shape[1]):
            x = V[i][0]
            y = V[i][1]
            z = V[i][2]
            color = ['B','R','G','O','P']
            fid.write('%c %.2f %.2f %.2f\n'%(color[int(A[i])],x,y,z))
        fid.close()
예제 #2
0
파일: NP_binary.py 프로젝트: cdknorow/MD
def structure_factor(VW, L, n_frames=10, n_start=1, 
        filters=0.05, dh=0.05,save='sf'):
    import MD.analysis.sfactor as sf
    #Find Structure Factor
    stmp,qx = sf.sfactor(VW[n_start:n_start+n_frames],L=L,l=20) 
    S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx)
    #Plot the graph
    xlabel = '$|\\vec{q}$ $|$'
    ylabel = '$S(\\vec{q}$ $)$ '
    pyplot.plot(Q, S, linestyle='', marker='x', 
            xlabel=xlabel, ylabel=ylabel, save=save)
    util.pickle_dump(Q,'Vsfx%i.pkl'%n_start)
    util.pickle_dump(S,'Vsfy%i.pkl'%n_start)
    #if len(QQ)>500:
    #    bars,height = sf.sf_max(QQ,qpeaks=8)
    #    db_x,db_y = sf.dbfactor(msdr=5)
    #    pyplot.plot_bar(bars, height, xlabel=xlabel, ylabel=ylabel,
    #            save=save)
    #    pyplot.plot(db_x, db_y, linestyle='--', xlabel=xlabel, ylabel=ylabel,
    #            save=save)
    #    #return q, s, bars, height, db_x, db_y
    #    return Q, S, primitive_vectors
    #filter out the noise
    Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors,
            filters=filters, save = 'sf%i'%n_start)
    return Q, S, primitive_vectors
예제 #3
0
파일: dna.py 프로젝트: cdknorow/MD
def ipy_single():
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    #initial file
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    delta = 10
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    L_cont = M.box_volume()
    L_cont[-1] = L_cont[-2]
    util.print_box_volume(L_cont,delta=delta)
    last = M.frames
    #V_index = M.get_index(['V'])
    #W_index = M.get_index(['W'])
    try:
        VW = util.pickle_load('VW.pkl')
    except:
         VW=M.cord_auto(['V','W'])
         #VW,Z,W = drift_remove_all(VW,Z,VW,L)
         util.pickle_dump(VW,'VW.pkl')
    #L_last = L_cont[0][0]
    #for i,j in enumerate(L_cont):
    #    if j[0] != L_last:
    #        L_last = j[0]
    #        if i - 5 > 0:
    #            x.append(i-5)
    x = range(0,last)
    index = M.get_index(['C','G'])
    ndna = len(index)/VW.shape[1]
    return [M,VW,L_cont,x,ndna]
예제 #4
0
파일: dna.py 프로젝트: cdknorow/MD
def _connections(M):
    try:
        con = util.pickle_load('conn.pkl')
    except:
        fid = open('conn_who.dat','r')
        c_index = M.get_index(['C'])
        g_index = M.get_index(['G'])
        con = []
        count = 0
        for line in fid.readlines():
            print count
            con_K = []
            con_T = []
            #linker alternates between c g and cc gg
            line = line.replace('}','')
            for i in line.split('{')[1].split():
                #translate connections
                try:
                    con_K.append(c_index.index(int(i)))
                except:
                    print 'error connection was not in list'
            for i in line.split('{')[2].split():
                #translate connections
                try:
                    con_T.append(g_index.index(int(i)))
                except:
                    print 'error connection was not in list'
            con.append([con_K,con_T])
            count += 1
        del con[-1]
        util.pickle_dump(con,'conn.pkl')
    return con
예제 #5
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def species_mixing(V,W,L,n_finish=1,n_start=0,delta=100,rcut=False):
    #The total number of frames we are going to look at
    if rcut == False:
        rcut=min_particle_distance(V[-1:],W[-1:],L)+6
    print rcut
    #rcut = 19
    rcut = 22
    n_frames = (n_finish-n_start)/delta
    x = np.arange(n_start,n_finish,delta)
    s = []
    o = []
    for k in x:
        Same = 0
        Other = 0
        print k
        for i in range(V[k].shape[0]):
            Same += len(nearest_neighbors_point(V[k],V[k][i],L,rcut)[0])
            Same += len(nearest_neighbors_point(W[k],W[k][i],L,rcut)[0])
            Other += len(nearest_neighbors_point(W[k],V[k][i],L,rcut)[0])
            Other += len(nearest_neighbors_point(V[k],W[k][i],L,rcut)[0])
        s.append(float(Same)/(W[k].shape[0]+V[k].shape[0]))
        o.append(float(Other)/(V[k].shape[0]+W[k].shape[0]))
    print s
    print o
    util.pickle_dump([x,s,o],'mix.pkl')
    pyplot.plot2(x, s, x, o, label1='Same',
            label2='other', save=('mixing_avg_cut%.1f'%rcut), showleg=True)
예제 #6
0
파일: NP_simple.py 프로젝트: cdknorow/MD
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')
예제 #7
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
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')
예제 #8
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def run_blah2():
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    surface =  util.pickle_load('surface.pkl')
    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 k in range(bcc.shape[0]):
        for i in range(bcc.shape[1]):
            if crystal[k][i][0] > L[0]:
                bcc[k][i]=0
            else:
                bcc[k][i]=1
    crystal = []
    for k in range(len(bcc)):
        c=[]
        for i in range(len(bcc[k])):
            if bcc[k][i] == 1:
                c.append(i)
        crystal.append(len(c))
    s = []
    for k in range(len(surface)):
        surf = []
        for i in range(len(surface[k])):
            if surface[k][i]:
                surf.append(i)
        s.append(surf)
    util.pickle_dump(s,'surface_diffusion.pkl')
    util.pickle_dump(crystal,'crystal_diffusion.pkl')
    lamda=4
    D=0.05
    ns = []
    dt = 10
    dmdt = []
    C = lamda**2/(D*24)
    start = 100
    finish = 350 
    for k in range(start,finish,dt):
        n = 0
        for i in range(dt):
            n += len(s[i+k]) 
        ns.append(n/dt)

    count = 0
    for i in range(start,finish,dt):
        dm = crystal[i]-crystal[i-dt]
        dmdt.append(C*dm/ns[count])
        count += 1
    x = np.arange(start,finish,dt)
    pyplot.plot(x,dmdt,save='diffusion')
예제 #9
0
파일: NP_simple.py 프로젝트: cdknorow/MD
def self_intermediate_scattering(VW, L, x, n_start=1, 
        filters=0.05, dh=0.05,save='sf',l=5,delta=5,calc=True):
    import MD.analysis.sfactor as sf
    #Find Structure Factor
    if calc:
        import time
        from MD.canalysis.int_scattering import int_scatter
        F = []
        for i in range(delta):
            print i
            print "caculating Average" 
            print VW.shape
            print "Structure Factor" 
            A = VW[n_start+i]
            stmp,qx = sf.sfactor(np.array([A]),L=L[n_start],l=l)
            S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx)
            S,Q,primitive_vectors = sf.sf_filter_max(S,Q,primitive_vectors,filters=0.5)
            index = S.index(max(S))
            k = primitive_vectors[S.index(max(S))]
            #take the average over different starting configurations
            print "Calculating Int Scattering" 
            start = time.clock()
            scat_c = int_scatter(VW[n_start+i:],np.array(L[0]),np.array(k),
                    np.array(x[:-(n_start+i)]))
            end = time.clock()
            print 'cython runtime'
            print end-start
            F.append(scat_c)
        F_avg = np.zeros((len(F[-1])))
        for i in F:
            for j in range(len(F[-1])):
                F_avg[j] += i[j]
        F_avg /= delta
        #reset the zero of x so that the plot starts at the correct time
        x = range(len(F[-1]))
        util.pickle_dump([x,F_avg],'si_scat.pkl')
    xlabel = 't'
    ylabel = 'F(q,t)'
    save = 'int_scatter'
    A = util.pickle_load('si_scat.pkl')
    x = A[0]
    F_avg = A[1]
    #Kohlraush-Williams-Watts function
    # A exp[-(t/tau_b)^beta]
    beta = 1.4
    tau_a = 6
    K = []
    K_x = []
    fid = open('self_scat.dat','w')
    for i in range(len(A[0])):
        fid.write('%i %.4f\n'%(A[0][i],A[1][i]))
    fid.close()
    for i in np.arange(1,len(x),0.1):
        K.append(F_avg[1] * math.exp(-(i/tau_a)**beta))
        K_x.append(i)
예제 #10
0
파일: NP_simple.py 프로젝트: cdknorow/MD
def structure_factor(VW, L, n_frames=10, n_start=1, 
        filters=0.05, dh=0.05,save='sf',l=10):
    import MD.analysis.sfactor as sf
    #Find Structure Factor
    A = Average(VW,L,n_start,n_frames)
    #A = VW[n_start]
    stmp,qx = sf.sfactor(np.array([A]),L=L[n_start],l=l)
    S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx)
    fid = open('sftotal.txt','w')
    fid.write('S  Q\n')
    for i in range(len(S)):
        fid.write('%.5f %.5f\n'%(S[i],Q[i]))
    fid.close()
    #Plot the graph
    xlabel = '$|\\vec{q}$ $|$'
    ylabel = '$S(\\vec{q}$ $)$ '
    #sp4 = 0.634698
    #sp12 = 0.530493
    #sc 1.121997
    #pyplot_eps.plot_sf(Q, S,0.552381, linestyle='', marker='x', 
            #xlabel=xlabel, ylabel=ylabel, save=save,xlen=20)
    pyplot.plot_sf(Q, S,0.552381, linestyle='', marker='x', 
            xlabel=xlabel, ylabel=ylabel, save=save,xlen=20)
    util.pickle_dump(Q,'Vsfx%i.pkl'%n_start)
    util.pickle_dump(S,'Vsfy%i.pkl'%n_start)
    print 'finished reconstruction'
    #if len(QQ)>500:
    #    bars,height = sf.sf_max(QQ,qpeaks=8)
    #    db_x,db_y = sf.dbfactor(msdr=5)
    #    pyplot.plot_bar(bars, height, xlabel=xlabel, ylabel=ylabel,
    #            save=save)
    #    pyplot.plot(db_x, db_y, linestyle='--', xlabel=xlabel, ylabel=ylabel,
    #            save=save)
    #    #return q, s, bars, height, db_x, db_y
    #    return Q, S, primitive_vectors
    #filter out the noise
    Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors,
            filters=filters,save=save)
    import MD.analysis.reconstruct_lattice as rl
    import MD.unit.make_bcc as mb
    con = True
    while con:
        a1,a2,a3 = rl.reconstruct_lattice(Q,primitive_vectors,save+'recipricol.txt')
        print a1,a2,a3
        mb.make_bcc(a1,a2,a3,A[0],L[n_start])
        if raw_input('Reselect? (y)/N') == 'N':
            con = False
    return Q, S, primitive_vectors
예제 #11
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def msd(VW,L,step=1,save='MSD_time',time_scale=1):
    from MD.analysis.msd import msd_no_drift #Find the msd of the system x,msd=msd_no_drift(VW,L,step=step)
    D=0.1
    D2=0.03
    tau=10
    try:
        M = util.pickle_load('msd.pkl')
        x = M[0][0]
        msd = M[1][0]
    except:
        x, msd = msd_no_drift(VW,L)
        x = x*time_scale
        util.pickle_dump([[x],[msd]],'msd.pkl')
    #msd_fit
    fit = []
    for i in x:
        fit.append((2*3*D2*(i) - tau*(1-math.e**(-i/tau)))**0.5)
    msd2 = (6*D*x)**0.5
    pyplot.plot(x,msd,xlabel='Time',ylabel='msd',save=save)
예제 #12
0
파일: qlattice.py 프로젝트: cdknorow/MD
def structure_factor(VW, L, n_frames=10, n_start=1, 
        filters=0.05, dh=0.05,save='sf',l=10):
    import MD.analysis.sfactor as sf
    #Find Structure Factor
    #Average_position
    stmp,qx = sf.sfactor(np.array([VW]),L=L,l=l)
    S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx)
    #Plot the graph
    xlabel = '$|\\vec{q}$ $|$'
    ylabel = '$S(\\vec{q}$ $)$ '
    pyplot.plot(Q, S, linestyle='', marker='x', 
            xlabel=xlabel, ylabel=ylabel, save=save)
    util.pickle_dump(Q,'Vsfx%i.pkl'%n_start)
    util.pickle_dump(S,'Vsfy%i.pkl'%n_start)
    print 'finished reconstruction'
    Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors,
            filters=filters,save=save)
    print 'sorting peaks'
    return Q, S, primitive_vectors
예제 #13
0
파일: defects.py 프로젝트: cdknorow/MD
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')
예제 #14
0
def get_crystals():
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    #initial file
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    delta = 10
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    L_cont = M.box_volume()
    L_cont[-1] = L_cont[-2]
    last = M.frames
    try:
        VW = util.pickle_load('VW.pkl')
    except:
         VW=M.cord_auto(['V','W','A0','A1'])
         util.pickle_dump(VW,'VW.pkl')
    #######################################
    delta = 1
    x = range(0,last-2*delta,delta)
    C = np.zeros((len(x),VW.shape[1]),dtype=int)
    os.mkdir('imd_trajectory')
    os.chdir('imd_trajectory')
    for i,k in enumerate(x):
        A = Average(VW,L_cont,k,delta)
        util.print_imd(np.array([A]),L_cont,k)
        ovitojs(k)
        os.system('ovito --script ovito.js --nogui')
        name = 'data'+'%i'%(k)+'.dump'
        fid = open(name,'r')
        for j in range(9):
            fid.readline()
        for j, line in enumerate(fid.readlines()):
            C[i][j] = int(line.split()[0])
        fid.close()
    os.chdir('../')
    crystal_count(C,delta)
예제 #15
0
def solid_particles(VW, L, VW_names, x, avg=1, step=5e4, bcc = True, sc = False, GenLattice = False):
    solid_particles = []
    solid_crystals = []
    try:
        solid_crystals = util.pickle_load('spcrystal.pkl')
        solid_particles = util.pickle_load('solidp.pkl')
    except:
        for k in x:
            print 'step', k
            A = av.average_position(VW,k,avg,L)
            if bcc:
                num, crystals = (bond_order.solid_particles(A,
                                L[k],c_cut=0.15, count=8,l=6,crystal=7))
            if sc:
                num, crystals = (bond_order.solid_particles(VW[k],
                                L[k],c_cut=0.175, count=6,l=4,crystal=5))
            solid_crystals.append(crystals)
            solid_particles.append(num)
        util.pickle_dump(solid_crystals,'spcrystal.pkl')
        util.pickle_dump(solid_particles,'solidp.pkl')

    fid = open('solidpart.txt','w')
    for i in range(len(x)):
        fid.write('%i %i %.2f\n'%(x[i], solid_particles[i], L[x[i]][0]))
    fid.close()

    if GenLattice:
        # make an xyz file of the crystals and there locations
        f = open('solidpcrystals.xyz','w')
        count=0
        for k in x:
            f.write(('%i \n\n')%(VW.shape[1]))
            for i in range((len(solid_crystals[count]))):
                if solid_crystals[count][i] == 1:
                        f.write(('%c %.2f %.2f %.2f \n')%('V',VW[k][i][0],VW[k][i][1],VW[k][i][2]))
                else:
                        f.write(('%c %.2f %.2f %.2f\n')%('W',4*L[k][0],4*L[k][0],4*L[k][0]))
            count += 1
        f.close()
    return x, solid_particles
예제 #16
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def msd_jump(VW,L):
    reload(diffuse)
    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))
    x = range(50,500,50)
    delta = 50
    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
    jumps = []
    for i in x:
        jumps.extend(diffuse.crystal_jump(VW,bcc,L,i,delta))
    print len(jumps)
    import MD.plot.pyplot_eps as pyplot_eps
    util.pickle_dump(jumps,'jump.pkl')
    hist_s,xs=histogram_reg(jumps,bins=20)
    pyplot_eps.plot_bar(xs,hist_s,xlabel=r'$\sigma$',ylabel='count',save='jump_hist')
예제 #17
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def msd_jump_average(VW,L):
    reload(diffuse)
    try:
        jump_d = util.pickle_load('jump_d.pkl')
        jump_t = util.pickle_load('jump_t.pkl')
    except:
        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
        jump_d, jump_t = diffuse.crystal_jump(VW,bcc,L)
        util.pickle_dump(jump_d,'jump_d.pkl')
        util.pickle_dump(jump_t,'jump_t.pkl')
    pyplot.plot(jump_t,jump_d,'','s',xlabel='time',ylabel='jump distance',save='msd_jump')
    hist_s,xs,max_hist=histogram(jump_d,bins=20)
    pyplot.plot(xs,hist_s,xlabel='distance',ylabel='count',save='jump_hist')
예제 #18
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def run_defect():
    #setup
    #print out directory
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    try:
        var = MD.util.get_path_variables()
    except:
        var = {'ndna':60}
    print var
    M=MD.ReadCord()
    L = M.box_length
    last = M.frames
    try:
        V = util.pickle_load('V.pkl')
        W = util.pickle_load('W.pkl')
        R = util.pickle_load('R.pkl')
        VW = util.pickle_load('VW.pkl')
    except:
        V=M.cord_auto(['V'])
        W=M.cord_auto(['W'])
        R=M.cord_auto(['R'])
        VW=M.cord_auto(['V','W'])
        VW,V,W = drift_remove_all(VW,V,W,L)
        R = drift_remove(R,L)
        util.pickle_dump(V,'V.pkl')
        util.pickle_dump(W,'W.pkl')
        util.pickle_dump(VW,'VW.pkl')
        util.pickle_dump(R,'R.pkl')
    x = range(0,last,last/5)
    #mylog()
    #plt.close()
    solid_particles_vmd(VW,V,W,L,var,skip=100)
    plt.close()
    #species_mixing(V,W,L,n_finish=last)
    #plt.close()
    #species_mixing_fcc(VW,L,n_finish=last)
    #plt.close()
    for i in x:
        #print "finding s(q)"
        structure_factor(VW, L, var, n_start=i,save='sf'+str(i))
        print "finding g(s)"
        distance_distribution(V,W,L,n_start=i)
        plt.close()
    msd(VW,L)
    plt.close()
    msd(R,L,save='msd_R')
    plt.close()
예제 #19
0
파일: dna.py 프로젝트: cdknorow/MD
def find_networks(M, VW, L,x,ndna=25):
    import MD.canalysis.connections as con
    import MD.analysis.connections as conn
    import MD.analysis.graph as graph
    #plot total number of connections
    connections = _connections(M)
    num_connections=conn.num_connections(connections,VW.shape[1])
    con_all = []
    for i in range(len(connections)):
        con_all.append(len(connections[i][0]))
    print len(x),len(num_connections)
    pyplot.plot(x,num_connections,xlabel='Time',
            ylabel='hyrbid. density', save='connections')
    pyplot.plot(x,con_all,xlabel='Time',
            ylabel='hyrbid', save='connections_all')
    plt.close()
    #get the info
    networks, num_networks, deg, neighbors, num_n, gr = graph.grapher(connections,VW.shape[1],ndna)
    util.pickle_dump(networks,'net.pkl')
    #plot the number of neighbors at each timesteps
    pyplot.plot(x,num_n,xlabel='Time',
            ylabel='num neighbors', save='neighbors')
    plt.close()
    print 'making plot'
    net = []
    for i in networks:
        net.append(len(i))
    pyplot.plot(x,net,xlabel='t',ylabel='networks',save='net')
    label = ['networks','1','2','3','4','5','6','7','8','9']
    x = [x for i in range(len(deg))]
    #pyplot.plot(x,num_networks,xlabel='t',ylabel='Networks',save='net')
    #pyplot.plot_multi(x[:4],deg[:4],label,xlabel='time',ylabel='number',save='con_net')
    plt.close()
    return networks, num_networks, deg, neighbors, num_n, gr

    #pyplot.plot_multi(x[:4],deg[:4],label,xlabel='time',ylabel='number',save='con_net')
    plt.close()
    return networks, num_networks, deg, neighbors, num_n, gr
예제 #20
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def run_test():
    #print out directory dirname = os.getcwd().partition('/')[-1]
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    print L
    last = M.frames
    delta = 25
    try:
        V = util.pickle_load('V.pkl')
        W = util.pickle_load('W.pkl')
        VW = util.pickle_load('VW.pkl')
    except:
        #V=M.cord_range(['V'],delta=delta)
        #W=M.cord_range(['W'],delta=delta)
        #VW=M.cord_range(['V','W'],delta=delta)
        V=M.cord_auto(['V'])
        W=M.cord_auto(['W'])
        VW=M.cord_auto(['V','W'])
        VW_index=M.get_names(['V','W'])
        VW,V,W = drift_remove_all(VW,V,W,L,VW_index)
        util.pickle_dump(V,'V.pkl')
        util.pickle_dump(W,'W.pkl')
        util.pickle_dump(VW,'VW.pkl')
    if V.shape[0]>5:
        x = range(0,V.shape[0],V.shape[0]/3)
    else:
        x = range(V.shape[0])
    delta = 1
    #step,temp = mylog(row = 2)
    #plt.close()
    mylog_average(row = 1,delta=20)
    msd(VW,L,time_scale=delta)
    print V
    #msd_phases(VW,L)
    #msd_jump(VW,L)
    #sd_index(VW,L)
    #jump_lattice(VW,L)
    #solid_particles_vmd(VW,V,W,L,M,skip=25)
    #solid_particles_vmd(VW[1000:],V[1000:],W[1000:],L,var,skip=10)
    #plt.close()
    #species_mixing(V,W,L,n_finish=last)
    #plt.close()
    #end_end(V,W,M,L)
    ##plt.close()
    for i in x:
        print "finding s(q)"
        structure_factor(VW, L, n_start=i,save='sf'+str(i))
        #structure_factor(V, L, n_start=i,save='sfV'+str(i))
        #structure_factor(W, L, n_start=i,save='sfW'+str(i))
        print "finding g(s)"
        distance_distribution(V,W,L,n_start=i)
        plt.close()
예제 #21
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def find_networks(M, VW, L, n_finish=1, n_start=0, delta=30, rcut=1.0, ndna=25):
    #The total number of frames we are going to look at
    x=np.arange(n_start,n_finish,delta)
    print len(x)
    #Find the number of connections at specific points x
    import MD.canalysis.connections as con
    import MD.analysis.connections as conn
    import MD.analysis.graph as graph
    try:
        connections = util.pickle_load('con.pkl')
    except:
        try:
            C = util.pickle_load('C.pkl')
            G = util.pickle_load('G.pkl')
        except:
            G=M.cord_auto(['G'])
            C=M.cord_auto(['C'])
            util.pickle_dump(C,'C.pkl')
            util.pickle_dump(G,'G.pkl')
        connections = con.connections(C[x],G[x],L,rcut=rcut)
        util.pickle_dump(connections,'con.pkl')
    #plot total number of connections
    num_connections=conn.num_connections(connections,VW.shape[1])
    con_all = []
    for i in range(len(connections)):
        con_all.append(len(connections[i])/2.)
    pyplot.plot(x,num_connections,xlabel='Time',
            ylabel='hyrbid. density', save='connections')
    pyplot.plot(x,con_all,xlabel='Time',
            ylabel='hyrbid', save='connections_all')
    plt.close()
    #get the info
    networks, num_networks, deg, neighbors, num_n, gr = graph.grapher(connections,VW.shape[1],ndna)
    util.pickle_dump(networks,'net.pkl')
    #plot the number of neighbors at each timesteps
    pyplot_eps.plot(x,num_n,xlabel='Time',
            ylabel='num neighbors', save='neighbors')
    plt.close()
    print 'making plot'
    net = []
    for i in networks:
        net.append(len(i))
    pyplot_eps.plot(x,net,xlabel='t',ylabel='networks',save='net')
    label = ['networks','1','2','3','4','5','6','7','8','9']
    pyplot_eps.plot(x,networks,xlabel='t',ylabel='Networks',save='net')
    pyplot.plot_multi(x,deg,label,xlabel='time',ylabel='number',save='con_net')
    return x, networks, connections
예제 #22
0
파일: NP_sphere.py 프로젝트: cdknorow/MD
def find_lifetime(M,L,steps,temp,step_range=30,delta=4,rcut=1.0,step=5e4):
    import MD.analysis.lifetime as life
    try:
        C = util.pickle_load('C.pkl')
        G = util.pickle_load('G.pkl')
    except:
        C=M.cord_auto(['C'])
        G=M.cord_auto(['G'])
        util.pickle_dump(C,'C.pkl')
        util.pickle_dump(G,'G.pkl')
    #The total number of frames we are going to look at
    for i in steps:
        try:
            print 'Frame',i,'Temp',temp[i]
        except:
            print i
        x=np.arange(i,step_range+i,delta)
        #Find he number of connections at specific points x
        remain = life.lifetime(C[x],G[x],L)
        x=np.arange(i,step_range+i,delta)*50000
        print remain
        pyplot_eps.plot(x,remain,xlabel='time', ylabel='remaining connections',
                save='lifetime%i'%i)
        plt.close()
예제 #23
0
파일: animate.py 프로젝트: cdknorow/MD
def animate_binary(frames=[0,1]):
    #print out directory
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = M.box_volume()
    last = M.frames
    try:
        Z = util.pickle_load('Z.pkl')
        VW = util.pickle_load('VW.pkl')
        npType = M.get_type(['V','W'])
    except:
        Z=M.cord_auto(['Z'])
        VW=M.cord_auto(['V','W'])
        npType = M.get_type(['V','W'])
        util.pickle_dump(Z,'Z.pkl')
        util.pickle_dump(VW,'VW.pkl')
    for k in frames:
    #apply boundary conditions to move particle
        for i in range(VW.shape[1]):
            for j in range(i*6,i*6+6):
                Z[k][j] = boundary(Z[k][j],VW[k][i],L[k])
    util.pickle_dump(Z,'Zbound.pkl')
    animate_script = open('animate/animate.tcl','w')
    #for binary systems use this A
    #fid = open('sc_num.txt','r')
    #crystal = []
    #for line in fid.readlines():
    #    crystal.append(float(line.split()[0]))
    #fid.close()
    A = []
    for i in range(VW.shape[1]):
        if npType[i] == 'V':
            A.append(0)
        else:
            A.append(1)
    for k in frames:
        fid = open('animate/square%i.tcl'%k,'w')
        for i in range(VW.shape[1]):
            c = VW[k][i]
            #v1 = Z[k][i*6] - c
            #v2 = Z[k][i*6+2] - c
            #v3 = Z[k][i*6+4] - c
            v1 = Z[k][i*6] - c
            v2 = Z[k][i*6+1] - c
            v3 = Z[k][i*6+5] - c
            #v1,v2,v3 = allign(v1,v2,v3)
            color = ['blue','red','green','orange','purple']
            dw.draw_cube(fid,c,v1,v2,v3,color[int(A[i])])
        cub.gaussmap_color(VW,Z,L,k,A)
        animate_script.write('\nsource square%i.tcl\n display update ui\n'%k)
        animate_script.write('\nafter 1000\ndraw delete all\n display update ui\n')
        fid.close()
예제 #24
0
파일: animate.py 프로젝트: cdknorow/MD
def animate(frames=[0,1]):
    #print out directory
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = M.box_volume()
    last = M.frames
    try:
        Z = util.pickle_load('Z.pkl')
        VW = util.pickle_load('VW.pkl')
    except:
        Z=M.cord_auto(['Z'])
        VW=M.cord_auto(['V','W'])
        util.pickle_dump(Z,'Z.pkl')
        util.pickle_dump(VW,'VW.pkl')
    cubic_order_animate(VW,Z,L,frames)
    for k in frames:
    #apply boundary conditions to move particle
        for i in range(VW.shape[1]):
            for j in range(i*6,i*6+6):
                Z[k][j] = boundary(Z[k][j],VW[k][i],L[k])
    util.pickle_dump(Z,'Zbound.pkl')
    animate_script = open('animate/animate.tcl','w')
    #for binary systems use this A
    #A = []
    #for i in range(VW.shape[1]):
    #    if i < VW.shape[1]/2:
    #        A.append(0)
    #    else:
    #        A.append(1)
    #for k in range(len(VW.shape[0])):
    for k in frames:
        fid = open('animate/square%i.tcl'%k,'w')
        fid2= open('animate/square%i.txt'%k,'w')
        A = read_color_index(frame=k)
        for i in range(VW.shape[1]):
            c = VW[k][i]
            v1 = Z[k][i*6] - c
            v2 = Z[k][i*6+2] - c
            v3 = Z[k][i*6+4] - c
            #v1 = Z[k][i*6] - c
            #v2 = Z[k][i*6+1] - c
            #v3 = Z[k][i*6+5] - c
            #v1,v2,v3 = allign(v1,v2,v3)
            color = ['blue','red','green','orange','purple']
            dw.draw_cube(fid,fid2,c,v1,v2,v3,color[int(A[i])])
        cub.gaussmap_color(VW,Z,L,k,A)
        animate_script.write('\nsource square%i.tcl\n display update ui\n'%k)
        animate_script.write('\nafter 1000\ndraw delete all\n display update ui\n')
        fid.close()
예제 #25
0
파일: dna.py 프로젝트: cdknorow/MD
def end_end_connected(M,L): #find the length of the polymer
    ## \brief end to end distance of hybridized vs nonhybridized polymers
    #
    # \returns average distance from start to end of polymer 
    #           for hybridizations and free polymer
    #
    # \param M - ReadCord Class  
    # \param L 
    #
    # V ----- A C k
    # W ----- F G T
    import MD.analysis.connections as con
    try:
        K=util.pickle_load('K.pkl')
        T=util.pickle_load('T.pkl')
        S=util.pickle_load('S.pkl')
    except:
        K=M.cord_auto(['K'])
        T=M.cord_auto(['T'])
        S=M.cord_auto(['M'])
        util.pickle_dump(K,'K.pkl')
        util.pickle_dump(T,'T.pkl')
        util.pickle_dump(S,'S.pkl')
    #get connections
    con = _connections(M)
    h_sum = []
    f_sum = []
    for k in range(len(con)):
        print k
        hybrid = []
        free = []
        #get the points that are not connected
        for i in range(K.shape[1]):
            if i in con[k][0]:
                hybrid.append(points.dist(K[k][i],S[k][i],L[k])[0]+0.5)
            else:
                free.append(points.dist(K[k][i],S[k][i],L[k])[0]+0.5)
        for i in range(T.shape[1]):
            if i in con[k][1]:
                hybrid.append(points.dist(T[k][i],S[k][i+K.shape[1]],L[k])[0]+0.5)
            else:
                free.append(points.dist(T[k][i],S[k][i+K.shape[1]],L[k])[0]+0.5)
        print hybrid
        h_sum.append(sum(hybrid)/len(hybrid))
        f_sum.append(sum(free)/len(free))
    f_sum[-1]= f_sum[-2]
    h_sum[-1]= h_sum[-2]
    x = range(S.shape[0])
    pyplot.plot2(x,h_sum,x,f_sum,xlabel='timestep',ylabel='sigma',label1='hybridizations',
        label2='free',save='free_hybrid_end_end_connections',showleg='true')
예제 #26
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
예제 #27
0
파일: NP_binary.py 프로젝트: cdknorow/MD
def run_binary():
    #print out directory dirname = os.getcwd().partition('/')[-1]
    dirname = os.getcwd().partition('/')[-1]
    print "Starting:",dirname.split('/')[-1]
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    print L
    last = M.frames
    L_cont = M.box_volume()
    try:
        V = util.pickle_load('V.pkl')
        W = util.pickle_load('W.pkl')
        VW = util.pickle_load('VW.pkl')
    except:
        #delta = 25
        #V=M.cord_range(['V'],delta=delta)
        #W=M.cord_range(['W'],delta=delta)
        #VW=M.cord_range(['V','W'],delta=delta)
        V=M.cord_auto(['V'])
        W=M.cord_auto(['W'])
        VW=M.cord_auto(['V','W'])
        VW_index=M.get_names(['V','W'])
        #VW,V,W = drift_remove_all(VW,V,W,L,VW_index)
        util.pickle_dump(V,'V.pkl')
        util.pickle_dump(W,'W.pkl')
        util.pickle_dump(VW,'VW.pkl')
    delta = 30
    x = range(0,V.shape[0],delta)
    print V.shape[0]
    print x
    #plt.close()
    msd(VW,L,time_scale=delta)
    type_ordering(VW,L_cont)
예제 #28
0
파일: NP_simple.py 프로젝트: cdknorow/MD
def run_():
    #setp
    dirname = os.getcwd().partition('/')[-1] 
    print "Starting:",dirname.split('/')[-1]
    M=MD.ReadCord()
    Lx = M.box_length
    Ly = M.box_length_y
    Lz = M.box_length_z
    L = np.array([Lx, Ly, Lz])
    L_cont = M.box_volume()
    L_cont[-1] =L_cont[-2]
    last = M.frames
    new = False
    try:
        V = util.pickle_load('V.pkl')
        if V.shape[0] != last:
            print 'generating new pickle'
            asdf
        #Z = util.pickle_load('Z.pkl')
    except:
        #V=M.cord_auto(['V','W'])
        new = True
        V=M.cord_auto(['V'])
        if V.shape[1] < 1:
            V=M.cord_auto(['A','A0','A1'])
        #Z=M.cord_auto(['Z'])
        #VW_index=M.get_names(['V','W'])
        #Z_index=M.get_names(['Z'])
        #V = drift_remove(V,L,VW_index)
        #Z = drift_remove(Z,L,Z_index)
        #dump_xyz(V)
        #dump_xyz(Z)
        util.pickle_dump(V,'V.pkl')
        #util.pickle_dump(Z,'Z.pkl')
    # if (os.path.isfile('msd.pkl') is False):
    #    msd(V,L)
    print V
    asdf
    x, xcount = util.get_box_size_steps(L_cont)
    print x
    x_set = []
    n_frames = []
    print xcount
    print x
    #F = filter(lambda x: x > 10, xcount)
    for i in range(len(xcount)):
        if xcount[i] > 10:
            x_set.append(x[i])
            n_frames.append(xcount[i]-10)
    print n_frames
    print x_set

    f = h5py.File('../pmf_dist.hdf5','w')
    for j,i in enumerate(x_set):
        if  i + n_frames[j] <= V.shape[0]:
            if L_cont[i] == L_cont[i+n_frames[j]]:
                print "L = ",L_cont[i][0]
                print "rho = ",V.shape[1]/L_cont[i][0]**3
                print "frame = ", i 
                print "n_frame", n_frames[j]
                PMF(f, V,L_cont[i],n_start=i,n_frames=n_frames[j])
            else:
                print "L is not the same reduce the n_frames"
    f.close()
예제 #29
0
 import MD
 from MD.dna_scripts.square import drift_remove_all
 print 'MD.L is '
 M=readxyz.ReadCord(trajectory = 'surface.xyz',frames=777)
 last = 777
 MD.L = [103.85,103.85,103.84]
 MD.last = last
 try:
     MD.V = util.pickle_load('Vs.pkl')
     MD.W = util.pickle_load('Ws.pkl')
     MD.VW = util.pickle_load('VWs.pkl')
 except:
     MD.V = M.cord_auto(['V'])
     MD.W = M.cord_auto(['W'])
     MD.VW = M.cord_auto(['V','W'])
     util.pickle_dump(MD.V,'Vs.pkl')
     util.pickle_dump(MD.W,'Ws.pkl')
     util.pickle_dump(MD.VW,'VWs.pkl')
 CV = util.pickle_load('CV.pkl')
 CW = util.pickle_load('CW.pkl')
 try:
     print 'attempting to load DW, DV'
     DV = util.pickle_load('DV_s.pkl')
     DW = util.pickle_load('DW_s.pkl')
     plot_def = util.pickle_load('plot_def_s.pkl')
 except:
     print 'finding the defects'
     DV, DW, plot_def =  find_defects_mod(CW,CV,MD.VW,MD.V,MD.W,MD.L,n_finish=MD.last-1,n_start=0,delta=1)
 plots = util.pickle_load('plot_def.pkl')
 for index,k in enumerate(x):
     Vn = []
예제 #30
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]