loading...
MoS2后处理脚本-计算磁矩
Published in:2021-12-30 |

已知:

该脚本是针对MoS2中991的k-mesh来展开的,主要K谷和K’谷刚好在第31和61个k点处,可在 MoS2_scf.crystal.KP中对应查看位置坐标

1.处理统计总磁矩

用法:将文件x,y,z方向的磁矩存在mag-raw.txt文件中,然后用下面脚本进行处理

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
#-*-coding=utf-8-*-
#Usage:提前准备一个mag.txt存放关于体系计算得到的总磁矩(x,y,z方向,依次从第二列开始),第一列为标定的时间
from numpy import *
import numpy as np
import scipy
from scipy.integrate import simps
from sympy import integrate,symbols
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from matplotlib.pyplot import MultipleLocator
#MultipleLocator设置刻度间隔

with open("C:\\Users\\14618\\Desktop\\mag-raw.txt",'r',encoding='UTF-8')as f:
with open("C:\\Users\\14618\\Desktop\\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('步数:',num_array)
To_mat = zeros((num_array, 3))
index = 0
for line in filelist_new:
x = line.strip('\n').split()
To_mat[index:] = x[0:3]
index += 1


To_mat1 = zeros((len(filelist_new), 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


y=0.05*To_mat1[:,1] #平衡位置在0.6
#To_mat1声子振动 To_mat 磁矩


#print(delta_t)
Sx=To_mat[:,0]
Sy=To_mat[:,1]
Sz=To_mat[:,2]

step=np.linspace(1,num_array,num_array)
x=15*0.048375*step
T=step
print(x)


#定义一个拟合函数
def func(x, a, b, c):
return a * np.exp(-b * x) + c

figure=plt.figure()


plt.plot(x[1:]-x[0],Sz[1:]-Sz[1],'b-',label='z direction')
plt.plot(x[1:]-x[0],Sy[1:]-Sy[1],'r-',label='y direction')
plt.plot(x[1:]-x[0],Sx[1:]-Sx[0],'k-',label='x direction')
plt.plot(x,y,'g--',lw=0.2)
#plt.plot(x, func(x, *popt_z), 'b--',label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt_z))
#
# #plt.plot(x,0.004*sin(0.051699*x),'g--',lw=1)
plt.xlabel('Time(fs)')
plt.ylabel('Total magnetization(Bohr mag/cell)')
plt.title('Magnetization-total')
y_major_locator=MultipleLocator(0.005)
ax=plt.gca() #获取当前轴
ax.yaxis.set_major_locator(y_major_locator) #设置间隔
plt.xlim([0,300])
plt.ylim([-0.016,0.0086])
plt.legend(loc=1)
plt.axhline(y=0,ls='--',lw=1,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-total.jpg",dpi=500)



f1.close()
f.close()


2.处理统计平均磁矩

用法:将文件x,y,z方向的磁矩存在mag-K.txt文件中,然后用下面脚本进行处理(由于实验要求不同,常用的求平均值法也不同,即所研究的区间段不同)

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
#-*-coding=utf-8-*-
#Usage:提前准备一个mag.txt存放关于体系计算得到的总磁矩(x,y,z方向,依次从第二列开始),第一列为标定的时间
from numpy import *
import numpy as np
import scipy
from scipy.integrate import simps
from sympy import integrate,symbols
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

with open("C:\\Users\\14618\\Desktop\\0\\mag-raw.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('步数:',num_array)
To_mat = zeros((num_array, 3))
index = 0
for line in filelist_new:
x = line.strip('\n').split()
To_mat[index:] = x[0:3]
index += 1


To_mat1 = zeros((len(filelist_new), 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


y=0.05*To_mat1[:,1] #平衡位置在0.6
#To_mat1声子振动 To_mat 磁矩


#print(delta_t)
Sx=To_mat[:,0]
Sy=To_mat[:,1]
Sz=To_mat[:,2]

step=np.linspace(2,420,419)


T=step-1
x = 15 * 0.048375 * T
print(x)

#定义
sum_up_z=[]
Sz_avg=[]
sum_up_y=[]
Sy_avg=[]
sum_up_x=[]
Sx_avg=[]
for i in range(len(Sz)):
sum_up_z.append(np.sum(Sz[:i+1]))
sum_up_y.append(np.sum(Sy[:i+1]))
sum_up_x.append(np.sum(Sx[:i+1]))

Sz_avg=np.divide(sum_up_z[1:], T)
Sy_avg=np.divide(sum_up_y[1:], T)
Sx_avg=np.divide(sum_up_x[1:], T)


#定义一个拟合函数
def func(x, a, b, c):
return a * np.exp(-b * x) + c
sigma=np.ones(len(x))
sigma[[0]]=0.01 #设置第一个点的权重,让其通过

c=Sz_avg-Sz_avg[0]
b=Sy_avg-Sy_avg[0]
a=Sx_avg-Sx_avg[0]

#popt_z, pcov_z = curve_fit(func,x,c,sigma=sigma)
# popt_y, pcov_y = curve_fit(func,x,b)
# popt_x, pcov_x = curve_fit(func,x,a)

#
figure=plt.figure()
#

plt.plot(x,c,'b-',label='z direction')
plt.plot(x,b,'r-',label='y direction')
plt.plot(x,a,'k-',label='x direction')
plt.plot(x,y[1:]-y[0],'g--',lw=0.2)
#plt.plot(x, func(x, *popt_z), 'b--',label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt_z))
#
# #plt.plot(x,0.004*sin(0.051699*x),'g--',lw=1)
plt.xlabel('Time(fs)')
plt.ylabel('Total magnetization(Bohr mag/cell)')
plt.title('Magnetization-average')
plt.xlim([0,300])
plt.legend(loc=1)
plt.axhline(y=0,ls='--',lw=1,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-new.jpg",dpi=500)



f1.close()
f.close()

3.处理统计总占据数

用法:将文件x,y,z方向的磁矩存在k.txt文件中,然后用下面脚本进行处理

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
#-*-coding=utf-8-*-
#Usage:提前准备一个文件,存放各个态的信息,现在这个文件就是为了提取K谷处的态的占据数
from numpy import *
import numpy as np
import matplotlib.pyplot as plt

with open("C:\\Users\\14618\\Desktop\\k.txt",'r',encoding='UTF-8')as f:
with open("C:\\Users\\14618\\Desktop\\pos.txt", 'r', encoding='UTF-8')as f1:
filelist=f.readlines()

filelist_new = np.array(filelist) # 转换成 array类型
num_array = filelist_new.size # 整个文件fx的行数
#print('整个文件f数据部分的行数:', filelist[0])
important_K=[]
for i in range(1,421):
important_K.append(filelist[82*i-52])
i+=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)
filelist1 = f1.readlines()
filelist_new1 = np.array(filelist1) # 转换成 array类型
num_array1 = filelist_new1.size # 整个文件fx的行数

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

#把提取到的占据态的信息储存在2.txt
np.savetxt("C:\\Users\\14618\\Desktop\\occ-k.txt",To_mat_K, delimiter=' ',header='整理')





step = np.linspace(1, 420, 420)
x = 15 * 0.048375 * step
y = 3*To_mat1[:, 1]

CM1=To_mat_K[:,2]
CM2=To_mat_K[:,3]
print(CM1)
# 画图
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[1:],CM1[1:],'b-', label='CM2')
plt.plot(x[1:],CM2[1:],'r-', label='CM1')#自洽
# plt.plot(x, CM1, 'b-', label='CM1')
# plt.plot(x, CM2, 'r-', label='CM2')
plt.plot(x, y[1:]-y[0], '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-Time')
plt.xlim([0, 300])
plt.legend(loc=1)
plt.axhline(y=0, ls='--', lw=0.5, 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()

4.处理统计平均占据数

用法:将文件x,y,z方向的占据数存在K.txt文件中,然后用下面脚本进行处理(由于实验要求不同,常用的求平均值法也不同,即所研究的区间段不同)

在k谷处的占据数

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()

在k’谷处的:

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
# -*-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\\k'.txt", 'r', encoding='UTF-8')as f:
with open("C:\\Users\\14618\\Desktop\\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 - 22])
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, 419, 419)
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)+1):
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,420,420)

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))
plt.plot(x,y[1:]-y[0],'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-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()

5.画三维的分子运动(MD)图,也包含二维的

用法:将 MoS2_scf.MD_CAR粘贴到MD.txt文件里

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*-coding=utf-8-*-
# Usage:处理位置坐标
from numpy import *
import numpy as np

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
with open("C:\\Users\\14618\\Desktop\\MD-1.txt", 'r', encoding='UTF-8')as f0:
with open("C:\\Users\\14618\\Desktop\\MD.txt", 'r', encoding='UTF-8')as f:
filelist0 = f0.readlines()
filelist_new0 = np.array(filelist0) # 转换成 array类型
num_array0 = filelist_new0.size # 整个文件fx的行数
lattice_vector0 = filelist0[2:5]


filelist = f.readlines()
filelist_new = np.array(filelist) # 转换成 array类型
num_array = filelist_new.size # 整个文件fx的行数
lattice_vector=filelist[2:5]





# for i in
lattice_vector_matrix0 = zeros((3, 3))
index = 0
for line in lattice_vector0:
x = line.strip('\n').split()
lattice_vector_matrix0[index:] = x[0:3]
index += 1
# print("晶矢为:",lattice_vector_matrix)
a0 = lattice_vector_matrix0[0, :]
b0 = lattice_vector_matrix0[1, :]
c0 = lattice_vector_matrix0[2, :]

Mo_position0 = []
S1_position0 = []
S2_position0 = []
for i in range(420): # 420步
Mo_position0.append(filelist_new0[10 * i + 7])
S1_position0.append(filelist_new0[10 * i + 8])
S2_position0.append(filelist_new0[10 * i + 9])
# Mo_position存储的是Mo原子位置的改变
# print(len(Mo_position))
Mo_position_matrix0 = zeros((len(Mo_position0), 3))
index = 0
for line in Mo_position0:
x = line.strip('\n').split()
Mo_position_matrix0[index:] = x[0:3]
index += 1

S1_position_matrix0 = zeros((len(S1_position0), 3))
index = 0
for line in S1_position0:
x = line.strip('\n').split()
S1_position_matrix0[index:] = x[0:3]
index += 1

S2_position_matrix0 = zeros((len(S2_position0), 3))
index = 0
for line in S2_position0:
x = line.strip('\n').split()
S2_position_matrix0[index:] = x[0:3]
index += 1

# print(S2_position_matrix[0][0])
# 针对Mo原子
Mo_position_matrix_x0 = Mo_position_matrix0[:, 0]
Mo_position_matrix_y0 = Mo_position_matrix0[:, 1]
Mo_position_matrix_z0 = Mo_position_matrix0[:, 2]

# 针对S1原子
S1_position_matrix_x0 = S1_position_matrix0[:, 0]
S1_position_matrix_y0 = S1_position_matrix0[:, 1]
S1_position_matrix_z0 = S1_position_matrix0[:, 2]

# 针对S2原子
S2_position_matrix_x0 = S2_position_matrix0[:, 0]
S2_position_matrix_y0 = S2_position_matrix0[:, 1]
S2_position_matrix_z0 = S2_position_matrix0[:, 2]



lattice_vector_matrix = zeros((3, 3))
index = 0
for line in lattice_vector:
x = line.strip('\n').split()
lattice_vector_matrix[index:] = x[0:3]
index += 1
#print("晶矢为:",lattice_vector_matrix)
a=lattice_vector_matrix[0,:]
b=lattice_vector_matrix[1,:]
c=lattice_vector_matrix[2,:]

Mo_position=[]
S1_position=[]
S2_position=[]
for i in range(420): #420步
Mo_position.append(filelist_new[10*i+7])
S1_position.append(filelist_new[10*i+8])
S2_position.append(filelist_new[10*i+9])
#Mo_position存储的是Mo原子位置的改变
#print(len(Mo_position))
Mo_position_matrix = zeros((len(Mo_position), 3))
index = 0
for line in Mo_position:
x = line.strip('\n').split()
Mo_position_matrix[index:] = x[0:3]
index += 1

S1_position_matrix = zeros((len(S1_position), 3))
index = 0
for line in S1_position:
x = line.strip('\n').split()
S1_position_matrix[index:] = x[0:3]
index += 1

S2_position_matrix = zeros((len(S2_position), 3))
index = 0
for line in S2_position:
x = line.strip('\n').split()
S2_position_matrix[index:] = x[0:3]
index += 1

#print(S2_position_matrix[0][0])
#针对Mo原子
Mo_position_matrix_x=Mo_position_matrix[:,0]
Mo_position_matrix_y=Mo_position_matrix[:,1]
Mo_position_matrix_z=Mo_position_matrix[:,2]

#针对S1原子
S1_position_matrix_x=S1_position_matrix[:,0]
S1_position_matrix_y=S1_position_matrix[:,1]
S1_position_matrix_z=S1_position_matrix[:,2]



#针对S2原子
S2_position_matrix_x=S2_position_matrix[:,0]
S2_position_matrix_y=S2_position_matrix[:,1]
S2_position_matrix_z=S2_position_matrix[:,2]


#画图
fig = plt.figure()
#ax = Axes3D(fig)
#ax.scatter(Mo_position_matrix_x, Mo_position_matrix_y, Mo_position_matrix_z)
#ax.scatter(S1_position_matrix_x, S1_position_matrix_y, S1_position_matrix_z)
#ax.scatter(S2_position_matrix_x, S2_position_matrix_y, S2_position_matrix_z)
plt.plot(S2_position_matrix_x,S2_position_matrix_y,'r--',label='With Excitation of Electrons')
plt.plot(S2_position_matrix_x0,S2_position_matrix_y0,'b--',label='Without Excitation of Electrons')
plt.xlabel('x direction')
plt.ylabel('y direction')
plt.title('The movement of Phonons in Plane x-y ')
plt.legend()
# 添加坐标轴(顺序是Z, Y, X)
# ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
# ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
# ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
plt.show()
fig.savefig(fname="C:\\Users\\14618\\Desktop\\figure.jpg", dpi=500)
f.close()
f0.close()
Prev:
QE错误集锦(未完待续...)
Next:
收敛常出现的问题汇总1
catalog
catalog