import re


def extract_bonds_and_angle_info(force_field):
    """ Given a force field files, extracts the values use for equilibrium
    bond lengths and angles. """
    info = {"bonds":{},
            "angles": {}}
    bond_regex = r"^(.{2}-.{2})\s+\S+\w+\s+(\S+)"
    angle_regex = r"^(.{2}-.{2}-.{2})\s+\S+\w+\s+(\S+)"
    with open(force_field, "r") as f:
        text = f.read()

    # Extract bond info
    matches = re.finditer(bond_regex, text, re.MULTILINE)
    for m in matches:
        atoms = m.group(1)
        length = m.group(2)
        info["bonds"][atoms] = float(length)

    # Extract angle info
    matches = re.finditer(angle_regex, text, re.MULTILINE)
    for m in matches:
        atoms = m.group(1)
        angle = m.group(2)
        info["angles"][atoms] = float(angle)

    return info