示例#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
文件: 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
示例#3
0
文件: primitive.py 项目: cdknorow/MD
import os
import sys
import numpy as np
sys.path.append('/home/cdknorow/Dropbox/Software')
import MD
import MD.unit.make_bcc as make_bcc




b1 = np.array([0.0,0.0,0.0])
p1 = np.array([-5.164,12.86,5.1])
p2 = np.array([9.311,10.361,4.205])
p3 = np.array([-4.126,10.339,-9.335])

a1 = p1-b1
a2 = p2-b1
a3 = p3-b1
b1 = np.array([-6.58,-3.91,7.6])
basis = b1
count = 0
for basis in [b1]:
    L = [67,67,67]
    VW, VW_names = make_bcc.make_bcc(a1,a2,a3,basis,L,S=5,name='bcc_unit%i.xyz'%count)
    count+=1
    import pickle
    output = open('bcc_unit.pkl','wb')
    S=pickle.dump(VW,output)
    output.close()