def to_file(self, dir_path='.', fname='amsetrun', force_write=True):
if not force_write:
n = 1
fname0 = fname
while os.path.exists(os.path.join(dir_path, '{}.json.gz'.format(fname))):
warnings.warn('The file, {} exists. AMSET outputs will be '
'written in {}'.format(fname, fname0+'_'+str(n)))
fname = fname0 + '_' + str(n)
n += 1
# make the output dict
out_d = {'kgrid': self.kgrid, 'egrid': self.egrid}
# write the output dict to file
with gzip.GzipFile(
os.path.join(dir_path, '{}.json.gz'.format(fname)), 'w') as fp:
jsonstr = json.dumps(out_d, cls=MontyEncoder)
fp.write(jsonstr)
评论列表
文章目录