0%

对称slab按照距离松弛上下表面python脚本

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
import os

#Need Modifycation!!!
#对称表面上下可以动的距离,读取当前文件下POSCAR内容
# distance = eval(input("请输入slab上下要松弛的距离(单位A)"))
distance = 3
f = open('POSCAR', 'r')
lines = f.readlines()
f.close()
new = []
for line in lines:
new.append(line.strip())

#沿c方向slab距离
slab_c = eval(new[4].split(" ")[-1])

os.rename('POSCAR','POSCAR_unfixed_atoms')

#加上Selective Dynamics变成可改变模式的
new.insert(7,'Selective Dynamics')

#去掉最后的字母元素符号
for i in range(9,len(new)):
if new[i][-2] == ' ':
new[i] = new[i][0:-2]
else:
new[i] = new[i][0:-3]

#获得slab层数及坐标
ls = []
for i in range(9,len(new)):
# num = 1
# while new[i][-num] != ' ':
# num += 1
# print(num-1)
# print(i,new[i][1-num:])
ls.append(eval(new[i][-8:]))
ls = list((set(ls)))
ls.sort()
print("此slab模型高度为{}A, 松弛上下{}A".format(slab_c,distance))

#加上FT模式
for i in range(9,len(new)):
if eval(new[i][-8:])*slab_c <= (ls[0]*slab_c+3):
new[i] = new[i]+" T T T"
elif eval(new[i][-8:])*slab_c >= (ls[-1]*slab_c-3):
new[i] = new[i]+" T T T"
else:
new[i] = new[i]+" F F F"

#保存文件
f = open('POSCAR', 'w')
for para in new:
f.write(para)
f.write('\n')
f.close()