zhangzeyingvv / MagneticKP

A package for quickly constructing k·p models of magnetic and non-magnetic crystals
GNU General Public License v3.0
17 stars 6 forks source link

calculate and plot energy band #3

Open kaiqi-wang opened 1 year ago

kaiqi-wang commented 1 year ago

Dear zeying, I use MagneticKP-python version to print Hamiltonian , and run the example in the file of /MagneticKP-main/MagneticKP-python/doc/html/index.html. I also want to know how to use this Hamiltonian to calculate and plot energy band ?

zhangzeyingvv commented 1 year ago

Hi kaiqi, You can use the matplotlib module to plot the band structure, Here is a simple example to plot the energy band structure of 2x2 model

import matplotlib.pyplot as plt

C_0_0 = 1
C_2_1 = 2

def matrix(kx):
    return np.array([
        [C_0_0, -C_2_1 * kx],
        [-C_2_1 * kx, C_0_0]
    ])

# Define the range of kx values
kx_range = np.linspace(-10, 10, 1000)

# Calculate the eigenvalues for each kx value
eigenvalues = [np.linalg.eigvals(matrix(kx_val)) for kx_val in kx_range]

# Unpack the eigenvalues into separate arrays
eval1, eval2 = zip(*eigenvalues)

# Plot the eigenvalues
plt.plot(kx_range, eval1, label="Eigenvalue 1")
plt.plot(kx_range, eval2, label="Eigenvalue 2")
plt.xlabel("kx")
plt.ylabel("Eigenvalues")
plt.legend()
plt.show()

Or you can use the Mathematica version of MagneticKP, and plot the band structure by bandManipulate and bandplot functions.

kaiqi-wang commented 1 year ago

Thank you very much ~ Is there a WeChat or QQ communication group? I would like to apply to join.

zhangzeyingvv commented 1 year ago

Yes! You can scan this QR code: 2309273d95bc4b2d2c001b35010cce2