Raising correct errors in extract_hoppings
extract_hoppings should raise ValueError if input expression doesn't contain valid wave function.
Current behavior:
>>> import sympy
>>> from discretizer.algorithms import extract_hoppings
>>> expr = sympy.sympify('A')
>>> extract_hoppings(expr)
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-12-4e6ae944cd76> in <module>()
1 expr = sympy.sympify('A')
----> 2 extract_hoppings(expr)
/home/raphael/discretizer/discretizer/algorithms.py in extract_hoppings(expr)
536 if expr.args[i].func.__name__ == wavefunction_name:
537 index = i
--> 538 if index < len(expr.args) - 1:
539 print('Psi is not in the very end of the term. Output will be wrong!')
540
UnboundLocalError: local variable 'index' referenced before assignment
and
>>> import sympy
>>> from discretizer.algorithms import extract_hoppings
>>> expr = sympy.sympify('A(x)+B')
>>> extract_hoppings(expr)
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-13-2b09f889c1de> in <module>()
1 expr = sympy.sympify('A(x)+B')
----> 2 extract_hoppings(expr)
/home/raphael/discretizer/discretizer/algorithms.py in extract_hoppings(expr)
525 if summand.args[i].func.__name__ == wavefunction_name:
526 index = i
--> 527 if index < len(summand.args) - 1:
528 print('Psi is not in the very end of the term. Output will be wrong!')
529 hoppings[read_hopping_from_wf(summand.args[-1])] += sympy.Mul(*summand.args[:-1])
UnboundLocalError: local variable 'index' referenced before assignment