import re


def parse_scwrl_out(scwrl_std_out, scwrl_pdb):
    """Parses SCWRL output and returns PDB and SCWRL score.
    Parameters
    ----------
    scwrl_std_out : str
        Std out from SCWRL.
    scwrl_pdb : str
        String of packed SCWRL PDB.
    Returns
    -------
    fixed_scwrl_str : str
        String of packed SCWRL PDB, with correct PDB format.
    score : float
        SCWRL Score
    """
    score = re.findall(
        r'Total minimal energy of the graph = ([-0-9.]+)', scwrl_std_out)[0]
    # Add temperature factors to SCWRL out
    split_scwrl = scwrl_pdb.splitlines()
    fixed_scwrl = []
    for line in split_scwrl:
        if len(line) < 80:
            line += ' ' * (80 - len(line))
        if re.search(r'H?E?T?ATO?M\s+\d+.+', line):
            front = line[:61]
            temp_factor = ' 0.00'
            back = line[66:]
            fixed_scwrl.append(''.join([front, temp_factor, back]))
        else:
            fixed_scwrl.append(line)
    fixed_scwrl_str = '\n'.join(fixed_scwrl) + '\n'
    return fixed_scwrl_str, float(score)