def get_restraints(contact_f):
    """Parse a contact file and retrieve the restraints."""
    restraint_dic = {}
    with open(contact_f) as fh:
        for line in fh.readlines():
            if not line:  # could be empty
                continue
            data = line.split()
            res_i = int(data[0])
            chain_i = data[1]
            res_j = int(data[3])
            chain_j = data[4]

            if chain_i not in restraint_dic:
                restraint_dic[chain_i] = []
            if chain_j not in restraint_dic:
                restraint_dic[chain_j] = []

            if res_i not in restraint_dic[chain_i]:
                restraint_dic[chain_i].append(res_i)
            if res_j not in restraint_dic[chain_j]:
                restraint_dic[chain_j].append(res_j)

    return restraint_dic