Beispiel #1
0
def superscript(num_or_str):
    """ Returns the unicode string superscript equivalent of `num` as a unicode string
    """
    supers = {
        '0': u'\u2070',
        '1': u'\u00B9',
        '2': u'\u00B2',
        '3': u'\u00B3',
        '4': u'\u2074',
        '5': u'\u2075',
        '6': u'\u2076',
        '7': u'\u2077',
        '8': u'\u2078',
        '9': u'\u2079',
    }
    minus = u'\u207B'
    i = u'\u2071'
    plus = u'\u207A'
    if (raises_error(int, num_or_str)) or (
            not raises_error(float, num_or_str)
            and not round(float(num_or_str)) == float(num_or_str)):
        raise TypeError("Only integers can be superscripts")
    ret_val = u''
    for digit in str(num_or_str):
        if digit == '-':
            ret_val += minus
        elif digit == '+':
            ret_val += plus
        elif digit == 'i':
            raise NotImplementedError(
                "Complex numbers as superscripts are not implemented yet.")
        elif digit in supers:
            ret_val += supers[digit]
    return ret_val
Beispiel #2
0
def superscript(num_or_str):
    """ Returns the unicode string superscript equivalent of `num` as a unicode string
    """
    supers = {
        '0' : u'\u2070',
        '1' : u'\u00B9',
        '2' : u'\u00B2',
        '3' : u'\u00B3',
        '4' : u'\u2074',
        '5' : u'\u2075',
        '6' : u'\u2076',
        '7' : u'\u2077',
        '8' : u'\u2078',
        '9' : u'\u2079',
    }
    minus = u'\u207B'
    i = u'\u2071'
    plus = u'\u207A'
    if (raises_error(int, num_or_str)) or (not raises_error(float, num_or_str) and not round(float(num_or_str)) == float(num_or_str)):
        raise TypeError("Only integers can be superscripts")
    ret_val = u''
    for digit in str(num_or_str):
        if digit == '-':
            ret_val += minus
        elif digit == '+':
            ret_val += plus
        elif digit == 'i':
            raise NotImplementedError("Complex numbers as superscripts are not implemented yet.")
        elif digit in supers:
            ret_val += supers[digit]
    return ret_val
Beispiel #3
0
def MolecularPropertyDerivative(prop, representation=CartesianRepresentation, order=1):
    """ Factory for creating `MolecularProperty` subclasses that represent the nth derivative
     of a `MolecularProperty` with respect to some set of coordinates.

     Several possibilities for `representation`:  If it's a `Representation` subclass, then we want that representation
     of the molecule in question (used when requesting the derivative).  If it's a representation instance, then we
     want the Derivative with respect to that specific representation (raises an error if it is not compatible).
     If it's an arbitrary callable, then the callable is called with the contents of the file and should return
     a representation, which the (typically parsed-from-a-file) derivative is considered to be with respect to.
     The default is `CartesianRepresentation`.

     Derivative properties can be automatically or manually transformed to other representations.
    """
    if not issubclass(prop, MolecularProperty):
        raise TypeError
    if raises_error(int, order):
        raise TypeError
    name = '_{1}Derivative{0}'.format(order, prop.__name__)
    if name in DerivativeProperty.known_subclasses:
        ret_val = PartiallyConstructed(DerivativeProperty.known_subclasses[name])
    else:
        ret = type(name, (DerivativeProperty,), {})
        DerivativeProperty.known_subclasses[name] = ret
        ret_val = PartiallyConstructed(ret)
    ret_val.with_attributes(order=order, representation=representation)
    return ret_val
Beispiel #4
0
def subscript(num_or_str):
    """ Returns the unicode string subscript equivalent of `num` as a unicode string
    """
    if (raises_error(int, num_or_str)) or (not raises_error(float, num_or_str) and not round(float(num_or_str)) == float(num_or_str)):
        raise TypeError("Only integers can be subscripts")
    plus = u'\u208A'
    minus = u'\u208B'
    ret_val = u''
    for digit in str(num_or_str):
        if digit == '-':
            ret_val += minus
        elif digit == '+':
            ret_val += plus
        elif digit in '0123456789':
            ret_val += unichr(0x2080 + int(digit))
    return ret_val
Beispiel #5
0
def subscript(num_or_str):
    """ Returns the unicode string subscript equivalent of `num` as a unicode string
    """
    if (raises_error(int, num_or_str)) or (
            not raises_error(float, num_or_str)
            and not round(float(num_or_str)) == float(num_or_str)):
        raise TypeError("Only integers can be subscripts")
    plus = u'\u208A'
    minus = u'\u208B'
    ret_val = u''
    for digit in str(num_or_str):
        if digit == '-':
            ret_val += minus
        elif digit == '+':
            ret_val += plus
        elif digit in '0123456789':
            ret_val += unichr(0x2080 + int(digit))
    return ret_val