Thanks, Anton!
Creating a fake system is a good idea, but it seems that it is still not a 
finalized system as it returns the following error: 

"TypeError: The system needs to be finalized."  
Here is the piece of code I use:
     syst_c=[]
        for item in finilized_sys.graph:            if 
finalized_sys.sites[item[0]].family in [a1, b1] :                    
syst_c.append  
syst_slice = SimpleNamespace(sites=syst_c)densities, box = 
kwant.plotter.interpolate_density(syst=syst_slice, density=densities)         
Best,Hadi


   On Friday, August 16, 2019, 9:16:29 AM GMT+1, Anton Akhmerov 
<anton.akhmerov...@gmail.com> wrote: 
 
 Hi Hadi,

The intended way would be to extend the density vector with np.nan, so
that it has a correct length. However since you mention performance,
I'm not sure if this would achieve what you are looking for.
Inspecting the source of interpolate_density [1], we see that the only
way the system is used is to get

sites = np.array([s.pos for s in syst.sites])

Therefore we can mock the necessary properties of the system by using
the following code:

from types import SimpleNamespace
# make a fake system that only contains the correct sites and isn't
actually a system
syst_slice = SimpleNamespace(sites=(site for site in syst.sites if where(site)))

It is certainly a hack, so a more reliable solution would be to take
over the bits of the source of interpolate_density and the low level
function that it uses [2] and re-purpose for your needs.

[1]: 
https://gitlab.kwant-project.org/kwant/kwant/blob/v1.4.1/kwant/plotter.py#L1793-1872
[2]: 
https://gitlab.kwant-project.org/kwant/kwant/blob/v1.4.1/kwant/plotter.py#L1637-1701

On Fri, 16 Aug 2019 at 10:03, Hadi Zahir <zahir....@gmail.com> wrote:
>
> Dear Kwant developers,
>
> I have a finalized closed system ''sys_f'' for which I computed the local 
> charge densities "ch_densities", which is basically a vector of 
> length=len(sys_f.sites).
>
> For complexity reason,  I'd like to feed a slice of sys_f  to the 
> interpolate_density() as:
>
> >> kwant.plotter.interpolate_density(syst=sys_p, density=ch_densities_p)
>
> where sys_p is a slice of sys_f and ch_densities_p is the corresponding 
> density vector.
> Could you please let me know how to do it?
>
> Best regards,
> Hadi
  

Reply via email to