def read_prepi(filename):
    """
    Function to read in some atomic data and bonding information from an AMBER prepi file

    Parameters
    ----------
    filename : str
        Name of the prepi file

    Returns
    -------
    atom_data : list
        A list containing a list for each atom, of the form [name, type, charge], where each are strings
    bonds : list
        A list containing one list per bond, of the form [name1, name2]
    """
    with open(filename, 'r') as f:
        lines = f.readlines()

    atom_dict = {}  #  Indicates the ID number of each atom name
    atom_data = []  #  Will store the name, type and charge of each atom
    bonds = []  #  List of bonds between atoms
    for i, line_i in enumerate(lines):
        line_data = line_i.split()
        # First read in the data from the atom lines
        if len(line_data) > 10:
            atom_id = line_data[0]
            atom_name = line_data[1]
            atom_type = line_data[2]
            bond_id = line_data[4]
            atom_charge = line_data[10]

            # Ignore dummies
            if atom_type == 'DU':
                continue

            atom_dict[atom_id] = atom_name
            atom_data.append([atom_name, atom_type, atom_charge])
            # Double checking the atom isn't bonded to a dummy before writing
            if int(bond_id) > 3:
                bond_name = atom_dict[bond_id]
                bonds.append([atom_name, bond_name])
        # Now read in the data from the loop-completion lines
        elif line_i.startswith('LOOP'):
            for line_j in lines[i + 1:]:
                if len(line_j.split()) == 2:
                    bonds.append(line_j.split())
                else:
                    break

    return atom_data, bonds