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
distance = 3 f = open('POSCAR', 'r') lines = f.readlines() f.close() new = [] for line in lines: new.append(line.strip())
slab_c = eval(new[4].split(" ")[-1])
os.rename('POSCAR','POSCAR_unfixed_atoms')
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]
ls = [] for i in range(9,len(new)):
ls.append(eval(new[i][-8:])) ls = list((set(ls))) ls.sort() print("此slab模型高度为{}A, 松弛上下{}A".format(slab_c,distance))
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()
|