import math


def BIC( np, lnL, length ):
  """
  BIC = -2 ln( L ) + k ln(n),
  n = number of observations = sample size = alignment length (nt)
  k = number of parameters
  ln( L ) = PAML lnL = log likelihood
  """
  lnL = float(lnL)
  np = int(np)
  length = int(length)
  return ( ((-2)* lnL) + (np * math.log(length)) )