示例#1
0
def refinePeaks(peaks,ibrav,A,ifX20=True):
    'needs a doc string'
    dmin = getDmin(peaks)
    smin = 1.0e10
    pwr = 8
    maxTries = 10
    OK = False
    tries = 0
    sgtype = G2lat.make_sgtype(ibrav)
    HKL = G2lat.GenHBravais(dmin,ibrav,A, sg_type=sgtype)
    while len(HKL) > 2 and IndexPeaks(peaks,HKL)[0]:
        Pwr = pwr - (tries % 2)
        HKL = []
        tries += 1
        osmin = smin
        oldA = A[:]
        Vold = G2lat.calc_V(oldA)
        OK,smin,A,result = FitHKL(ibrav,peaks,A,Pwr)
        Vnew = G2lat.calc_V(A)
        if Vnew > 2.0*Vold or Vnew < 2.:
            A = ranAbyR(ibrav,oldA,tries+1,maxTries,ran2axis)
            OK = False
            continue
        try:
            HKL = G2lat.GenHBravais(dmin,ibrav,A, sgtype)
        except FloatingPointError:
            A = oldA
            OK = False
            break
        if len(HKL) == 0: break                         #absurd cell obtained!
        rat = (osmin-smin)/smin
        if abs(rat) < 1.0e-5 or not OK: break
        if tries > maxTries: break
    if OK:
        OK,smin,A,result = FitHKL(ibrav,peaks,A,2)
        Peaks = np.array(peaks).T
        H = Peaks[4:7]
        try:
            Peaks[8] = 1./np.sqrt(G2lat.calc_rDsq(H,A))
            peaks = Peaks.T
        except FloatingPointError:
            A = oldA
        
    M20,X20 = calc_M20(peaks,HKL,ifX20)
    return len(HKL),M20,X20,A
def refinePeaksT(peaks, difC, ibrav, A, Zero, ZeroRef):
    'needs a doc string'
    dmin = getDmin(peaks)
    OK, smin, Aref, Z, result = FitHKLT(difC, ibrav, peaks, A, Zero, ZeroRef)
    Peaks = np.array(peaks).T
    H = Peaks[4:7]
    Peaks[8] = 1. / np.sqrt(G2lat.calc_rDsqT(H, Aref, Z, Peaks[0], difC))
    peaks = Peaks.T
    HKL = G2lat.GenHBravais(dmin, ibrav, A)
    M20, X20 = calc_M20(peaks, HKL)
    return len(HKL), M20, X20, Aref, Z
def refinePeaksTSS(peaks, difC, Inst, SGData, SSGData, maxH, ibrav, A, vec,
                   vecRef, Zero, ZeroRef):
    'needs a doc string'
    dmin = getDmin(peaks)
    OK, smin, Aref, Vref, Z, result = FitHKLTSS(difC, ibrav, peaks, A, vec,
                                                vecRef, Zero, ZeroRef)
    Peaks = np.array(peaks).T
    H = Peaks[4:8]
    Peaks[9] = 1. / np.sqrt(
        G2lat.calc_rDsqTSS(H, Aref, Vref, Z, Peaks[0], difC))
    peaks = Peaks.T
    HKL = G2pwd.getHKLMpeak(dmin, Inst, SGData, SSGData, Vref, maxH, Aref)
    HKL = G2lat.GenHBravais(dmin, ibrav, A)
    M20, X20 = calc_M20SS(peaks, HKL)
    return len(HKL), M20, X20, Aref, Vref, Z
示例#4
0
def findBestCell(dlg,ncMax,A,Ntries,ibrav,peaks,V1,ifX20=True):
    'needs a doc string'
# dlg & ncMax are used for wx progress bar 
# A != 0 find the best A near input A,
# A = 0 for random cell, volume normalized to V1;
# returns number of generated hkls, M20, X20 & A for best found
    mHKL = [3,3,3, 5,5, 5,5, 7,7,7,7,7,7, 9,9,9, 10]
    dmin = getDmin(peaks)-0.05
    amin = 2.5
    amax = 5.*getDmax(peaks)
    Asave = []
    GoOn = True
    Skip = False
    if A:
        HKL = G2lat.GenHBravais(dmin,ibrav,A[:])
        if len(HKL) > mHKL[ibrav]:
            peaks = IndexPeaks(peaks,HKL)[1]
            Asave.append([calc_M20(peaks,HKL,ifX20),A[:]])
    tries = 0
    while tries < Ntries and GoOn:
        if A:
            Abeg = ranAbyR(ibrav,A,tries+1,Ntries,ran2axis)
            if ibrav > 12:         #monoclinic & triclinic
                Abeg = ranAbyR(ibrav,A,tries/10+1,Ntries,ran2axis)
        else:
            Abeg = ranAbyV(ibrav,amin,amax,V1)
        HKL = G2lat.GenHBravais(dmin,ibrav,Abeg)
        Nc = len(HKL)
        if Nc >= ncMax:
            GoOn = False
        else:
            if dlg:
                dlg.Raise()
                GoOn = dlg.Update(100*Nc/ncMax)[0]
                if Skip or not GoOn:
                    GoOn = False
                    break
        
        if IndexPeaks(peaks,HKL)[0] and len(HKL) > mHKL[ibrav]:
            Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg,ifX20)
            Asave.append([calc_M20(peaks,HKL,ifX20),Aref[:]])
            if ibrav in [9,10,11]:                          #C-centered orthorhombic
                for i in range(2):
                    Abeg = rotOrthoA(Abeg[:])
                    Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg,ifX20)
                    HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
                    peaks = IndexPeaks(peaks,HKL)[1]
                    Asave.append([calc_M20(peaks,HKL,ifX20),Aref[:]])
            elif ibrav == 13:                      #C-centered monoclinic
                Abeg = swapMonoA(Abeg[:])
                Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg,ifX20)
                HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
                peaks = IndexPeaks(peaks,HKL)[1]
                Asave.append([calc_M20(peaks,HKL,ifX20),Aref[:]])
        else:
            break
        Nc = len(HKL)
        tries += 1
    X = sortM20(Asave)
    if X:
        Lhkl,M20,X20,A = refinePeaks(peaks,ibrav,X[0][1],ifX20)
        return GoOn,Skip,Lhkl,M20,X20,A        
    else:
        return GoOn,Skip,0,0,0,0
示例#5
0
def DoIndexPeaks(peaks, controls, bravais, ifX20=True):
    'needs a doc string'

    delt = 0.005  #lowest d-spacing cushion - can be fixed?
    amin = 2.5
    amax = 5.0 * getDmax(peaks)
    dmin = getDmin(peaks) - delt
    bravaisNames = [
        'Cubic-F', 'Cubic-I', 'Cubic-P', 'Trigonal-R', 'Trigonal/Hexagonal-P',
        'Tetragonal-I', 'Tetragonal-P', 'Orthorhombic-F', 'Orthorhombic-I',
        'Orthorhombic-C', 'Orthorhombic-P', 'Monoclinic-C', 'Monoclinic-P',
        'Triclinic'
    ]
    tries = [
        '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th'
    ]
    N1s = [1, 1, 1, 5, 5, 5, 5, 50, 50, 50, 50, 50, 50, 200]
    N2s = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4]
    Nm = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4]
    Nobs = len(peaks)
    zero, ncno = controls[1:3]
    ncMax = Nobs * ncno
    print "%s %8.3f %8.3f" % ('lattice parameter range = ', amin, amax)
    print "%s %.4f %s %d %s %d" % ('Zero =', zero, 'Nc/No max =', ncno,
                                   ' Max Nc =', ncno * Nobs)
    cells = []
    for ibrav in range(14):
        begin = time.time()
        if bravais[ibrav]:
            print 'cell search for ', bravaisNames[ibrav]
            print '      M20  X20  Nc       a          b          c        alpha       beta      gamma     volume      V-test'
            V1 = controls[3]
            bestM20 = 0
            topM20 = 0
            cycle = 0
            while cycle < 5:
                dlg = wx.ProgressDialog(
                    "Generated reflections",
                    tries[cycle] + " cell search for " + bravaisNames[ibrav],
                    ncMax,
                    style=wx.PD_ELAPSED_TIME | wx.PD_AUTO_HIDE
                    | wx.PD_REMAINING_TIME | wx.PD_CAN_ABORT)
                screenSize = wx.ClientDisplayRect()
                Size = dlg.GetSize()
                dlg.SetPosition(
                    wx.Point(screenSize[2] - Size[0] - 305, screenSize[1] + 5))
                try:
                    GoOn = True
                    while GoOn:  #Loop over increment of volume
                        N2 = 0
                        while N2 < N2s[ibrav]:  #Table 2 step (iii)
                            if ibrav > 2:
                                if not N2:
                                    A = []
                                    GoOn, Nc, M20, X20, A = findBestCell(
                                        dlg, ncMax, A, Nm[ibrav] * N1s[ibrav],
                                        ibrav, peaks, V1, ifX20)
                                if A:
                                    GoOn, Nc, M20, X20, A = findBestCell(
                                        dlg, ncMax, A[:], N1s[ibrav], ibrav,
                                        peaks, 0, ifX20)
                            else:
                                GoOn, Nc, M20, X20, A = findBestCell(
                                    dlg, ncMax, 0, Nm[ibrav] * N1s[ibrav],
                                    ibrav, peaks, V1, ifX20)
                            if Nc >= ncMax:
                                GoOn = False
                                break
                            elif 3 * Nc < Nobs:
                                N2 = 10
                                break
                            else:
                                if not GoOn:
                                    break
                                if M20 > 1.0:
                                    bestM20 = max(bestM20, M20)
                                    A = halfCell(ibrav, A[:], peaks)
                                    if ibrav in [12]:
                                        A = monoCellReduce(ibrav, A[:])
                                    HKL = G2lat.GenHBravais(dmin, ibrav, A)
                                    peaks = IndexPeaks(peaks, HKL)[1]
                                    a, b, c, alp, bet, gam = G2lat.A2cell(A)
                                    V = G2lat.calc_V(A)
                                    if M20 >= 2.0:
                                        print "%10.3f %3d %3d %10.5f %10.5f %10.5f %10.3f %10.3f %10.3f %10.2f %10.2f" % (
                                            M20, X20, Nc, a, b, c, alp, bet,
                                            gam, V, V1)
                                        cells.append([
                                            M20, X20, ibrav, a, b, c, alp, bet,
                                            gam, V, False, False
                                        ])
                            if not GoOn:
                                break
                            N2 += 1
                        if ibrav < 11:
                            V1 *= 1.1
                        elif ibrav in range(11, 14):
                            V1 *= 1.05
                        if not GoOn:
                            if bestM20 > topM20:
                                topM20 = bestM20
                                if cells:
                                    V1 = cells[0][9]
                                else:
                                    V1 = 25
                                ncMax += Nobs
                                cycle += 1
                                print 'Restart search, new Max Nc = ', ncMax
                            else:
                                cycle = 10
                finally:
                    dlg.Destroy()
            print '%s%s%s%s'%('finished cell search for ',bravaisNames[ibrav], \
                ', elapsed time = ',G2lat.sec2HMS(time.time()-begin))

    if cells:
        return True, dmin, cells
    else:
        return False, 0, []