passing site potential by its number in the finalized system

Dear all, Imagine that I have an external potential in a form of a list of values, corresponding to the site numbers in finalized system (this has appeared from mean-field account of Hubbard interactions). Now I want to feed this back to Kwant to compute the modes. The standard function to specify the potential has Site as an argument, with no access to its number in the finalized system. Is there a fast way to get the site number? I found an old reply of Anton:
/site_numbers = {tuple(site.pos(i)): i for i in xrange(sys.graph.num_nodes)} />/site_numbers[(1, 1)] # Find the number of the site with coordinates (1, 1). /
but it does not look efficient. Any suggestions? Thanks, Sergey

Hi,
Imagine that I have an external potential in a form of a list of values, corresponding to the site numbers in finalized system (this has appeared from mean-field account of Hubbard interactions). Now I want to feed this back to Kwant to compute the modes.
The standard function to specify the potential has Site as an argument, with no access to its number in the finalized system. Is there a fast way to get the site number?
I found an old reply of Anton:
/site_numbers = {tuple(site.pos(i)): i for i in xrange(sys.graph.num_nodes)} />/site_numbers[(1, 1)] # Find the number of the site with coordinates (1, 1). / but it does not look efficient.
Looks pretty efficient to me! Python dictionaries have O(1) lookup, and you would only need to construct the mapping once (on finalization). In fact, since Kwant 1.3 this mapping already exists in the finalized system under the attribute name "id_by_site". In the future we will have vectorized evaluation of Hamiltonian value functions that will make all this much more efficient, but in any case an extra dictionary lookup is probably not going to be your speed bottleneck. Happy Kwanting, Joe
participants (2)
-
Joseph Weston
-
Sergey Slizovskiy