def seperate_symbols(func):
    params = []
    vars = []
    for symbol in func.free_symbols:
        if not isidentifier(str(symbol)):
            continue
        if isinstance(symbol, Parameter):
            params.append(symbol)
        elif isinstance(symbol, Idx):
            pass
        elif isinstance(symbol, (MatrixExpr, Expr)):
            vars.append(symbol)
        else:
            raise TypeError('model contains an unknown symbol type, {}'.format(type(symbol)))
    for der in func.atoms(sympy.Derivative):
        if der.expr in vars and all(isinstance(s, Parameter) for s in der.variables):
            vars.append(der)
    params.sort(key=lambda symbol: symbol.name)
    vars.sort(key=lambda symbol: symbol.name)
    return vars, params