def parse_contacts(contact_file, itypes):
    """
    Parses the contact file and returns it a list of atomic contacts. Atom strings are converted to tuples by splitting
    on ":".

    Parameters
    ----------
    contact_file: file
        Contact-file generated by dynamic_contacts.py

    itypes: set of str
        A set of interaction types to retain.

    Returns
    -------
    list of tuples of (str, str, tuple, tuple [[, tuple], tuple])
        Each entry contains a column of the contact_file, e.g.
        `[("0", "hbbb", ("A", "ARG", "4", "H"), ("A", "PHE", "22", "O")), (..) ]`
    """
    def parse_atom(atom_str):
        atom_tokens = atom_str.split(":")
        return tuple(atom_tokens)

    ret = []
    for line in contact_file:
        line = line.strip()
        if not line or line[0] == "#":
            continue  # Ignore empty and commented lines

        # Check number of columns is correct and skip if interaction type is not specified
        columns = line.split("\t")
        if not len(columns) in range(4, 7):
            raise AssertionError("Invalid interaction line: '"+line+"'")
        if not columns[1] in itypes:
            continue

        # Parse atoms
        columns[2] = parse_atom(columns[2])
        columns[3] = parse_atom(columns[3])
        if len(columns) >= 5:
            columns[4] = parse_atom(columns[4])
        if len(columns) == 6:
            columns[5] = parse_atom(columns[5])

        ret.append(tuple(columns))

    contact_file.close()

    return ret