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()
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)
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.")
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.")
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()