version 0.0.17
This commit is contained in:
parent
960e363190
commit
972bde59d0
@ -58,8 +58,8 @@ hamiltonian = guan.hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10,
|
||||
|
||||
# calculate band structures # Source code: https://py.guanjihuan.com/calculate_band_structures
|
||||
eigenvalue = guan.calculate_eigenvalue(hamiltonian)
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x, hamiltonian_function):
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(x, y, hamiltonian_function)
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function):
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function)
|
||||
|
||||
# calculate wave functions # Source code: https://py.guanjihuan.com/calculate_wave_functions
|
||||
eigenvector = guan.calculate_eigenvector(hamiltonian)
|
||||
@ -106,13 +106,13 @@ wilson_loop_array = guan.calculate_wilson_loop(hamiltonian_function, k_min=-pi,
|
||||
# read and write # Source code: https://py.guanjihuan.com/read_and_write
|
||||
x, y = guan.read_one_dimensional_data(filename='a')
|
||||
x, y, matrix = guan.read_two_dimensional_data(filename='a')
|
||||
guan.write_one_dimensional_data(x, y, filename='a')
|
||||
guan.write_two_dimensional_data(x, y, matrix, filename='a')
|
||||
guan.write_one_dimensional_data(x_array, y_array, filename='a')
|
||||
guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a')
|
||||
|
||||
# plot figures # Source code: https://py.guanjihuan.com/plot_figures
|
||||
guan.plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None)
|
||||
guan.plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None)
|
||||
guan.plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0)
|
||||
guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None)
|
||||
guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None)
|
||||
guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0)
|
||||
|
||||
# download # Source code: https://py.guanjihuan.com/download
|
||||
guan.download_with_scihub(address=None, num=1)
|
||||
|
@ -1,7 +1,7 @@
|
||||
[metadata]
|
||||
# replace with your username:
|
||||
name = guan
|
||||
version = 0.0.16
|
||||
version = 0.0.17
|
||||
author = guanjihuan
|
||||
author_email = guanjihuan@163.com
|
||||
description = An open source python package
|
||||
|
@ -12,34 +12,34 @@ def calculate_eigenvalue(hamiltonian):
|
||||
eigenvalue = np.sort(np.real(eigenvalue))
|
||||
return eigenvalue
|
||||
|
||||
def calculate_eigenvalue_with_one_parameter(x, hamiltonian_function):
|
||||
dim_x = np.array(x).shape[0]
|
||||
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function):
|
||||
dim_x = np.array(x_array).shape[0]
|
||||
i0 = 0
|
||||
if np.array(hamiltonian_function(0)).shape==():
|
||||
eigenvalue_array = np.zeros((dim_x, 1))
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
hamiltonian = hamiltonian_function(x0)
|
||||
eigenvalue_array[i0, 0] = np.real(hamiltonian)
|
||||
i0 += 1
|
||||
else:
|
||||
dim = np.array(hamiltonian_function(0)).shape[0]
|
||||
eigenvalue_array = np.zeros((dim_x, dim))
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
hamiltonian = hamiltonian_function(x0)
|
||||
eigenvalue, eigenvector = np.linalg.eig(hamiltonian)
|
||||
eigenvalue_array[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||
i0 += 1
|
||||
return eigenvalue_array
|
||||
|
||||
def calculate_eigenvalue_with_two_parameters(x, y, hamiltonian_function):
|
||||
dim_x = np.array(x).shape[0]
|
||||
dim_y = np.array(y).shape[0]
|
||||
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function):
|
||||
dim_x = np.array(x_array).shape[0]
|
||||
dim_y = np.array(y_array).shape[0]
|
||||
if np.array(hamiltonian_function(0,0)).shape==():
|
||||
eigenvalue_array = np.zeros((dim_y, dim_x, 1))
|
||||
i0 = 0
|
||||
for y0 in y:
|
||||
for y0 in y_array:
|
||||
j0 = 0
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
hamiltonian = hamiltonian_function(x0, y0)
|
||||
eigenvalue_array[i0, j0, 0] = np.real(hamiltonian)
|
||||
j0 += 1
|
||||
@ -48,9 +48,9 @@ def calculate_eigenvalue_with_two_parameters(x, y, hamiltonian_function):
|
||||
dim = np.array(hamiltonian_function(0, 0)).shape[0]
|
||||
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
|
||||
i0 = 0
|
||||
for y0 in y:
|
||||
for y0 in y_array:
|
||||
j0 = 0
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
hamiltonian = hamiltonian_function(x0, y0)
|
||||
eigenvalue, eigenvector = np.linalg.eig(hamiltonian)
|
||||
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
|
||||
|
@ -4,20 +4,20 @@
|
||||
|
||||
import numpy as np
|
||||
|
||||
def plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None):
|
||||
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None):
|
||||
import matplotlib.pyplot as plt
|
||||
fig, ax = plt.subplots()
|
||||
plt.subplots_adjust(bottom=0.20, left=0.18)
|
||||
ax.plot(x, y, type)
|
||||
ax.plot(x_array, y_array, type)
|
||||
ax.grid()
|
||||
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||
if y_min!=None or y_max!=None:
|
||||
if y_min==None:
|
||||
y_min=min(y)
|
||||
y_min=min(y_array)
|
||||
if y_max==None:
|
||||
y_max=max(y)
|
||||
y_max=max(y_array)
|
||||
ax.set_ylim(y_min, y_max)
|
||||
ax.tick_params(labelsize=20)
|
||||
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||
@ -28,19 +28,19 @@ def plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, t
|
||||
plt.show()
|
||||
plt.close('all')
|
||||
|
||||
def plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None):
|
||||
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None):
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import cm
|
||||
from matplotlib.ticker import LinearLocator
|
||||
matrix = np.array(matrix)
|
||||
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
|
||||
plt.subplots_adjust(bottom=0.1, right=0.65)
|
||||
x, y = np.meshgrid(x, y)
|
||||
x_array, y_array = np.meshgrid(x_array, y_array)
|
||||
if len(matrix.shape) == 2:
|
||||
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||
surf = ax.plot_surface(x_array, y_array, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||
elif len(matrix.shape) == 3:
|
||||
for i0 in range(matrix.shape[2]):
|
||||
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||
@ -67,12 +67,12 @@ def plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='',
|
||||
plt.show()
|
||||
plt.close('all')
|
||||
|
||||
def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
|
||||
def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
|
||||
import matplotlib.pyplot as plt
|
||||
fig, ax = plt.subplots()
|
||||
plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)
|
||||
x, y = np.meshgrid(x, y)
|
||||
contour = ax.contourf(x,y,matrix,cmap='jet')
|
||||
x_array, y_array = np.meshgrid(x_array, y_array)
|
||||
contour = ax.contourf(x_array,y_array,matrix,cmap='jet')
|
||||
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||
|
@ -52,30 +52,30 @@ def read_two_dimensional_data(filename='a'):
|
||||
matrix = np.append(matrix, [matrix_row], axis=0)
|
||||
return x, y, matrix
|
||||
|
||||
def write_one_dimensional_data(x, y, filename='a'):
|
||||
def write_one_dimensional_data(x_array, y_array, filename='a'):
|
||||
with open(filename+'.txt', 'w') as f:
|
||||
i0 = 0
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
f.write(str(x0)+' ')
|
||||
if len(y.shape) == 1:
|
||||
f.write(str(y[i0])+'\n')
|
||||
elif len(y.shape) == 2:
|
||||
for j0 in range(y.shape[1]):
|
||||
f.write(str(y[i0, j0])+' ')
|
||||
if len(y_array.shape) == 1:
|
||||
f.write(str(y_array[i0])+'\n')
|
||||
elif len(y_array.shape) == 2:
|
||||
for j0 in range(y_array.shape[1]):
|
||||
f.write(str(y_array[i0, j0])+' ')
|
||||
f.write('\n')
|
||||
i0 += 1
|
||||
|
||||
def write_two_dimensional_data(x, y, matrix, filename='a'):
|
||||
def write_two_dimensional_data(x_array, y_array, matrix, filename='a'):
|
||||
with open(filename+'.txt', 'w') as f:
|
||||
f.write('0 ')
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
f.write(str(x0)+' ')
|
||||
f.write('\n')
|
||||
i0 = 0
|
||||
for y0 in y:
|
||||
for y0 in y_array:
|
||||
f.write(str(y0))
|
||||
j0 = 0
|
||||
for x0 in x:
|
||||
for x0 in x_array:
|
||||
f.write(' '+str(matrix[i0, j0])+' ')
|
||||
j0 += 1
|
||||
f.write('\n')
|
||||
|
24
tutorial.py
24
tutorial.py
@ -18,10 +18,10 @@ print('sigma_y:\n', guan.sigma_y(), '\n')
|
||||
print('sigma_z:\n', guan.sigma_z(), '\n')
|
||||
|
||||
## Fourier transform / calculate band structures / plot figures
|
||||
x = np.linspace(-pi, pi, 100)
|
||||
x_array = np.linspace(-pi, pi, 100)
|
||||
hamiltonian_function = functools.partial(guan.one_dimensional_fourier_transform, unit_cell=0, hopping=1)
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x, hamiltonian_function)
|
||||
guan.plot(x, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function)
|
||||
guan.plot(x_array, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
|
||||
## Hamiltonian of finite size
|
||||
print(guan.finite_size_along_one_direction(3), '\n')
|
||||
@ -29,11 +29,11 @@ print(guan.finite_size_along_two_directions_for_square_lattice(2, 2), '\n')
|
||||
print(guan.finite_size_along_three_directions_for_cubic_lattice(2, 2, 2), '\n')
|
||||
|
||||
## Hamiltonian of models in the reciprocal space / calculate band structures / plot figures
|
||||
x = np.linspace(-pi, pi, 100)
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x, guan.hamiltonian_of_square_lattice_in_quasi_one_dimension)
|
||||
guan.plot(x, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x, guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension)
|
||||
guan.plot(x, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
x_array = np.linspace(-pi, pi, 100)
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, guan.hamiltonian_of_square_lattice_in_quasi_one_dimension)
|
||||
guan.plot(x_array, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension)
|
||||
guan.plot(x_array, eigenvalue_array, xlabel='k', ylabel='E', type='-k')
|
||||
|
||||
## calculate density of states
|
||||
hamiltonian = guan.finite_size_along_two_directions_for_square_lattice(2,2)
|
||||
@ -109,12 +109,12 @@ p = np.log(wilson_loop_array)/2/pi/1j
|
||||
print('p =', p, '\n')
|
||||
|
||||
## read and write
|
||||
x = np.array([1, 2, 3])
|
||||
y = np.array([5, 6, 7])
|
||||
guan.write_one_dimensional_data(x, y, filename='one_dimensional_data')
|
||||
x_array = np.array([1, 2, 3])
|
||||
y_array = np.array([5, 6, 7])
|
||||
guan.write_one_dimensional_data(x_array, y_array, filename='one_dimensional_data')
|
||||
matrix = np.zeros((3, 3))
|
||||
matrix[0, 1] = 11
|
||||
guan.write_two_dimensional_data(x, y, matrix, filename='two_dimensional_data')
|
||||
guan.write_two_dimensional_data(x_array, y_array, matrix, filename='two_dimensional_data')
|
||||
x_read, y_read = guan.read_one_dimensional_data('one_dimensional_data')
|
||||
print(x_read, '\n')
|
||||
print(y_read, '\n\n')
|
||||
|
Loading…
x
Reference in New Issue
Block a user