Hi,
Hello Joseph,
Sorry I copied the wrong pieces of code:
---------------------------------------------------- ham_mat = kwant_sys.hamiltonian_submatrix(sparse=False) ev = sla.eigsh(ham_mat, k=48, which='SM') evecs = ev[1] lat1 = lattice.sublattices[1] lat3 = lattice.sublattices[3] J = kwant.operator.Current(kwant_sys, where=[(lat1(1, 0, 0), lat3(0, 0, 0))]) current = J(evecs[:, 1]) IJ = kwant.plotter.interpolate_current(kwant_sys, current) ---------------------------------------------------------------------------
ValueError Traceback (most recent call last) <ipython-input-162-090a8a157546> in <module>() 5 J = kwant.operator.Current(kwant_sys, where=[(lat1(1, 0, 0), lat3(0, 0, 0))]) 6 current = J(evecs[:, 1]) ----> 7 IJ = kwant.plotter.interpolate_current(kwant_sys, current) 8 print(current) 9
~\Anaconda3\lib\site-packages\kwant\plotter.py in interpolate_current(syst, current, relwidth, abswidth, n) 1851 1852 if len(current) != syst.graph.num_edges: -> 1853 raise ValueError("Current and hoppings arrays do not have the same" 1854 " length.") 1855
ValueError: Current and hoppings arrays do not have the same length.
print(current) [7.65418274e-10] --------------------------------------------------
Ah right, you are only calculating the current over a single hopping, but 'interpolate_current' requires the current over *all* hoppings. What extra information do you hope to get by plotting in realspace the current across a single hopping? This reason this restriction is in place is that 'interpolate_current' accepts just an array of numbers for the current. This means that there is no way for 'interpolate_current' to know which number corresponds to the current across which hopping without further information. This 'further information' is the fact that the array of currents is in the same order as 'syst.graph'; if we don't specify all the hoppings there's know way to know which ones we've specified.
--------------------------------------------------- ham_mat = kwant_sys.hamiltonian_submatrix(sparse=False) ev = sla.eigsh(ham_mat, k=48, which='SM') evecs = ev[1] J = kwant.operator.Current(kwant_sys) current = J(evecs[:, 1]) IJ = kwant.plotter.interpolate_current(kwant_sys, current) ---------------------------------------------------------------------------
ValueError Traceback (most recent call last) <ipython-input-164-ae3dc103f55d> in <module>() 6 J = kwant.operator.Current(kwant_sys) 7 current = J(evecs[:, 1]) ----> 8 IJ = kwant.plotter.interpolate_current(kwant_sys, current) 9
~\Anaconda3\lib\site-packages\kwant\plotter.py in interpolate_current(syst, current, relwidth, abswidth, n) 1900 # this check. This check is done here to keep changes local 1901 if dim != 2: -> 1902 raise ValueError("'interpolate_current' only works for 2D systems.") 1903 factor = (3 / np.pi) / (width / 2) 1904 scale = 2 / width
ValueError: 'interpolate_current' only works for 2D systems.
-----------------------------------------------------------
The restriction of 'interpolate_current' to 2D was lifted a while ago (https://gitlab.kwant-project.org/kwant/kwant/merge_requests/166) but we have not made an official release since. If you're feeling adventurous you can install the Kwant directly from the 'master' branch of the git repository (post back here if you don't know how). Happy Kwanting, Joe