pymatgen读/写各种文件

pymatgen读/写各种文件

 

pymatgen是材料大数据计算的必备程序包了,其也作为API与materials project对接,可以批量下载自己想要的材料结构、性质,它也提供了大量VASP计算后的数据处理、计算,堪称材料基因组学的神器!

 

pymatgen提供了读取CIF、json、POSCAR、CONTCAR等文件的程序,可以批量读取、转化、另存。不过,作为初学者,里面很多功能是很难理解的,特别是对python语言不熟的同学。

 

1. pymatgen读取json文件,转化为Structure对象,并保存为CIF文件

from pymatgen import Structure, Lattice, MPRester, Molecule
import json
from pymatgen.io.cif import CifWriter


# 如果只有一个结构
#data_file = open("../db-1.json", "r")
#all_structures = data_file.readlines()
#structure = json.loads(all_structure)["structure"]
structure = Structure.from_dict(structure)
c = CifWriter(structure)
c.write_file("1.cif")


# 如果是一个结构数据库,读取后保存为cif文件
data_file = open("db.json", "r")
all_structures = data_file.readlines()
i = 0
for structure in all_structures:
    structure = json.loads(structure)["structure"]
    structure = Structure.from_dict(structure)
    i = i + 1
    c = CifWriter(structure)
    c.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章