'Split the input files by fingerprint records.'

def split(cls, input_datasets, subdir_generator_function, split_params):

    if (split_params is None):
        return None
    if (len(input_datasets) > 1):
        raise Exception('FPS-file    splitting    does    not    support    multiple    files')
    input_files = [ds.file_name for ds in input_datasets]
    chunk_size = None
    if (split_params['split_mode'] == 'number_of_parts'):
        raise Exception(('Split    mode    "%s"    is    currently    not    implemented    for    MOL2-files.' % split_params['split_mode']))
    elif (split_params['split_mode'] == 'to_size'):
        chunk_size = int(split_params['split_size'])
    else:
        raise Exception(('Unsupported    split    mode    %s' % split_params['split_mode']))
    def _write_part_fingerprint_file(accumulated_lines):
        part_dir = subdir_generator_function()
        part_path = os.path.join(part_dir, os.path.basename(input_files[0]))
        part_file = open(part_path, 'w')
        part_file.writelines(accumulated_lines)
        part_file.close()
    try:
        header_lines = []
        lines_accumulated = []
        fingerprint_counter = 0
        for line in open(input_files[0]):
            if (not line.strip()):
                continue
            if line.startswith('#'):
                header_lines.append(line)
            else:
                fingerprint_counter += 1
                lines_accumulated.append(line)
            if ((fingerprint_counter != 0) and ((fingerprint_counter % chunk_size) == 0)):
                _write_part_fingerprint_file((header_lines + lines_accumulated))
                lines_accumulated = []
        if lines_accumulated:
            _write_part_fingerprint_file((header_lines + lines_accumulated))
    except Exception as e:
        log.error(('Unable    to    split    files:    %s' % str(e)))
        raise
