# Use static, inline figures
%matplotlib inline

"""
Explanation: Welcome to the OBPDS Tutorial
This tutorial runs under IPython Notebook (inside of Jupyter). To run the code segments below:

Click on a code cell to select it.
Press SHIFT+ENTER on your keyboard or press the run cell button (<button class='fa-step-forward fa icon-play btn btn-xs btn-default'></button>) in the toolbar above to run the code cell and step forward.

A full tutorial for using the notebook interface is available here.
Let's begin by configuring matplotlib to insert plots inline (between code segments):
End of explanation
"""


from obpds import *

"""
Explanation: Next, let's import everything from OBPDS:
End of explanation
"""


# Create a simple pn diode
p = Layer(thickness=1*um, alloy=GaAs, doping=1e17/cm3)  # using key-word arguments
n = Layer(1*um, GaAs, -1e17/cm3)  # using positional arguments
d = TwoTerminalDevice(layers=[p, n],
                      Fp='left',  # define which contact controls the hole quasi-Fermi energy
                      Fn='right') # define which contact controls the electron quasi-Fermi energy

"""
Explanation: Now we can use the Layer and TwoTerminalDevice classes to create a simple $pn$ diode:
End of explanation
"""


# Simulate and show the device at equilibrium at room temperature (300 K).
d.show_equilibrium()

"""
Explanation: Next, let's simulate the device at equilibrium at room temperature (i.e. at 300 K):
End of explanation
"""


# Simulate and show the device at equilibrium at 77 K (assuming all dopants are still ionized).
d.show_equilibrium(T=77)

"""
Explanation: We can also simulate the device at equilibrium at other temperatures (e.g. at 77 K):
End of explanation
"""


# Simulate and show the device at -3 V, under the zero-current approximation.
d.show_zero_current(V=-3)

"""
Explanation: We can even simulate the device at a given bias, under the zero-current approximation:
End of explanation
"""


# Simulate the Capacitance-Voltage characteristics of the diode from -2 to 0.2 V, under the zero-current approximation.
d.show_cv(-2, 0.2)

"""
Explanation: Note that the quasi-Fermi energies (the dashed red and blue lines in the top-most plot) are constant. If they were not constant, then electorn and/or hole drift-diffusion currents would be flowing through the device. Such drift-diffusion simulations are not yet implemented.
However, even under the zero-current approximation, we can still simulate the C-V characteristics:
End of explanation
"""


from ipywidgets import interactive, fixed
interactive(d.show_zero_current, V=(-10,1), N=fixed(1000), approx=fixed('kane'))

"""
Explanation: Using the ipywidgets package, we can create interactive plots:
End of explanation
"""


p = Layer(1*um, GaAs,  1e17/cm3)
N = Layer(1*um, AlGaAs(Al=0.3), -1e17/cm3)
d = TwoTerminalDevice(layers=[p, N],
                      Fp='left',
                      Fn='right')
interactive(d.show_zero_current, V=(-10,1), T=fixed(300), N=fixed(1000), approx=fixed('kane'))

"""
Explanation: There are many III-V alloys available to work with. They are imported from the openbandparams package, which is documented here. Here's an example of a GaAs/AlGaAs $pN$ heterojunction diode:
End of explanation
"""


