Changeset 73


Ignore:
Timestamp:
Jun 2, 2010 12:26:01 PM (12 years ago)
Author:
vondreel
Message:

remove Bob's bad code & simplify calc_rVsq

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIlattice.py

    r71 r73  
    2020    '''
    2121    a,b,c,alp,bet,gam = cell
    22     g = np.array([[a*a,a*b*cosd(gam),a*c*cosd(bet)],[a*b*cosd(gam),b*b,b*c*cosd(alp)],
    23         [a*c*cosd(bet),b*c*cosd(alp),c*c]])
     22    g = np.array([
     23        [a*a,  a*b*cosd(gam),  a*c*cosd(bet)],
     24        [a*b*cosd(gam),  b*b,  b*c*cosd(alp)],
     25        [a*c*cosd(bet) ,b*c*cosd(alp),   c*c]])
    2426    return g
    2527           
     
    3436
    3537def A2Gmat(A):
    36     '''Compute reciprocal metric tensor (G) from A tensor
     38    '''Fill reciprocal metric tensor (G) from A
    3739    returns reciprocal (G) & real (g) metric tensors (list of two 3x3 arrays)
    3840    '''
    3941    G = np.zeros(shape=(3,3))
    40     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]]]
     42    G = [
     43        [A[0],  A[3]/2.,  A[4]/2.],
     44        [A[3]/2.,A[1],    A[5]/2.],
     45        [A[4]/2.,A[5]/2.,    A[2]]]
    4146    g = nl.inv(G)
    4247    return G,g
    4348
    4449def Gmat2A(G):
    45     'Compute A tensor from reciprocal metric tensor (G)'
     50    'Extract A from reciprocal metric tensor (G)'
    4651    return [G[0][0],G[1][1],G[2][2],2.*G[0][1],2.*G[0][2],2.*G[1][2]]
    4752   
     
    6065    '''Compute lattice parameters from real metric tensor (g)
    6166    returns tuple with a,b,c,alpha, beta, gamma (degrees)
     67    Alternatively,compute reciprocal lattice parameters from inverse metric tensor (G)
     68    returns tuple with a*,b*,c*,alpha*, beta*, gamma* (degrees)
    6269    '''
    6370    a = np.sqrt(max(0,g[0][0]))
     
    8087       
    8188def calc_rVsq(A):
    82     'Compute the square of the reciprocal lattice volume (V* **2) from A tensor'
    83     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)
     89    'Compute the square of the reciprocal lattice volume (V* **2) from A'
     90    G,g = A2Gmat(A)
     91    rVsq = nl.det(G)
    8492    if rVsq < 0:
    8593        return 1
     
    100108    G,g = A2Gmat(A)
    101109    return Gmat2cell(G)
    102     # Code below is broken
    103     ainv = np.sqrt(max(0.,A[0]))
    104     binv = np.sqrt(max(0.,A[1]))
    105     cinv = np.sqrt(max(0.,A[2]))
    106     gaminv = acosd(max(-0.5,min(0.5,0.5*A[3]/(ainv*binv))))
    107     betinv = acosd(max(-0.5,min(0.5,0.5*A[4]/(ainv*cinv))))
    108     alpinv = acosd(max(-0.5,min(0.5,0.5*A[5]/(binv*cinv))))
    109     return ainv,binv,cinv,alpinv,betinv,gaminv
    110110
    111111def cell2AB(cell):
     
    127127    A[2][2] = 1/cellstar[2]         # 1/c*
    128128    B = nl.inv(A)
    129     return A,B
    130     # bob's code:
    131     G,g = cell2Gmat(cell)       #reciprocal & real metric tensors
    132     cosAlpStar = G[2][1]/np.sqrt(G[1][1]*G[2][2])
    133     sinAlpStar = np.sqrt(1.0-cosAlpStar**2)
    134     B = np.eye(3)
    135     B *= cell[:3]
    136     A = np.zeros(shape=(3,3))
    137     A[0][0] = 1.0
    138     A[0][1] = cosd(cell[5])
    139     A[1][1] = sinAlpStar*sind(cell[5])
    140     A[1][2] = -cosAlpStar*sind(cell[5])
    141     A[0][2] = cosd(cell[4])
    142     A[2][2] = sind(cell[4])
    143     B = np.dot(A,B)
    144     A = nl.inv(B)
    145129    return A,B
    146130
Note: See TracChangeset for help on using the changeset viewer.