import math


def single_site_statmech_model(KdRatio, conc=16, consensusKd=16, concO=0.6):
    """
    This method takes as input the affinity (ratio of Kd to Kd consensus) of a single transcription factor binding site, and outputs
    the mean occupancy based on a statistical mechanical model of transcription factor binding (Philips).
    

    Parameters
    ----------
    KdRatio : float
        Kd-site/Kd-consensus.
    conc : float, optional
        Concentration of transcription factor for the model. The default is 16, corresponding to the Kd of the consensus sequence
        (therefore, setting the occupancy of the consensus sequence to 0.5 -- similar to Maerkl 2007 and before)
    consensusKd : float, optional
        Kd of the consensus sequence, used to convert the KdRatio to actual Kd. The default is 16.
    concO : float, optional
        Reference concentration for the Philips'ian stat.mech. model. The default is 0.6.

    Returns
    -------
    meanOcc. The mean occupancy of the binding site, according to the supplied parameters.

    """
    delE = math.log(KdRatio*consensusKd/concO)
    
    relMult = (conc/concO)*math.exp(-delE)
    meanOcc = relMult/(1+relMult)
    
    return meanOcc