Beispiel #1
0
 def _calc_g(self):
     """
     Calculate the metric tensors and recip lattice params
     self.g  = real space metric tensor
     self.gr = recip space metric tensor
     """
     (a,b,c,alp,bet,gam) = self.cell()
     # real metric tensor
     self.g = num.array([ [ a*a, a*b*cosd(gam), a*c*cosd(bet) ],
                          [ b*a*cosd(gam), b*b, b*c*cosd(alp) ],
                          [ c*a*cosd(bet), c*b*cosd(alp), c*c ] ])
     # recip lattice metric tensor
     # and recip lattice params
     self.gr     = num.linalg.inv(self.g)
     self.ar     = num.sqrt(self.gr[0,0])
     self.br     = num.sqrt(self.gr[1,1])
     self.cr     = num.sqrt(self.gr[2,2])
     self.alphar = arccosd(self.gr[1,2]/(self.br*self.cr))
     self.betar  = arccosd(self.gr[0,2]/(self.ar*self.cr))
     self.gammar = arccosd(self.gr[0,1]/(self.ar*self.br))
Beispiel #2
0
 def _calc_g(self):
     """
     Calculate the metric tensors and recip lattice params
     self.g  = real space metric tensor
     self.gr = recip space metric tensor
     """
     (a, b, c, alp, bet, gam) = self.cell()
     # real metric tensor
     self.g = num.array([[a * a, a * b * cosd(gam), a * c * cosd(bet)],
                         [b * a * cosd(gam), b * b, b * c * cosd(alp)],
                         [c * a * cosd(bet), c * b * cosd(alp), c * c]])
     # recip lattice metric tensor
     # and recip lattice params
     self.gr = num.linalg.inv(self.g)
     self.ar = num.sqrt(self.gr[0, 0])
     self.br = num.sqrt(self.gr[1, 1])
     self.cr = num.sqrt(self.gr[2, 2])
     self.alphar = arccosd(self.gr[1, 2] / (self.br * self.cr))
     self.betar = arccosd(self.gr[0, 2] / (self.ar * self.cr))
     self.gammar = arccosd(self.gr[0, 1] / (self.ar * self.br))
Beispiel #3
0
    def _calc_sigma_az(self):
        """
        sigma_az = angle between the z-axis and n
        in the phi frame
        """
        # calc n in the lab frame (unrotated) and make a unit vector
        n_phi = num.dot(self.UB, self.n)
        n_phi = n_phi / cartesian_mag(n_phi)

        # note result of acosd is between 0 and pi
        # get correct sign from the sign of the x-component
        #sigma_az = num.sign(n_phi[0])*arccosd(n_phi[2])
        sigma_az = arccosd(n_phi[2])
        self.pangles['sigma_az'] = sigma_az
 def _calc_sigma_az(self):
     """
     sigma_az = angle between the z-axis and n
     in the phi frame
     """
     # calc n in the lab frame (unrotated) and make a unit vector
     n_phi = num.dot(self.UB,self.n)
     n_phi = n_phi/cartesian_mag(n_phi)
     
     # note result of acosd is between 0 and pi
     # get correct sign from the sign of the x-component
     #sigma_az = num.sign(n_phi[0])*arccosd(n_phi[2])
     sigma_az = arccosd(n_phi[2])
     self.pangles['sigma_az'] = sigma_az
Beispiel #5
0
 def angle_rr(self, x, h):
     """
     Calculate the angle between a real vector x = [x,y,z]
     and a recip vector h = [h,k,l]
     """
     x = num.array(x, dtype=float)
     h = num.array(h, dtype=float)
     hx = num.sum(x * h)
     xm = self.mag(x, recip=False)
     hm = self.mag(h, recip=True)
     arg = hx / (hm * xm)
     if num.fabs(arg) > 1.0:
         arg = arg / num.fabs(arg)
     alpha = arccosd(arg)
     return alpha
Beispiel #6
0
 def angle_rr(self,x,h):
     """
     Calculate the angle between a real vector x = [x,y,z]
     and a recip vector h = [h,k,l]
     """
     x = num.array(x,dtype=float)
     h = num.array(h,dtype=float)
     hx = num.sum(x*h)
     xm = self.mag(x,recip=False)
     hm = self.mag(h,recip=True)
     arg = hx/(hm*xm)
     if num.fabs(arg) > 1.0:
         arg = arg / num.fabs(arg)
     alpha = arccosd(arg)
     return alpha
Beispiel #7
0
    def _calc_tth(self):
        """
        Calculate 2Theta, the scattering angle

        Notes:
        ------
        This should be the same as:
          (ki,kr) = calc_kvecs(nu,delta,lambda)
           tth = cartesian_angle(ki,kr)

        You can also get this given h, the reciprocal lattice
        vector that is in the diffraction condition.  E.g.
          h   = self.calc_h()
          tth = self.lattice.tth(h)
        """
        nu = self.angles['nu']
        delta = self.angles['delta']
        tth = arccosd(cosd(delta) * cosd(nu))
        self.pangles['tth'] = tth
    def _calc_tth(self):
        """
        Calculate 2Theta, the scattering angle

        Notes:
        ------
        This should be the same as:
          (ki,kr) = calc_kvecs(nu,delta,lambda)
           tth = cartesian_angle(ki,kr)

        You can also get this given h, the reciprocal lattice
        vector that is in the diffraction condition.  E.g.
          h   = self.calc_h()
          tth = self.lattice.tth(h)
        """
        nu    = self.angles['nu']
        delta = self.angles['delta']
        tth   = arccosd(cosd(delta)*cosd(nu))
        self.pangles['tth'] = tth
Beispiel #9
0
    def angle(self, u, v, recip=False):
        """
        Calculate the angle between two vectors (u,v)

        Notes:
        ------
        * If u and v are real space vectors, use recip = False
        * If u and v are recip space vectors, use recip = True

        Note u and v are assumed to be normal numpy arrays
        (ie not matrix objects)
        """
        uv = self.dot(u, v, recip=recip)
        um = self.mag(u, recip=recip)
        vm = self.mag(v, recip=recip)
        arg = uv / (um * vm)
        if num.fabs(arg) > 1.0:
            arg = arg / num.fabs(arg)
        alpha = arccosd(arg)
        return alpha
Beispiel #10
0
    def angle(self,u,v,recip=False):
        """
        Calculate the angle between two vectors (u,v)

        Notes:
        ------
        * If u and v are real space vectors, use recip = False
        * If u and v are recip space vectors, use recip = True

        Note u and v are assumed to be normal numpy arrays
        (ie not matrix objects)
        """
        uv = self.dot(u,v,recip=recip)
        um = self.mag(u,recip=recip)
        vm = self.mag(v,recip=recip)
        arg = uv/(um*vm)
        if num.fabs(arg) > 1.0:
            arg = arg / num.fabs(arg)
        alpha = arccosd(arg)
        return alpha
Beispiel #11
0
    def _calc_psi(self):
        """
        calc psi, this is the azmuthal angle of n wrt Q. 
        ie for tau != 0, psi is the rotation of n about Q

        Notes:
        ------
        Note this must be calc after tth, tau, and alpha!
        """
        tau = self.pangles['tau']
        tth = self.pangles['tth']
        alpha = self.pangles['alpha']
        #beta = self.calc_beta()
        #xx = (-cosd(tau)*sind(tth/2.) + sind(beta))
        xx = (cosd(tau) * sind(tth / 2.) - sind(alpha))
        denom = (sind(tau) * cosd(tth / 2.))
        if denom == 0:
            self.pangles['psi'] = 0.
            return
        xx = xx / denom
        psi = arccosd(xx)
        self.pangles['psi'] = psi
    def _calc_psi(self):
        """
        calc psi, this is the azmuthal angle of n wrt Q. 
        ie for tau != 0, psi is the rotation of n about Q

        Notes:
        ------
        Note this must be calc after tth, tau, and alpha!
        """
        tau   = self.pangles['tau']
        tth   = self.pangles['tth']
        alpha = self.pangles['alpha']
        #beta = self.calc_beta()
        #xx = (-cosd(tau)*sind(tth/2.) + sind(beta))
        xx    = (cosd(tau)*sind(tth/2.) - sind(alpha))
        denom = (sind(tau)*cosd(tth/2.))
        if denom == 0: 
            self.pangles['psi'] = 0.
            return
        xx    = xx /denom
        psi = arccosd( xx )
        self.pangles['psi'] = psi