def split_castep(filename):
    """
    Split .castep file into each calculation

    Running CASTEP several times yields a single .castep file with concatenated output.
    This function splits the outputs into a list of each calculation run.

    Parameters
    --------
    filename : str
        path to the .castep file

    Returns
    --------
    run_list : list
        list of lines of castep output for each run
    """
    with open(filename, "rt") as f:
        lines = f.readlines()
    castep_header = [
        ' +-------------------------------------------------+\n',
        ' |                                                 |\n',
        ' |      CCC   AA    SSS  TTTTT  EEEEE  PPPP        |\n',
        ' |     C     A  A  S       T    E      P   P       |\n',
        ' |     C     AAAA   SS     T    EEE    PPPP        |\n',
        ' |     C     A  A     S    T    E      P           |\n',
        ' |      CCC  A  A  SSS     T    EEEEE  P           |\n',
        ' |                                                 |\n',
        ' +-------------------------------------------------+\n'
    ]
    header_position_list = list()
    for l in range(len(lines) - 9):
        if lines[l: l + 9] == castep_header:
            header_position_list.append(l)
    header_position_list.append(-1)
    run_list = [lines[l_s:l_e] for l_s, l_e in zip(header_position_list[:-1], header_position_list[1:])]
    return run_list