1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| # -*-coding=utf-8-*- # Usage:提前准备一个文件,存放各个态的信息,现在这个文件就是为了提取K谷处的态的占据数 #pos 记得提前去掉两行 from numpy import * import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit
with open("C:\\Users\\14618\\Desktop\\0\\k.txt", 'r', encoding='UTF-8')as f: with open("C:\\Users\\14618\\Desktop\\0\\pos.txt", 'r', encoding='UTF-8')as f1: filelist = f.readlines() filelist_new = np.array(filelist) # 转换成 array类型 num_array = filelist_new.size # 整个文件fx的行数
filelist1 = f1.readlines() filelist_new1 = np.array(filelist1) # 转换成 array类型 num_array1 = filelist_new1.size # 整个文件fx的行数
# print('整个文件f数据部分的行数:', filelist[0]) important_K = [] for i in range(1, 421): important_K.append(filelist[82 * i - 52]) i += 1 # print(important[-1]) To_mat_K = zeros((len(important_K), 4))
index = 0 for line in important_K: x = line.strip('\n').split() To_mat_K[index:] = x[0:4] index += 1 #print(To_mat_K) # 把提取到的占据态的信息To_mat_K储存在2.txt To_mat1 = zeros((len(filelist_new1), 3)) print(len(To_mat1)) index = 0 for line in filelist_new1: x = line.strip('\n').split() To_mat1[index:] = x[0:3] index += 1 # print(To_mat)
steps = np.linspace(1, num_array-1, num_array-1) x = 15 * 0.048375 * steps y = 6*To_mat1[:, 1] np.savetxt("C:\\Users\\14618\\Desktop\\occ-k.txt", To_mat_K, delimiter=' ', header='整理')
CM1_raw=To_mat_K[:, 2] CM2_raw=To_mat_K[:, 3] CM1=CM1_raw[1:] CM2=CM2_raw[1:]
print('CM1',CM1) #求平均 CM1_sum = [] CM1_avg = [] CM2_sum = [] CM2_avg = []
for i in range(0,len(CM1)): CM1_sum.append(np.sum(CM1[:i + 1])) CM2_sum.append(np.sum(CM2[:i + 1]))
print('CM1_sum',CM1_sum) print('CM2_sum',CM2_sum)
step=np.linspace(1,419,419)
CM1_avg = np.divide(CM1_sum,step) CM2_avg = np.divide(CM2_sum,step)
print('CM1_avg',CM1_avg) print('CM2_avg',CM2_avg) #去掉列表里的第一个数 print('len',len(CM1_avg))
x=15*0.048378*step # # #拟合 def func1(x, a, b, c): return a * np.exp(-b * x) + c def func2(x, a, b, c): return -a * np.exp(-b * x) + c sigma=np.ones(len(x)) sigma[[0]]=0.01 #设置第一个点的权重,让其通过
#popt_CM1, pcov_CM1 = curve_fit(func1,x,CM1_avg,sigma=sigma) #popt_CM2, pcov_CM2 = curve_fit(func2,x,CM2_avg,sigma=sigma)
# 画图 figure = plt.figure()
#plt.plot(x, To_mat_K[:, 0], 'b-', label='VM1') #plt.plot(x, To_mat_K[:, 1], 'r-', label='VM2') plt.plot(x,CM2_avg, 'r-', label='CM1') plt.plot(x,CM1_avg, 'b-', label='CM2') #出现能级交叉,因此这里更改了Label
#plt.plot(x, func2(x, *popt_CM2), 'r--', #label='fit: a=-%5.3f, b=%5.3f, c=%5.3f' % tuple(popt_CM2)) #plt.plot(x, func1(x, *popt_CM1), 'b--', #label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt_CM1)) print(x) print(len(y)) plt.plot(x,y[2:]-y[2],'g--',lw=0.5) #plt.plot(x, 0.2 * sin(0.051699 * x), 'g--', lw=1) plt.xlabel('Time(fs)') plt.ylabel('Occupations') plt.title('Occupations_Average-Time') plt.xlim([0, 300]) plt.legend(loc=1) plt.axhline(y=0, ls='--', lw=0.2, c='#808080') plt.axvline(x=121.53398, ls='--', lw=0.5, c='#808080') plt.axvline(x=243.06796, ls='--', lw=0.5, c='#808080') plt.axvline(x=60.76699, ls='--', lw=0.5, c='#808080') plt.axvline(x=182.30097, ls='--', lw=0.5, c='#808080')
plt.show() figure.savefig(fname="C:\\Users\\14618\\Desktop\\figure.jpg", dpi=500)
f.close() f1.close()
|