Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote:
Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
Anton, Thanks for the rapid response, now it works  of course. I have started to wrestle with Python only because of Kwant, so it will take some time before I fully understand your reply. In the meantime, would you be so kind and suggest how to plot ldos for spinup and spindown components separately? Jerzy
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote:
Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
In the meantime, would you be so kind and suggest how to plot ldos for spinup and spindown components separately?
You basically need get only the even or only odd elements of an array local_dos. For that you can use
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Such stuff is explained in NumPy tutorial, and this particular question over here: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
Cheers, Anton
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote:
Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
Let me just add briefly to Anton's answer:
Let's assume you have M degrees of freedom on each lattice site ( the same on each lattice site). This implies that the value for each lattice site is an MxM matrix; in the case of spin M=2.
Consider the way how you usually describe a wave function in such a system: The wave function is an Mdimensional vector for each lattice point (for spin, it is a 2dimensional spinor; where spinor for our purposes is just a fancy name for vector).
In the result of ldos (the same also holds for wave_function, and ldos is for real energies nothing more than just a sum over all scattering wave functions times some prefactors), these Mdimensional vectors are stored one after each other for each lattice point. In particular, the sth entry of the vector at lattice site i is stored in
local_dos[s + i*M]
where I now used the python convention that indexing starts from 0, i.e. s = 0, 1, ..., M1
For spin, this now means that you can get all of spinup and down by doing
Nsites = local_dos.shape[0] / 2 spin_up = np.zeros((Nsites,)) spin_down = np.zeros((Nsites,)) for i in xrange(Nsites): spin_up[i] = local_dos[i * 2] spin_down[i] = local_dos[i * 2 + 1]
In fact, this is just a very long version of what Anton wrote in his email:
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Numpy allows you to do all kinds of tricks with indexing, which are very neat and powerful, and what might look cryptic in the beginning is in fact very simple.
Hope that helps,
Michael
Am 24 sep. 2013 um 22:17 schrieb Anton Akhmerov anton.akhmerov@gmail.com:
In the meantime, would you be so kind and suggest how to plot ldos for spinup and spindown components separately?
You basically need get only the even or only odd elements of an array local_dos. For that you can use
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Such stuff is explained in NumPy tutorial, and this particular question over here: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
Cheers, Anton
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote: Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
Michael, Anton, Thanks again for explanations. I have some experience with Octave/Matlab so, hopefully, I will manage with Python. Jerzy P.S. Just a side question from the experimentalist: When spinorbit is present, spin is no longer a good quantum number. So, what is in fact stored in 2dimensional vector (spinor) at each lattice site?
Let me just add briefly to Anton's answer:
Let's assume you have M degrees of freedom on each lattice site ( the same on each lattice site). This implies that the value for each lattice site is an MxM matrix; in the case of spin M=2.
Consider the way how you usually describe a wave function in such a system: The wave function is an Mdimensional vector for each lattice point (for spin, it is a 2dimensional spinor; where spinor for our purposes is just a fancy name for vector).
In the result of ldos (the same also holds for wave_function, and ldos is for real energies nothing more than just a sum over all scattering wave functions times some prefactors), these Mdimensional vectors are stored one after each other for each lattice point. In particular, the sth entry of the vector at lattice site i is stored in
local_dos[s + i*M]
where I now used the python convention that indexing starts from 0, i.e. s = 0, 1, ..., M1
For spin, this now means that you can get all of spinup and down by doing
Nsites = local_dos.shape[0] / 2 spin_up = np.zeros((Nsites,)) spin_down = np.zeros((Nsites,)) for i in xrange(Nsites): spin_up[i] = local_dos[i * 2] spin_down[i] = local_dos[i * 2 + 1]
In fact, this is just a very long version of what Anton wrote in his email:
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Numpy allows you to do all kinds of tricks with indexing, which are very neat and powerful, and what might look cryptic in the beginning is in fact very simple.
Hope that helps,
Michael
Am 24 sep. 2013 um 22:17 schrieb Anton Akhmerov anton.akhmerov@gmail.com:
In the meantime, would you be so kind and suggest how to plot ldos for spinup and spindown components separately?
You basically need get only the even or only odd elements of an array local_dos. For that you can use
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Such stuff is explained in NumPy tutorial, and this particular question over here: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
Cheers, Anton
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote: Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
Hi Jerzy,
Spin is indeed not conserved in systems with spinorbit coupling. That means that the eigenstates of the Hamiltonian aren't necessarily eigenstates of any of the spin component. However the spin is still defined, and the two degrees of freedom correspond to local spin polarizations up or down. It's really no different from position: it isn't a good quantum number, however different lattice sites correspond to different positions.
Best, Anton
On Wed, Sep 25, 2013 at 8:01 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote:
Michael, Anton, Thanks again for explanations. I have some experience with Octave/Matlab so, hopefully, I will manage with Python. Jerzy P.S. Just a side question from the experimentalist: When spinorbit is present, spin is no longer a good quantum number. So, what is in fact stored in 2dimensional vector (spinor) at each lattice site?
Let me just add briefly to Anton's answer:
Let's assume you have M degrees of freedom on each lattice site ( the same on each lattice site). This implies that the value for each lattice site is an MxM matrix; in the case of spin M=2.
Consider the way how you usually describe a wave function in such a system: The wave function is an Mdimensional vector for each lattice point (for spin, it is a 2dimensional spinor; where spinor for our purposes is just a fancy name for vector).
In the result of ldos (the same also holds for wave_function, and ldos is for real energies nothing more than just a sum over all scattering wave functions times some prefactors), these Mdimensional vectors are stored one after each other for each lattice point. In particular, the sth entry of the vector at lattice site i is stored in
local_dos[s + i*M]
where I now used the python convention that indexing starts from 0, i.e. s = 0, 1, ..., M1
For spin, this now means that you can get all of spinup and down by doing
Nsites = local_dos.shape[0] / 2 spin_up = np.zeros((Nsites,)) spin_down = np.zeros((Nsites,)) for i in xrange(Nsites): spin_up[i] = local_dos[i * 2] spin_down[i] = local_dos[i * 2 + 1]
In fact, this is just a very long version of what Anton wrote in his email:
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Numpy allows you to do all kinds of tricks with indexing, which are very neat and powerful, and what might look cryptic in the beginning is in fact very simple.
Hope that helps,
Michael
Am 24 sep. 2013 um 22:17 schrieb Anton Akhmerov anton.akhmerov@gmail.com:
In the meantime, would you be so kind and suggest how to plot ldos for spinup and spindown components separately?
You basically need get only the even or only odd elements of an array local_dos. For that you can use
local_dos[0::2] # Only even elements local_dos[1::2] # Only odd elements
Such stuff is explained in NumPy tutorial, and this particular question over here: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
Cheers, Anton
Hi Jerzy,
Note for the future: it is always helpful to add the actual error messages to your reports. In this case however, the problem is clear:
kwant.ldos calculates local density of states on each degree of freedom of the system (so spin up and spin down separately). On the other hand, kwant.plotter.map expects to have as many values to plot as there are sites in the system, not more and not less. Both of these things are behaving as written in the docs. You can modify your function to plot the density of states per site for example like this:
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) # Calculate ldos per site, by summing spin up and spin down components local_dos = np.sum(local_dos.reshape(1, 2), axis=1) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
The line that I have added, as you can check, uses NumPy functions for manipulations with arrays: first out of a 1D array with shape (2xN) an array with shape (N, 2): my_array.reshape(1, 2) where the elements with the same value of the 0th coordinate (NumPy counts array axes starting from 0) have the same site number. Then I sum this array along the second axis: np.sum(my_array, axis=1)
I hope this helps.
Best, Anton
On Tue, Sep 24, 2013 at 8:20 PM, Jerzy Wrobel wrobel@ifpan.edu.pl wrote: Hi All,
I have modified quantum_wire_revisited.py by adding new function
def plot_ldos(sys, energy): # Compute local dos local_dos = kwant.ldos(sys, energy) kwant.plotter.map(sys, local_dos, num_lead_cells=5)
and adding new command
plot_ldos(sys, energy=0.5)
to the already existing function main().
It works well. However, when I have modified the spinorbit.py file in the same way, program halts. Some cryptic messages, which ended with ValueError: different number of values and points, are generated.
How to resolve this? Thanks in advance,
Jerzy
participants (3)

Anton Akhmerov

Jerzy Wrobel

Michael Wimmer