Exemplo n.º 1
0
 def handle_con(self, args):
     if not args:
         return self._hklcalc.constraints.__str__()
     
     if len(args) > 6:
         raise TypeError("Unexpected args: " + str(args))
     
     cons_value_pairs = []
     while args:
         scn_or_str = args.pop(0)
         name = getNameFromScannableOrString(scn_or_str)
         if args and isinstance(args[0], (int, long, float)):
             value = args.pop(0)
         else:
             value = None
         cons_value_pairs.append((name, value))
     
     if len(cons_value_pairs) == 1:
         pass
     elif len(cons_value_pairs) == 3:
         self._hklcalc.constraints.clear_constraints()
     else:
         raise TypeError("Either one or three constraints must be specified")
     for name, value in cons_value_pairs:
         self._hklcalc.constraints.constrain(name)
         if value is not None:
             self._hklcalc.constraints.set_constraint(name, value)
     return '\n'.join(self._hklcalc.constraints.report_constraints_lines())
Exemplo n.º 2
0
def _handle_con(args):
    if not args:
        return hklcalc.constraints.__str__()

    if len(args) > 6:
        raise TypeError("Unexpected args: " + str(args))

    cons_value_pairs = []
    while args:
        scn_or_str = args.pop(0)
        name = getNameFromScannableOrString(scn_or_str)
        if args and isinstance(args[0], (int, long, float)):
            value = args.pop(0)
        else:
            value = None
        cons_value_pairs.append((name, value))

    if len(cons_value_pairs) == 1:
        pass
    elif len(cons_value_pairs) == 3:
        hklcalc.constraints.clear_constraints()
    else:
        raise TypeError("Either one or three constraints must be specified")
    for name, value in cons_value_pairs:
        hklcalc.constraints.constrain(name)
        if value is not None:
            hklcalc.constraints.set_constraint(name, value)
    return '\n'.join(hklcalc.constraints.report_constraints_lines())
Exemplo n.º 3
0
def _handle_con(args):
    if not args:
        return hklcalc.constraints.__str__()

    if len(args) > 6:
        raise TypeError("Unexpected args: " + str(args))

    cons_value_pairs = []
    while args:
        scn_or_str = args.pop(0)
        ext_name = getNameFromScannableOrString(scn_or_str)
        if args and isinstance(args[0], (int, float)):
            ext_value = args.pop(0)
        else:
            try:
                ext_value = settings.hardware.get_position_by_name(ext_name)
            except ValueError:
                ext_value = None
        cons_name, cons_value = settings.geometry.map_to_internal_position(
            ext_name, ext_value)
        cons_value_pairs.append((cons_name, cons_value))

    if len(cons_value_pairs) == 1:
        pass
    elif len(cons_value_pairs) == 3:
        hklcalc.constraints.clear_constraints()
    else:
        raise TypeError("Either one or three constraints must be specified")
    for name, value in cons_value_pairs:
        hklcalc.constraints.constrain(name)
        if value is not None:
            hklcalc.constraints.set_constraint(name, value)
    return '\n'.join(hklcalc.constraints.report_constraints_lines())
Exemplo n.º 4
0
    def uncon(self, scn_or_string):
        """uncon <name> -- remove constraint

        See also 'con'
        """
        name = getNameFromScannableOrString(scn_or_string)
        self._hklcalc.constraints.unconstrain(name)
        print '\n'.join(self._hklcalc.constraints.report_constraints_lines())
Exemplo n.º 5
0
def uncon(scn_or_string):
    """uncon <name> -- remove constraint

    See also 'con'
    """
    name = getNameFromScannableOrString(scn_or_string)
    hklcalc.constraints.unconstrain(name)
    print '\n'.join(hklcalc.constraints.report_constraints_lines())
Exemplo n.º 6
0
def uncon(scn_or_string):
    """uncon <name> -- remove constraint

    See also 'con'
    """
    ext_name = getNameFromScannableOrString(scn_or_string)
    cons_name = settings.geometry.map_to_internal_name(ext_name)
    hklcalc.constraints.unconstrain(cons_name)
    print('\n'.join(hklcalc.constraints.report_constraints_lines()))

    diffcalc.ub.ub.ubcalc.save()
Exemplo n.º 7
0
def setpar(scannable_or_string=None, val=None):
    """setpar {parameter_scannable {{val}} -- sets or shows a parameter'
    setpar {parameter_name {val}} -- sets or shows a parameter'
    """

    if scannable_or_string is None:
        #show all
        parameterDict = hklcalc.parameter_manager.getParameterDict()
        names = parameterDict.keys()
        names.sort()
        for name in names:
            print _representParameter(name)
    else:
        name = getNameFromScannableOrString(scannable_or_string)
        if val is None:
            _representParameter(name)
        else:
            oldval = _getParameter(name)
            _setParameter(name, float(val))
            print _representParameter(name, oldval, float(val))
Exemplo n.º 8
0
    def setpar(self, scannable_or_string=None, val=None):
        """setpar {parameter_scannable {{val}} -- sets or shows a parameter'
        setpar {parameter_name {val}} -- sets or shows a parameter'
        """

        if scannable_or_string is None:
            #show all
            parameterDict = self._hklcalc.parameter_manager.getParameterDict()
            names = parameterDict.keys()
            names.sort()
            for name in names:
                print self._representParameter(name)
        else:
            name = getNameFromScannableOrString(scannable_or_string)
            if val is None:
                self._representParameter(name)
            else:
                oldval = self._getParameter(name)
                self._setParameter(name, float(val))
                print self._representParameter(name, oldval, float(val))
Exemplo n.º 9
0
 def uncon(self, scn_or_string):
     """uncon <constraint> -- unconstrains constraint
     """
     name = getNameFromScannableOrString(scn_or_string)
     self._hklcalc.constraints.unconstrain(name)
     print self._report_constraints()