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

MATLAB scripting

As described in section 14.1 OghmaNano simulations are stored in .json files zipped up inside a zip archive. Matlab has both a zip decompressor and a json decoder. Therefore it is straight forward to edit and read and edit .oghma files in MATLAB. You can then use MATLAB to perform quite complex parameter scans. The example script below in listing [matlab-example] demonstrates how to run multiple simulations with mobilities ranging from 1e-7 to 1e-5 \(m^{2}V^{-1}s^{-1})\). The script starts off by unzipping the sim.json file, if you already have extracted your sim.json file from the sim.oghma file you don’t need these lines. The code then reads in sim.json using the MATLAB json decoder \(jsondecode\). A new directory is made which corresponds to the mobility value, the sim.oghma file copied into that directory. Then \(json\_data.epitaxy.layer0.shape\_dos.mue_y\) is set to the desired value of mobility and the simulation saved using \(jsonencode\) and \(fopen,fprintf,fclose\). The \(system\) call is then used to run \(oghma\_core.exe\) to perform the simulation. Out put parameters such as \(J_{sc}\) are stored in sim_data.dat again in json format, see section 4.1.4, although this is not done in this simple script.



if exist("sim.oghma", 'file')==false
 sprintf("No sim.oghma file found"); %Check if we have a sim.oghma file
end

if exist("sim.json", 'file')==false
 unzip("sim.oghma")  %if we don't have a sim.json file
                                      %try to extract it
end

A = fileread("sim.json");  %Read the json file.
json_data=jsondecode(A);  %Decode the json file

mobility=1e-7  %Start mobility
origonal_path=pwd  %working with the current dir
base_dir="mobility_scan"  %output directory name
while(mobility<1e-5)
    dir_name=sprintf("%e",mobility);
    full_path=fullfile(origonal_path,base_dir,dir_name)    %join paths
    mkdir(full_path)  %make the dir
    cd(full_path)  %cd to the dir

   %Update the json mobility
    json_data.epitaxy.layer0.shape_dos.mue_y=mobility  %Change mobility
                                                                                                      %of layer0
    
    copyfile(fullfile(origonal_path,"sim.oghma"),\\
           fullfile(origonal_path,base_dir,dir_name,"sim.oghma"))

   %now write the json file back to disk
    out=jsonencode(json_data);
    json_data
    fid = fopen("sim.json",'w');
    fprintf(fid, '%s', out);
    fclose(fid);

   %run oghma - This won't work if you have not added the oghma
   %install directory to your windows paths 
    system("oghma_core.exe")
    
   %Multiply mobility by 10
    mobility=mobility*10;
end

%Move back to the original dir
cd(origonal_path)

The built in calculator

OghmaNano has a built-in calculator that can be used to perform simple mathematical operations. This functionality is useful for setting up fitting procedures and defining equations in various parts of the code. The calculator is based on Reverse Polish Notation (RPN).

Supported Operations

Arithmetic and Comparison Operators
Operation Operator Example
Exponentiation ^ 2 ^3 = 8
Multiplication \(*\) \(2 * 3 = 6\)
Division \(/\) \(6 / 2 = 3\)
Addition \(+\) \(2 + 3 = 5\)
Subtraction \(-\) \(5 - 3 = 2\)
Greater than \(>\) \(5 > 3\) is 1
Less than \(<\) \(2 < 5\) is 1
Greater than or equal \(>=\) \(5 >= 5\) is 1
Less than or equal \(<=\) \(3 <= 4\) is 1

Supported Functions

Supported Functions
Function Name Function Example
Sine sin \(\sin(\pi/2) = 1\)
Cosine cos \(\cos(0) = 1\)
Absolute Value abs \(\text{abs}(-3) = 3\)
Positive Value pos \(\text{pos}(-3) = 0, \text{pos}(3) = 3\)
Logarithm (base 10) log \(\log(100) = 2\)
Exponential exp \(\exp(2) = e^2\)
Square Root sqrt \(sqrt(9) = 3\)
Minimum min \(\min(2, 3) = 2\)
Maximum max \(\max(2, 3) = 3\)
Random rand \(\text{rand}(a, b)\) generates a random number between \(a\) and \(b\)
Log-random randlog \(\text{randlog}(a, b)\) generates a log-random number between \(a\) and \(b\)