将vasp中分数坐标的POSCAR转化为笛卡尔坐标(无原子固定情况)
# -*- coding: utf-8 -*- """ Created on Wed Jan 1 19:22:26 2025 @author: Zhu """ with open('POSCAR')as xdat: lines = xdat.readlines() a1,a2,a3 = lines[2].split(),lines[3].split(),lines[4].split() a1 = [float(x) for x in a1] a2 = [float(x) for x in a2] a3 = [float(x) for x in a3] atoms_num = lines[6].split() atoms_num = [int(x) for x in atoms_num] total_atoms = sum(atoms_num) coord = [] for i in range(8,total_atoms+8): coord.append(lines[i].split()) coord = [[float(t) for s in sublist for t in s.split(', ')] for sublist in coord] cartesian = [] for i in coord: px = i[0]*a1[0]+i[1]*a2[0]+i[2]*a3[0] py = i[0]*a1[1]+i[1]*a2[1]+i[2]*a3[1] pz = i[0]*a1[2]+i[1]*a2[2]+i[2]*a3[2] cartesian.append([px,py,pz]) with open('POSCAR+','w') as newpos: for i in range(0,7): newpos.write(lines[i]) newpos.write("Cartesian\n") for i in cartesian: for j in i: newpos.write(str(j)+" ") newpos.write("\n")
参考:
图片来源:https://yxli8023.github.io/2020/09/25/Vasp-DC.html
本文来自博客园,作者:BangBro,转载请注明原文链接:https://www.cnblogs.com/bangbro/p/18646246