Exemplo n.º 1
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, []
Exemplo n.º 2
0
def DoIndexPeaks(peaks,controls,bravais,dlg,ifX20=True,timeout=None):
    '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-A',
        'Orthorhombic-B','Orthorhombic-C',
        'Orthorhombic-P','Monoclinic-I','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,  100,100,100, 200]
    N2s = [1,1,1,   2,2,  2,2,     2,2,2,2,2,2,   2,2,2,   4]
    Nm  = [1,1,1,   1,1,  1,1,     1,1,1,1,1,1,   2,2,2,   4]
    notUse = 0
    for peak in peaks:
        if not peak[2]:
            notUse += 1
    Nobs = len(peaks)-notUse
    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 = []
    lastcell = np.zeros(7)
    for ibrav in range(17):
        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:
                if dlg:
                    dlg.Raise()
                    dlg.Update(0,newmsg=tries[cycle]+" cell search for "+bravaisNames[ibrav])
                try:
                    GoOn = True
                    while GoOn:                                                 #Loop over increment of volume
                        N2 = 0
                        while N2 < N2s[ibrav]:                                  #Table 2 step (iii)               
                            if time.time() - begin > timeout: 
                                GoOn = False
                                break
                            if ibrav > 2:
                                if not N2:
                                    A = []
                                    GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,A,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20)
                                    if Skip:
                                        break
                                if A:
                                    GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,A[:],N1s[ibrav],ibrav,peaks,0,ifX20)
                            else:
                                GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,0,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20)
                            if Skip:
                                break
                            elif Nc >= ncMax:
                                GoOn = False
                                break
                            elif 3*Nc < Nobs:
                                N2 = 10
                                break
                            else:
                                if not GoOn:
                                    break
                                if 1.e6 > M20 > 1.0:    #exclude nonsense
                                    bestM20 = max(bestM20,M20)
                                    A = halfCell(ibrav,A[:],peaks)
                                    if ibrav in [14,]:
                                        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 >= 10.0 and X20 <= 2:
                                        cell = [M20,X20,ibrav,a,b,c,alp,bet,gam,V,False,False, Nc]
                                        newcell = np.array(cell[3:10])
                                        if not np.allclose(newcell,lastcell):
                                            print ("%10.3f %3d %3d %10.5f %10.5f %10.5f %10.3f %10.3f %10.3f %10.2f %10.2f %s"  \
                                                %(M20,X20,Nc,a,b,c,alp,bet,gam,V,V1,bravaisNames[ibrav]))
                                            cells.append(cell)
                                        lastcell = np.array(cell[3:10])
                            if not GoOn:
                                break
                            N2 += 1
                        if Skip:
                            cycle = 10
                            GoOn = False
                            break
                        if ibrav < 13:
                            V1 *= 1.1
                        elif ibrav in range(13,17):
                            V1 *= 1.025
                        if not GoOn:
                            if bestM20 > topM20:
                                topM20 = bestM20
                                if cells:
                                    V1 = cells[0][9]
                                else:
                                    V1 = controls[3]
                                ncMax += Nobs
                                cycle += 1
                                print ('Restart search, new Max Nc = %d'%ncMax)
                            else:
                                cycle = 10
                finally:
                    pass
#                dlg.Destroy()
            print ('%s%s%s%s%s%d'%('finished cell search for ',bravaisNames[ibrav], \
                ', elapsed time = ',G2lat.sec2HMS(time.time()-begin),' Vfinal ',V1))
            
    if cells:
        return True,dmin,cells
    else:
        return False,0,[]
Exemplo n.º 3
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,[]