kwant.continuum.
sympify
(expr, locals=None)[source]¶Sympify object using special rules for Hamiltonians.
If ‘expr` is already a type that SymPy understands, it will do nothing
but return that value. Note that locals
will not be used in this
situation.
Otherwise, it is sympified by sympy.sympify
with a modified namespace
such that
sympy.physics.quantum.TensorProduct
, and
“identity” to sympy.eye
,In addition, Python list literals are interpreted as SymPy matrices.
Warning
This function uses eval
(because it calls sympy.sympify
), and
thus should not be used on unsanitized input.
Parameters:  expr : str or SymPy expression
locals : dict or


Returns:  result : SymPy object 
Examples
>>> sympify('k_x * A(x) * k_x + V(x)')
k_x*A(x)*k_x + V(x) # as valid sympy object
>>> sympify('k_x**2 + V', locals={'V': 'V_0 + V(x)'})
k_x**2 + V(x) + V_0
>>> ns = {'sigma_plus': [[0, 2], [0, 0]]}
>>> sympify('k_x**2 * sigma_plus', ns)
Matrix([
[0, 2*k_x**2],
[0, 0]])
>>> sympify('k_x * A(c) * k_x', locals={'c': 'x'})
k_x*A(x)*k_x
>>> sympify('k_x * A(c) * k_x', locals={'c': sympy.Symbol('x')})
A(x)*k_x**2