300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python库读取cif文件_Pymatgen读/写各种文件 pymatgen 读写

python库读取cif文件_Pymatgen读/写各种文件 pymatgen 读写

时间:2022-09-02 16:57:24

相关推荐

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.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。