def charged_kinds(in_atoms, in_kinds):
    """
    Get charged atom kinds from charged atoms and kinds.

    For each kind of atom to be charged, goes through the list of atoms and
    makes an average of the partial atomic charge of atoms of that type.

    Parameters
    ----------
    in_atoms : Mol object
        The atoms should be charged and some of them at least should be of the
        relevant kind
    in_kinds : list of tuples
        The tuples are of the form (a,b) where a is an element string (like 'C')
        and b is a frozenset of ((element string,order of connection),amount of
        connections). (a,b) is known as an atom kind

    Returns
    -------
    q_kinds : list of tuples
        Each tuple is now (average charge,kind). This tuple is known as a
        charged kind

    """
    q_kinds = []
    for kind in in_kinds:
        charges = []
        for atom in in_atoms:
            if atom.kind == kind:
                charges.append(atom.q)
        if charges:
            avg_charge = sum(charges) / float(len(charges))
        else:
            avg_charge = 0
        q_kinds.append((avg_charge, kind))
    return q_kinds
