import re


def get_dihedrals(qm_scan_file):

    """
    Returns dihedrals from the torsiondrive scan file.

    Parameters
    ----------
    qm_scan_file : str
        Output scan file containing torsiondrive scans.

    Returns
    -------
    dihedrals : list
        List of all the dihedral values from the qm scan file.

    """
    with open(qm_scan_file, "r") as f:
        lines = f.readlines()
    energy_dihedral_lines = []
    for i in range(len(lines)):
        if "Dihedral" in lines[i]:
            energy_dihedral_lines.append(lines[i])
    dihedrals = []
    for i in energy_dihedral_lines:
        energy_dihedral = i
        energy_dihedral = re.findall(r"[-+]?\d+[.]?\d*", energy_dihedral)
        dihedral = float(energy_dihedral[0])
        dihedrals.append(dihedral)
    return dihedrals