Exemple #1
0
    def __init__(self, name, *args):
        '''Creates a new lattice and calculates related values.

        Keyword arguments:
            name -- a string
            a,b,c,alpha,beta,gamma -- lengths and angles (in degrees)
        '''

        self._name = name
        self._a1 = None
        self._a2 = None
        self._a3 = None
        self._alpha1 = None
        self._alpha2 = None
        self._alpha3 = None
        self._system = "Triclinic"
        if allnum(args):
            # Set the direct lattice parameters
            a, b, c, alpha, beta, gamma = args
            self._a1 = a
            self._a2 = b
            self._a3 = c
            self._alpha1 = alpha * TORAD
            self._alpha2 = beta * TORAD
            self._alpha3 = gamma * TORAD
            self._set_reciprocal_cell(self._a1, self._a2, self._a3,
                                      self._alpha1, self._alpha2, self._alpha3)
        else:
            self._system = args[0]
            self._set_cell_for_system(self._system, *args[1:])
Exemple #2
0
def setlat(name=None, *args):
    """
    setlat  -- interactively enter lattice parameters (Angstroms and Deg)
    setlat name a -- assumes cubic
    setlat name a b -- assumes tetragonal
    setlat name a b c -- assumes ortho
    setlat name a b c gamma -- assumes mon/hex with gam not equal to 90
    setlat name a b c alpha beta gamma -- arbitrary
    """

    if name is None:  # Interactive
        name = promptForInput("crystal name")
        a = promptForNumber('    a', 1)
        b = promptForNumber('    b', a)
        c = promptForNumber('    c', a)
        alpha = promptForNumber('alpha', 90)
        beta = promptForNumber('beta', 90)
        gamma = promptForNumber('gamma', 90)
        ubcalc.set_lattice(name, a, b, c, alpha, beta, gamma)

    elif (isinstance(name, str) and len(args) in (1, 2, 3, 4, 6)
          and allnum(args)):
        # first arg is string and rest are numbers
        ubcalc.set_lattice(name, *args)
    else:
        raise TypeError()
Exemple #3
0
def setlat(name=None, *args):
    """
    setlat  -- interactively enter lattice parameters (Angstroms and Deg)
    setlat name a -- assumes cubic
    setlat name a b -- assumes tetragonal
    setlat name a b c -- assumes ortho
    setlat name a b c gamma -- assumes mon/hex with gam not equal to 90
    setlat name a b c alpha beta gamma -- arbitrary
    """

    if name is None:  # Interactive
        name = promptForInput("crystal name")
        a = promptForNumber('    a', 1)
        b = promptForNumber('    b', a)
        c = promptForNumber('    c', a)
        alpha = promptForNumber('alpha', 90)
        beta = promptForNumber('beta', 90)
        gamma = promptForNumber('gamma', 90)
        ubcalc.set_lattice(name, a, b, c, alpha, beta, gamma)

    elif (isinstance(name, str) and
          len(args) in (1, 2, 3, 4, 6) and
          allnum(args)):
        # first arg is string and rest are numbers
        ubcalc.set_lattice(name, *args)
    else:
        raise TypeError()
Exemple #4
0
def sim(scn, hkl):
    """sim hkl scn -- simulates moving scannable (not all)
    """
    if not isinstance(hkl, (tuple, list)):
        raise TypeError()

    if not allnum(hkl):
        raise TypeError()

    try:
        print scn.simulateMoveTo(hkl)
    except AttributeError:
        raise TypeError("The first argument does not support simulated moves")
Exemple #5
0
def sim(self, scn, hkl):
    """sim hkl scn -- simulates moving scannable (not all)
    """
    if not isinstance(hkl, (tuple, list)):
        raise TypeError

    if not allnum(hkl):
        raise TypeError()

    try:
        print scn.simulateMoveTo(hkl)
    except AttributeError:
        raise TypeError("The first argument does not support simulated moves")
    def sim(self, scn, hkl):
        """sim hkl scn -- simulates moving scannable (not all)
        """
        if not isinstance(hkl, (tuple, list)):
            raise TypeError

        if not allnum(hkl):
            raise TypeError()

        try:
            print scn.simulateMoveTo(hkl)
        except AttributeError:
            if diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS:
                raise TypeError(
                    "The first argument does not support simulated moves")
            else:
                print "The first argument does not support simulated moves"
 def set_lattice(self, name, *shortform):
     """
     Converts a list shortform crystal parameter specification to a six-long
     tuple. See setlat() for a description of the shortforms supported.
     """
     if not shortform:
         raise TypeError("Please specify unit cell parameters.")
     elif allnum(shortform):
         sf = shortform
         if len(sf) == 1:
             system = "Cubic"
         elif len(sf) == 2:
             system = "Tetragonal"
         elif len(sf) == 3:
             system = "Orthorhombic"
         elif len(sf) == 4:
             if abs(sf[0] - sf[1]) < SMALL and sf[3] == 120:
                 system = "Hexagonal"
             else:
                 system = "Monoclinic"
         elif len(sf) == 6:
             system = "Triclinic"
         else:
             raise TypeError(
                 "Invalid number of input parameters to set unit lattice.")
         fullform = (system, ) + shortform
     else:
         if not isinstance(shortform[0], basestring):
             raise TypeError("Invalid unit cell parameters specified.")
         fullform = shortform
     if self._state.name is None:
         raise DiffcalcException(
             "Cannot set lattice until a UBCalcaluation has been started "
             "with newubcalc")
     self._state.crystal = CrystalUnderTest(name, *fullform)
     # Clear U and UB if these exist
     if self._U is not None:  # (UB will also exist)
         print(
             "Warning: Setting new unit cell parameters.\n"
             "         The old UB calculation has been cleared.")
     self.save()
Exemple #8
0
def setref2(scn, hkl):
    """setref2 scn [h k l] -- setup hkloffset scannable to scan for second reflection [hkl]"""
    
    if not isinstance(hkl, (tuple, list)):
        raise DiffcalcException("Please specify hkl values for a second reference reflection to search.")

    if not allnum(hkl):
        raise DiffcalcException("Please specify numeric values for hkl.")

    try:
        hkl_ref = scn._diffcalc._ub.ubcalc.get_reflection(0)[0]
    except IndexError:
        raise DiffcalcException("Please add one reference reflection into the reflection list.")
    pol, az, sc = scn._diffcalc._ub.ubcalc.calc_offset_for_hkl(hkl, hkl_ref)
    hkl_rot = [sc * val for val in hkl_ref]
    hkl_sc = hkl_rot[:]
    hkl_rot.extend([pol * TODEG, az * TODEG])
    hkl_sc.extend([0, 0])

    print ('\nRescaled hkl reference for second reflection : %9.4f  %.4f  %.4f' % (hkl_sc[0], hkl_sc[1], hkl_sc[2]))
    print ('         polar and azimuthal rotation angles : %9.4f  %.4f\n' % (pol * TODEG, az * TODEG))

    sim(scn, hkl_sc)
    print ('IMPORTANT: Applying subsequent polar and azimuthal rotations might fail. In this case, please manually\n'
           '           find accessible azimuthal rotation range to scan for second reference reflection.')
    reply = getInputWithDefault('Move to rescaled hkl position', 'y')
    if reply in ('y', 'Y', 'yes'):
        scn.asynchronousMoveTo(hkl_sc)
    else:
        print 'Aborting'
        return

    sim(scn, hkl_rot)
    reply = getInputWithDefault('Apply polar and azimuthal rotations', 'y')
    if reply in ('y', 'Y', 'yes'):
        scn.asynchronousMoveTo(hkl_rot)
    else:
        print 'Aborting'
        return