def test1():
    if NeedTestData: TestData()
    ibrav, A, Pwr, peaks = TestData2
    print('bad cell:', G2lat.A2cell(A))
    print('FitHKL')
    OK, smin, A, result = FitHKL(ibrav, peaks, A, Pwr)
    result = refinePeaks(peaks, ibrav, A)
    N, M20, X20, A = result
    print('refinePeaks:', N, M20, X20, A)
def test0():
    if NeedTestData: TestData()
    ibrav, cell, bestcell, Pwr, peaks = TestData
    print('best cell:', bestcell)
    print('old cell:', cell)
    Peaks = np.array(peaks)
    HKL = Peaks[4:7]
    print(calc_M20(peaks, HKL))
    A = G2lat.cell2A(cell)
    OK, smin, A, result = FitHKL(ibrav, peaks, A, Pwr)
    print('new cell:', G2lat.A2cell(A))
    print('x:', result[0])
    print('cov_x:', result[1])
    print('infodict:')
    for item in result[2]:
        print(item, result[2][item])
    print('msg:', result[3])
    print('ier:', result[4])
    result = refinePeaks(peaks, ibrav, A)
    N, M20, X20, A = result
    print('refinePeaks:', N, M20, X20, G2lat.A2cell(A))
    print('compare bestcell:', bestcell)
Beispiel #3
0
def test0():
    if NeedTestData: TestData()
    msg = 'test FitHKL'
    ibrav, cell, bestcell, Pwr, peaks = TestData
    print 'best cell:', bestcell
    print 'old cell:', cell
    Peaks = np.array(peaks)
    HKL = Peaks[4:7]
    print calc_M20(peaks, HKL)
    A = G2lat.cell2A(cell)
    OK, smin, A, result = FitHKL(ibrav, peaks, A, Pwr)
    print 'new cell:', G2lat.A2cell(A)
    print 'x:', result[0]
    print 'cov_x:', result[1]
    print 'infodict:'
    for item in result[2]:
        print item, result[2][item]
    print 'msg:', result[3]
    print 'ier:', result[4]
    result = refinePeaks(peaks, ibrav, A)
    N, M20, X20, A = result
    print 'refinePeaks:', N, M20, X20, G2lat.A2cell(A)
    print 'compare bestcell:', bestcell
Beispiel #4
0
 def convert_lattice(self, paramList, params):
     '''
         Convert between A and unit cell parameters. A is defined in GSAS-II
         as A = [G11, G22, G33, 2*G12, 2*G13, 2*G23] with G as the
         reciprocal metric tensor elements.
     '''
     latparamList = [
         '0::A0', '1::A0', '2::A0', '3::A0', '4::A0', '5::A0', '6::A0',
         '7::A0', '8::A0', '9::A0', '10::A0'
     ]
     check = any(item in paramList for item in latparamList)
     if check is True:
         return G2latt.A2cell(params)
     else:
         return G2latt.cell2A(params)
Beispiel #5
0
def ranAbyV(Bravais,dmin,dmax,V):
    'needs a doc string'
    cell = [0,0,0,0,0,0]
    bad = True
    while bad:
        bad = False
        cell = rancell(Bravais,dmin,dmax)
        G,g = G2lat.cell2Gmat(cell)
        A = G2lat.Gmat2A(G)
        if G2lat.calc_rVsq(A) < 1:
            scaleAbyV(A,V)
            cell = G2lat.A2cell(A)
            for i in range(3):
                bad |= cell[i] < dmin
    return A
Beispiel #6
0
def monoCellReduce(ibrav,A):
    'needs a doc string'
    a,b,c,alp,bet,gam = G2lat.A2cell(A)
    G,g = G2lat.A2Gmat(A)
    if ibrav in [13]:
        u = [0,0,-1]
        v = [1,0,2]
        anew = math.sqrt(np.dot(np.dot(v,g),v))
        if anew < a:
            cang = np.dot(np.dot(u,g),v)/(anew*c)
            beta = acosd(-abs(cang))
            A = G2lat.cell2A([anew,b,c,90,beta,90])
    else:
        u = [-1,0,0]
        v = [1,0,1]
        cnew = math.sqrt(np.dot(np.dot(v,g),v))
        if cnew < c:
            cang = np.dot(np.dot(u,g),v)/(a*cnew)
            beta = acosd(-abs(cang))
            A = G2lat.cell2A([a,b,cnew,90,beta,90])
    return A
Beispiel #7
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,[]
Beispiel #8
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, []