import re


def parse_thickness(filename):
    """
    Parses an .opm file and returns the thickness if any.

    Args:
        filename: .opm file.

    Returns:
        Either half of the bilayer thickness or None if not present.
    """
    thicknesses = []
    with open(filename, "r") as fh:
        for line in fh:
            if line.startswith("REMARK") and re.search("1/2 of bilayer thickness:", line):
                thicknesses.append(float(line.strip().split()[-1]))
    if len(thicknesses) == 0:
        return None
    else:
        return sum(thicknesses)/len(thicknesses)