import hashlib


def hash_ecfp_pair(ecfp_pair, size):
  """Returns an int < size representing that ECFP pair.

  Input must be a tuple of strings. This utility is primarily used for
  spatial contact featurizers. For example, if a protein and ligand
  have close contact region, the first string could be the protein's
  fragment and the second the ligand's fragment. The pair could be
  hashed together to achieve one hash value for this contact region.

  Parameters
  ----------
  ecfp_pair: tuple
    Pair of ECFP fragment strings
  size: int, optional (default 1024)
    Hash to an int in range [0, size) 
  """
  ecfp = "%s,%s" % (ecfp_pair[0], ecfp_pair[1])
  ecfp = ecfp.encode('utf-8')
  md5 = hashlib.md5()
  md5.update(ecfp)
  digest = md5.hexdigest()
  ecfp_hash = int(digest, 16) % (size)
  return (ecfp_hash)