this function can calculate the builtin voltage of a pn junction diode this is calculated from the given three values examples builtinvoltagedonorconc1e17 acceptorconc1e17 intrinsicconc1e10 0 833370010652644 builtinvoltagedonorconc0 acceptorconc1600 intrinsicconc200 traceback most recent call last valueerror donor concentration should be positive builtinvoltagedonorconc1000 acceptorconc0 intrinsicconc1200 traceback most recent call last valueerror acceptor concentration should be positive builtinvoltagedonorconc1000 acceptorconc1000 intrinsicconc0 traceback most recent call last valueerror intrinsic concentration should be positive builtinvoltagedonorconc1000 acceptorconc3000 intrinsicconc2000 traceback most recent call last valueerror donor concentration should be greater than intrinsic concentration builtinvoltagedonorconc3000 acceptorconc1000 intrinsicconc2000 traceback most recent call last valueerror acceptor concentration should be greater than intrinsic concentration temperature unit k donor concentration acceptor concentration intrinsic concentration this function can calculate the builtin voltage of a pn junction diode this is calculated from the given three values examples builtin_voltage donor_conc 1e17 acceptor_conc 1e17 intrinsic_conc 1e10 0 833370010652644 builtin_voltage donor_conc 0 acceptor_conc 1600 intrinsic_conc 200 traceback most recent call last valueerror donor concentration should be positive builtin_voltage donor_conc 1000 acceptor_conc 0 intrinsic_conc 1200 traceback most recent call last valueerror acceptor concentration should be positive builtin_voltage donor_conc 1000 acceptor_conc 1000 intrinsic_conc 0 traceback most recent call last valueerror intrinsic concentration should be positive builtin_voltage donor_conc 1000 acceptor_conc 3000 intrinsic_conc 2000 traceback most recent call last valueerror donor concentration should be greater than intrinsic concentration builtin_voltage donor_conc 3000 acceptor_conc 1000 intrinsic_conc 2000 traceback most recent call last valueerror acceptor concentration should be greater than intrinsic concentration
from math import log

from scipy.constants import Boltzmann, physical_constants

T = 300  


def builtin_voltage(
    donor_conc: float,  
    acceptor_conc: float,  
    intrinsic_conc: float,  
) -> float:
    

    if donor_conc <= 0:
        raise ValueError("Donor concentration should be positive")
    elif acceptor_conc <= 0:
        raise ValueError("Acceptor concentration should be positive")
    elif intrinsic_conc <= 0:
        raise ValueError("Intrinsic concentration should be positive")
    elif donor_conc <= intrinsic_conc:
        raise ValueError(
            "Donor concentration should be greater than intrinsic concentration"
        )
    elif acceptor_conc <= intrinsic_conc:
        raise ValueError(
            "Acceptor concentration should be greater than intrinsic concentration"
        )
    else:
        return (
            Boltzmann
            * T
            * log((donor_conc * acceptor_conc) / intrinsic_conc**2)
            / physical_constants["electron volt"][0]
        )


if __name__ == "__main__":
    import doctest

    doctest.testmod()