def show_cell(file,
              n=[0, 0, 1],
              bopt=1,
              x0=[0, 0, 0],
              rep=[1, 1, 1],
              **kwargs):
    crys = Crystal.from_cif(file)
    tail = ''.join(np.array(n, dtype=str))
    n = get_vec(n, crys, bopt)

    #unit cells,lattice vectors,atom coordinates
    cell_mesh = crys.mesh(range(rep[0] + 1), range(rep[1] + 1),
                          range(rep[2] + 1))
    surfs = get_unit_cell(cell_mesh, n)
    uvw = rcc.orient_crystal(np.array(crys.lattice_vectors), n_u=n, T=True)
    pattern, lat_params = APAP_xyz(name, n, rep, dopt='s', tail=tail)
    E, X, Y, Z = pattern[:, :4].T
    scat = [X, Y, Z, [cs[int(e)] for e in E]]

    scat2 = []
    # pattern2,lat_params = APAP_xyz(name,n,rep,dopt='')
    # E2,X2,Y2,Z2 = pattern2[:,:4].T
    # scat2       = [X2,Y2,Z2, [cs[int(e)] for e in E2]];#print(E2)

    #display options
    c1, c2, c3 = (X.min() + X.max()) / 2, (Y.min() + Y.max()) / 2, (
        Z.min() + Z.max()) / 2
    w = 0.75 * max(X.max() - X.min(), Y.max() - Y.min(), Z.max() - Z.min())
    xylims = [
        c1 - w / 2, c1 + w / 2, c2 - w / 2, c2 + w / 2, c3 - w / 2, c3 + w / 2
    ]
    fig, ax = dsp.stddisp(scat=scat, ms=100, surfs=surfs, rc='3d', std=0)
    rcc.show_trihedron(ax,
                       uvw=uvw,
                       x0=[0, 0, 0],
                       cs=['r', 'g', 'b'],
                       labs=['$a$', '$b$', '$c$'],
                       lw=2,
                       rc=0.1,
                       h=0.2)
    rcc.show_trihedron(ax,
                       x0=x0,
                       labs=['$x$', '$y$', '$z$'],
                       lw=2,
                       rc=0.1,
                       h=0.2)
    dsp.stddisp(ax=ax,
                ms=50,
                scat=scat2,
                xylims=xylims,
                axPos=[0, 0, 1, 1],
                pOpt='eXp',
                **kwargs)

    hdl = handler_3d(fig, persp=False)
示例#2
0
 def show_Fhkl(self, s=None, opts='m', h3D=0, **kwargs):
     '''Displays structure factor over grid
     - opts : see get_fz
     - s : slice or str('k=0' => Fhkl(k=0)) or int('l==<int>')
     '''
     fz, fz_str = get_fz(opts)
     s, s_str = self._get_slice(s)
     tle = 'Structure factor($\AA$), showing %s in %s' % (fz_str, s_str)
     h, k, l = self.hklF
     Fhkl = self.Fhkl  #.copy()
     if isinstance(s, tuple):
         Fhkl = Fhkl[s]
         nx, ny = np.array((np.array(Fhkl.shape) - 1) / 2, dtype=int)
         i, j = np.meshgrid(np.arange(-nx, nx + 1), np.arange(-ny, ny + 1))
         fig, ax = dsp.stddisp(scat=[i, j, fz(Fhkl)], title=tle, **kwargs)
     else:
         fig, ax = dsp.stddisp(scat=[h, k, l, fz(self.Fhkl)],
                               title=tle,
                               rc='3d',
                               **kwargs)
         if h3D: h3d.handler_3d(fig, persp=False)
示例#3
0
def show_cell(file,
              n=[0, 0, 1],
              bopt=1,
              x0=None,
              rep=[1, 1, 1],
              h3D=1,
              xylims=None,
              axPos=[],
              **kwargs):
    '''Show unit cell and coords from cif file '''
    crys = Crystal.from_cif(file)
    n = get_vec(n, crys, bopt)

    #unit cells,lattice vectors,atom coordinates
    cell_mesh = crys.mesh(range(rep[0] + 1), range(rep[1] + 1),
                          range(rep[2] + 1))
    surfs = get_unit_cell(cell_mesh, n)
    uvw = rcc.orient_crystal(np.array(crys.lattice_vectors), n_u=n, T=True)
    pattern = import_cif(file, n=n, rep=rep)
    E, X, Y, Z = pattern[:, :4].T
    scat = [X, Y, Z, [cs[int(e)] for e in E]]

    #display options
    if x0 == None: x0 = -1
    if isinstance(x0, float) or isinstance(x0, int): x0 = np.array([x0] * 3)
    if not xylims:
        c1, c2, c3 = (X.min() + X.max()) / 2, (Y.min() + Y.max()) / 2, (
            Z.min() + Z.max()) / 2
        w = 0.75 * max(X.max() - X.min(), Y.max() - Y.min(), Z.max() - Z.min())
        xylims = [
            c1 - w / 2, c1 + w / 2, c2 - w / 2, c2 + w / 2, c3 - w / 2,
            c3 + w / 2
        ]
        # print(xylims)
    if not axPos: axPos = [0, 0, 1, 0.95]
    fig, ax = dsp.stddisp(scat=scat, ms=100, surfs=surfs, rc='3d', std=0)
    show_trihedron(ax,
                   uvw=uvw,
                   x0=[0, 0, 0],
                   cs=['r', 'g', 'b'],
                   labs=['$a$', '$b$', '$c$'],
                   lw=2,
                   rc=0.1,
                   h=0.2)
    show_trihedron(ax, x0=x0, labs=['$x$', '$y$', '$z$'], lw=2, rc=0.1, h=0.2)
    dsp.stddisp(ax=ax, xylims=xylims, axPos=axPos, pOpt='Xpt', **kwargs)

    if h3D: hdl = h3d.handler_3d(fig, persp=False)
示例#4
0
    def show_ewald_sphere(self,frame=None,Smax=0.01,Nmax=10,h3d=0,
        nts=100,nps=200,**kwargs):
        K = self.get_beam(frame)
        Kx,Ky,Kz = K

        (h,k,l),(qx,qy,qz) = self.get_lattice(Nmax)
        x,y,z = self.get_ewald(frame,nts,nps)
        df    = self.get_excitation_errors(frame,Smax=Smax,Nmax=Nmax)

        print('small excitation error beams',uvw)
        if frame:print('frame %d:' %frame)
        print(df[['h','k','l']])

        scat = ([qx,qy,qz,5,'b','o'],[0,0,0,'r','s'])
        scat+= ([df.qx,df.qy,df.qz,50,'g','s'],)
        surf = [x,y,z,{'alpha':0.4,'color':'r'}]
        plts = [[0,Kx],[0,Ky],[0,Kz],'r']
        # scat+=([x0,y0,z0])
        fig,ax = dsp.stddisp(plts,scat=scat,surfs=[surf],lw=3,
            labs=['x','y','z'],rc='3d',**kwargs)
        if h3d:h3d = h3D.handler_3d(fig,persp=False)
示例#5
0
    def compare_xyz_pxpy(self,frame=32,opts='oa',view=[90,90],**kwargs):
        rpl0    = self.rpl.loc[self.rpl.F==frame]
        pxc,pyc = self.cen.iloc[frame-1][['px','py']].values.T
        alpha   = rpl0.alpha.iloc[0]

        px,py = rpl0[['px','py']].values.T
        px    =  self.aper*(px-pxc)
        py    = -self.aper*(py-pyc)
        xyz0  = np.vstack([px,py,np.zeros(px.shape)])

        R = np.identity(3)
        if 'o' in opts:
            omega_r = np.deg2rad(self.omega)
            ct,st  = np.cos(omega_r),np.sin(omega_r)
            Romega = np.array([[ct,st,0],[-st,ct,0],[0,0,1]]) #get_crystal_rotation(u=[0,0,-1],alpha=self.omega)
            R = Romega
        if 'a' in opts:
            alpha_r = np.deg2rad(alpha)
            ct,st   = np.cos(alpha_r),np.sin(alpha_r)
            Ra = np.array([[1,0,0],[0,ct,st],[0,-st,ct]])
            R  = Ra.dot(R)
        x0,y0,z0  = R.dot(xyz0)

        xyz   = rpl0[['x','y','z']].values.T
        x,y,z = xyz

        Im = np.array(rpl0.Im.values/10,dtype=int)
        if isinstance(view,str):
            if   view=='x':labs,scat = ['y','z'],([y,z,Im,'b','o'],[y0,z0,Im,'r','o'])
            elif view=='y':labs,scat = ['x','z'],([x,z,Im,'b','o'],[x0,z0,Im,'r','o'])
            elif view=='z':labs,scat = ['x','y'],([x,y,Im,'b','o'],[x0,y0,Im,'r','o'])
            dsp.stddisp(xylims=1.5,scat=scat,labs=labs,legElt={'pxpy':'bo','xyz':'ro'},**kwargs)
        else:
            scat = ([x,y,z,Im,'b','o'],[x0,y0,z0,Im,'r','o'])
            fig,ax  = dsp.stddisp(rc='3d',view=view,xylims=1.5,scat=scat,labs=['x','y','z'],**kwargs)
            h3d = h3D.handler_3d(fig,persp=True)
示例#6
0
 def show_hkl(self,**kwargs):
     h,k,l,I = self.HKL[['h','k','l','I']].values.T
     fig2,ax = dsp.stddisp(rc='3d',scat=[h,k,l,I,'b'],labs=['h','k','l'],**kwargs)
     h3d2 = h3D.handler_3d(fig2,persp=False)
示例#7
0
 def show_xyz(self,**kwargs):
     x,y,z = self.XYZ
     fig2,ax = dsp.stddisp(rc='3d',scat=[x,y,z,2,'b'],labs=['x','y','z'],**kwargs)
     h3d2 = h3D.handler_3d(fig2,persp=False)