Beispiel #1
0
def calc_A_P_Q(Qmax, g_inv, surface_tmp, parameter, param_usage, use_bulk_water, use_lay_el):
    global_parms, surface = param_unfold(parameter, param_usage, surface_tmp, use_bulk_water, use_lay_el)
    natoms = len(surface)
    occ_el, K, sig_el, sig_el_bar, d_el, d0_el, sig_water, sig_water_bar, d_water, zwater, Scale, specScale, beta = (
        global_parms
    )
    A = []
    P = []
    L = Num.arange(0.1, Qmax, 0.01)
    for l in L:
        Q = Num.array([0, 0, l], float)
        Q_ang = Num.array([0, 0, l * g_inv[2][2] ** 0.5], float)
        re_Fq = 0
        im_Fq = 0
        for n in range(natoms):
            R = Num.array([surface[n][1], surface[n][2], surface[n][3]], float)

            U = Num.ndarray((3, 3), float)
            U[0][0] = surface[n][4]
            U[0][1] = U[1][0] = surface[n][7] * (surface[n][4] * surface[n][5]) ** 0.5
            U[0][2] = U[2][0] = surface[n][8] * (surface[n][4] * surface[n][6]) ** 0.5
            U[1][1] = surface[n][5]
            U[1][2] = U[2][1] = surface[n][9] * (surface[n][5] * surface[n][6]) ** 0.5
            U[2][2] = surface[n][6]

            theta = surface[n][10]
            re_Fq = re_Fq + (
                theta
                * Num.cos(2 * Num.pi * (Q[0] * R[0] + Q[1] * R[1] + Q[2] * R[2]))
                * Num.exp(-2 * Num.pi ** 2 * Num.dot(Num.dot(Q_ang, U), Q_ang))
            )
            im_Fq = im_Fq + (
                theta
                * Num.sin(2 * Num.pi * (Q[0] * R[0] + Q[1] * R[1] + Q[2] * R[2]))
                * Num.exp(-2 * Num.pi ** 2 * Num.dot(Num.dot(Q_ang, U), Q_ang))
            )
        if use_lay_el:
            re_lay, im_lay = calc_F_lay_el(Q, occ_el, K, sig_el, sig_el_bar, d_el, d0_el, g_inv)
            re_Fq = re_Fq + re_lay
            im_Fq = im_Fq + im_lay

        PR = Num.arctan(im_Fq / re_Fq) / (2 * Num.pi)
        AR = re_Fq / Num.cos(2 * Num.pi * PR)

        if AR < 0 and PR < 0.5 and PR > 0.0:
            PR = PR + 0.5
            AR = -AR
        elif AR < 0 and PR > 0.5:
            PR = PR - 0.5
            AR = -AR
        elif PR < 0 and AR > 0:
            PR = PR + 1.0
        elif AR < 0 and PR < 0 and PR > -0.5:
            PR = PR + 0.5
            AR = -AR
        if PR > 1:
            PR = PR - 1
        A.append(AR)
        P.append(PR)
    return L, A, P
Beispiel #2
0
    def OnClickUpdate(self,e):
        global_parms, surface_new = param_unfold(self.nb.parameter,self.nb.parameter_usage,self.nb.surface,\
                                                 self.nb.MainControlPage.UBW_flag, self.nb.MainControlPage.use_lay_el)
        bulk = self.nb.bulk 
        surface = RB_update(self.nb.rigid_bodies, surface_new, self.nb.parameter, self.allrasd.cell)
        for Rasd in self.allrasd.list:
            Rasd.re_FNR ,Rasd.im_FNR = calcFNR(Rasd.Q,global_parms, self.allrasd.cell, bulk, surface, database,\
                                               self.allrasd.g_inv, self.nb.MainControlPage.UBW_flag,\
                                               self.nb.MainControlPage.use_lay_el, str.lower(self.resel))

        for item in range(len(self.allrasd.list)):
            self.allrasd.list[item] = RASD_Fourier(self.allrasd, item)
            self.datacontrol1[item].SetValue(str(round(self.allrasd.list[item].AR,3)))
            self.datacontrol2[item].SetValue(str(round(self.allrasd.list[item].PR,3)))
Beispiel #3
0
    def OnClickUpdate(self, e):
        global_parms, surface_new = param_unfold(self.nb.parameter,self.nb.parameter_usage,self.nb.surface,\
                                                 self.nb.MainControlPage.UBW_flag, self.nb.MainControlPage.use_lay_el)
        bulk = self.nb.bulk
        surface = RB_update(self.nb.rigid_bodies, surface_new,
                            self.nb.parameter, self.allrasd.cell)
        for Rasd in self.allrasd.list:
            Rasd.re_FNR ,Rasd.im_FNR = calcFNR(Rasd.Q,global_parms, self.allrasd.cell, bulk, surface, database,\
                                               self.allrasd.g_inv, self.nb.MainControlPage.UBW_flag,\
                                               self.nb.MainControlPage.use_lay_el, str.lower(self.resel))

        for item in range(len(self.allrasd.list)):
            self.allrasd.list[item] = RASD_Fourier(self.allrasd, item)
            self.datacontrol1[item].SetValue(
                str(round(self.allrasd.list[item].AR, 3)))
            self.datacontrol2[item].SetValue(
                str(round(self.allrasd.list[item].PR, 3)))
Beispiel #4
0
def Rasd_difference(allrasd, surface_tmp, parameter, param_usage, use_bulk_water, Refine_Data):
    allrasd.RMS = 0
    allrasd.ndata = 0
    
    zwater, sig_water,sig_water_bar, d_water, Scale,specScale, beta, surface = param_unfold(parameter,param_usage, surface_tmp, use_bulk_water)
    natoms = len(surface)
                 
    for Rasd in allrasd.list:
        if Rasd.use_in_Refine:
            Q = Num.zeros((3),float)
            Q[0] = allrasd.g_inv[0][0]**0.5 * Rasd.Q[0]
            Q[1] = allrasd.g_inv[1][1]**0.5 * Rasd.Q[1]
            Q[2] = allrasd.g_inv[2][2]**0.5 * Rasd.Q[2]
        
            j = 0
            re_Fq = 0
            im_Fq = 0
            for n in range(natoms):
                R = Num.array([surface[n][1],surface[n][2],surface[n][3]],float)
                U = Num.array([[surface[n][4],surface[n][7],surface[n][8]],[surface[n][7],surface[n][5],surface[n][9]],[surface[n][8],surface[n][9],surface[n][6]]],float)
                theta = surface[n][10]
                re_Fq = re_Fq + (theta * Num.cos(2*Num.pi*(Rasd.Q[0]*R[0]+Rasd.Q[1]*R[1]+Rasd.Q[2]*R[2])) * Num.exp(-2* Num.pi**2 * Num.dot(Num.dot(Q,U),Q)))
                im_Fq = im_Fq + (theta * Num.sin(2*Num.pi*(Rasd.Q[0]*R[0]+Rasd.Q[1]*R[1]+Rasd.Q[2]*R[2])) * Num.exp(-2* Num.pi**2 * Num.dot(Num.dot(Q,U),Q)))
                                                
            Rasd.re_FR = Rasd.f1 * re_Fq - Rasd.f2 * im_Fq
            Rasd.im_FR = Rasd.f1 * im_Fq + Rasd.f2 * re_Fq

            Rasd.re_Fq = re_Fq
            Rasd.im_Fq = im_Fq

            if Refine_Data:
                vec = [Rasd.a, Rasd.b]
                result = leastsq(Wiggle2, vec, args=(Rasd), Dfun = Jacobi2, col_deriv = 1)
                vec = result[0]
                Rasd.a, Rasd.b = vec

                Rasd.F_calc = (Rasd.a+Rasd.b*(Rasd.E - Rasd.E0))*((Rasd.re_FNR + Rasd.re_FR)**2 + (Rasd.im_FNR + Rasd.im_FR)**2) 
                Rasd.delta_F = (Rasd.F - Rasd.F_calc)**2/Rasd.Ferr**2
                Rasd.norm = (Rasd.a+ Rasd.b* (Rasd.E - Rasd.E0))*(Rasd.re_FNR**2 + Rasd.im_FNR**2)
                Rasd.RMS = Num.sum(Rasd.delta_F)/Rasd.ndata
        
                allrasd.RMS = allrasd.RMS + Num.sum(Rasd.delta_F)
                allrasd.ndata = allrasd.ndata + Rasd.ndata
            else:
                PR = Num.arctan(Rasd.im_Fq/Rasd.re_Fq)/(2*Num.pi)
                AR = Rasd.re_Fq /Num.cos(2*Num.pi*PR)
                if AR < 0 and PR < 0.5 and PR > 0.:
                    PR = PR + 0.5
                    AR = -AR
                elif AR < 0 and PR > 0.5:
                    PR = PR - 0.5
                    AR = -AR
                elif PR < 0 and AR > 0:
                    PR = PR + 1.
                elif AR < 0 and PR < 0 and PR > -0.5:
                    PR = PR + 0.5
                    AR = -AR
                if PR > 1: PR = PR -1
                Rasd.AR_refine = AR
                Rasd.PR_refine = PR

                Rasd.RMS = (Rasd.re_Fq / Num.cos(2*Num.pi*Rasd.PR) - Rasd.AR)**2 + (Rasd.im_Fq / Num.sin(2*Num.pi*Rasd.PR) - Rasd.AR)**2
                allrasd.RMS = allrasd.RMS + Rasd.RMS
                allrasd.ndata = allrasd.ndata + 1
        
    allrasd.RMS = allrasd.RMS/allrasd.ndata

    return allrasd
Beispiel #5
0
def read_RSD(allrasd, bulk_tmp, surface_tmp, parameter, param_usage,
             rigid_bodies, database, rasddata, use_bulk_water, dirname,
             parent):
    """    
    read in data in RasdList of RasdAna objects for fitting
   """
    if len(allrasd.E) == 0 and len(allrasd.f1) == 0:
        dlg = wx.MessageDialog(parent, "Please read in f1f2 data first", "",
                               wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    elif allrasd.E0 == 0:
        dlg = wx.MessageDialog(parent, "Please specify Edge Energy first", "",
                               wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    else:
        zwater, sig_water, sig_water_bar, d_water, Scale, specScale, beta, surface_new = param_unfold(
            parameter, param_usage, surface_tmp, use_bulk_water)
        bulk = bulk_tmp  #shift_bulk(zwater, bulk_tmp)
        surface = RB_update(rigid_bodies, surface_new, parameter, allrasd.cell)

        cell = allrasd.cell
        g_inv = allrasd.g_inv
        allrasd.ndata = 0

        for dat in rasddata:
            n = len(dat)
            if dat[n - 1] == '\n':
                dat = str.rstrip(dat, '\n')
            Q = None
            f = file(dirname + '/' + dat, 'r')
            data = f.readlines()
            f.close()
            Rasd = RasdAna()
            for i in range(len(data)):
                if '#' not in data[i]:
                    tmp = str.rsplit(data[i])
                    if Q == None:
                        Q = Num.array([tmp[1], tmp[2], tmp[3]], float)
                        Rasd.Q = Q
                        Rasd.mod_Q = Num.dot(Num.dot(Q, g_inv), Q)**0.5
                        Rasd.re_FNR, Rasd.im_FNR = calcFNR(
                            Q, sig_water, sig_water_bar, d_water, zwater, cell,
                            bulk, surface, database, g_inv, use_bulk_water)

                    Rasd.E = Num.append(Rasd.E, int(round(float(tmp[0]))))
                    Rasd.F = Num.append(Rasd.F, float(tmp[4])**2)
                    Rasd.Ferr = Num.append(Rasd.Ferr, float(tmp[5])**2)
                    Rasd.Alpha = Num.append(Rasd.Alpha, float(tmp[6]))
                    Rasd.Beta = Num.append(Rasd.Beta, float(tmp[7]))
            Rasd.E0 = allrasd.E0
            for x in Rasd.E:
                Rasd.Eorig = Num.append(Rasd.Eorig, x)
            Rasd.abs_corr = Num.ones((len(Rasd.E)), float)
            Rasd.ndata = len(Rasd.E)
            Rasd.file = dat
            allrasd.ndata = allrasd.ndata + Rasd.ndata

            i = 0
            Rasd.f1 = Num.ndarray((Rasd.ndata), float)
            Rasd.f2 = Num.ndarray((Rasd.ndata), float)
            for i in range(Rasd.ndata):
                j = 0
                for j in range(len(allrasd.E)):
                    if Rasd.E[i] == allrasd.E[j]:
                        Rasd.f1[i] = allrasd.f1[j]
                        Rasd.f2[i] = allrasd.f2[j]

            allrasd.list.append(Rasd)
        allrasd.dims = len(allrasd.list)

        return allrasd
Beispiel #6
0
    def OnClickUpdate(self, e):
        zwater, sig_water,sig_water_bar, d_water, Scale,specScale, beta, surface_new = param_unfold(self.nb.parameter,self.nb.parameter_usage,\
                                                                                                    self.nb.surface, self.nb.MainControlPage.UBW_flag)
        bulk = self.nb.bulk  #shift_bulk(zwater, self.nb.bulk)
        surface = RB_update(self.nb.rigid_bodies, surface_new,
                            self.nb.parameter, self.allrasd.cell)
        for Rasd in self.allrasd.list:
            Rasd.re_FNR ,Rasd.im_FNR = calcFNR(Rasd.Q,sig_water,sig_water_bar,d_water,zwater, self.allrasd.cell, bulk, surface, database,\
                                               self.allrasd.g_inv, self.nb.MainControlPage.UBW_flag)

        for item in range(len(self.allrasd.list)):
            self.allrasd.list[item] = RASD_Fourier(self.allrasd, item)
            self.datacontrol1[item].SetValue(
                str(round(self.allrasd.list[item].AR, 3)))
            self.datacontrol2[item].SetValue(
                str(round(self.allrasd.list[item].PR, 3)))
Beispiel #7
0
def Rasd_difference(allrasd, surface_tmp, parameter, param_usage, use_bulk_water, Refine_Data, use_lay_el, fix_bckg = False):
    allrasd.RMS = 0
    allrasd.ndata = 0
    
    global_parms, surface = param_unfold(parameter,param_usage, surface_tmp, use_bulk_water, use_lay_el)
    natoms = len(surface)
    occ_el, K,sig_el,sig_el_bar,d_el,d0_el,sig_water, sig_water_bar, d_water, zwater, Scale, specScale, beta= global_parms
    
    for Rasd in allrasd.list:
        if Rasd.use_in_Refine:
            Q = Num.zeros((3),float)
            Q[0] = allrasd.g_inv[0][0]**0.5 * Rasd.Q[0]
            Q[1] = allrasd.g_inv[1][1]**0.5 * Rasd.Q[1]
            Q[2] = allrasd.g_inv[2][2]**0.5 * Rasd.Q[2]
        
            j = 0
            re_Fq = 0
            im_Fq = 0
            for n in range(natoms):
                R = Num.array([surface[n][1],surface[n][2],surface[n][3]],float)

                U = Num.ndarray((3,3),float)
                U[0][0] = surface[n][4]
                U[0][1] = U[1][0] = surface[n][7]*(surface[n][4]*surface[n][5])**0.5
                U[0][2] = U[2][0] = surface[n][8]*(surface[n][4]*surface[n][6])**0.5
                U[1][1] = surface[n][5]
                U[1][2] = U[2][1] = surface[n][9]*(surface[n][5]*surface[n][6])**0.5
                U[2][2] = surface[n][6]
                
                theta = surface[n][10]
                re_Fq = re_Fq + (theta * Num.cos(2*Num.pi*(Rasd.Q[0]*R[0]+Rasd.Q[1]*R[1]+Rasd.Q[2]*R[2])) * Num.exp(-2* Num.pi**2 * Num.dot(Num.dot(Q,U),Q)))
                im_Fq = im_Fq + (theta * Num.sin(2*Num.pi*(Rasd.Q[0]*R[0]+Rasd.Q[1]*R[1]+Rasd.Q[2]*R[2])) * Num.exp(-2* Num.pi**2 * Num.dot(Num.dot(Q,U),Q)))
            if use_lay_el and Q[0] == 0 and Q[1] == 0:
                re_lay, im_lay = calc_F_lay_el(Rasd.Q, occ_el, K, sig_el, sig_el_bar, d_el, d0_el, allrasd.g_inv)
                re_Fq = re_Fq + re_lay
                im_Fq = im_Fq + im_lay                                    
            Rasd.re_FR = Rasd.f1 * re_Fq - Rasd.f2 * im_Fq
            Rasd.im_FR = Rasd.f1 * im_Fq + Rasd.f2 * re_Fq

            Rasd.re_Fq = re_Fq
            Rasd.im_Fq = im_Fq

            if Refine_Data:
                if not fix_bckg:
                    vec = [Rasd.a, Rasd.b]
                    result = leastsq(Wiggle2, vec, args=(Rasd), Dfun = Jacobi2, col_deriv = 1)
                    vec = result[0]
                    Rasd.a, Rasd.b = vec

                Rasd.F_calc = (Rasd.a+Rasd.b*(Rasd.E - Rasd.E0))*((Rasd.re_FNR + Rasd.re_FR)**2 + (Rasd.im_FNR + Rasd.im_FR)**2) 
                Rasd.delta_F = ((Rasd.F - Rasd.F_calc)/Rasd.Ferr)**2
                Rasd.norm = (Rasd.a+ Rasd.b* (Rasd.E - Rasd.E0))*(Rasd.re_FNR**2 + Rasd.im_FNR**2)
                Rasd.RMS = Num.sum(Rasd.delta_F)/Rasd.ndata
        
                allrasd.RMS = allrasd.RMS + Num.sum(Rasd.delta_F)
                allrasd.ndata = allrasd.ndata + Rasd.ndata
            else:
                PR = Num.arctan(Rasd.im_Fq/Rasd.re_Fq)/(2*Num.pi)
                AR = Rasd.re_Fq /Num.cos(2*Num.pi*PR)
                if AR < 0 and PR < 0.5 and PR > 0.:
                    PR = PR + 0.5
                    AR = -AR
                elif AR < 0 and PR > 0.5:
                    PR = PR - 0.5
                    AR = -AR
                elif PR < 0 and AR > 0:
                    PR = PR + 1.
                elif AR < 0 and PR < 0 and PR > -0.5:
                    PR = PR + 0.5
                    AR = -AR
                if PR > 1: PR = PR -1
                Rasd.AR_refine = AR
                Rasd.PR_refine = PR

                Rasd.RMS = (Rasd.re_Fq / Num.cos(2*Num.pi*Rasd.PR) - Rasd.AR)**2 + (Rasd.im_Fq / Num.sin(2*Num.pi*Rasd.PR) - Rasd.AR)**2
                allrasd.RMS = allrasd.RMS + Rasd.RMS
                allrasd.ndata = allrasd.ndata + 1
        
    allrasd.RMS = allrasd.RMS/allrasd.ndata

    return allrasd
def createStructureRenderer(surface,cell,param,param_use,rigid_bodies,atom_styles):
    global_parms, surface = \
            param_unfold(param, param_use, surface, False, False)
    surface = RB_update(rigid_bodies, surface, param, cell)
    actors = []
    M = calcM(cell)

    supercell = []
    for i in surface:
        if i[10] > 0:
            uxy = i[7] * (i[4] * i[5])**0.5
            uxz = i[8] * (i[4] * i[6])**0.5
            uyz = i[9] * (i[5] * i[6])**0.5            
            U = Num.array([[i[4],uxy,uxz],\
                           [uxy,i[5],uyz],\
                           [uxz,uyz,i[6]]],float)
            Uinv = Num.linalg.inv(U)
            supercell.append([i[0],Num.array([i[1],i[2],i[3]]),Uinv])
            supercell.append([i[0],Num.array([i[1]+1,i[2],i[3]]),Uinv])
            supercell.append([i[0],Num.array([i[1],i[2]+1,i[3]]),Uinv])
            supercell.append([i[0],Num.array([i[1]+1,i[2]+1,i[3]]),Uinv])


    #create an ellipsoid for every atom in supercell
    for i in range(len(supercell)):
        # create source
        point = supercell[i][1]
        [point] = aff2euk(M,[point])
        Uinv = supercell[i][2]
        if supercell[i][0] not in atom_styles.keys():
            color = [1,1,1]
        else:
            color = atom_styles[supercell[i][0]]
        actor = Ellipsoid(point, color, Uinv)
        actors.append(actor)
 
    # Create cell corner points
    points = []
    for i in [0.,1.]:
        for j in [0.,1.]:
            for k in [0.,1.]:
                points.append([i,j,k])
    points = aff2euk(M, points)

    #create cell edge lines
    line_id1 = [0,0,0,1,1,2,2,3,4,4,5,6]
    line_id2 = [1,2,4,3,5,3,6,7,5,6,7,7]
    for i in range(12):
        line = vtk.vtkLineSource()
        line.SetPoint1(points[line_id1[i]])
        line.SetPoint2(points[line_id2[i]])
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(line.GetOutput())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(1,1,1) # (R,G,B)
        actors.append(actor)

    # create a renderer
    ren = vtk.vtkRenderer()
    # assign actors to the renderer
    for actor in actors:
        ren.AddActor(actor)

    ren.SetBackground(0.0,0.0,0.0)
    ren.GetActiveCamera().ParallelProjectionOn()
    ren.ResetCamera()
    ren.GetActiveCamera().Azimuth(180)
    ren.GetActiveCamera().Elevation(270)
    ren.ResetCameraClippingRange()
    return ren
Beispiel #9
0
def read_RSD(
    allrasd,
    bulk_tmp,
    surface_tmp,
    parameter,
    param_usage,
    rigid_bodies,
    database,
    rasddata,
    use_bulk_water,
    use_lay_el,
    el,
    dirname,
    parent,
):
    """    
    read in data in RasdList of RasdAna objects for fitting
   """
    if len(allrasd.E) == 0 and len(allrasd.f1) == 0:
        dlg = wx.MessageDialog(parent, "Please read in f1f2 data first", "", wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    elif allrasd.E0 == 0:
        dlg = wx.MessageDialog(parent, "Please specify Edge Energy first", "", wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    else:
        global_parms, surface_new = param_unfold(parameter, param_usage, surface_tmp, use_bulk_water, use_lay_el)
        bulk = bulk_tmp
        surface = RB_update(rigid_bodies, surface_new, parameter, allrasd.cell)

        cell = allrasd.cell
        g_inv = allrasd.g_inv
        allrasd.ndata = 0
        allrasd.RMS = 0
        f1 = interp1d(allrasd.E, allrasd.f1, "cubic")
        f2 = interp1d(allrasd.E, allrasd.f2, "cubic")

        for dat in rasddata:
            n = len(dat)
            if dat[n - 1] == "\n":
                dat = str.rstrip(dat, "\n")
            Q = None
            f = file(dirname + "/" + dat, "r")
            data = f.readlines()
            f.close()
            Rasd = RasdAna()
            for i in range(len(data)):
                if "#" not in data[i]:
                    tmp = str.rsplit(data[i])
                    if Q == None:
                        Q = Num.array([tmp[1], tmp[2], tmp[3]], float)
                        Rasd.Q = Q
                        Rasd.mod_Q = Num.dot(Num.dot(Q, g_inv), Q) ** 0.5
                        Rasd.re_FNR, Rasd.im_FNR = calcFNR(
                            Q, global_parms, cell, bulk, surface, database, g_inv, use_bulk_water, use_lay_el, el
                        )

                    Rasd.E = Num.append(Rasd.E, float(tmp[0]))
                    Rasd.F = Num.append(Rasd.F, float(tmp[4]) ** 2)
                    Rasd.f1 = Num.append(Rasd.f1, f1(Rasd.E[-1]))
                    Rasd.f2 = Num.append(Rasd.f2, f2(Rasd.E[-1]))
                    if float(tmp[5]) == 0:
                        Rasd.Ferr = Num.append(Rasd.Ferr, 1.0)
                    else:
                        Rasd.Ferr = Num.append(Rasd.Ferr, float(tmp[5]) ** 2)
                    Rasd.Alpha = Num.append(Rasd.Alpha, float(tmp[6]))
                    Rasd.Beta = Num.append(Rasd.Beta, float(tmp[7]))
            Rasd.E0 = allrasd.E0
            for x in Rasd.E:
                Rasd.Eorig = Num.append(Rasd.Eorig, x)
            Rasd.abs_corr = Num.ones((len(Rasd.E)), float)
            Rasd.ndata = len(Rasd.E)
            Rasd.file = dat
            allrasd.ndata = allrasd.ndata + Rasd.ndata
            allrasd.list.append(Rasd)
        allrasd.dims = len(allrasd.list)
        allrasd.RMS = allrasd.RMS / allrasd.ndata

        return allrasd
Beispiel #10
0
def calc_A_P_Q(Qmax, g_inv, surface_tmp, parameter, param_usage,
               use_bulk_water, use_lay_el):
    global_parms, surface = param_unfold(parameter, param_usage, surface_tmp,
                                         use_bulk_water, use_lay_el)
    natoms = len(surface)
    occ_el, K, sig_el, sig_el_bar, d_el, d0_el, sig_water, sig_water_bar, d_water, zwater, Scale, specScale, beta = global_parms
    A = []
    P = []
    L = Num.arange(0.1, Qmax, 0.01)
    for l in L:
        Q = Num.array([0, 0, l], float)
        Q_ang = Num.array([0, 0, l * g_inv[2][2]**0.5], float)
        re_Fq = 0
        im_Fq = 0
        for n in range(natoms):
            R = Num.array([surface[n][1], surface[n][2], surface[n][3]], float)

            U = Num.ndarray((3, 3), float)
            U[0][0] = surface[n][4]
            U[0][1] = U[1][0] = surface[n][7] * (surface[n][4] *
                                                 surface[n][5])**0.5
            U[0][2] = U[2][0] = surface[n][8] * (surface[n][4] *
                                                 surface[n][6])**0.5
            U[1][1] = surface[n][5]
            U[1][2] = U[2][1] = surface[n][9] * (surface[n][5] *
                                                 surface[n][6])**0.5
            U[2][2] = surface[n][6]

            theta = surface[n][10]
            re_Fq = re_Fq + (
                theta * Num.cos(2 * Num.pi *
                                (Q[0] * R[0] + Q[1] * R[1] + Q[2] * R[2])) *
                Num.exp(-2 * Num.pi**2 * Num.dot(Num.dot(Q_ang, U), Q_ang)))
            im_Fq = im_Fq + (
                theta * Num.sin(2 * Num.pi *
                                (Q[0] * R[0] + Q[1] * R[1] + Q[2] * R[2])) *
                Num.exp(-2 * Num.pi**2 * Num.dot(Num.dot(Q_ang, U), Q_ang)))
        if use_lay_el:
            re_lay, im_lay = calc_F_lay_el(Q, occ_el, K, sig_el, sig_el_bar,
                                           d_el, d0_el, g_inv)
            re_Fq = re_Fq + re_lay
            im_Fq = im_Fq + im_lay

        PR = Num.arctan(im_Fq / re_Fq) / (2 * Num.pi)
        AR = re_Fq / Num.cos(2 * Num.pi * PR)

        if AR < 0 and PR < 0.5 and PR > 0.:
            PR = PR + 0.5
            AR = -AR
        elif AR < 0 and PR > 0.5:
            PR = PR - 0.5
            AR = -AR
        elif PR < 0 and AR > 0:
            PR = PR + 1.
        elif AR < 0 and PR < 0 and PR > -0.5:
            PR = PR + 0.5
            AR = -AR
        if PR > 1:
            PR = PR - 1
        A.append(AR)
        P.append(PR)
    return L, A, P
Beispiel #11
0
def read_RSD(allrasd, bulk_tmp, surface_tmp, parameter, param_usage,
             rigid_bodies, database, rasddata, use_bulk_water, use_lay_el, el,
             dirname, parent):
    """    
    read in data in RasdList of RasdAna objects for fitting
   """
    if len(allrasd.E) == 0 and len(allrasd.f1) == 0:
        dlg = wx.MessageDialog(parent, "Please read in f1f2 data first", "",
                               wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    elif allrasd.E0 == 0:
        dlg = wx.MessageDialog(parent, "Please specify Edge Energy first", "",
                               wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    else:
        global_parms, surface_new = param_unfold(parameter, param_usage,
                                                 surface_tmp, use_bulk_water,
                                                 use_lay_el)
        bulk = bulk_tmp
        surface = RB_update(rigid_bodies, surface_new, parameter, allrasd.cell)

        cell = allrasd.cell
        g_inv = allrasd.g_inv
        allrasd.ndata = 0
        allrasd.RMS = 0
        f1 = interp1d(allrasd.E, allrasd.f1, 'cubic')
        f2 = interp1d(allrasd.E, allrasd.f2, 'cubic')

        for dat in rasddata:
            n = len(dat)
            if dat[n - 1] == '\n':
                dat = str.rstrip(dat, '\n')
            Q = None
            f = file(dirname + '/' + dat, 'r')
            data = f.readlines()
            f.close()
            Rasd = RasdAna()
            for i in range(len(data)):
                if '#' not in data[i]:
                    tmp = str.rsplit(data[i])
                    if Q == None:
                        Q = Num.array([tmp[1], tmp[2], tmp[3]], float)
                        Rasd.Q = Q
                        Rasd.mod_Q = Num.dot(Num.dot(Q, g_inv), Q)**0.5
                        Rasd.re_FNR, Rasd.im_FNR = calcFNR(
                            Q, global_parms, cell, bulk, surface, database,
                            g_inv, use_bulk_water, use_lay_el, el)

                    Rasd.E = Num.append(Rasd.E, float(tmp[0]))
                    Rasd.F = Num.append(Rasd.F, float(tmp[4])**2)
                    Rasd.f1 = Num.append(Rasd.f1, f1(Rasd.E[-1]))
                    Rasd.f2 = Num.append(Rasd.f2, f2(Rasd.E[-1]))
                    if float(tmp[5]) == 0:
                        Rasd.Ferr = Num.append(Rasd.Ferr, 1.0)
                    else:
                        Rasd.Ferr = Num.append(Rasd.Ferr, float(tmp[5])**2)
                    Rasd.Alpha = Num.append(Rasd.Alpha, float(tmp[6]))
                    Rasd.Beta = Num.append(Rasd.Beta, float(tmp[7]))
            Rasd.E0 = allrasd.E0
            for x in Rasd.E:
                Rasd.Eorig = Num.append(Rasd.Eorig, x)
            Rasd.abs_corr = Num.ones((len(Rasd.E)), float)
            Rasd.ndata = len(Rasd.E)
            Rasd.file = dat
            allrasd.ndata = allrasd.ndata + Rasd.ndata
            allrasd.list.append(Rasd)
        allrasd.dims = len(allrasd.list)
        allrasd.RMS = allrasd.RMS / allrasd.ndata

        return allrasd
Beispiel #12
0
def read_RSD(allrasd, bulk_tmp, surface_tmp, parameter, param_usage, rigid_bodies, database, rasddata, use_bulk_water, dirname, parent):
    """    
    read in data in RasdList of RasdAna objects for fitting
   """
    if len(allrasd.E)== 0 and len(allrasd.f1) == 0:
        dlg = wx.MessageDialog(parent, "Please read in f1f2 data first","", wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    elif allrasd.E0 == 0:
        dlg = wx.MessageDialog(parent, "Please specify Edge Energy first","", wx.OK | wx.STAY_ON_TOP)
        if dlg.ShowModal() == wx.OK:
            dlg.Destroy()
        return allrasd
    else:
        zwater, sig_water,sig_water_bar, d_water, Scale,specScale, beta, surface_new = param_unfold(parameter,param_usage, surface_tmp, use_bulk_water)
        bulk = bulk_tmp #shift_bulk(zwater, bulk_tmp)
        surface = RB_update(rigid_bodies, surface_new, parameter, allrasd.cell)

        cell = allrasd.cell
        g_inv = allrasd.g_inv
        allrasd.ndata = 0
        
        for dat in rasddata:
            n = len(dat)
            if dat[n-1] == '\n':
                dat = str.rstrip(dat,'\n')
            Q = None
            f = file(dirname+'/'+dat, 'r')
            data = f.readlines()
            f.close()
            Rasd = RasdAna()
            for i in range(len(data)):
                if '#' not in data[i]:
                    tmp = str.rsplit(data[i])
                    if Q == None:
                        Q = Num.array([tmp[1],tmp[2],tmp[3]], float)
                        Rasd.Q = Q
                        Rasd.mod_Q = Num.dot(Num.dot(Q,g_inv),Q)**0.5
                        Rasd.re_FNR ,Rasd.im_FNR = calcFNR(Q,sig_water,sig_water_bar,d_water,zwater, cell, bulk, surface, database, g_inv, use_bulk_water)
                    
                    Rasd.E = Num.append(Rasd.E, int(round(float(tmp[0]))))
                    Rasd.F = Num.append(Rasd.F, float(tmp[4])**2)
                    Rasd.Ferr = Num.append(Rasd.Ferr, float(tmp[5])**2)
                    Rasd.Alpha = Num.append(Rasd.Alpha, float(tmp[6]))
                    Rasd.Beta = Num.append(Rasd.Beta, float(tmp[7]))
            Rasd.E0 = allrasd.E0
            for x in Rasd.E:
                Rasd.Eorig = Num.append(Rasd.Eorig, x)
            Rasd.abs_corr = Num.ones((len(Rasd.E)),float)
            Rasd.ndata = len(Rasd.E)
            Rasd.file = dat
            allrasd.ndata = allrasd.ndata + Rasd.ndata
        
            i=0
            Rasd.f1 = Num.ndarray((Rasd.ndata), float)
            Rasd.f2 = Num.ndarray((Rasd.ndata), float)
            for i in range(Rasd.ndata):
                j = 0
                for j in range(len(allrasd.E)):
                    if Rasd.E[i] == allrasd.E[j]:
                        Rasd.f1[i] = allrasd.f1[j]
                        Rasd.f2[i] = allrasd.f2[j]
        
            allrasd.list.append(Rasd)
        allrasd.dims = len(allrasd.list)

        return allrasd
Beispiel #13
0
    def OnClickUpdate(self,e):
        zwater, sig_water,sig_water_bar, d_water, Scale,specScale, beta, surface_new = param_unfold(self.nb.parameter,self.nb.parameter_usage,\
                                                                                                    self.nb.surface, self.nb.MainControlPage.UBW_flag)
        bulk = self.nb.bulk #shift_bulk(zwater, self.nb.bulk)
        surface = RB_update(self.nb.rigid_bodies, surface_new, self.nb.parameter, self.allrasd.cell)
        for Rasd in self.allrasd.list:
            Rasd.re_FNR ,Rasd.im_FNR = calcFNR(Rasd.Q,sig_water,sig_water_bar,d_water,zwater, self.allrasd.cell, bulk, surface, database,\
                                               self.allrasd.g_inv, self.nb.MainControlPage.UBW_flag)

        for item in range(len(self.allrasd.list)):
            self.allrasd.list[item] = RASD_Fourier(self.allrasd, item)
            self.datacontrol1[item].SetValue(str(round(self.allrasd.list[item].AR,3)))
            self.datacontrol2[item].SetValue(str(round(self.allrasd.list[item].PR,3)))