数据来源:materials project网站下载的.json.gz压缩包
使用gzip
包可以免解压直接读取
解压出来json
文件的数据结构大概如代码所示
使用pymatgen.io.vasp
的Chgcar
对象,可以装载从json
文件读出的结构数据和电荷密度数据
with gzip.open(os.path.join(self.chgcar_dir, self.chgcar_list[idx]), 'rt') as gz_file:raw_data = json.load(gz_file)struc = raw_data['data']['poscar']chgcar_data = {'total': raw_data['data']['data']["total"]["data"],'diff': raw_data['data']['data']["diff"]["data"]}chgcar_object = Chgcar(poscar=Poscar.from_dict(struc), data=chgcar_data)with gzip.open(os.path.join(self.aeccar0_dir, self.aeccar0_list[idx]), 'rt') as gz_file:raw_data0 = json.load(gz_file)with gzip.open(os.path.join(self.aeccar2_dir, self.aeccar2_list[idx]), 'rt') as gz_file:raw_data2 = json.load(gz_file)aeccar0_data = {'total': raw_data0['data']['data']["total"]["data"]}struc = raw_data0['data']['poscar']aeccar0_object = Chgcar(poscar=Poscar.from_dict(struc), data=aeccar0_data)aeccar2_data = {'total': raw_data2['data']['data']["total"]["data"]}struc = raw_data2['data']['poscar']aeccar2_object = Chgcar(poscar=Poscar.from_dict(struc), data=aeccar2_data)
``