Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
735 views
�
�F�V(�@sTddlZddlZddlmZddlmZddlZddlZddl	m	Z	e
dd�ejjd�dd�D��dkr�e
d��ndd
ddgZedejddgddgg�dejddgddgg�dejddgddgg�dejddgddgg��Zejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ejejej�e_ ejejej�e_!ejejej�e_"ejejej�e_#ejejej�e_$ejejej�e_%dddddddddddddddd�Z&dd�Z'ddddddd
�Z(dS)�N)�copy)�SimpleNamespace)�
wraparoundccs|]}t|�VqdS)N)�int)�.0�i�r�../code/functions.py�	<genexpr>sr
�.���znumpy >= (1, 8, 0) is required�spectrum�hamiltonian_array�h_k�pauli�s0g�?g�sx�syy�?�szcsjtjdfdtjdfg}|dkr:t�}n|jj�|||g}dd�|D�}�fdd�t|�D�}|\}}}t|||||d	�\}}t|�dkr�tjj	|��nt|�dkr�t
d��ngt|�d
kr�|dkrb|ddd
j�krQdj|dd�}qb|dd}n|dkrwd}nt
j|dd
�fd||g�}i}t|	tj�r�t|	�|d<n|	dkr�n
|	|d<t|
tj�r	t|
�|d<nt|
t�r%|
|d<n|dk	r=t|�n	td�}|
dk	rat|
�n	td�}
t|�r�|j||��}n|||
fdi|d6�St|�dkrZi�|	dkr�|ddd
j�kr�|�d<n|
dkr-|d
dd
j�kr-|�d<n|dkr~|ddd
j�krmdj|dd�}q~|dd}n|dkr�|d
dd
j�kr�dj|d
d�}q�|d
d}n|dkr�d}n|dk	r�|�d<n|dkr@tjt|dd
�t|dd
�gd�}n|
dkr�tjt|dd
�t|dd
�gd�}
n|dkr�d}ni|d|
d|d|d
|
d
|d
fd6||gd6|gd6�t
j���fdd�t�jd �D��}t|�r?|j||��}n|diidd6d6�St
d��dS)!ahFunction that plots system spectrum for varying parameters or momenta.

    Parameters:
    -----------
    sys : kwant.Builder object
        The un-finalized (in)finite system.
    p : SimpleNamespace object
        A container used to store Hamiltonian parameters. The parameters that
        are sequences are used as plot axes.
    k_x, k_y, k_z : floats or sequences of floats
        Real space momenta at which the Hamiltonian has to be evaluated.
        If the system dimensionality is low, extra momenta are ignored.
    title : function
        Function that takes p as argument and generates a string.
    xdim, ydim, zdim : holoviews.Dimension or string
        The labels of the axes. Default to best guess, and extra ones
        are ignored.
    xticks, yticks zticks : list
        Lists of axes xticks, extra ones are ignored.
    xlims, ylims, zlims : tuple
        Upper and lower plot limit of the axes. If None the upper and lower
        limits of the ticks are used. Extra ones are ignored.

    Returns:
    --------
    plot : holoviews.Path object
        Plot of varying parameter vs. spectrum.
    z$-\pi$r�$0$z$\pi$NcSs>g|]4}|dkr4tjtjtjd�n|�qS)N�e)�np�linspace�pi)rrrrr	�
<listcomp>Ks	zspectrum.<locals>.<listcomp>cs.g|]$\}}|�kr$|nd�qS)rr)r�jr)�dimensionalityrr	rMs	Tr
�zA 0D plot requestedzk_x k_y k_zz${}$z$E$�kdims�xticks�yticks�plot�Path�zticks�extents�vdimscsDg|]:}tj�dd�dd�|f��d���qS)Nr#)�hv�Surface)rr)�energies�kwargs�stylerr	r�s	���fig_size�OverlayzCannot make 4D plots yet.)rr)r
r)NN�����)rrr�symmetry�num_directions�	enumerater�len�linalg�eigvalsh�
ValueError�split�formatr(r$�
isinstance�collections�Iterable�listr�slice�callable�relabel�round�min�maxr/�range�shape)�sys�p�k_x�k_y�k_z�title�xdim�ydim�zdimr!r"r%ZxlimsZylimsZzlimsZpi_ticks�k�hamiltonians�	variablesr#�ticksr)rr*r+r,r	r's�"	
!	)

$$&
&
	
77	

cCst|||�dS)zNFunction that returns the Hamiltonian of a kwant 1D system as a momentum.
    r)r)rFrGZmomentumrrr	r�sFc
s�|dkrt�}ny�
jjjd�	Wntk
rId�	YnX�
jj�t|���dkr��
j��
dd��n�t�
jj�dkr��fdd��nTt	j
�
jj�j}|jt	j
j|jj|������	fdd��t�
�j��
t�}x<�jj�D]+\}}	t|	tj�r5|	||<q5q5Wxrd�fd	�fd
�fgD]O\}}	||kr�tdj|���nt|	tj�r�|	||<q�q�W|s%�
j�g����g�dd
�d}
|r|
gfS|
Sn������
fdd��tt|j���\�}��fdd�tj|�D�}
t|
dj�}t	j
|
�jdd�|D�|�}
|r�|
tt�|��fS|
SdS)a4Evaluate the Hamiltonian of a system over a grid of parameters.

    Parameters:
    -----------
    sys : kwant.Builder object
        The un-finalized kwant system whose Hamiltonian is calculated.
    p : SimpleNamespace object
        A container of Hamiltonian parameters. The parameters that are
        sequences are used to loop over.
    k_x, k_y, k_z : floats or sequences of floats
        Momenta at which the Hamiltonian has to be evaluated.  If the system
        only has 1 translation symmetry, only `k_x` is used, and interpreted as
        lattice momentum. Otherwise the momenta are in reciprocal space.
    return_grid : bool
        Whether to also return the names of the variables used for expansion,
        and their values.

    Returns:
    --------
    hamiltonians : numpy.ndarray
        An array with the Hamiltonians. The first n-2 dimensions correspond to
        the expanded variables.
    parameters : list of tuples
        Names and ranges of values that were used in evaluation of the
        Hamiltonians.

    Examples:
    ---------
    >>> hamiltonian_array(sys, SimpleNamespace(t=1, mu=np.linspace(-2, 2)),
    ...                   k_x=np.linspace(-np.pi, np.pi))
    >>> hamiltonian_array(sys_2d, p, np.linspace(-np.pi, np.pi),
    ...                   np.linspace(-np.pi, np.pi))

    Nr
rcSsgS)Nr)rOrrr	�momentum_to_lattice�sz.hamiltonian_array.<locals>.momentum_to_latticecs0t|�d��r%td��n|dgS)Nz0Dispersion is 1D, but more momenta are provided.r)�anyr7)rO)rrr	rS�scsctjj�|d���dd�\}}tjt|�dk�rYtd��nt|�S)NrgH�����z>z>Requested momentum doesn't correspond to any lattice momentum.)rr5�lstsqrT�abs�RuntimeErrorr=)rO�	residuals)�A�space_dimensionalityrr	rS�s/rHrIrJzUOne of the system parameters is {}, which is reserved for momentum. Please rename it.�sparseF.csl�jj|�|jd��|jd��|jd��g}�|�}�jd�g|dd�S)NrHrIrJ�argsr[F)�__dict__�update�get�hamiltonian_submatrix)�valuesrO)rHrIrJrS�parsrFrr	�hamiltonians
z&hamiltonian_array.<locals>.hamiltoniancs+g|]!}�tt�|����qSr)�dict�zip)r�value)rc�namesrr	rs	z%hamiltonian_array.<locals>.<listcomp>cSsg|]}t|��qSr)r4)rrfrrr	rs	r0)N.)rr1�periodsrE�AttributeErrorr2r�	finalizedr4r�array�T�dotr5�invrrdr]�itemsr:r;r<rWr9r`re�sorted�	itertools�productr=�reshape)
rFrGrHrIrJZreturn_grid�BZchanging�keyrfrPra�sizer)rYrrcrHrIrJrSrgrbrZrFr	r�sX#
'	.	

!)r
rry��g�))rqr;r�typesr�numpyr�	holoviewsr(r�tuple�__version__r8rW�__all__rkr�kronrZs0s0rZs0sxrZs0syrZs0szZsxs0ZsxsxZsxsyZsxszZsys0ZsysxZsysyZsyszZszs0ZszsxZszsyZszszrrrrrrr	�<module>sD5'!!$�