Changeset 70


Ignore:
Timestamp:
May 28, 2010 11:45:13 AM (12 years ago)
Author:
toby
Message:

move lattice operations into GSASIIlattice w/unit tests

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIcomp.py

    r65 r70  
    1010import pypowder as pyp              #assumes path has been amended to include correctr bin directory
    1111import GSASIIplot as G2plt
     12from GSASIIlattice import * # these routines should eventually be reference in G2lattice
    1213
    1314# trig functions in degrees
     
    300301    rdsq = calc_rDsq(H,A)+Z*math.sin(tth*rpd)*2.0*rpd/(lam*lam)
    301302    return rdsq
    302    
    303 def calc_rVsq(A):
    304     rVsq = A[0]*A[1]*A[2]+0.25*(A[3]*A[4]*A[5]-A[0]*A[5]**2-A[1]*A[4]**2-A[2]*A[3]**2)
    305     if rVsq < 0:
    306         return 1
    307     return rVsq
    308    
    309 def calc_rV(A):
    310     return math.sqrt(calc_rVsq(A))
    311    
    312 def calc_V(A):
    313     return 1./calc_rV(A)
    314303   
    315304def scaleAbyV(A,V):
     
    429418    return [a,b,c,alp,bet,gam]
    430419   
    431 def A2Gmat(A):
    432     G = np.zeros(shape=(3,3))
    433     G = [[A[0],A[3]/2.,A[4]/2.], [A[3]/2.,A[1],A[5]/2.], [A[4]/2.,A[5]/2.,A[2]]]
    434     g = nl.inv(G)
    435     return G,g
    436    
    437 def fillgmat(cell):
    438     a,b,c,alp,bet,gam = cell
    439     g = np.array([[a*a,a*b*cosd(gam),a*c*cosd(bet)],[a*b*cosd(gam),b*b,b*c*cosd(alp)],
    440         [a*c*cosd(bet),b*c*cosd(alp),c*c]])
    441     return g
    442            
    443 def cell2Gmat(cell):
    444     #returns reciprocal (G) & real (g) metric tensors
    445     g = fillgmat(cell)
    446     G = nl.inv(g)       
    447     return G,g
    448    
    449 def invcell2Gmat(invcell):
    450     G = fillgmat(invcell)
    451     g = nl.inv(G)
    452     return G,g
    453    
    454 def Gmat2cell(g):
    455     #returns lattice parameters from real metric tensor (g)
    456     a = math.sqrt(max(0,g[0][0]))
    457     b = math.sqrt(max(0,g[1][1]))
    458     c = math.sqrt(max(0,g[2][2]))
    459     alp = acosd(g[2][1]/(b*c))
    460     bet = acosd(g[2][0]/(a*c))
    461     gam = acosd(g[0][1]/(a*b))
    462     return a,b,c,alp,bet,gam
    463    
    464 def Gmat2A(G):
    465     return [G[0][0],G[1][1],G[2][2],2.*G[0][1],2.*G[0][2],2.*G[1][2]]
    466    
    467 def cell2A(cell):
    468     G,g = cell2Gmat(cell)
    469     return Gmat2A(G)
    470    
    471 def A2cell(A):
    472     G,g = A2Gmat(A)
    473     return Gmat2cell(g)
    474    
    475 def A2invcell(A):
    476     ainv = math.sqrt(max(0.,A[0]))
    477     binv = math.sqrt(max(0.,A[1]))
    478     cinv = math.sqrt(max(0.,A[2]))
    479     gaminv = acosd(max(-0.5,min(0.5,0.5*A[3]/(ainv*binv))))
    480     betinv = acosd(max(-0.5,min(0.5,0.5*A[4]/(ainv*cinv))))
    481     alpinv = acosd(max(-0.5,min(0.5,0.5*A[5]/(binv*cinv))))
    482     return ainv,binv,cinv,alpinv,betinv,gaminv
    483    
    484 def cell2AB(cell):
    485     #from real lattice parameters - cell
    486     # returns A for Cartesian to crystal transformations A*X = x
    487     # and inverse B for crystal to Cartesian transformation B*x = X
    488     G,g = cell2Gmat(cell)       #reciprocal & real metric tensors
    489     cosAlpStar = G[2][1]/math.sqrt(G[1][1]*G[2][2])
    490     sinAlpStar = math.sqrt(1.0-cosAlpStar**2)
    491     B = np.eye(3)
    492     B *= cell[:3]
    493     A = np.zeros(shape=(3,3))
    494     A[0][0] = 1.0
    495     A[0][1] = cosd(cell[5])
    496     A[1][1] = sinAlpStar*sind(cell[5])
    497     A[1][2] = -cosAlpStar*sind(cell[5])
    498     A[0][2] = cosd(cell[4])
    499     A[2][2] = sind(cell[4])
    500     B = np.dot(A,B)
    501     A = nl.inv(B)
    502     return A,B
    503    
    504420def makeMat(Angle,Axis):
    505421    #Make rotation matrix from Angle in degrees,Axis =0 for rotation about x, =1 for about y, etc.
     
    556472 
    557473def GenHBravais(dmin,Bravais,A):
     474    '''Generate the positionally unique powder diffraction reflections
     475    for a lattice and Bravais type'''
    558476# dmin - minimum d-spacing
    559477# Bravais in range(14) to indicate Bravais lattice; 0-2 cubic, 3,4 - hexagonal/trigonal,
     
    677595                                   
    678596def GenHLaue(dmin,Laue,Cent,Axis,A):
     597    '''Generate the crystallographically unique powder diffraction reflections
     598    for a lattice and Bravais type
     599    '''
    679600# dmin - minimum d-spacing
    680601# Laue - Laue group symbol = '-1','2/m','mmmm','4/m','6/m','4/mmm','6/mmm',
  • trunk/unit_tests.py

    r61 r70  
    11import GSASIIspc
     2import GSASIIlattice as G2l
    23def test_GSASIIspc():
    34    GSASIIspc.test0()
     
    89def test_GSASIIspc3():
    910    GSASIIspc.test3()
     11def test_GSASIIlattice0():
     12    G2l.test0()
     13def test_GSASIIlattice1():
     14    G2l.test1()
     15def test_GSASIIlattice2():
     16    G2l.test2()
     17def test_GSASIIlattice3():
     18    G2l.test3()
     19def test_GSASIIlattice4():
     20    G2l.test4()
     21def test_GSASIIlattice5():
     22    G2l.test5()
     23
     24
     25
    1026
    1127if __name__ == '__main__':
     
    1430    test_GSASIIspc2()
    1531    test_GSASIIspc3()
     32    G2l.test0()
     33    G2l.test1()
     34    G2l.test2()
     35    G2l.test3()
     36    G2l.test4()
     37    G2l.test5()
    1638    print "OK"
Note: See TracChangeset for help on using the changeset viewer.