Python 脚本
相关的 YouTube 视频:
![]() |
Python 脚本:钙钛矿太阳能电池仿真 |
通过 python 与 .oghmafiles 交互有两种方式:使用原生 python 命令,或使用 OghmaNano 类结构。下面给出了两者的示例。
原生 python 方式
如第 14.1 节所述,.oghmafiles 只是打包在归档中的 json 文件。若从 sim.oghmafile 中提取 sim.json 文件,你可以使用 Python 的 json 读写代码直接编辑 .json 配置文件; 这是一种快速且粗糙但可行的方法。然后你可以使用 \(os.system\) 调用运行 oghma_core 来执行 OghmaNano。
例如,如果想把第 1 个器件层的迁移率改为 1.0,然后运行一次仿真, 可以使用清单 [python-example] 中列出的代码。
import json
import os
import sys
f=open('sim.json') #open the sim.json file
lines=f.readlines()
f.close()
lines="".join(lines) #convert the text to a python json object
data = json.loads(lines)
#Edit a value (use firefox as a json viewer
# to help you figure out which value to edit)
# this time we are editing the mobility of layer 1
data['epitaxy']['layer1']['shape_dos']['mue_y']=1.0
#convert the json object back to a string
jstr = json.dumps(data, sort_keys=False, indent='\t')
#write it back to disk
f=open('sim.json',"w")
f.write(jstr)
f.close()
#run the simulation using oghma_core
os.system("oghma_core.exe")
如果 sim.json 中的仿真被设置为运行一条 JV 曲线,那么会在 仿真目录中写出一个名为 sim_data.dat 的文件,其中包含 PCE、填充因子、\(J_{sc}\) 以及 \(V_{oc}\) 等参数。这同样是一个原始 json 文件;要使用 python 读取该文件, 并把 \(V_oc\) 的值写入第二个文件,可以使用清单 [python-example2] 中给出的代码。
f=open('sim_info.dat')
lines=f.readlines()
f.close()
lines="".join(lines)
data = json.loads(lines)
f=open('out.dat',"a")
f.write(str(data["Voc"])+"\n");
f.close()
