Home Examples Screenshots User manual Bluesky logo
OghmaNano Simulate organic/Perovskite Solar Cells, OFETs, and OLEDs DOWNLOAD

Python scripting

Related YouTube videos:

image Python scripting perovskite solar cell simulation

There are two ways to interact with .oghmafiles via python, using native python commands or by using the OghmaNano class structures, examples of both are given below.

The native python way

As described in section 14.1, .oghmafiles are simply json files zipped up in an archive. If you extract the sim.json file form the sim.oghmafile you can use Python’s json reading/writing code to edit the .json config file directly, this is a quick and dirty approach which will work. You can then use the \(os.system\) call to run oghma_core to execute OghmaNano.

For example were one to want to change the mobility of the 1st device layer to 1.0 and then run a simulation you would use the code listed in listing [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")

If the simulation in sim.json is setup to run a JV curve, then a file called sim_data.dat will be written to the simulation directory containing paramters such as PCE, fill factor, \(J_{sc}\) and \(V_{oc}\). This again is a raw json file, to read this file in using python and write out the value of \(V_oc\) to a second file use the code given in listing [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()