Difference between revisions of "Talk:Unit cell"

From GISAXS
Jump to: navigation, search
Line 31: Line 31:
 
\end{alignat}
 
\end{alignat}
 
</math>
 
</math>
 +
 +
==Calculate q_hkl generally==
 +
<source lang="python">
 +
    def q_hkl(self, h, k, l):
 +
        """Determines the position in reciprocal space for the given reflection."""
 +
       
 +
        # The 'unitcell' coordinate system assumes:
 +
        #  a-axis lies along x-axis
 +
        #  b-axis is in x-y plane
 +
        #  c-axis is vertical (or at a tilt, depending on beta)
 +
       
 +
        # Convert from (unitcell) Cartesian to (unitcell) fractional coordinates
 +
        reduced_volume = sqrt( 1 - (cos(self.alpha))**2 - (cos(self.beta))**2 - (cos(self.gamma))**2 + 2*cos(self.alpha)*cos(self.beta)*cos(self.gamma) )
 +
        #volume = reduced_volume*self.lattice_spacing_a*self.lattice_spacing_b*self.lattice_spacing_c
 +
        a = ( self.lattice_spacing_a , \
 +
                0.0 , \
 +
                0.0  )
 +
        b = ( self.lattice_spacing_b*cos(self.gamma) , \
 +
                self.lattice_spacing_b*sin(self.gamma) , \
 +
                0.0 )
 +
        c = ( self.lattice_spacing_c*cos(self.beta) , \
 +
                self.lattice_spacing_c*( cos(self.alpha) - cos(self.beta)*cos(self.gamma) )/( sin(self.gamma) ) , \
 +
                self.lattice_spacing_c*reduced_volume/( sin(self.gamma) ) )
 +
       
 +
        # Compute (unitcell) reciprocal-space lattice vectors
 +
        volume = np.dot( a, np.cross(b,c) )
 +
        u = np.cross( b, c ) / volume # Along qx
 +
        v = np.cross( c, a ) / volume # Along qy
 +
        w = np.cross( a, b ) / volume # Along qz
 +
       
 +
        qhkl_vector = 2*pi*( h*u + k*v + l*w )
 +
        qhkl = sqrt( qhkl_vector[0]**2 + qhkl_vector[1]**2 + qhkl_vector[2]**2 )
 +
       
 +
        return (qhkl, qhkl_vector)
 +
 +
               
 +
       
 +
    def q_hkl_length(self, h, k, l):
 +
       
 +
        qhkl, qhkl_vector = self.q_hkl(h,k,l)
 +
        #qhkl = sqrt( qhkl_vector[0]**2 + qhkl_vector[1]**2 + qhkl_vector[2]**2 )
 +
       
 +
        return qhkl
 +
</source>

Revision as of 11:18, 13 April 2020

Extra math expressions

A given real-space cubic lattice will have dimensions:

Such that the position of any particular cell within the infinite lattice is:

Where h, k, and l are indices. The corresponding inverse-space lattice would be:

In the case where :

TBD: Reciprocal vector components

Calculate q_hkl generally

    def q_hkl(self, h, k, l):
        """Determines the position in reciprocal space for the given reflection."""
        
        # The 'unitcell' coordinate system assumes:
        #  a-axis lies along x-axis
        #  b-axis is in x-y plane
        #  c-axis is vertical (or at a tilt, depending on beta)
        
        # Convert from (unitcell) Cartesian to (unitcell) fractional coordinates
        reduced_volume = sqrt( 1 - (cos(self.alpha))**2 - (cos(self.beta))**2 - (cos(self.gamma))**2 + 2*cos(self.alpha)*cos(self.beta)*cos(self.gamma) )
        #volume = reduced_volume*self.lattice_spacing_a*self.lattice_spacing_b*self.lattice_spacing_c
        a = ( self.lattice_spacing_a , \
                0.0 , \
                0.0  )
        b = ( self.lattice_spacing_b*cos(self.gamma) , \
                self.lattice_spacing_b*sin(self.gamma) , \
                0.0 )
        c = ( self.lattice_spacing_c*cos(self.beta) , \
                self.lattice_spacing_c*( cos(self.alpha) - cos(self.beta)*cos(self.gamma) )/( sin(self.gamma) ) , \
                self.lattice_spacing_c*reduced_volume/( sin(self.gamma) ) )
        
        # Compute (unitcell) reciprocal-space lattice vectors
        volume = np.dot( a, np.cross(b,c) )
        u = np.cross( b, c ) / volume # Along qx
        v = np.cross( c, a ) / volume # Along qy
        w = np.cross( a, b ) / volume # Along qz
        
        qhkl_vector = 2*pi*( h*u + k*v + l*w )
        qhkl = sqrt( qhkl_vector[0]**2 + qhkl_vector[1]**2 + qhkl_vector[2]**2 )
        
        return (qhkl, qhkl_vector)

                
        
    def q_hkl_length(self, h, k, l):
        
        qhkl, qhkl_vector = self.q_hkl(h,k,l)
        #qhkl = sqrt( qhkl_vector[0]**2 + qhkl_vector[1]**2 + qhkl_vector[2]**2 )
        
        return qhkl