# -*- coding: utf-8 -*- """ Qiang Li Command: python3 vib_correct.py This is a temporary script file. """ import numpy as np from ase.io import read, write import os
#获取虚频开始行 l_position = 0#虚频振动方向部分在OUTCAR中的起始行数 withopen('OUTCAR') as f_in: lines = f_in.readlines() wave_num = 0.0 for num, line inenumerate(lines): if'f/i'in line: wave_tem = float(line.rstrip().split()[6]) if wave_tem > wave_num: #获取最大的虚频 wave_num = wave_tem l_position = num+2 # ASE读POSCAR model = read('POSCAR') model_positions = model.get_positions() num_atoms = len(model) #print(model_positions)
# 获取虚频对应的OUTCAR部分 vib_lines = lines[l_position:l_position + num_atoms] #振动部分 7222到7248行 #print(vib_lines) vib_dis = [] for line in vib_lines: #model_positions = [float(i) for i in line.rstrip().split()[:3]] vib_infor = [float(i) for i in line.rstrip().split()[3:]] # dx, dy, dz对应的那三列 vib_dis.append(vib_infor) vib_dis = np.array(vib_dis) #将振动部分写到一个array中。
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Qiang Li Command: python3 vib_correct.py This is a temporary script file. """ import numpy as np import os
#获取虚频开始行 l_position = 0#虚频振动方向部分在OUTCAR中的起始行数 withopen('OUTCAR') as f_in: lines = f_in.readlines() wave_num = 0.0 for num, line inenumerate(lines): if'f/i'in line: wave_tem = float(line.rstrip().split()[6]) if wave_tem > wave_num: #获取最大的虚频 wave_num = wave_tem l_position = num+2 # 读POSCAR withopen('POSCAR') as f_pos: lines_pos = f_pos.readlines()
# 获取虚频对应的OUTCAR部分 num_atoms = sum([int(i) for i in lines_pos[6].rstrip().split()]) vib_lines = lines[l_position:l_position + num_atoms] #振动部分 7222到7248行
model_positions = [] vib_dis = [] for line in vib_lines: position = [float(i) for i in line.rstrip().split()[:3]] vib_infor = [float(i) for i in line.rstrip().split()[3:]] # dx, dy, dz对应的那三列 model_positions.append(position) vib_dis.append(vib_infor)
###保存结构 f_out = open('POSCAR_new','w') f_out.writelines(lines_pos[:8]) f_out.write('Cartesian\n') for i in new_positions: f_out.write(' '.join([str(coord) for coord in i]) + ' F F F\n') f_out.close()