python库读取cif文件_Pymatgen读/写各种文件,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.
總結
以上是生活随笔為你收集整理的python库读取cif文件_Pymatgen读/写各种文件,pymatgen,读写的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 支付宝1元买黄金能赚钱吗?小心这些陷阱
- 下一篇: python 条件概率_机器学习中的概率