Esempio n. 1
0
def editref(num):
    """editref num -- interactively edit a reflection.
    """
    num = int(num)

    # Get old reflection values
    [oldh, oldk, oldl], oldExternalAngles, oldEnergy, oldTag, oldT = \
        ubcalc.get_reflection_in_external_angles(num)
    del oldT  # current time will be used.

    h = promptForNumber('h', oldh)
    k = promptForNumber('k', oldk)
    l = promptForNumber('l', oldl)
    if None in (h, k, l):
        _handleInputError("h,k and l must all be numbers")
    reply = promptForInput('update position with current hardware setting',
                           'n')
    if reply in ('y', 'Y', 'yes'):
        positionList = settings.hardware.get_position()  # @UndefinedVariable
        energy = settings.hardware.get_energy()  # @UndefinedVariable
    else:
        positionList = []
        names = settings.hardware.get_axes_names()  # @UndefinedVariable
        for i, angleName in enumerate(names):
            val = promptForNumber(angleName.rjust(7), oldExternalAngles[i])
            if val is None:
                _handleInputError("Please enter a number, or press "
                                  "Return to accept default!")
                return
            positionList.append(val)
        muliplier = settings.hardware.energyScannableMultiplierToGetKeV  # @UndefinedVariable
        energy = promptForNumber('energy', oldEnergy / muliplier)
        if val is None:
            _handleInputError("Please enter a number, or press Return "
                              "to accept default!")
            return
        energy = energy * muliplier
    tag = promptForInput("tag", oldTag)
    if tag == '':
        tag = None
    pos = settings.geometry.physical_angles_to_internal_position(
        positionList)  # @UndefinedVariable
    ubcalc.edit_reflection(num, h, k, l, pos, energy, tag, datetime.now())
Esempio n. 2
0
def editref(num):
    """editref num -- interactively edit a reflection.
    """
    num = int(num)

    # Get old reflection values
    [oldh, oldk, oldl], oldExternalAngles, oldEnergy, oldTag, oldT = \
        ubcalc.get_reflection_in_external_angles(num)
    del oldT  # current time will be used.

    h = promptForNumber('h', oldh)
    k = promptForNumber('k', oldk)
    l = promptForNumber('l', oldl)
    if None in (h, k, l):
        _handleInputError("h,k and l must all be numbers")
    reply = promptForInput('update position with current hardware setting',
                           'n')
    if reply in ('y', 'Y', 'yes'):
        positionList = settings.hardware.get_position()  # @UndefinedVariable
        energy = settings.hardware.get_energy()  # @UndefinedVariable
    else:
        positionList = []
        names = settings.hardware.get_axes_names()  # @UndefinedVariable
        for i, angleName in enumerate(names):
            val = promptForNumber(angleName.rjust(7), oldExternalAngles[i])
            if val is None:
                _handleInputError("Please enter a number, or press "
                                      "Return to accept default!")
                return
            positionList.append(val)
        energy = promptForNumber('energy', oldEnergy)
        if val is None:
            _handleInputError("Please enter a number, or press Return "
                                  "to accept default!")
            return
        energy = energy * settings.hardware.energyScannableMultiplierToGetKeV  # @UndefinedVariable
    tag = promptForInput("tag", oldTag)
    if tag == '':
        tag = None
    pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
    ubcalc.edit_reflection(num, h, k, l, pos, energy, tag,
                                datetime.now())
Esempio n. 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()
Esempio n. 4
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()
Esempio n. 5
0
def editorient(idx):
    """editorient num | 'tag' -- interactively edit a crystal orientation.
    """

    # Get old reflection values
    [oldh, oldk, oldl], [oldx, oldy, oldz], oldExternalAngles, oldTag, oldT = \
        ubcalc.get_orientation_in_external_angles(idx, True)
    del oldT  # current time will be used.

    h = promptForNumber('h', oldh)
    k = promptForNumber('k', oldk)
    l = promptForNumber('l', oldl)
    if None in (h, k, l):
        _handleInputError("h,k and l must all be numbers")
    x = promptForNumber('x', oldx)
    y = promptForNumber('y', oldy)
    z = promptForNumber('z', oldz)
    if None in (x, y, z):
        _handleInputError("x,y and z must all be numbers")
    reply = promptForInput('update position with current hardware setting',
                           'n')
    if reply in ('y', 'Y', 'yes'):
        positionList = settings.hardware.get_position()  # @UndefinedVariable
    else:
        positionList = []
        names = settings.hardware.get_axes_names()  # @UndefinedVariable
        for i, angleName in enumerate(names):
            val = promptForNumber(angleName.rjust(7), oldExternalAngles[i])
            if val is None:
                _handleInputError("Please enter a number, or press "
                                      "Return to accept default!")
                return
            positionList.append(val)
    tag = promptForInput("tag", oldTag)
    if tag == '':
        tag = None
    pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
    ubcalc.edit_orientation(idx, h, k, l, x, y, z, pos, tag,
                                datetime.now())
Esempio n. 6
0
def addorient(*args):
    """
    addorient -- add crystal orientation interactively
    addorient [h k l] [x y z] {'tag'} -- add crystal orientation in laboratory frame
    """

    if len(args) == 0:
        h = promptForNumber('h', 0.)
        k = promptForNumber('k', 0.)
        l = promptForNumber('l', 0.)
        if None in (h, k, l):
            _handleInputError("h,k and l must all be numbers")

        x = promptForNumber('x', 0.)
        y = promptForNumber('y', 0.)
        z = promptForNumber('z', 0.)
        if None in (x, y, z):
            _handleInputError("x,y and z must all be numbers")

        tag = promptForInput("tag")
        if tag == '':
            tag = None
        ubcalc.add_orientation(h, k, l, x, y, z, tag, datetime.now())
    elif len(args) in (1, 2, 3):
        args = list(args)
        h, k, l = args.pop(0)
        if not (isnum(h) and isnum(k) and isnum(l)):
            raise TypeError()
        x, y, z = args.pop(0)
        if not (isnum(x) and isnum(y) and isnum(z)):
            raise TypeError()
        if len(args) == 1:
            tag = args.pop(0)
            if not isinstance(tag, str):
                raise TypeError()
        else:
            tag = None
        ubcalc.add_orientation(h, k, l, x, y, z, tag, datetime.now())
    else:
        raise TypeError()
Esempio n. 7
0
def editorient(num):
    """editorient num -- interactively edit a crystal orientation.
    """
    num = int(num)

    # Get old reflection values
    [oldh, oldk, oldl], [oldx, oldy, oldz], oldTag, oldT = \
        ubcalc.get_orientation(num)
    del oldT  # current time will be used.

    h = promptForNumber('h', oldh)
    k = promptForNumber('k', oldk)
    l = promptForNumber('l', oldl)
    if None in (h, k, l):
        _handleInputError("h,k and l must all be numbers")
    x = promptForNumber('x', oldx)
    y = promptForNumber('y', oldy)
    z = promptForNumber('z', oldz)
    if None in (x, y, z):
        _handleInputError("x,y and z must all be numbers")
    tag = promptForInput("tag", oldTag)
    if tag == '':
        tag = None
    ubcalc.edit_orientation(num, h, k, l, x, y, z, tag, datetime.now())
Esempio n. 8
0
def refineub(*args):
    """
    refineub {[h k l]} {pos} -- refine unit cell dimensions and U matrix to match diffractometer angles for a given hkl value
    """
    if len(args) > 0:
        args = list(args)
        h, k, l = args.pop(0)
        if not (isnum(h) and isnum(k) and isnum(l)):
            raise TypeError()
    else:
        h = promptForNumber('h', 0.)
        k = promptForNumber('k', 0.)
        l = promptForNumber('l', 0.)
        if None in (h, k, l):
            _handleInputError("h,k and l must all be numbers")
    if len(args) == 1:
        pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                args.pop(0))
    elif len(args) == 0:
        reply = promptForInput('current pos', 'y')
        if reply in ('y', 'Y', 'yes'):
            positionList = settings.hardware.get_position()  # @UndefinedVariable
        else:
            currentPos = settings.hardware.get_position()  # @UndefinedVariable
            positionList = []
            names = settings.hardware.get_axes_names()  # @UndefinedVariable
            for i, angleName in enumerate(names):
                val = promptForNumber(angleName.rjust(7), currentPos[i])
                if val is None:
                    _handleInputError("Please enter a number, or press"
                                          " Return to accept default!")
                    return
                positionList.append(val)
        pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
    else:
        raise TypeError()
    
    pos.changeToRadians()
    scale, lat = ubcalc.rescale_unit_cell(h, k, l, pos)
    if scale:
        lines = ["Unit cell scaling factor:".ljust(9) +
                         "% 9.5f" % scale]
        lines.append("Refined crystal lattice:")
        lines.append("   a, b, c:".ljust(9) +
                         "% 9.5f % 9.5f % 9.5f" % (lat[1:4]))
        lines.append(" " * 12 +
                         "% 9.5f % 9.5f % 9.5f" % (lat[4:]))
        lines.append("")
        print('\n'.join(lines))
        reply = promptForInput('Update crystal settings?', 'y')
        if reply in ('y', 'Y', 'yes'):
            ubcalc.set_lattice(*lat)
    else:
        print("No unit cell mismatch detected")
    mc_angle, mc_axis = ubcalc.calc_miscut(h, k, l, pos)
    if mc_angle:
        lines = ["Miscut parameters:",]
        lines.append("      angle:".ljust(9) + "% 9.5f" % mc_angle)
        lines.append("       axis:".ljust(9) + "% 9.5f % 9.5f % 9.5f" % tuple(mc_axis))
        print('\n'.join(lines))
        reply = promptForInput('Apply miscut parameters?', 'y')
        if reply in ('y', 'Y', 'yes'):
            ubcalc.set_miscut(mc_axis, -mc_angle * TORAD, True)
    else:
        print("No miscut detected for the given settings")
        ubcalc.set_miscut(None, 0, True)
Esempio n. 9
0
def addorient(*args):
    """
    addorient -- add crystal orientation interactively
    addorient [h k l] [x y z] {'tag'} -- add crystal orientation with current position in laboratory frame
    addorient [h k l] [x y z] (p1, .., pN) {'tag'} -- add crystal orientation in laboratory frame
    """

    if len(args) == 0:
        h = promptForNumber('h', 0.)
        k = promptForNumber('k', 0.)
        l = promptForNumber('l', 0.)
        if None in (h, k, l):
            _handleInputError("h,k and l must all be numbers")

        x = promptForNumber('x', 0.)
        y = promptForNumber('y', 0.)
        z = promptForNumber('z', 0.)
        if None in (x, y, z):
            _handleInputError("x,y and z must all be numbers")

        reply = promptForInput('current pos', 'y')
        if reply in ('y', 'Y', 'yes'):
            positionList = settings.hardware.get_position()  # @UndefinedVariable
        else:
            currentPos = settings.hardware.get_position()  # @UndefinedVariable
            positionList = []
            names = settings.hardware.get_axes_names()  # @UndefinedVariable
            for i, angleName in enumerate(names):
                val = promptForNumber(angleName.rjust(7), currentPos[i])
                if val is None:
                    _handleInputError("Please enter a number, or press"
                                          " Return to accept default!")
                    return
                positionList.append(val)
        tag = promptForInput("tag")
        if tag == '':
            tag = None
        pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
        ubcalc.add_orientation(h, k, l, x , y, z, pos, tag,
                                   datetime.now())
    elif len(args) in (2, 3, 4):
        args = list(args)
        h, k, l = args.pop(0)
        if not (isnum(h) and isnum(k) and isnum(l)):
            raise TypeError("h,k and l must all be numbers")
        x, y, z = args.pop(0)
        if not (isnum(x) and isnum(y) and isnum(z)):
            raise TypeError("x,y and z must all be numbers")
        if len(args) > 1:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                args.pop(0))
        else:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                settings.hardware.get_position())  # @UndefinedVariable
        if len(args) == 1:
            tag = args.pop(0)
            if not isinstance(tag, str):
                raise TypeError("Tag value must be a string.")
            if tag == '':
                tag = None
        else:
            tag = None
        ubcalc.add_orientation(h, k, l, x, y ,z, pos, tag,
                                   datetime.now())
    else:
        raise TypeError("Invalid number of parameters specified for addorient command.")
Esempio n. 10
0
def addref(*args):
    """
    addref -- add reflection interactively
    addref [h k l] {'tag'} -- add reflection with current position and energy
    addref [h k l] (p1, .., pN) energy {'tag'} -- add arbitrary reflection
    """

    multiplier = settings.hardware.energyScannableMultiplierToGetKeV
    if len(args) == 0:
        h = promptForNumber('h', 0.)
        k = promptForNumber('k', 0.)
        l = promptForNumber('l', 0.)
        if None in (h, k, l):
            _handleInputError("h,k and l must all be numbers")
        reply = promptForInput('current pos', 'y')
        if reply in ('y', 'Y', 'yes'):
            positionList = settings.hardware.get_position()  # @UndefinedVariable
            energy = settings.hardware.get_energy()  # @UndefinedVariable
        else:
            currentPos = settings.hardware.get_position()  # @UndefinedVariable
            positionList = []
            names = settings.hardware.get_axes_names()  # @UndefinedVariable
            for i, angleName in enumerate(names):
                val = promptForNumber(angleName.rjust(7), currentPos[i])
                if val is None:
                    _handleInputError("Please enter a number, or press"
                                          " Return to accept default!")
                    return
                positionList.append(val)
            energy = promptForNumber('energy', settings.hardware.get_energy() / multiplier)  # @UndefinedVariable
            if energy is None:
                _handleInputError("Please enter a number, or press "
                                      "Return to accept default!")
                return
            energy *= multiplier
        tag = promptForInput("tag")
        if tag == '':
            tag = None
        pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
        ubcalc.add_reflection(h, k, l, pos, energy, tag,
                                   datetime.now())
    elif len(args) in (1, 2, 3, 4):
        args = list(args)
        h, k, l = args.pop(0)
        if not (isnum(h) and isnum(k) and isnum(l)):
            raise TypeError("h,k and l must all be numbers")
        if len(args) >= 2:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                args.pop(0))
            energy = args.pop(0) * multiplier
            if not isnum(energy):
                raise TypeError("Energy value must be a number")
        else:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                settings.hardware.get_position())  # @UndefinedVariable
            energy = settings.hardware.get_energy()  # @UndefinedVariable
        if len(args) == 1:
            tag = args.pop(0)
            if not isinstance(tag, str):
                raise TypeError("Tag value must be a string")
            if tag == '':
                tag = None
        else:
            tag = None
        ubcalc.add_reflection(h, k, l, pos, energy, tag,
                                   datetime.now())
    else:
        raise TypeError("Too many parameters specified for addref command.")
Esempio n. 11
0
def setlat(name=None, *args):
    """
    setlat  -- interactively enter lattice parameters (Angstroms and Deg)

    setlat name 'Cubic' a -- sets Cubic system
    setlat name 'Tetragonal' a c -- sets Tetragonal system
    setlat name 'Hexagonal' a c -- sets Hexagonal system
    setlat name 'Orthorhombic' a b c -- sets Orthorombic system
    setlat name 'Rhombohedral' a alpha -- sets Rhombohedral system
    setlat name 'Monoclinic' a b c beta -- sets Monoclinic system
    setlat name 'Triclinic' a b c alpha beta gamma -- sets Triclinic system

    setlat name a -- assumes Cubic system
    setlat name a b -- assumes Tetragonal system
    setlat name a b c -- assumes Orthorombic system
    setlat name a b c angle -- assumes Monoclinic system with beta not equal to 90 or
                                       Hexagonal system if a = b and gamma = 120
    setlat name a b c alpha beta gamma -- sets Triclinic system
    """

    if name is None:  # Interactive
        name = promptForInput("crystal name")
        system = None
        systen_dict = {1: "Triclinic",
                       2: "Monoclinic",
                       3: "Orthorhombic",
                       4: "Tetragonal",
                       5: "Rhombohedral",
                       6: "Hexagonal",
                       7: "Cubic"}
        while system is None:
            system_fmt = "\n".join(["crystal system",] + 
                                   ["%d) %s" % (k, v) 
                                    for (k, v) in systen_dict.items()] +
                                   ['',])
            system = promptForNumber(system_fmt, 1)
            if system not in systen_dict.keys():
                print("Invalid crystal system index selection.\n")
                print("Please select vale between 1 and 7.")
                system = None
        a = promptForNumber('    a', 1)
        args = (a,)
        if system in (1, 2, 3):
            b = promptForNumber('    b', a)
            args += (b,)
        if system in (1, 2, 3, 4, 6):
            c = promptForNumber('    c', a)
            args += (c,)
        if system in (1, 5):
            alpha = promptForNumber('alpha', 90)
            args += (alpha,)
        if system in (1, 2):
            beta = promptForNumber('beta', 90)
            args += (beta,)
        if system in (1,):
            gamma = promptForNumber('gamma', 90)
            args += (gamma,)
        args = (systen_dict[system],) + args
    elif not isinstance(name, str):
        raise TypeError("Invalid crystal name.")
    ubcalc.set_lattice(name, *args)
Esempio n. 12
0
def addref(*args):
    """
    addref -- add reflection interactively
    addref [h k l] {'tag'} -- add reflection with current position and energy
    addref [h k l] (p1, .., pN) energy {'tag'} -- add arbitrary reflection
    """

    if len(args) == 0:
        h = promptForNumber('h', 0.)
        k = promptForNumber('k', 0.)
        l = promptForNumber('l', 0.)
        if None in (h, k, l):
            _handleInputError("h,k and l must all be numbers")
        reply = promptForInput('current pos', 'y')
        if reply in ('y', 'Y', 'yes'):
            positionList = settings.hardware.get_position()  # @UndefinedVariable
            energy = settings.hardware.get_energy()  # @UndefinedVariable
        else:
            currentPos = settings.hardware.get_position()  # @UndefinedVariable
            positionList = []
            names = settings.hardware.get_axes_names()  # @UndefinedVariable
            for i, angleName in enumerate(names):
                val = promptForNumber(angleName.rjust(7), currentPos[i])
                if val is None:
                    _handleInputError("Please enter a number, or press"
                                          " Return to accept default!")
                    return
                positionList.append(val)
            energy = promptForNumber('energy', settings.hardware.get_energy())  # @UndefinedVariable
            if val is None:
                _handleInputError("Please enter a number, or press "
                                      "Return to accept default!")
                return
            muliplier = settings.hardware.energyScannableMultiplierToGetKeV  # @UndefinedVariable
            energy = energy * muliplier
        tag = promptForInput("tag")
        if tag == '':
            tag = None
        pos = settings.geometry.physical_angles_to_internal_position(positionList)  # @UndefinedVariable
        ubcalc.add_reflection(h, k, l, pos, energy, tag,
                                   datetime.now())
    elif len(args) in (1, 2, 3, 4):
        args = list(args)
        h, k, l = args.pop(0)
        if not (isnum(h) and isnum(k) and isnum(l)):
            raise TypeError()
        if len(args) >= 2:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                args.pop(0))
            energy = args.pop(0)
            if not isnum(energy):
                raise TypeError()
        else:
            pos = settings.geometry.physical_angles_to_internal_position(  # @UndefinedVariable
                settings.hardware.get_position())  # @UndefinedVariable
            energy = settings.hardware.get_energy()  # @UndefinedVariable
        if len(args) == 1:
            tag = args.pop(0)
            if not isinstance(tag, str):
                raise TypeError()
        else:
            tag = None
        ubcalc.add_reflection(h, k, l, pos, energy, tag,
                                   datetime.now())
    else:
        raise TypeError()